public void ApplyMemoryRuleTest() { var userId = Guid.NewGuid(); var ruleExpression = new TariffAuthRuleExpression(); var context = new AuthContext { UserId = userId }; var tariff = new Tariff { UserId = userId }; var result = ruleExpression.Apply(context).Compile()(tariff); result.Should().BeTrue(); }
public void ApplyQueryableRuleTest() { using var dbContext = GetDbContext(); var ruleExpression = new TariffAuthRuleExpression(); var userId = Guid.NewGuid(); var context = new AuthContext { UserId = userId }; Expression <Func <Tariff, bool> > expression = tariff => (context.CompanyId.HasValue && tariff.CompanyId == context.CompanyId) || tariff.UserId == context.UserId; var qs1 = dbContext.Tariffs !.Where(ruleExpression.Apply(context)).ToQueryString(); var qs2 = dbContext.Tariffs !.Where(expression).ToQueryString(); qs1.Should().Be(qs2); }