Example #1
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);
        }
Example #2
0
        public void ContextRemovesAPlayer()
        {
            var player = new Player {
                Id = 1, FirstName = "First 2", LastName = "Last 2"
            };
            var mockPlayerRepository = new MockPlayerRepository().StubGetByToReturn(player);
            var mockPlayerMapper     = new MockPlayerMapper();
            var playersContext       = new PlayersContext(mockPlayerRepository, mockPlayerMapper);

            playersContext.Remove(player.Id);

            mockPlayerRepository.VerifyGetByCalledWith(player.Id);
            mockPlayerRepository.VerifyRemoveCalledWith(player);
        }
Example #3
0
        public void ContextSavesANewPlayer()
        {
            var player = new Player {
                Id = 4, FirstName = "New First", LastName = "New Last"
            };
            var playerViewModel = new PlayerViewModel {
                Id = 4, FirstName = "New First", LastName = "New Last"
            };
            var mockPlayerRepository = new MockPlayerRepository();
            var mockPlayerMapper     = new MockPlayerMapper().StubMapToReturn(player);
            var playerContext        = BuildPlayerContext(mockPlayerRepository, playerMapper: mockPlayerMapper);

            playerContext.Save(playerViewModel);

            mockPlayerRepository.VerifyGetByCalledWith(playerViewModel.Id);
            mockPlayerRepository.VerifyAddCalledWith(player);
            mockPlayerMapper.VerifyMapCalledWith(playerViewModel);
        }
Example #4
0
        public void ContextSavesAnUpdatedPlayer()
        {
            var player = new Player {
                Id = 2, FirstName = "First 2", LastName = "Last 2"
            };
            var playerViewModel = new PlayerViewModel
            {
                Id        = 2,
                FirstName = "Updated First",
                LastName  = "Updated Last"
            };
            var mockPlayerRepository = new MockPlayerRepository().StubGetByToReturn(player);
            var playerContext        = BuildPlayerContext(mockPlayerRepository);

            playerContext.Save(playerViewModel);

            mockPlayerRepository.VerifyGetByCalledWith(playerViewModel.Id);
            mockPlayerRepository.VerifyUpdateCalledWith(player);
        }