コード例 #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);
        }
コード例 #2
0
        public void CreatesAGamesContext()
        {
            var mockGameRepository = new MockGameRepository();
            var mockGameMapper     = new MockGameMapper();
            var gamesContext       = new GamesContext(mockGameRepository, mockGameMapper);

            Assert.NotNull(gamesContext);
        }
コード例 #3
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);
        }
コード例 #4
0
 private static PlayerContext BuildPlayerContext(MockPlayerRepository playerRepository = null,
                                                 MockGameRepository gameRepository     = null, MockPlayerMapper playerMapper = null,
                                                 MockGameMapper gameMapper             = null)
 {
     playerRepository = playerRepository ?? new MockPlayerRepository();
     gameRepository   = gameRepository ?? new MockGameRepository();
     playerMapper     = playerMapper ?? new MockPlayerMapper();
     gameMapper       = gameMapper ?? new MockGameMapper();
     return(new PlayerContext(playerRepository, gameRepository, playerMapper, gameMapper));
 }
コード例 #5
0
        public void ContextBuildsAViewModel()
        {
            var mockGameRepository = new MockGameRepository();
            var mockGameMapper     = new MockGameMapper();
            var gamesContext       = new GamesContext(mockGameRepository, mockGameMapper);

            var viewModel = gamesContext.BuildViewModel();

            Assert.NotNull(viewModel);
            Assert.IsType <GamesViewModel>(viewModel);
        }
コード例 #6
0
        public void ContextRemovesAGame()
        {
            var game = new Game {
                Name = "Game 2"
            };
            var mockGameRepository = new MockGameRepository().StubGetByToReturn(game);
            var mockGameMapper     = new MockGameMapper();
            var gamesContext       = new GamesContext(mockGameRepository, mockGameMapper);

            gamesContext.Remove(game.Id);

            mockGameRepository.VerifyGetByCalledWith(game.Id);
            mockGameRepository.VerifyRemoveCalledWith(game);
        }
コード例 #7
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);
        }
コード例 #8
0
        public void ContextSavesAnUpdatedGame()
        {
            var game = new Game {
                Id = 2, Name = "Game 2", Description = "This is game 2"
            };
            var gameViewModel = new GameViewModel
            {
                Id          = 2,
                Name        = "Updated Game",
                Description = "This is an updated game"
            };
            var mockGameRepository = new MockGameRepository().StubGetByToReturn(game);
            var mockGameMapper     = new MockGameMapper();
            var gameContext        = BuildGameContext(mockGameRepository, mockGameMapper: mockGameMapper);

            gameContext.Save(gameViewModel);

            mockGameRepository.VerifyGetByCalledWith(gameViewModel.Id);
            mockGameRepository.VerifyUpdateCalledWith(game);
        }
コード例 #9
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);
        }
コード例 #10
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);
        }
コード例 #11
0
 private GameContext BuildGameContext(MockGameRepository mockGameRepository         = null,
                                      MockCategoryRepository mockCategoryRepository = null, MockGameMapper mockGameMapper             = null,
                                      MockCategoryMapper mockCategoryMapper         = null, MockPlayedDateMapper mockPlayedGameMapper = null)
 {
     mockGameRepository     = mockGameRepository ?? new MockGameRepository();
     mockCategoryRepository = mockCategoryRepository ?? new MockCategoryRepository();
     mockGameMapper         = mockGameMapper ?? new MockGameMapper();
     mockCategoryMapper     = mockCategoryMapper ?? new MockCategoryMapper();
     mockPlayedGameMapper   = mockPlayedGameMapper ?? new MockPlayedDateMapper();
     return(new GameContext(mockGameRepository, mockCategoryRepository, mockGameMapper, mockCategoryMapper, mockPlayedGameMapper));
 }