.NET Core 2.1带有一个称为的新工厂HttpClientFactory
,但是我不知道如何模拟它来对包含REST服务调用的某些方法进行单元测试。
正在使用.NET Core IoC容器注入工厂,该方法的作用是从工厂创建一个新客户端:
var client = _httpClientFactory.CreateClient();
Run Code Online (Sandbox Code Playgroud)
然后使用客户端从REST服务获取数据:
var result = await client.GetStringAsync(url);
Run Code Online (Sandbox Code Playgroud) 我一直在使用表达式树的 EF Core 查询的动态过滤器类中工作,一切看起来都很好,过滤器正在工作,我可以传递一个过滤器集合并且它可以工作,但是当我查看 SQL 语句时,它正在查询整个表并对结果集合应用过滤器,这是我的课程......
public static class QueryExpressionBuilder
{
private static readonly MethodInfo ContainsMethod = typeof(string).GetMethod("Contains", new[] { typeof(string) });
private static readonly MethodInfo StartsWithMethod = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
private static readonly MethodInfo EndsWithMethod = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
#region DynamicWhere
/// <summary>Where expression generator.</summary>
/// <typeparam name="T"></typeparam>
/// <param name="filters">The filters.</param>
/// <returns></returns>
public static Expression<Func<T, bool>> GetExpression<T>(IList<Filter> filters)
{
if (filters.Count == 0)
return null;
ParameterExpression param = Expression.Parameter(typeof(T), "t");
Expression exp = …
Run Code Online (Sandbox Code Playgroud)