Example #1
0
        public void ExecuteFinishesGameIfVerifyWinConditionIsTrue()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<ITurn>();
            turn.Setup(t => t.Player).Returns(players.First());
            turn.Setup(t => t.CanExecute(It.IsAny<GameCommand>())).Returns(true);

            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var command = new Mock<IPlayerCommand>();
            command.Setup(c => c.Player).Returns(players.First());
            var bank = new Mock<IBank>();
            bank.Setup(b => b.VerifyWinCondition(It.IsAny<IPlayer>())).Returns(true);

            var game = new Game(players, provider.Object, bank.Object);
            game.Start();

            bool finished = false;
            game.Finished += (sender, args) => { finished = true; };

            game.Execute(command.Object);

            Assert.True(finished);
        }
Example #2
0
        public void CanNoLongerExecuteWhenGameIsFinished()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<ITurn>();
            turn.Setup(t => t.Player).Returns(players.First());
            turn.Setup(t => t.CanExecute(It.IsAny<GameCommand>())).Returns(true);

            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var command = new Mock<IPlayerCommand>();
            command.Setup(c => c.Player).Returns(players.First());
            var bank = new Mock<IBank>();
            bank.Setup(b => b.VerifyWinCondition(It.IsAny<IPlayer>())).Returns(true);

            var game = new Game(players, provider.Object, bank.Object);
            game.Start();

            game.Execute(command.Object);

            Assert.Throws<InvalidOperationException>(() => game.Execute(command.Object));
        }
Example #3
0
        public void ExecuteTest()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<ITurn>();
            turn.Setup(t => t.Player).Returns(players.First());
            turn.Setup(t => t.CanExecute(It.IsAny<GameCommand>())).Returns(true);

            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var command = new Mock<IPlayerCommand>();
            command.Setup(c => c.Player).Returns(players.First());
            var bank = new Mock<IBank>();

            var game = new Game(players, provider.Object, bank.Object);
            game.Start();

            game.Execute(command.Object);

            command.Verify(c => c.Execute());
            bank.Verify(b => b.VerifyWinCondition(It.IsAny<IPlayer>()));
            bank.Verify(b => b.UpdateAchievements(It.IsAny<IPlayer>()));
            turn.Verify(t => t.AfterExecute(It.IsAny<GameCommand>()));
        }
Example #4
0
        public void ExecuteFailsIfGameNotStarted()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<ITurn>();
            turn.Setup(t => t.Player).Returns(players.First());
            turn.Setup(t => t.CanExecute(It.IsAny<GameCommand>())).Returns(true);

            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var command = new Mock<IPlayerCommand>();
            command.Setup(c => c.Player).Returns(players.First());
            var bank = new Mock<IBank>();

            var game = new Game(players, provider.Object, bank.Object); ;

            Assert.Throws<InvalidOperationException>(() => game.Execute(command.Object));
        }
Example #5
0
        public void ExecuteFailsIfCurrentTurnCantExecuteCommand()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<ITurn>();
            var player = players.First();
            turn.Setup(t => t.Player).Returns(player);
            turn.Setup(t => t.CanExecute(It.IsAny<GameCommand>())).Returns(false);

            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var command = new Mock<IPlayerCommand>();
            command.Setup(c => c.Player).Returns(player);
            var bank = new Mock<IBank>();

            var game = new Game(players, provider.Object, bank.Object);
            game.Start();

            Assert.Throws<ArgumentException>(() => game.Execute(command.Object));
        }
Example #6
0
        public void ExecuteSucceedsWithDifferentPlayerIfCommandIsTrade()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<ITurn>();
            turn.Setup(t => t.Player).Returns(players.First());
            turn.Setup(t => t.CanExecute(It.IsAny<GameCommand>())).Returns(true);

            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var command = new Mock<IPlayerCommand>();
            command.Setup(c => c.Player).Returns(players.Skip(1).First());
            command.Setup(c => c.Type).Returns(GameCommand.Trade);
            var bank = new Mock<IBank>();

            var game = new Game(players, provider.Object, bank.Object);
            game.Start();
            game.Execute(command.Object);

            command.Verify(c => c.Execute());
            turn.Verify(t => t.AfterExecute(It.IsAny<GameCommand>()));
        }
Example #7
0
        public void ExecuteFailsIfCommandNull()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<ITurn>();
            provider.Setup(p => p.GetNext()).Returns(turn.Object);
            var bank = new Mock<IBank>();

            var game = new Game(players, provider.Object, bank.Object);
            game.Start();

            Assert.Throws<ArgumentNullException>(() => game.Execute(null));
        }