public async Task ProjectedListBuilder(int?pageSize, int?pageNumber, string sortField, bool sortOrderAscending) { var listRequest = new ListRequest { PageSize = pageSize, PageNumber = pageNumber, SortField = sortField, SortOrderAscending = sortOrderAscending }; var builder = _repo.ProjectedListBuilder(OrderDto.ProjectionFromEntity(), listRequest) .OrderBy(o => o.Id) .ConditionalOrder("customerName", o => o.CustomerName) .ConditionalOrder("fullAddress", o => o.FullDeliveryAdressWithCountry); var orders = await builder.ExecuteAsync(); var totalCount = await builder.CountAsync(); var expectedCount = 55; Assert.Equal(expectedCount, totalCount); if (pageNumber <= 4) { Assert.Equal(pageSize, orders.Count); } else { Assert.Equal(5, orders.Count); // last page has 5 records } if (sortField == null) { var orderId = (pageNumber * pageSize) + 1; Assert.Equal($"Address for OrderId {orderId}, country: Brazil", orders[0].FullDeliveryAdressWithCountry); Assert.Equal(orderId, orders[0].Id); } }
public async void ProjectedList() { // this is still being resolved by https://github.com/dotnet/efcore/issues/17620 // the error only happens with an in-memory database. With SqlServer is all good var orders = await _repo.ProjectedListBuilder(OrderDto.ProjectionFromEntity()) .WhereEntity(o => Order.HasItemsOverPrice(90).Invoke(o)) .ExecuteAsync(); Assert.Equal(54, orders.Count); Assert.Equal(50, orders[0].Items[0].Quantity); Assert.Equal(30, orders[0].Items[1].Quantity); Assert.Equal(80, orders[0].Items[0].Price); Assert.Equal(120, orders[0].Items[1].Price); }