Ejemplo n.º 1
0
        public void PlayNextTurn_CyclesEveryPlayerInOrder()
        {
            var mockPlayerA = new Mock<IDartsPlayer>();
            mockPlayerA.SetupGet(p => p.RemainingPoints).Returns(100);
            var mockPlayerB = new Mock<IDartsPlayer>();
            mockPlayerB.SetupGet(p => p.RemainingPoints).Returns(100);
            var game = new Darts301Game(mockPlayerA.Object, mockPlayerB.Object);

            game.PlayNextTurn();
            mockPlayerA.Verify(p => p.PlayTurn(), Times.Once, "First player should play first");

            game.PlayNextTurn();
            mockPlayerB.Verify(p => p.PlayTurn(), Times.Once, "Second player should play next");
            Assert.Equal(mockPlayerA.Object, game.NextTurnPlayer);
        }
Ejemplo n.º 2
0
        public void PlayNextTurn_IncreasesTheTurnIndex()
        {
            var mockPlayer = new Mock<IDartsPlayer>();
            mockPlayer.SetupGet(p => p.RemainingPoints).Returns(5);
            var game = new Darts301Game(mockPlayer.Object);
            game.PlayNextTurn();

            Assert.Equal(2, game.TurnNumber);
        }
Ejemplo n.º 3
0
        public void PlayNextTurn_WhenGameIsFinished_ThrowsException()
        {
            var mockPlayer = new Mock<IDartsPlayer>();
            mockPlayer.SetupGet(p => p.RemainingPoints).Returns(0);
            var game = new Darts301Game(mockPlayer.Object);

            Assert.Throws<InvalidOperationException>(() => game.PlayNextTurn());
        }
Ejemplo n.º 4
0
        public void PlayNextTurn_WillGetBackToFirstPlayer_AfterAllPlayersPlayed()
        {
            var mockPlayerA = new Mock<IDartsPlayer>();
            mockPlayerA.SetupGet(p => p.RemainingPoints).Returns(100);
            var mockPlayerB = new Mock<IDartsPlayer>();
            mockPlayerB.SetupGet(p => p.RemainingPoints).Returns(100);
            var game = new Darts301Game(mockPlayerA.Object, mockPlayerB.Object);

            game.PlayNextTurn();
            mockPlayerA.Verify(p => p.PlayTurn(), Times.Once, "First player should play first");

            game.PlayNextTurn();
            mockPlayerB.Verify(p => p.PlayTurn(), Times.Once, "Second player should play next");

            game.PlayNextTurn();
            mockPlayerA.Verify(p => p.PlayTurn(), Times.Exactly(2), "First player should play again");
        }
Ejemplo n.º 5
0
        public void PlayNextTurn_StartsByFirstPlayerAndMovesToSecond()
        {
            var mockPlayerA = new Mock<IDartsPlayer>();
            mockPlayerA.SetupGet(p => p.RemainingPoints).Returns(100);
            var mockPlayerB = new Mock<IDartsPlayer>();
            mockPlayerB.SetupGet(p => p.RemainingPoints).Returns(100);
            var game = new Darts301Game(mockPlayerA.Object, mockPlayerB.Object);

            game.PlayNextTurn();
            var nextPlayer = game.NextTurnPlayer;

            Assert.Equal(mockPlayerB.Object, nextPlayer);
            mockPlayerA.Verify(p => p.PlayTurn(), Times.Once);
        }