public async Task GeneratedQueryWithStringFilterEqualityTest() { using (var context = new TestContext()) { var compiledQueryCache = GetCompiledQueryCache(context); var previousNumberOfCacheEntries = GetNumberOfCacheEntries(compiledQueryCache); var querySource = new DbContextQuerySource(context); var queryModel = QueryModel.Create( builder => builder.Get <ReceiptDetail>(), builder => new ReceiptDetail { ReceiptId = builder.ReceiptId, ArticleId = builder.ArticleId, }) .HasKey(receipt => receipt.ReceiptId) .Build(); FilterItem[] filterItems = { new StringBinaryFilterItem(new PathValueExpression(nameof(ReceiptDetail.Description)), new StringConstantValue("abc"), StringOperator.Equal) }; var queryConfiguration = new QueryConfiguration(filterItems); var query1 = queryModel.GetQuery(querySource, queryConfiguration); var result1 = await query1.ToListAsync(); filterItems = new FilterItem[] { new StringBinaryFilterItem(new PathValueExpression(nameof(ReceiptDetail.Description)), new ConstantValueExpression <string>("xyz"), StringOperator.Equal) }; queryConfiguration = new QueryConfiguration(filterItems); var query2 = queryModel.GetQuery(querySource, queryConfiguration); var result2 = await query2.ToListAsync(); var expectedNumberOfCacheEntries = previousNumberOfCacheEntries + 1; var currentNumberOfCacheEntries = GetNumberOfCacheEntries(compiledQueryCache); Assert.Equal(expectedNumberOfCacheEntries, currentNumberOfCacheEntries); } }
public async Task ExcludeDateTimePropertiesWithSelectItemsOnCustomType() { var optionsBuilder = new DbContextOptionsBuilder <TestContext>(); optionsBuilder.UseSqlServer("Data Source=(localdb)\\mssqllocaldb;Initial Catalog=LucileTestContext;Integrated Security=true;"); using (var context = new TestContext(optionsBuilder.Options)) { await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); await FillDatabaseAsync(context); var querySource = new DbContextQuerySource(context); var queryModel = QueryModel.Create( builder => builder.Get <ReceiptDetail>(), builder => new ReceiptDetailInfo { ReceiptId = builder.ReceiptId, Description = builder.Description, DeliveryTime = builder.DeliveryTime }) .HasKey(receipt => receipt.ReceiptId) .Build(); var selectItems = new[] { new SelectItem("ReceiptId"), new SelectItem("Description") }; var queryConfiguration = new QueryConfiguration(selectItems); var query1 = queryModel.GetQuery(querySource, queryConfiguration); var result1 = await query1.ToListAsync(); Assert.All(result1, p => Assembly.Equals(DateTime.MinValue, p.DeliveryTime)); } }