コード例 #1
0
        public void ShouldUseRulesEachRound()
        {
            var match   = new RockPaperScissors.Match(rulesMock.Object);
            var results = match.Play(3, rockPlayerMock.Object, paperPlayerMock.Object);

            rulesMock.Verify(m => m.GetScore(It.IsAny <Move>(), It.IsAny <Move>()), Times.Exactly(3));
        }
コード例 #2
0
        public void ShouldUsePlayersMovesEachRound()
        {
            var match   = new RockPaperScissors.Match(rulesMock.Object);
            var results = match.Play(3, rockPlayerMock.Object, paperPlayerMock.Object);

            rockPlayerMock.Verify(m => m.Move(), Times.Exactly(3));
            paperPlayerMock.Verify(m => m.Move(), Times.Exactly(3));
        }
コード例 #3
0
        public void MatchResultsHaveCorrectNumberOfRounds()
        {
            var match   = new RockPaperScissors.Match(rulesMock.Object);
            var results = match.Play(5, rockPlayerMock.Object, paperPlayerMock.Object);

            Assert.AreEqual(5, results.Rounds.Count());
            results = match.Play(3, rockPlayerMock.Object, paperPlayerMock.Object);
            Assert.AreEqual(3, results.Rounds.Count());
        }
コード例 #4
0
        public void ProducesRoundsWithCorrectResults()
        {
            var match      = new RockPaperScissors.Match(rulesMock.Object);
            var results    = match.Play(3, rockPlayerMock.Object, paperPlayerMock.Object);
            var firstRound = results.Rounds.First();

            Assert.AreEqual(Move.Rock, firstRound.Player1Move);
            Assert.AreEqual(Move.Paper, firstRound.Player2Move);
            Assert.AreEqual(-1, firstRound.Player1Score);
            Assert.AreEqual(1, firstRound.Player2Score);
        }
コード例 #5
0
        public void EachRoundRaisesRoundPlayedEvent()
        {
            var rounds = new List <MatchResults.Round>();
            var match  = new RockPaperScissors.Match(rulesMock.Object);

            match.RoundPlayed += (o, e) =>
            {
                rounds.Add(e.Round);
            };
            match.Play(3, rockPlayerMock.Object, paperPlayerMock.Object);
            Assert.AreEqual(3, rounds.Count);
        }
コード例 #6
0
        public void PlayerTwoWinsTwoGamesAndMatch()
        {
            match = new RockPaperScissors.Match(mockPlayerOne.Object, mockPlayerTwo.Object);

            mockPlayerOne.SetupSequence(x => x.GetPlayerMove())
            .Returns(Move.Scissors)
            .Returns(Move.Paper)
            .Returns(Move.Rock);

            mockPlayerTwo.SetupSequence(x => x.GetPlayerMove())
            .Returns(Move.Rock)
            .Returns(Move.Rock)
            .Returns(Move.Paper);

            Assert.AreEqual(MatchResult.PlayerTwoWins, match.Start());
        }
コード例 #7
0
        public void AllGamesDrawSoMatchIsADraw()
        {
            match = new RockPaperScissors.Match(mockPlayerOne.Object, mockPlayerTwo.Object);


            mockPlayerOne.SetupSequence(x => x.GetPlayerMove())
            .Returns(Move.Rock)
            .Returns(Move.Paper)
            .Returns(Move.Scissors);

            mockPlayerTwo.SetupSequence(x => x.GetPlayerMove())
            .Returns(Move.Rock)
            .Returns(Move.Paper)
            .Returns(Move.Scissors);


            Assert.AreEqual(MatchResult.Draw, match.Start());
        }