小编Mau*_*che的帖子

如何使用Moq在.NET Core 2.1中模拟新的HttpClientFactory

.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)

c# unit-testing moq asp.net-core-2.1 httpclientfactory

10
推荐指数
4
解决办法
8360
查看次数

EF Core 动态滤波器

我一直在使用表达式树的 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)

c# linq expression-trees ef-core-2.1

1
推荐指数
1
解决办法
2271
查看次数