Пример #1
0
        private void RegisterFilter(GamePipeline gamePipeline, FilterDTO filter, int page, PageSize pageSize)
        {
            if (filter.SelectedGenresName != null && filter.SelectedGenresName.Any())
            {
                gamePipeline.Register(new GameFilterByGenre(filter.SelectedGenresName));
            }

            if (filter.MaxPrice != null)
            {
                gamePipeline.Register(new GameFilterByPrice(filter.MaxPrice.Value, null));
            }

            if (filter.MinPrice != null)
            {
                gamePipeline.Register(new GameFilterByPrice(null, filter.MinPrice.Value));
            }

            if (filter.MaxPrice != null && filter.MinPrice != null)
            {
                gamePipeline.Register(new GameFilterByPrice(filter.MaxPrice.Value, filter.MinPrice.Value));
            }

            if (filter.SelectedPlatformTypesName != null && filter.SelectedPlatformTypesName.Any())
            {
                gamePipeline.Register(new GameFilterByPlatform(filter.SelectedPlatformTypesName));
            }

            if (filter.SelectedPublishersName != null && filter.SelectedPublishersName.Any())
            {
                gamePipeline.Register(new GameFilterByPublisher(filter.SelectedPublishersName));
            }

            if (filter.SearchGameName != null && filter.SearchGameName.Length >= 3)
            {
                gamePipeline.Register(new GameFilterByName(filter.SearchGameName));
            }

            if (filter.FilterDate != FilterDate.all)
            {
                gamePipeline.Register(new GameFilterByDate(filter.FilterDate));
            }

            gamePipeline.Register(new GameSortFilter(filter.SortType))
            .Register(new GameFilterByPage(page, pageSize));
        }
Пример #2
0
        public void GetGamesByFilter_FilterByDateTwoYear_GetedGames()
        {
            var filterDto = new FilterDTO()
            {
                FilterDate = FilterDate.twoYear
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameFilterByDate(filterDto.FilterDate));
            var gamesAfteFilter = gamePipeline.Process(_fakeGamesForFilter);

            Assert.True(gamesAfteFilter.ElementAt(0).PublishDate > gamesAfteFilter.ElementAt(1).PublishDate);
        }
Пример #3
0
        public void GetGamesByFilter_FilterByDateWeek_GetedGames()
        {
            var filterDto = new FilterDTO()
            {
                FilterDate = FilterDate.week
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameFilterByDate(filterDto.FilterDate));
            var gamesAfteFilter = gamePipeline.Process(_fakeGamesForFilter);

            Assert.True(gamesAfteFilter.First().PublishDate >= DateTime.Today.AddDays(-7));
        }
Пример #4
0
        public void GetGamesByFilter_FilterByDateMonth_GetedGames()
        {
            var filterDto = new FilterDTO()
            {
                FilterDate = FilterDate.month
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameFilterByDate(filterDto.FilterDate));
            var gamesAfteFilter = gamePipeline.Process(_fakeGamesForFilter);

            Assert.True(gamesAfteFilter.ElementAt(0).PublishDate >= DateTime.Today.AddMonths(-1));
        }
Пример #5
0
        public void GetGamesByFilter_SortFilterMostPopular_GetedGames()
        {
            var filterDto = new FilterDTO()
            {
                SortType = SortType.MostPopular
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameSortFilter(filterDto.SortType));
            var gamesAfteFilter = gamePipeline.Process(_fakeGamesForFilter);

            Assert.True(gamesAfteFilter.ElementAt(0).Views > gamesAfteFilter.ElementAt(1).Views);
        }
Пример #6
0
        public void GetGamesByFilter_SortFilterPriceAsc_GetedGames()
        {
            var filterDto = new FilterDTO()
            {
                SortType = SortType.PriceAsc
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameSortFilter(filterDto.SortType));
            var gamesAfteFilter = gamePipeline.Process(_fakeGamesForFilter);

            Assert.True(gamesAfteFilter.ElementAt(0).Price < gamesAfteFilter.ElementAt(1).Price);
        }
Пример #7
0
        public void GetGamesByFilter_FilterByFilterByMinPrice_GetedGames()
        {
            var filterDto = new FilterDTO()
            {
                MaxPrice = 30
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameFilterByPrice(filterDto.MaxPrice.Value, null));
            var gamesAfteFilter = gamePipeline.Process(_fakeGamesForFilter);

            Assert.Equal(_fakeGamesForFilter.Count, gamesAfteFilter.Count());
        }
Пример #8
0
        public void GetGamesByFilter_FilterByName_GetedGames()
        {
            var filterDto = new FilterDTO()
            {
                SearchGameName = "game"
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameFilterByName(filterDto.SearchGameName));
            var gamesAfteFilter = gamePipeline.Process(_fakeGamesForFilter);

            Assert.Equal(_fakeGamesForFilter.Count, gamesAfteFilter.Count());
        }
Пример #9
0
        public void GetGamesByFilter_FilterByPublisher_GetedGames()
        {
            var filterDto = new FilterDTO()
            {
                SelectedPublishersName = new List <string>()
                {
                    "Publisher"
                }
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameFilterByPublisher(filterDto.SelectedPublishersName));
            var gamesAfteFilter = gamePipeline.Process(_fakeGamesForFilter);

            Assert.Equal(_fakeGamesForFilter.Count, gamesAfteFilter.Count());
        }
Пример #10
0
        public void GetGamesByFilter_FilterByPageSizeAll_GetedGames()
        {
            var fakeGamesForFilter = new List <Game>()
            {
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра1", Key = "Игра1"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра2", Key = "Игра2"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра3", Key = "Игра3"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра4", Key = "Игра4"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра5", Key = "Игра5"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра6", Key = "Игра6"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра7", Key = "Игра7"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра8", Key = "Игра8"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра9", Key = "Игра9"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра10", Key = "Игра10"
                },
                new Game {
                    Id = Guid.NewGuid(), NameRu = "Игра11", Key = "Игра11"
                },
            };
            var gamePipeline = new GamePipeline();

            gamePipeline.Register(new GameFilterByPage(1, PageSize.All));
            var gamesAfteFilter = gamePipeline.Process(fakeGamesForFilter);

            Assert.True(gamesAfteFilter.ElementAt(10).NameRu == "Игра11");
        }