Exemplo n.º 1
0
        public void ContextBuildsAViewModelWithAllGames()
        {
            var game = new Game {
                Name = "Game 1"
            };
            var gameViewModel = new GameViewModel {
                Name = "Game 1"
            };
            var games = new List <Game> {
                game
            };
            var mockGameRepository = new MockGameRepository().StubGetAllToReturn(games);
            var mockGameMapper     = new MockGameMapper().StubMapToReturn(gameViewModel);
            var gamesContext       = new GamesContext(mockGameRepository, mockGameMapper);

            var viewModel = gamesContext.BuildViewModel();

            Assert.NotNull(viewModel);
            Assert.IsType <GamesViewModel>(viewModel);
            Assert.Equal(games.Count, viewModel.Games.Count());

            var gameViewModels = viewModel.Games.ToList();

            Assert.Equal(game.Id, gameViewModels.First()
                         .Id);
            Assert.Equal(game.Name, gameViewModels.First()
                         .Name);
            Assert.Equal(game.Description, gameViewModels.First()
                         .Description);

            mockGameRepository.VerifyGetAllCalled();
            mockGameMapper.VerifyMapCalledWith(game);
        }
Exemplo n.º 2
0
        public void ContextBuildsAViewModelWithEditedPlayer()
        {
            var game = new Game {
                Id = 1, Name = "Game 1"
            };
            var games = new List <Game> {
                game
            };
            var item = new SelectListItem {
                Value = "1", Text = "Game 1"
            };
            var gameSelectListItems = new List <SelectListItem> {
                item
            };
            var gameViewModel = new GameViewModel {
                Id = 1, Name = "Game 1"
            };
            var gamesOwned = new List <GameViewModel> {
                gameViewModel
            };
            var player = new Player {
                Id = 2, FirstName = "First 2", LastName = "Last 2"
            };
            var playerViewModel = new PlayerViewModel
            {
                Id         = 2,
                FirstName  = "First 2",
                LastName   = "Last 2",
                FullName   = "First 2 Last 2",
                Games      = gameSelectListItems,
                GamesOwned = gamesOwned
            };

            var mockPlayerRepository =
                new MockPlayerRepository().StubGetAllGamesByToReturn(games)
                .StubGetByToReturn(player);
            var mockGameRepository = new MockGameRepository().StubGetAllToReturn(games);
            var mockPlayerMapper   = new MockPlayerMapper().StubMapWithGamesToReturn(playerViewModel);
            var mockGameMapper     = new MockGameMapper().StubMapToReturn(gameViewModel)
                                     .StubSelectMapToReturn(item);
            var playerContext = BuildPlayerContext(mockPlayerRepository, mockGameRepository, mockPlayerMapper,
                                                   mockGameMapper);

            var viewModel = playerContext.BuildViewModel(player.Id);

            Assert.NotNull(viewModel);
            Assert.Equal("First 2 Last 2", viewModel.FullName);
            Assert.Equal(1, viewModel.Games.Count());
            Assert.Equal(1, viewModel.GamesOwned.Count());
            mockPlayerRepository.VerifyGetByCalledWith(player.Id);
            mockPlayerRepository.VerifyGetAllGamesByCalledWith(player.Id);
            mockGameRepository.VerifyGetAllCalled();
            mockPlayerMapper.VerifyMapCalledWith(player, gameSelectListItems, gamesOwned);
            mockGameMapper.VerifySelectMapCalledWith(game);
            mockGameMapper.VerifyMapCalledWith(game);
        }
Exemplo n.º 3
0
        public void ContextSavesANewGame()
        {
            var game = new Game {
                Id = 4, Name = "New Game", Description = "This is new game"
            };
            var gameViewModel = new GameViewModel {
                Id = 4, Name = "New Game", Description = "This is a new game"
            };
            var mockGameRepository = new MockGameRepository();
            var mockGameMapper     = new MockGameMapper().StubMapToReturn(game);
            var gameContext        = BuildGameContext(mockGameRepository, mockGameMapper: mockGameMapper);

            gameContext.Save(gameViewModel);

            mockGameRepository.VerifyGetByCalledWith(gameViewModel.Id);
            mockGameRepository.VerifyAddCalledWith(game);
            mockGameMapper.VerifyMapCalledWith(gameViewModel);
        }
Exemplo n.º 4
0
        public void ContextBuildsAViewModelWithNewGame()
        {
            var category = new Category {
                Id = 1, Description = "Category 1"
            };
            var categories = new List <Category> {
                category
            };
            var item = new SelectListItem {
                Value = "1", Text = "Category 1"
            };
            var categorySelectListItems = new List <SelectListItem> {
                item
            };
            var electedCategories = new List <CategoryViewModel>();
            var playedDates       = new List <PlayedDateViewModel>();
            var game          = new Game();
            var gameViewModel = new GameViewModel
            {
                Categories        = categorySelectListItems,
                ElectedCategories = electedCategories,
                PlayedDates       = playedDates
            };
            var mockGameRepository     = new MockGameRepository().StubGetByToReturn(game);
            var mockCategoryRepository = new MockCategoryRepository().StubGetAllToReturn(categories);
            var mockGameMapper         = new MockGameMapper().StubMapWithCategoriesToReturn(gameViewModel);
            var mockCategoryMapper     = new MockCategoryMapper().StubSelectMapToReturn(item);
            var gameContext            = BuildGameContext(mockGameRepository, mockCategoryRepository, mockGameMapper,
                                                          mockCategoryMapper);

            var viewModel = gameContext.BuildViewModel(game.Id);

            Assert.NotNull(viewModel);
            Assert.Equal(1, viewModel.Categories.Count());
            mockGameRepository.VerifyGetByCalledWith(game.Id);
            mockCategoryRepository.VerifyGetAllCalled();
            mockGameMapper.VerifyMapCalledWith(game, categorySelectListItems, electedCategories, playedDates);
            mockCategoryMapper.VerifySelectMapCalledWith(category);
        }
Exemplo n.º 5
0
        public void ContextBuildsAViewModelWithEditedGame()
        {
            var category = new Category {
                Id = 1, Description = "Category 1"
            };
            var categories = new List <Category> {
                category
            };
            var item = new SelectListItem {
                Value = "1", Text = "Category 1"
            };
            var categorySelectListItems = new List <SelectListItem> {
                item
            };
            var categoryViewModel = new CategoryViewModel {
                Id = 1, Description = "Category 1"
            };
            var electedCategories = new List <CategoryViewModel> {
                categoryViewModel
            };
            var playedDateViewModel = new PlayedDateViewModel {
                Id = 1, FormattedPlayedDate = "1/1/2016"
            };
            var playedDates = new List <PlayedDateViewModel> {
                playedDateViewModel
            };
            var game = new Game {
                Id = 2, Name = "Game 2", Description = "This is game 2"
            };
            var gamePlayedDate = new GamePlayedDate {
                Id = 1, GameId = game.Id, Game = game, PlayedDate = new DateTime(2016, 1, 1)
            };
            var gamePlayedDates = new List <GamePlayedDate> {
                gamePlayedDate
            };
            var gameViewModel = new GameViewModel
            {
                Id                = 2,
                Name              = "Game 2",
                Description       = "This is game 2",
                Categories        = categorySelectListItems,
                ElectedCategories = electedCategories,
                PlayedDates       = playedDates
            };
            var mockGameRepository = new MockGameRepository()
                                     .StubGetAllCategoriesByToReturn(categories)
                                     .StubGetAllPlayedDatesByToReturn(gamePlayedDates)
                                     .StubGetByToReturn(game);
            var mockCategoryRepository = new MockCategoryRepository()
                                         .StubGetAllToReturn(categories);
            var mockGameMapper = new MockGameMapper()
                                 .StubMapWithCategoriesToReturn(gameViewModel);
            var mockCategoryMapper = new MockCategoryMapper()
                                     .StubMapToReturn(categoryViewModel)
                                     .StubSelectMapToReturn(item);
            var mockPlayedDateMapper = new MockPlayedDateMapper()
                                       .StubMapToReturn(playedDateViewModel);
            var gameContext = BuildGameContext(mockGameRepository, mockCategoryRepository, mockGameMapper, mockCategoryMapper, mockPlayedDateMapper);

            var viewModel = gameContext.BuildViewModel(game.Id);

            Assert.NotNull(viewModel);
            Assert.Equal(1, viewModel.Categories.Count());
            Assert.Equal(1, viewModel.ElectedCategories.Count());
            Assert.Equal(1, viewModel.PlayedDates.Count());
            mockGameRepository.VerifyGetByCalledWith(game.Id);
            mockGameRepository.VerifyGetAllCategoriesByCalledWith(game.Id);
            mockGameRepository.VerifyGetAllPlayedDatesByCalledWith(game.Id);
            mockCategoryRepository.VerifyGetAllCalled();
            mockGameMapper.VerifyMapCalledWith(game, categorySelectListItems, electedCategories, playedDates);
            mockCategoryMapper.VerifySelectMapCalledWith(category);
            mockCategoryMapper.VerifyMapCalledWith(category);
            mockPlayedDateMapper.VerifyMapCalledWith(gamePlayedDate);
        }