我正在使用OData V4客户端在我的asp.net mvc 5中创建代理.我想使用Moq对控制器进行单元测试.有没有办法可以通过容器模拟OData服务响应.下面是OData容器实例化器:
public static class ControlEntityContextHelper
{
/// <summary>
/// Returns OData service context
/// </summary>
/// <returns></returns>
public static Container GetEntityContext()
{
// create the container
var container = new Container(new Uri("http://localhost/services/odata/"));
container.Timeout = 1800;
return container;
}
}
Run Code Online (Sandbox Code Playgroud)
下面是MVC控制器:
public JsonResult GetEmployees(string employeeId)
{
var odataContext = ControlEntityContextHelper.GetEntityContext();
var employee = odataContext.Employees.Where(emp => emp.EmployeeId == employeeId);
return Json(employee, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
可能重复:
如何查找最慢的查询
在Sql Server 2008中,是否有任何选项可以找出所有存储过程在所有存储过程中运行缓慢(当存储过程的数量非常大时.例如:500)
我们在 WebAPI 中有要求,以 JSON 的形式从外部 API 提取有效负载,清理并将其发布到 Azure Sql 中。对于此要求,我们目前依赖于 blob 存储,将 json 有效负载存储到 azure blob 中,并将其检索到 UI 中以进行数据清理活动。用户可以花费大量时间来验证数据并根据需要进行修改。用户可能会起草几天,并在完成所有清理后单击“导入”按钮。现在,我观察到,在这些草稿期间,blob 只是被检索并反序列化到对象列表中,以找到要更新的相应属性。一旦更新完成,当用户单击“草稿”时,同一列表将被序列化为 json 并存储回 blob。序列化/反序列化的过程似乎很昂贵。相反,我正在考虑用 Cosmos DB 替换 blob。这真的会即兴表演吗?建议 Azure Sql Json 支持是否比所有这些选项更可行?我什至想到了 Redis 缓存?决策的主要因素也是成本效益。
json azure azure-redis-cache azure-blob-storage azure-cosmosdb
在最近的代码审查中,我通过IComponentContext找到了类解析器,如下例所示:
using Autofac;
public class BaseClass
{
protected IComponentContext _componentContext;
public BaseClass(IComponentContext componentContext)
{
_componentContext = componentContext;
}
}
public class MyClass1: BaseClass
{
protected IMyClass2 _myClass2 = _componentContext.Resolve<MyClass2>();
public void Operation1()
{
_myClass2.Operation2();
}
}
Run Code Online (Sandbox Code Playgroud)
我觉得上面的代码是在Class1()构造函数之外解析MyClass2.它不是服务定位器模式和消息IOC吗?
最近我在讨论中被要求写一个算法来实现一个句子的单词的反转(不是整个句子的反转),而不使用除了ToCharArray和Length之外的字符串操作,如Split/Replace/Reverse/Join.以下是我在5分钟内设计的内容.虽然算法工作正常,但似乎有点丑陋的实现方式.有些人可以通过抛光代码来帮助我.
string ReverseWords(string s)
{
string reverseString = string.Empty;
string word = string.Empty;
var chars = s.ToCharArray();
List<ArrayList> words = new List<ArrayList>();
ArrayList addedChars = new ArrayList();
Char[] reversedChars = new Char[chars.Length];
int i = 1;
foreach (char c in chars)
{
if (c != ' ')
{
addedChars.Add(c);
}
else
{
words.Add(new ArrayList(addedChars));
addedChars.Clear();
}
if (i == s.Length)
{
words.Add(new ArrayList(addedChars));
addedChars.Clear();
}
i++;
}
foreach (ArrayList a in words)
{
for (int counter = a.Count - 1; …Run Code Online (Sandbox Code Playgroud)