예제 #1
0
        public void Play_WontPlayIfAlreadyFinished()
        {
            var game = new Mock<IDartsGame>();
            game.Setup(g => g.Finished).Returns(true);

            var gameDriver = new GameDriver(game.Object);
            gameDriver.Play();

            game.Verify(g => g.PlayNextTurn(), Times.Never);
        }
예제 #2
0
        public void Play_KeepsPlayingTurnUntilGameIsFinished()
        {
            var game = new Mock<IDartsGame>();
            game.SetupSequence(g => g.Finished)
                .Returns(false)
                .Returns(false)
                .Returns(true);

            var gameDriver = new GameDriver(game.Object);
            gameDriver.Play();

            game.Verify(g => g.PlayNextTurn(), Times.Exactly(2));
        }
예제 #3
0
        public void PlayOnceForSolvedBoard()
        {
            GameDriver      gameDriver = GetGameDriver(out GameDriverContext gameDriverContext);
            AccessibleBoard board      = new AccessibleBoard
            {
                AccessibleIsSolved = true
            };
            GameFlow flow = gameDriver.Play(board);

            gameDriverContext.BoardRenderer.Verify(br => br.Render(It.IsAny <Board>()), Times.Once);
            gameDriverContext.IO.Verify(io => io.Clear(), Times.Once);
            gameDriverContext.IO.Verify(io => io.WriteLine(Match.Create <string>(b => b == RENDERED_BOARD), It.IsAny <int>()), Times.Once);
            gameDriverContext.IO.Verify(io => io.Read(It.IsAny <string>()), Times.Once);
            Assert.Equal(GameFlow.NEW_GAME, flow);
        }
예제 #4
0
        public void ADarts301GameCanBePlayed()
        {
            var playerAMockThrower = new Mock<IDartsThrower>();
            playerAMockThrower.SetupSequence(dt => dt.ThrowDart()).Returns(60).Returns(60).Returns(60).Returns(60).Returns(60).Returns(1);
            var playerBMockThrower = new Mock<IDartsThrower>();
            playerBMockThrower.Setup(dt => dt.ThrowDart()).Returns(20);

            var game = new Darts301Game(
                            new DartsPlayer(playerAMockThrower.Object),
                            new DartsPlayer(playerBMockThrower.Object));
            var gameDriver = new GameDriver(game);
            gameDriver.Play();

            Assert.True(game.Finished);
            Assert.Equal(game.Winner, game.Players.First());
        }
예제 #5
0
        public void StopPlayingWhenFlowIsNotKeepPlaying()
        {
            GameDriver      gameDriver = GetGameDriver(out GameDriverContext gameDriverContext);
            AccessibleBoard board      = new AccessibleBoard
            {
                AccessibleIsSolved = false
            };

            gameDriverContext.ActionReader.Setup(ar => ar.ReadAction(It.IsAny <Board>())).Returns("some action");
            gameDriverContext.ActionApplier.Setup(aa => aa.ApplyAction(It.IsAny <Board>(), It.IsAny <string>())).Returns(GameFlow.END_GAME);

            GameFlow flow = gameDriver.Play(board);

            gameDriverContext.BoardRenderer.Verify(br => br.Render(It.IsAny <Board>()), Times.Once);
            gameDriverContext.IO.Verify(io => io.Clear(), Times.Once);
            gameDriverContext.IO.Verify(io => io.WriteLine(Match.Create <string>(b => b == RENDERED_BOARD), It.IsAny <int>()), Times.Once);
            gameDriverContext.ActionReader.Verify(ar => ar.ReadAction(It.IsAny <Board>()), Times.Once);
            gameDriverContext.ActionApplier.Verify(aa => aa.ApplyAction(It.IsAny <Board>(), It.IsAny <string>()), Times.Once);
            Assert.Equal(GameFlow.END_GAME, flow);
        }