public void it_should_apply_the_query_paging_and_ordering_when_the_pagingAndSortingInfo_parameter_is_not_null() { var sut = new QueryHandler_SpecificQuery_Mock(); var title = "wa"; var queryObject = new FindMoviesByTitleQuery(title); var property = sut.GetType().GetProperty("InitialItems", BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance); var items = (IQueryable<Movie>)property.GetValue(sut); var pagingInfo = new PagingAndSortingInfo(page: 2, pageSize: 1); var pageIndex = pagingInfo.Page - 1; var expectedItems = items.Where(x => x.Title.ToLower().Contains(title.ToLower())); var expectedPagedItems = expectedItems.OrderByDescending(x => x.ID).Skip(pageIndex * pagingInfo.PageSize).Take(pagingInfo.PageSize); var res = sut.HandleQuery(queryObject, pagingInfo); res.Should().NotBeNull(); res.VirtualRowsCount.Should().Be(expectedItems.Count()); res.Results.Should().NotBeNull() .And.HaveCount(expectedPagedItems.Count()); expectedPagedItems.ToList().ForEach(z => { var item = res.Results.FirstOrDefault(x => x.ID.Equals(z.ID)); item.Should().NotBeNull("The expected item should belong to the res list"); }); }
public void it_should_sort_descending_and_page_using_the_specified_order_field_when_order_field_is_not_null_nor_empty() { var items = Builder<Movie>.CreateListOfSize(10).Build().AsQueryable(); var sut = new FindMoviesByTitleQueryHandlerBuilder().SetMovies(items).Build(); var query = new FindMoviesByTitleQuery(string.Empty); var pagingAndSortingInfo = new PagingAndSortingInfo(3, 3, "ID", OrderDirection.Descending); var processedItems = items.OrderByDescending(x => x.ID).Skip(6).Take(3); var res = sut.HandleQuery(query, pagingAndSortingInfo); res.Should().NotBeNull(); res.VirtualRowsCount.Should().Be(10); res.Results.Should().NotBeNull() .And.HaveCount(3) .And.ContainInOrder(processedItems); }
public void it_should_not_apply_the_query_when_the_title_is_null_or_empty() { var numberOfElements = 10; var builder = new FindMoviesByTitleQueryHandlerBuilder(); var sut = builder.Build(); var movies = builder.Movies; var queryObject = new FindMoviesByTitleQuery(string.Empty); var res = sut.HandleQuery(queryObject); res.Should().NotBeNull(); res.VirtualRowsCount.Should().Be(numberOfElements); res.Results.Should().NotBeNull() .And.HaveCount(numberOfElements) .And.ContainInOrder(movies); }
public void it_should_apply_the_query_without_paging_nor_ordering_when_the_pagingAndSortingInfo_parameter_is_null() { var sut = new QueryHandler_SpecificQuery_Mock(); var title = "wa"; var queryObject = new FindMoviesByTitleQuery(title); var property = sut.GetType().GetProperty("InitialItems", BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance); var items = (IQueryable<Movie>)property.GetValue(sut); var expectedItems = items.Where(x => x.Title.ToLower().Contains(title.ToLower())); var res = sut.HandleQuery(queryObject); res.Should().NotBeNull(); res.VirtualRowsCount.Should().Be(expectedItems.Count()); res.Results.Should().NotBeNull() .And.HaveCount(expectedItems.Count()); res.Results.ToList().ForEach(z => { var item = expectedItems.FirstOrDefault(x => x.ID.Equals(z.ID)); item.Should().NotBeNull(); }); }
public void it_should_apply_the_query_and_return_the_matching_elements_when_the_title_is_not_null_nor_empty() { var numberOfElements = 10; var movies = Builder<Movie>.CreateListOfSize(numberOfElements) .TheFirst(1) .With(x => x.Title, "Warcraft") .TheNext(1) .With(x => x.Title, "Avatar") .TheNext(1) .With(x => x.Title, "World War II") .Build().AsQueryable(); var sut = new FindMoviesByTitleQueryHandlerBuilder().SetMovies(movies).Build(); var titleFilter = "war"; var queryObject = new FindMoviesByTitleQuery(titleFilter); var res = sut.HandleQuery(queryObject); var filteredMovies = movies.Where(x => x.Title.Contains(titleFilter)); res.Should().NotBeNull(); res.VirtualRowsCount.Should().Be(2); res.Results.Should().NotBeNull() .And.HaveCount(2) .And.ContainInOrder(filteredMovies); }