예제 #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 WhenBankrupt_RespondsCorrectly()
        {
            var mockGameRepository   = new MockGameRepository();
            var mockCircleRepository = new MockCircleRepository();
            var mockRandomProvider   = new MockRandomProvider();
            var interactor           = new SpinCircle(mockGameRepository, mockCircleRepository, mockRandomProvider);
            var gameIdentifier       = Guid.Parse("00000000-0000-0000-0000-000000000001");

            mockGameRepository.Games.Add(gameIdentifier, new Game(new string[] { "Alice", "Bob" }, "TestPhrase"));
            mockCircleRepository.Circle = GetCircle();
            const int indexBankrupt = 0;

            mockRandomProvider.Values.Add((0, 13), indexBankrupt);
            var requestModel = new SpinCircle.RequestModel()
            {
                GameIdentifier = gameIdentifier
            };
            var presenter = new Presenter <SpinCircle.ResponseModel>();

            interactor.HandleRequest(requestModel, presenter);
            var responseModel = presenter.ResponseModel;

            Assert.Equal("Bankrupt", responseModel.ResultDescription);
            Assert.False(responseModel.RequestLetter);
            Assert.Equal("Bob", responseModel.CurrentPlayerName);
        }
예제 #3
0
        public void CreatesAGamesContext()
        {
            var mockGameRepository = new MockGameRepository();
            var mockGameMapper     = new MockGameMapper();
            var gamesContext       = new GamesContext(mockGameRepository, mockGameMapper);

            Assert.NotNull(gamesContext);
        }
예제 #4
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);
        }
예제 #5
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));
 }
예제 #6
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);
        }
예제 #7
0
        public void ContextRemovesAnElectedCategory()
        {
            var gameId             = 1;
            var categoryId         = 1;
            var mockGameRepository = new MockGameRepository();
            var gameContext        = BuildGameContext(mockGameRepository);

            gameContext.RemoveElectedCategory(gameId, categoryId);

            mockGameRepository.VerifyRemoveElectedCategoryCalledWith(gameId, categoryId);
        }
예제 #8
0
        public void ContextRemovesAPlayedDate()
        {
            var gameId             = 1;
            var playedDate         = new DateTime(2016, 1, 1);
            var mockGameRepository = new MockGameRepository();
            var gameContext        = BuildGameContext(mockGameRepository);

            gameContext.RemovePlayedDate(gameId, playedDate);

            mockGameRepository.VerifyRemovePlayedDateCalledWith(gameId, playedDate);
        }
예제 #9
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));
 }
예제 #10
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);
        }
        public void FullShortGameTest()
        {
            var mockCircleRepository = new MockCircleRepository();
            var mockGameRepository   = new MockGameRepository();
            var mockPhraseRepository = new MockPhraseRepository();
            var mockRandomProvider   = new MockRandomProvider();

            mockCircleRepository.Circle = GetCircle();
            mockPhraseRepository.Phrase = "Short Game Test";
            const int indexOneThousand = 7;

            mockRandomProvider.Values.Add((0, 13), indexOneThousand);
            var startNewGamePresenter  = new Presenter <StartNewGame.ResponseModel>();
            var startNewGameInteractor = new StartNewGame(mockPhraseRepository, mockGameRepository);

            startNewGameInteractor.HandleRequest(new StartNewGame.RequestModel()
            {
                PlayerNames = new string[]
                {
                    "Alice", "Bob", "Charlie"
                }
            }, startNewGamePresenter);
            var spinCirclePresenter  = new Presenter <SpinCircle.ResponseModel>();
            var spinCircleInteractor = new SpinCircle(mockGameRepository, mockCircleRepository, mockRandomProvider);

            spinCircleInteractor.HandleRequest(new SpinCircle.RequestModel()
            {
                GameIdentifier = startNewGamePresenter.ResponseModel.GameIdentifier
            }, spinCirclePresenter);
            var pickLetterPresenter  = new Presenter <PickLetter.ResponseModel>();
            var pickLetterInteractor = new PickLetter(mockGameRepository);

            pickLetterInteractor.HandleRequest(new PickLetter.RequestModel()
            {
                GameIdentifier = startNewGamePresenter.ResponseModel.GameIdentifier,
                Letter         = 'e'
            }, pickLetterPresenter);
            var guessPhrasePresenter  = new Presenter <GuessPhrase.ResponseModel>();
            var guessPhraseInteractor = new GuessPhrase(mockGameRepository);

            guessPhraseInteractor.HandleRequest(new GuessPhrase.RequestModel()
            {
                GameIdentifier = startNewGamePresenter.ResponseModel.GameIdentifier,
                Guess          = "Short Game Test"
            }, guessPhrasePresenter);
            Assert.Equal("Short Game Test", guessPhrasePresenter.ResponseModel.Phrase);
            Assert.Equal("Alice", guessPhrasePresenter.ResponseModel.CurrentPlayerName);
            Assert.Equal(2000, guessPhrasePresenter.ResponseModel.Reward);
            Assert.True(mockGameRepository.Games.Single().Value.IsOver);
        }
예제 #12
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);
        }
예제 #13
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);
        }
        public void StartsNewGameCorrectly()
        {
            var mockPhraseRepository = new MockPhraseRepository();
            var mockGameRepository   = new MockGameRepository();
            var interactor           = new StartNewGame(mockPhraseRepository, mockGameRepository);

            mockPhraseRepository.Phrase       = "Small Test Phrase";
            mockGameRepository.GameIdentifier = Guid.Parse("00000000-0000-0000-0000-000000000001");
            var requestModel = new StartNewGame.RequestModel()
            {
                PlayerNames = new string[] { "Alice", "Bob", "Charlie" }
            };
            var presenter = new Presenter <StartNewGame.ResponseModel>();

            interactor.HandleRequest(requestModel, presenter);
            var responseModel = presenter.ResponseModel;

            Assert.Equal(Guid.Parse("00000000-0000-0000-0000-000000000001"), responseModel.GameIdentifier);
            Assert.Equal("_____ ____ ______", responseModel.Phrase);
            Assert.Equal("Alice", responseModel.CurrentPlayerName);
        }
예제 #15
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);
        }
예제 #16
0
        public void PicksLetterThatIsMissingCorrectly()
        {
            var mockGameRepository = new MockGameRepository();
            var interactor         = new PickLetter(mockGameRepository);
            var gameIdentifier     = Guid.Parse("00000000-0000-0000-0000-000000000001");
            var game = new Game(new string[] { "Alice", "Bob" }, "TestPhrase");

            game.HandleSpace(new CircleSpace(CircleSpace.SpaceType.Dollar, 1400));
            mockGameRepository.Games.Add(gameIdentifier, game);
            var requestModel = new PickLetter.RequestModel()
            {
                GameIdentifier = gameIdentifier,
                Letter         = 'Z'
            };
            var presenter = new Presenter <PickLetter.ResponseModel>();

            interactor.HandleRequest(requestModel, presenter);
            var responseModel = presenter.ResponseModel;

            Assert.Equal("__________", responseModel.Phrase);
            Assert.Equal("Bob", responseModel.CurrentPlayerName);
        }
        public void WhenGuessCorrect_RespondsCorrectly()
        {
            var mockGameRepository = new MockGameRepository();
            var interactor         = new GuessPhrase(mockGameRepository);
            var gameIdentifier     = Guid.Parse("00000000-0000-0000-0000-000000000001");
            var game = new Game(new string[] { "Alice", "Bob" }, "TestPhrase");

            game.HandleSpace(new CircleSpace(CircleSpace.SpaceType.Dollar, 1600));
            game.HandleLetter('e');
            mockGameRepository.Games.Add(gameIdentifier, game);
            var requestModel = new GuessPhrase.RequestModel()
            {
                GameIdentifier = gameIdentifier,
                Guess          = "TestPhrase"
            };
            var presenter = new Presenter <GuessPhrase.ResponseModel>();

            interactor.HandleRequest(requestModel, presenter);
            var responseModel = presenter.ResponseModel;

            Assert.Equal("TestPhrase", responseModel.Phrase);
            Assert.Equal("Alice", responseModel.CurrentPlayerName);
            Assert.Equal(3200, responseModel.Reward);
        }
예제 #18
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);
        }