예제 #1
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));
        }
예제 #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 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));
        }
예제 #4
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));
        }
예제 #5
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)));
        }
예제 #6
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));
        }
예제 #7
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);
        }
예제 #8
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));
        }
예제 #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 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));
        }
예제 #11
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>()));
        }
예제 #12
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));
        }
예제 #13
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);
        }