public void Play_OutcomeWinNonHumanPlayersMove2Wins_ReturnsExpectedGameResult()
        {
            //Arrange
            GameId = 3;

            var player1Mock = new Mock <IPlayer>();

            player1Mock.Setup(m => m.Rules).Returns(GameRules);
            player1Mock.Setup(m => m.Name).Returns("John Hanley");

            PlayerMocks.Add(player1Mock);
            var player1 = player1Mock.Object;

            Players.Add(player1);
            var player1Move = new Move(GameAction.Paper, Players[0]);

            player1Mock.Setup(m => m.SelectMove()).Returns(player1Move);

            var player2Mock = new Mock <IPlayer>();

            player2Mock.Setup(m => m.Rules).Returns(GameRules);
            player2Mock.Setup(m => m.Name).Returns("Other Player");

            PlayerMocks.Add(player2Mock);
            var player2 = player2Mock.Object;

            Players.Add(player2);
            var player2Move = new Move(GameAction.Scissors, Players[1]);

            player2Mock.Setup(m => m.SelectMove()).Returns(player2Move);

            var commencementMessage = $"Game<{GameId}>: Commence...";

            UiControllerMock.SetupSequence(m => m.Output(commencementMessage)).Pass();
            UserInteractionController = UiControllerMock.Object;

            Game = new Game(GameId, Players, Moves, UserInteractionController);

            //Act
            var result = (GameResult)Game.Play(GameRules);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(ContestOutcome.Win, result.Outcome);
            UiControllerMock.Verify(m => m.Output(It.IsAny <string>()), Times.Exactly(3));
            PlayerMocks[0].Verify(m => m.SelectMove(), Times.Once);
            PlayerMocks[1].Verify(m => m.SelectMove(), Times.Once);
            PlayerMocks[0].Verify(m => m.Name, Times.Once);
            PlayerMocks[1].Verify(m => m.Name, Times.Once);
            Assert.IsNotNull(result.WinningMove);
            Assert.AreEqual(result.WinningMove, player2Move);
        }
Exemple #2
0
        public void Run_ExecutesGamePipeLineWithTacticalOpponent_DoesAllExpectedWork()
        {
            //Arrange
            const string playerName         = "James Kibirige";
            const string nameRequestMessage = "Please Enter your name:\n\n{A-Z,a-z, }";

            UiControllerMock.Setup(m => m.RequestInput(nameRequestMessage)).Returns("James Kibirige");

            var opponentTypeEnumerator     = new EnumEnumerator <OpponentType>();
            var opponentTypeOptions        = string.Join(",", opponentTypeEnumerator.EnumerateEnum());
            var opponentTypeRequestMessage = $"Select an Opponent Type from the choices:\n\n{{{opponentTypeOptions}}}";

            UiControllerMock.Setup(m => m.RequestInput(opponentTypeRequestMessage)).Returns("Tactical");

            var numRoundsrequestMessage = $"Please Specify number of rounds to play in Match:\n\n{{number using digits 1-9 between 1 and 10}}";

            UiControllerMock.Setup(m => m.RequestInput(numRoundsrequestMessage)).Returns("3");

            var possibleActions         = string.Join(",", Rules.PossibleGameActions());//String literal listing possible game actions
            var playerSelectMoveMessage = string.Format("Player <{0}>\nSelect a Move from the possible choices:\n{{{1}}}", playerName, possibleActions);

            UiControllerMock.SetupSequence(m => m.RequestInput(playerSelectMoveMessage)).Returns("Rock").Returns("Paper").Returns("Scissors");

            var yesNoOptions            = "Yes,Y,No,N";
            var playAgainRequestMessage = $"Do want to Play Again?\n\n{{{yesNoOptions}}}";

            UiControllerMock.Setup(m => m.RequestInput(playAgainRequestMessage)).Returns("no");

            var theApp = (Application)Application;

            //Act
            theApp.Run();

            //Assert
            UiControllerMock.Verify(m => m.Output(It.IsAny <string>()), Times.AtLeast(3));
            UiControllerMock.Verify(m => m.RequestInput(It.IsAny <string>()), Times.AtLeast(3));
        }