Exemplo n.º 1
0
        public void Execute_GameDoesNotHaveWinner_InvalidOperationException()
        {
            //Arrange
            IGameRepository repository = RepositoryFactory.GetGameRepository();
            int             maxWins    = 3;
            Move            move1      = new Move("Rock");
            Move            move2      = new Move("Scissors");
            Move            move3      = new Move("Paper");
            GameRules       rules      = new GameRules(maxWins);

            move1.AddKill(move2.Name);
            move2.AddKill(move3.Name);
            move3.AddKill(move1.Name);

            rules.AddMove(move1);
            rules.AddMove(move2);
            rules.AddMove(move3);

            Game game = new Game(rules, "player1", "player2");

            game.Play(move1.Name, move2.Name);
            game.Play(move3.Name, move1.Name);

            RegisterGameResult transaction = new RegisterGameResult(repository, game);

            //Act
            transaction.Execute();
        }
Exemplo n.º 2
0
        public void RegisterGameResult(Game game)
        {
            RegisterGameResult transaction =
                TransactionFactory.GetRegisterGameResultTransaction(game);

            transaction.Execute();
        }
Exemplo n.º 3
0
        public void Execute_ValidPlayer_GamesFound()
        {
            //Arrange
            IGameRepository repository = RepositoryFactory.GetGameRepository();
            int             maxWins    = 3;
            Move            move1      = new Move("Rock");
            Move            move2      = new Move("Scissors");
            Move            move3      = new Move("Paper");
            GameRules       rules      = new GameRules(maxWins);

            move1.AddKill(move2.Name);
            move2.AddKill(move3.Name);
            move3.AddKill(move1.Name);

            rules.AddMove(move1);
            rules.AddMove(move2);
            rules.AddMove(move3);

            Game game = new Game(rules, "player1", "player2");

            game.Play(move1.Name, move2.Name);
            game.Play(move3.Name, move1.Name);
            game.Play(move2.Name, move3.Name);

            RegisterGameResult registerGameTransaction =
                new RegisterGameResult(repository, game);

            registerGameTransaction.Execute();

            GetPlayedGamesByPlayer getPlayedTransaction =
                new GetPlayedGamesByPlayer(repository, "player1");

            //Act
            getPlayedTransaction.Execute();

            //Assert
            IEnumerable <GameData> result = getPlayedTransaction.GetResult();
            GameData playedGame           = result.ElementAt(0);

            Assert.AreEqual(3, playedGame.ScorePlayer1);
            Assert.AreEqual(0, playedGame.ScorePlayer2);
            Assert.AreEqual("player1", playedGame.WinnerName);
        }