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); }
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); }
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)); }
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)); }
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)); }
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)); }
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)); }
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))); }
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>())); }
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); }
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)); }
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)); }
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>())); }
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)); }
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); }