public void Instance_Is_ByLanguageIdQuery_Of_IResultWithTotalCount_Of_AccommodationItem() { //Arrange var type = typeof(ByLanguageIdQuery <IResultWithTotalCount <AccommodationItem> >); var providerMock = new Mock <IQueryDispatcher>(); //Act var query = new PagedAccommodationItemsByLanguageIdQuery(providerMock.Object); //Assert Assert.IsInstanceOf(type, query); }
public void HandleAsync_Return_Task_Of_IResultWithTotalCount_Of_AccommodationItem() { //Arrange var type = typeof(Task <IResultWithTotalCount <AccommodationItem> >); var handler = Handler(); var providerMock = new Mock <IQueryDispatcher>(); var query = new PagedAccommodationItemsByLanguageIdQuery(providerMock.Object); //Act var result = handler.HandleAsync(query); //Assert Assert.IsInstanceOf(type, result); }
private static IQueryable <LocalizedRealEstate> PreHandle(IQueryable <RealEstate> source, PagedAccommodationItemsByLanguageIdQuery query) { var localizedAccommodations = source.SelectMany(p => p.LocalizedAccommodations); var localizedAccommodationQueryable = localizedAccommodations.Include(p => p.RealEstate).Where(p => p.LanguageId == query.LanguageId); var localizedAccommodationOrderedQueryable = query.Sorting(localizedAccommodationQueryable); return(localizedAccommodationOrderedQueryable); }
public override async Task <IResultWithTotalCount <AccommodationItem> > HandleAsync(PagedAccommodationItemsByLanguageIdQuery query, CancellationToken cancellationToken) { var localizedAccommodations = PreHandle(Source, query); var accommodationItems = ProjectTo <AccommodationItem>(localizedAccommodations); var result = new ResultWithTotalCount <AccommodationItem> { Result = await accommodationItems.Skip(query.Paging.CalculateSkip()).Take(query.Paging.PageSize).ToArrayAsync(cancellationToken), TotalCount = await accommodationItems.CountAsync(cancellationToken) }; return(result); }