예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        public void Check_That_CombinePredicate_Combines_Predicates_With_Or_Properly()
        {
            // Arrange
            var list = new List <int> {
                1, 2, 3, 4, 5
            };

            var conditions = new List <Func <int, bool> >
            {
                x => x < 2,
                x => x > 3,
            };

            // Act
            Func <int, bool> resultCondition = CombinePredicate <int> .CombineWithOr(conditions);

            IEnumerable <int> result = list.Where(x => (resultCondition(x)));

            // Assert
            Assert.IsTrue(result.Count() == 3);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }