Пример #1
0
        public void CanExecuteIfCurrentStateHasCommand(GameCommand command, IEnumerable<GameCommand> stateCommands, bool expected)
        {
            var player = new Mock<IPlayer>();
            var state = new Mock<ITurnState>();
            state.Setup(s => s.Commands).Returns(stateCommands);
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(state.Object);

            var turn = new Turn(player.Object, provider.Object);
            turn.NextFlowState();

            bool result = turn.CanExecute(command);

            Assert.Equal(expected, result);
        }
Пример #2
0
        public void ExpectNextFlowStateToCallStateProviderForTheNextState()
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();
            var state2 = new Mock<ITurnState>();
            var stateQueue = new Queue<ITurnState>(new[] { state1.Object, state2.Object });
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(() => stateQueue.Dequeue());

            var turn = new Turn(player.Object, provider.Object);

            bool stateChanged = false;
            turn.StateChanged += (sender, args) =>
            {
                stateChanged = true;
                Assert.Equal(state1.Object, args);
            };
            turn.NextFlowState();

            Assert.True(stateChanged);
            provider.Verify(p => p.GetNext());
        }
Пример #3
0
        public void ExpectPlayDevelopmentCardToSetDevelomentCardState(DevelopmentCardType type)
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(state1.Object);
            state1.Setup(s => s.Commands).Returns(new GameCommand[] { GameCommand.PlayDevelopmentCard });

            var card = new Mock<IDevelopmentCard>();
            card.Setup(c => c.Type).Returns(type);
            var turn = new Turn(player.Object, provider.Object);
            turn.NextFlowState();

            bool changed = false;
            turn.StateChanged += (sender, args) => { changed = true; };

            turn.PlayDevelopmentCard(card.Object);

            provider.Verify(p => p.Get(type));
            Assert.True(changed);
        }
Пример #4
0
        public void CantPlayDevelopmentMultipleDevelopmentCardsIn1Turn()
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(state1.Object);
            state1.Setup(s => s.Commands).Returns(new GameCommand[] { GameCommand.PlayDevelopmentCard });

            var card = new Mock<IDevelopmentCard>();
            card.Setup(c => c.Type).Returns(DevelopmentCardType.Monopoly);
            var turn = new Turn(player.Object, provider.Object);
            turn.NextFlowState();

            turn.PlayDevelopmentCard(card.Object);
            Assert.Throws<InvalidOperationException>(() => turn.PlayDevelopmentCard(card.Object));
        }
Пример #5
0
        public void ExpectPlayDevelopmentCardToFailIfCardIsVictoryPoint()
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(state1.Object);
            state1.Setup(s => s.Commands).Returns(new GameCommand[] { GameCommand.PlayDevelopmentCard });

            var card = new Mock<IDevelopmentCard>();
            card.Setup(c => c.Type).Returns(DevelopmentCardType.VictoryPoint);
            var turn = new Turn(player.Object, provider.Object);
            turn.NextFlowState();

            Assert.Throws<ArgumentException>(() => turn.PlayDevelopmentCard(card.Object));
        }
Пример #6
0
        public void ExpectPlayDevelopmentCardToFailIfNull()
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(state1.Object);
            state1.Setup(s => s.Commands).Returns(new GameCommand[] { GameCommand.PlayDevelopmentCard });

            var turn = new Turn(player.Object, provider.Object);
            turn.NextFlowState();

            Assert.Throws<ArgumentNullException>(() => turn.PlayDevelopmentCard(null));
        }
Пример #7
0
        public void ExpectPlayDevelopmentCardToFailIfCurrentStateCantExecute()
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(state1.Object);
            state1.Setup(s => s.Commands).Returns(new GameCommand[] { GameCommand.BuildRoad });

            var card = new Mock<IDevelopmentCard>();
            card.Setup(c => c.Type).Returns(DevelopmentCardType.RoadBuilding);

            var turn = new Turn(player.Object, provider.Object);
            turn.NextFlowState();

            Assert.Throws<InvalidOperationException>(() => turn.PlayDevelopmentCard(card.Object));
        }
Пример #8
0
        public void ExpectAfterExectueToDelegateCallToCurrentState()
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();
            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(true);
            provider.Setup(p => p.GetNext()).Returns(state1.Object);

            var turn = new Turn(player.Object, provider.Object);
            turn.NextFlowState();
            turn.AfterExecute(GameCommand.RollDice);

            state1.Verify(s => s.AfterExecute(GameCommand.RollDice));
        }
Пример #9
0
        public void ExpectToEndTurnifNoNextFlowState()
        {
            var player = new Mock<IPlayer>();
            var state1 = new Mock<ITurnState>();

            var provider = new Mock<IStateProvider>();
            provider.Setup(p => p.HasNext()).Returns(false);
            provider.Setup(p => p.GetNext()).Returns(state1.Object);

            var turn = new Turn(player.Object, provider.Object);
            bool ended = false;
            turn.Ended += (sender, args) => { ended = true; };

            turn.NextFlowState();
            provider.Verify(p => p.GetNext(), Times.Never);
            Assert.True(ended);     
        }