private void SetDataForGettingFilteredGames(GamesFilterAttributes attributes) { const SortingObject anySortingObject = SortingObject.New; const PageSize anyPageSize = PageSize.OneHundredItems; attributes.Genres = new List <int>() { It.IsAny <int>() }; attributes.PlatformTypes = new List <int>() { It.IsAny <int>() }; attributes.Publishers = new List <int>() { It.IsAny <int>() }; attributes.SortingObject = anySortingObject; attributes.GameNameSearchingString = "some searching string"; attributes.PageInfo = new PageInfo() { PageSize = anyPageSize }; _pipelineMock.Setup(m => m.Register(It.IsAny <IFilter <Game> >())) .Returns(_pipelineMock.Object); _pipelineMock.Setup(m => m.Process(It.IsAny <IQueryable <Game> >())) .Returns(It.IsAny <IQueryable <Game> >()); }
public HttpResponseMessage Get([FromUri] GamesFilterModel model) { SetUpModelForGamesFilter(model); if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } GamesFilterAttributes attributes = GetAttributesFromModel(model); model.Games = _gameService.GetGames(attributes).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, model)); }
private GamesFilterAttributes GetAttributesFromModel(GamesFilterModel model) { var attributes = new GamesFilterAttributes { Genres = model.SelectedGenresIds.ToList(), PlatformTypes = model.SelectedPlatformTypesIds.ToList(), Publishers = model.SelectedPublishersIds.ToList(), SortingObject = model.SortingObject, PublishingDatePeriod = model.PublishingDatePeriod, MinPrice = model.MinPrice, MaxPrice = model.MaxPrice, GameNameSearchingString = model.GameName, PageInfo = model.PageInfo }; return(attributes); }
public ViewResult GetAllGames(GamesViewModel model) { SetUpModelForGamesFilter(model); if (!ModelState.IsValid) { model.Games = _gameService.GetGames(null).Select(g => g.ToShortViewModel()).ToList(); return(View(model)); } GamesFilterAttributes attributes = GetAttributesFromModel(model); IEnumerable <GameDto> gameDtos = _gameService.GetGames(attributes); model.Games = gameDtos.Select(g => g.ToShortViewModel()).ToList(); return(View(model)); }
public IEnumerable <GameDto> GetGames(GamesFilterAttributes attributes) { if (attributes == null) { return(UnitOfWork.Games.GetAll().Select(g => g.ToDto()).ToList()); } _pipeline.Register(_filterFactory.MakeSortedGamesFilter()) .Register(_filterFactory.MakeGamesByPriceRangeFilter(attributes.MinPrice, attributes.MaxPrice)) .Register(_filterFactory.MakeGamesByPublishingDateFilter(attributes.PublishingDatePeriod)); if (attributes.Genres != null && attributes.Genres.Count > 0) { _pipeline.Register(_filterFactory.MakeGamesByGenresWithIdsFilter(attributes.Genres)); } if (attributes.PlatformTypes != null && attributes.PlatformTypes.Count > 0) { _pipeline.Register(_filterFactory.MakeGamesByPlatformTypesWithIdsFilter(attributes.PlatformTypes)); } if (attributes.Publishers != null && attributes.Publishers.Count > 0) { _pipeline.Register(_filterFactory.MakeGamesByPublishersWithIdsFilter(attributes.Publishers)); } if (attributes.SortingObject != SortingObject.Default) { _pipeline.Register(_filterFactory.MakeGamesBySortingObjectFilter(attributes.SortingObject)); } if (!string.IsNullOrEmpty(attributes.GameNameSearchingString)) { _pipeline.Register(_filterFactory.MakeGamesByGameNameFilter(attributes.GameNameSearchingString)); } if (attributes.PageInfo.PageSize != PageSize.AllItems) { _pipeline.Register(_filterFactory.MakeGamesPaginationFilter(attributes.PageInfo)); } return(UnitOfWork.Games.Find(_pipeline) .Select(g => g.ToDto())); }
public void ShouldReturnFilteredGamesWhenAttributesNotEqualNull() { const int processCallingCount = 9; var games = new List <Game> { new Game() }; _unitOfWorkMock.Setup(m => m.Games.Find(It.IsAny <IPipeline <Game> >())) .Returns(games); var attributes = new GamesFilterAttributes(); SetDataForGettingFilteredGames(attributes); IEnumerable <GameDto> gamesDtos = _service.GetGames(attributes); Assert.AreEqual(games.Count, gamesDtos.Count()); _pipelineMock.Verify(p => p.Register(It.IsAny <IFilter <Game> >()), Times.Exactly(processCallingCount)); }