コード例 #1
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        public void ConstructionSucceedsWith2To4Players(int playerCount)
        {
            var players = CreateFakePlayers(playerCount);
            var provider = new Mock<ITurnProvider>();
            var bank = new Mock<IBank>();

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

            Assert.Equal(players, game.Players);
        }
コード例 #2
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        public void SecondStartShouldCallShouldDoNothing()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            provider.Setup(p => p.GetNext()).Returns(new Mock<ITurn>().Object);
            var bank = new Mock<IBank>();

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

            int turnSwitches = 0;
            game.TurnStarted += (sender, args) => { turnSwitches++; };

            game.Start();
            game.Start();

            provider.Verify(p => p.GetNext(), Times.Once);
            Assert.Equal(1, turnSwitches);
        }
コード例 #3
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        public void BuyDevelopmentCardFailsIfPlayerNotCurrentTurnPlayer()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<IGameTurn>();
            var player = new Mock<IPlayer>();

            turn.Setup(t => t.Player).Returns(new Mock<IPlayer>().Object);
            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var card = new Mock<IDevelopmentCard>();
            var bank = new Mock<IBank>();

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

            Assert.Throws<InvalidOperationException>(() => game.BuyDevelopmentCard(player.Object));
        }
コード例 #4
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        public void BuyDevelopmentCardTest()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<IGameTurn>();
            var player = new Mock<IPlayer>();

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

            var card = new Mock<IDevelopmentCard>();
            var bank = new Mock<IBank>();

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

            game.BuyDevelopmentCard(player.Object);

            bank.Verify(b => b.BuyDevelopmentCard(player.Object, turn.Object));
        }
コード例 #5
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        public void PlayDevelopmentCardCallsCurrentTurn()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<IGameTurn>();
            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var card = new Mock<IDevelopmentCard>();
            var bank = new Mock<IBank>();

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

            game.PlayDevelopmentCard(card.Object);

            turn.Verify(t => t.PlayDevelopmentCard(card.Object));
        }
コード例 #6
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        public void BuyDevelopmentCardFailsIfPlayerNull()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<IGameTurn>();
            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var card = new Mock<IDevelopmentCard>();
            var bank = new Mock<IBank>();

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

            Assert.Throws<ArgumentNullException>(() => game.BuyDevelopmentCard(null));
        }
コード例 #7
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        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));
        }
コード例 #8
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        public void CantPlayDevelopmentCardIfCurrentTurnIsNotGameTurn()
        {
            var players = CreateFakePlayers(3);
            var provider = new Mock<ITurnProvider>();
            var turn = new Mock<ITurn>();
            provider.Setup(p => p.GetNext()).Returns(turn.Object);

            var card = new Mock<IDevelopmentCard>();
            var bank = new Mock<IBank>();

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

            Assert.Throws<InvalidOperationException>((() => game.PlayDevelopmentCard(card.Object)));
        }
コード例 #9
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        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>()));
        }
コード例 #10
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        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);
        }
コード例 #11
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        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));
        }
コード例 #12
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        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));
        }
コード例 #13
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        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>()));
        }
コード例 #14
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        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));
        }
コード例 #15
0
ファイル: GameTest.cs プロジェクト: Corne/VOC
        public void GameShouldGoToNextTurnIfTurnEnds()
        {
            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);

            int turnSwitches = 0;
            game.TurnStarted += (sender, args) => { turnSwitches++; };

            game.Start();

            turn.Raise(t => t.Ended += null, EventArgs.Empty);

            provider.Verify(p => p.GetNext(), Times.Exactly(2));
            Assert.Equal(2, turnSwitches);
        }