public GamesTransferModel GetGamesByFilter(GamesFilterModel filterModel, PaginationModel paginationModel) { var container = new GameFilterContainer { Model = filterModel, }; IPipeline <GameFilterContainer> pipeline = GetPipelineWithFilters(); pipeline.ExecuteAll(container); Func <Game, bool> resultCondition = CombinePredicate <Game> .CombineWithAnd(container.Conditions); IEnumerable <Game> games = _unitOfWork.GameRepository.GetMany( resultCondition, (int)paginationModel.PageCapacity, paginationModel.CurrentPage, container.SortCondition); var gameModels = Mapper.Map <IEnumerable <GameModel> >(games); paginationModel.ItemsNumber = _unitOfWork.GameRepository.GetCount(resultCondition); var transferModel = new GamesTransferModel { Games = gameModels, PaginationModel = paginationModel, }; return(transferModel); }
public void Check_That_Pipeline_Executes_Filter() { //Arrange var pipeline = new Pipeline <GameFilterContainer>(); var container = new GameFilterContainer(); var mockFilter = new Mock <IFilter <GameFilterContainer> >(); mockFilter.Setup(m => m.Execute(It.IsAny <GameFilterContainer>())); pipeline.Filter = mockFilter.Object; //Act pipeline.ExecuteAll(container); //Assert mockFilter.Verify(m => m.Execute(It.IsAny <GameFilterContainer>())); }
public void Check_That_PriceFilter_Returns_Right_Delegate() { // Arrange var container = new GameFilterContainer { Model = new GamesFilterModel { PriceFrom = 5, PriceTo = (decimal)10.5, } }; var filter = new PriceFilter(); var list = new List <Game> { new Game { Price = (decimal)4.9, }, new Game { Price = 5, }, new Game { Price = 7, }, new Game { Price = (decimal)10.5, }, new Game { Price = (decimal)10.6, }, }; // Act filter.Execute(container); Func <Game, bool> resultCondition = CombinePredicate <Game> .CombineWithAnd(container.Conditions); IEnumerable <Game> result = list.Where(x => (resultCondition(x))); // Assert Assert.IsTrue(result.Count() == 3); }
public void Check_That_PublisherFilter_Returns_Right_Delegate() { // Arrange var container = new GameFilterContainer { Model = new GamesFilterModel { Publishers = new List <int> { 1, 2 } } }; var filter = new PublisherFilter(); var list = new List <Game> { new Game { PublisherId = 1, }, new Game { PublisherId = 2, }, new Game { PublisherId = 3, }, }; // Act filter.Execute(container); Func <Game, bool> resultCondition = CombinePredicate <Game> .CombineWithAnd(container.Conditions); IEnumerable <Game> result = list.Where(x => (resultCondition(x))); // Assert Assert.IsTrue(result.Count() == 2); }
public void Check_That_SortFilter_Returns_Right_Sorting_Order_For_MostCommented() { // Arrange var container = new GameFilterContainer { Model = new GamesFilterModel { SortCondition = SortCondition.MostCommented, } }; var filter = new SortingFilter(); IEnumerable <Game> list = GetGamesList(); // Act filter.Execute(container); IEnumerable <Game> result = list.OrderBy(x => (container.SortCondition(x))); // Assert Assert.IsTrue(result.First().GameLocalizations.First().Name == "game4"); Assert.IsTrue(result.Last().GameLocalizations.First().Name == "game1"); }
public void Check_That_DateFilter_Returns_Right_Delegate_By_LastMonth() { // Arrange var container = new GameFilterContainer { Model = new GamesFilterModel { DatePeriod = DatePeriod.LastMonth, } }; var filter = new DateFilter(); IEnumerable <Game> list = GetGamesList(); // Act filter.Execute(container); Func <Game, bool> resultCondition = CombinePredicate <Game> .CombineWithAnd(container.Conditions); IEnumerable <Game> result = list.Where(x => (resultCondition(x))); // Assert Assert.IsTrue(result.Count() == 2); }
public void Check_That_NameFilter_Returns_Right_Delegate() { // Arrange var container = new GameFilterContainer { Model = new GamesFilterModel { GameNamePart = "name", } }; var filter = new NameFilter(); var list = new List <Game> { new Game { GameLocalizations = new List <GameLocalization> { new GameLocalization { Name = "name1", Language = new Language { Code = "en", LanguageId = 1, } } }, }, new Game { GameLocalizations = new List <GameLocalization> { new GameLocalization { Name = "name2", Language = new Language { Code = "en", LanguageId = 1, } } }, }, new Game { GameLocalizations = new List <GameLocalization> { new GameLocalization { Name = "nam", Language = new Language { Code = "en", LanguageId = 1, } } }, }, }; // Act filter.Execute(container); Func <Game, bool> resultCondition = CombinePredicate <Game> .CombineWithAnd(container.Conditions); IEnumerable <Game> result = list.Where(x => (resultCondition(x))); // Assert Assert.IsTrue(result.Count() == 2); }
public void Check_That_GenreFilter_Returns_Right_Delegate() { // Arrange var genres = new List <Genre> { new Genre { GenreId = 1 }, new Genre { GenreId = 2 }, new Genre { GenreId = 3 }, new Genre { GenreId = 4 }, }; var container = new GameFilterContainer { Model = new GamesFilterModel { Genres = new List <int> { 1, 2 } } }; var filter = new GenreFilter(); var list = new List <Game> { new Game { Genres = new List <Genre> { genres[0], genres[1], } }, new Game { Genres = new List <Genre> { genres[1], genres[2], } }, new Game { Genres = new List <Genre> { genres[2], genres[3], } }, new Game { Genres = new List <Genre> { genres[0], genres[3], } }, }; // Act filter.Execute(container); Func <Game, bool> resultCondition = CombinePredicate <Game> .CombineWithAnd(container.Conditions); IEnumerable <Game> result = list.Where(x => (resultCondition(x))); // Assert Assert.IsTrue(result.Count() == 3); }