public void BuildRoadSegment_MainPlayerFirstToBuildLongestRoad_MainPlayerGetsTwoVictoryPoints() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 5); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Act localGameController.BuildRoadSegment(turnToken, 4, 3); localGameController.BuildRoadSegment(turnToken, 3, 2); localGameController.BuildRoadSegment(turnToken, 2, 1); localGameController.BuildRoadSegment(turnToken, 1, 0); // Assert player.VictoryPoints.ShouldBe(4u); }
public void StartOfMainPlayerTurn_ChooseResourceFromOpponentCalledOutOfSequence_MeaningfulErrorIsReceived() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 7u, 0u }); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; var resourceUpdateReceived = false; localGameController.ResourcesTransferredEvent = (ResourceTransactionList r) => { resourceUpdateReceived = true; }; // Act localGameController.ChooseResourceFromOpponent(testInstances.FirstOpponent.Id); // Assert resourceUpdateReceived.ShouldBeFalse(); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot call 'ChooseResourceFromOpponent' until 'SetRobberLocation' has completed."); }
public void LaunchGame_GameLaunchedAfterJoining_InitialBoardPassedBack() { var mockDice = new MockDiceCreator() .AddExplicitDiceRollSequence(new uint[] { 12, 10, 8, 2 }) .Create(); var player = new MockPlayer(PlayerName); var opponents = new[] { new MockComputerPlayer(FirstOpponentName), new MockComputerPlayer(SecondOpponentName), new MockComputerPlayer(ThirdOpponentName) }; var mockPlayerFactory = LocalGameControllerTestCreator.CreateMockPlayerPool(player, opponents); var localGameController = new LocalGameControllerCreator().ChangeDice(mockDice).ChangePlayerPool(mockPlayerFactory).Create(); GameBoardSetup gameBoardData = null; localGameController.InitialBoardSetupEvent = (GameBoardSetup g) => { gameBoardData = g; }; localGameController.JoinGame(); localGameController.LaunchGame(); gameBoardData.ShouldNotBeNull(); }
public void BuildRoadSegment_WithoutRequiredResourcesAvailable_MeaningfulErrorIsReceived(Int32 brickCount, Int32 lumberCount, String expectedErrorMessage) { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; var player = testInstances.MainPlayer; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); player.AddResources(new ResourceClutch(brickCount, 0, lumberCount, 0, 0)); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Act localGameController.BuildRoadSegment(turnToken, 4u, 3u); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe(expectedErrorMessage); }
public void BuildSettlement_ValidScenario_SettlementBuiltEventRaised() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment); // Need resources to build the precursor road player.AddResources(ResourceClutch.Settlement); Boolean settlementBuilt = false; localGameController.SettlementBuiltEvent = s => { settlementBuilt = true; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); localGameController.BuildRoadSegment(turnToken, MainRoadOneEnd, 3); // Act localGameController.BuildSettlement(turnToken, 3); // Assert settlementBuilt.ShouldBeTrue(); player.VictoryPoints.ShouldBe(3u); player.Resources.Count.ShouldBe(0); }
public void BuildRoadSegment_MainPlayerFirstToBuildLongestRoad_LongestRoadEventRaised() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 5); Guid previousPlayerId = player.Id; // Ensure there is a noticable state change; Guid newPlayerId = Guid.NewGuid(); localGameController.LongestRoadBuiltEvent = (Guid pid, Guid nid) => { previousPlayerId = pid; newPlayerId = nid; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Act localGameController.BuildRoadSegment(turnToken, 4, 3); localGameController.BuildRoadSegment(turnToken, 3, 2); localGameController.BuildRoadSegment(turnToken, 2, 1); localGameController.BuildRoadSegment(turnToken, 1, 0); // Assert previousPlayerId.ShouldBe(Guid.Empty); newPlayerId = player.Id; }
public void BuildCity_InsufficientResources_MeaningfulErrorIsReceived(Int32 grainCount, Int32 oreCount, String expectedMessage) { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; var player = testInstances.MainPlayer; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); player.AddResources(new ResourceClutch(0, grainCount, 0, oreCount, 0)); Boolean cityBuilt = false; localGameController.CityBuiltEvent = c => { cityBuilt = true; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); // Act localGameController.BuildCity(turnToken, MainSettlementOneLocation); // Assert cityBuilt.ShouldBeFalse(); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe(expectedMessage); }
public void BuildCity_OnExistingCityBelongingToOpponent_MeaningfulErrorIsReceived() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); var player = testInstances.MainPlayer; var firstOpponent = testInstances.FirstOpponent; testInstances.Dice.AddSequence(new[] { 8u, 8u, 8u, 8u, 8u }); player.AddResources(ResourceClutch.City); firstOpponent.AddResources(ResourceClutch.City); firstOpponent.AddBuildCityInstruction(new BuildCityInstruction { Location = FirstSettlementOneLocation }); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); localGameController.EndTurn(turnToken); // Act localGameController.BuildCity(turnToken, FirstSettlementOneLocation); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build city. Location " + FirstSettlementOneLocation + " is owned by player '" + FirstOpponentName + "'."); }
private LocalGameControllerTestCreator.TestInstances TestSetupWithExplictGameBoard(Guid bankId, DevelopmentCard developmentCard, GameBoard gameBoard) { MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; LocalGameControllerTestCreator.CreateDefaultPlayerInstances(out player, out firstOpponent, out secondOpponent, out thirdOpponent); var playerPool = LocalGameControllerTestCreator.CreateMockPlayerPool(player, firstOpponent, secondOpponent, thirdOpponent); playerPool.GetBankId().Returns(bankId); var playerSetup = new LocalGameControllerTestCreator.PlayerSetup(player, firstOpponent, secondOpponent, thirdOpponent, playerPool); var testInstances = LocalGameControllerTestCreator.CreateTestInstances( null, playerSetup, this.CreateMockCardDevelopmentCardHolder(developmentCard), gameBoard); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); // First turn roll i.e. no robber triggered return(testInstances); }
public void BuyDevelopmentCard_InsufficientResources_MeaningfulErrorIsReceived(Int32 grainCount, Int32 oreCount, Int32 woolCount, String expectedErrorMessage) { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); var player = testInstances.MainPlayer; testInstances.Dice.AddSequence(new[] { 8u }); player.AddResources(new ResourceClutch(0, grainCount, 0, oreCount, woolCount)); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; Boolean developmentCardPurchased = false; localGameController.DevelopmentCardPurchasedEvent = (DevelopmentCard d) => { developmentCardPurchased = true; }; localGameController.StartGamePlay(); // Act localGameController.BuyDevelopmentCard(turnToken); // Assert developmentCardPurchased.ShouldBeFalse(); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe(expectedErrorMessage); }
private LocalGameControllerTestCreator.TestInstances TestSetupWithExplicitDevelopmentCardHolder(IDevelopmentCardHolder developmentCardHolder) { var testInstances = LocalGameControllerTestCreator.CreateTestInstances(developmentCardHolder); LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(testInstances.LocalGameController); testInstances.Dice.AddSequence(new[] { 8u }); // First turn roll i.e. no robber triggered return(testInstances); }
private TestInstances TestSetup(IDevelopmentCardHolder developmentCardHolder) { var testInstances = LocalGameControllerTestCreator.CreateTestInstances(developmentCardHolder); LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(testInstances.LocalGameController); testInstances.Dice.AddSequence(new[] { 8u }); return(testInstances); }
public void CompleteSetupForPlayer_PlayerGetsExpectedStartingVictoryPoints() { var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.MainPlayer.VictoryPoints.ShouldBe(2u); }
public void CompleteSetupForComputerPlayers_ComputerPlayersGetExpectedStartingVictoryPoints() { var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(testInstances.LocalGameController); testInstances.FirstOpponent.VictoryPoints.ShouldBe(2u); testInstances.SecondOpponent.VictoryPoints.ShouldBe(2u); testInstances.ThirdOpponent.VictoryPoints.ShouldBe(2u); }
private LocalGameControllerTestCreator.TestInstances TestSetup() { var testInstances = LocalGameControllerTestCreator.CreateTestInstances(null, null, null, new GameBoard(BoardSizes.Standard)); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); // First turn roll i.e. no robber triggered return(testInstances); }
protected LocalGameController CreateLocalGameController(INumberGenerator dice, IPlayer firstPlayer, params IPlayer[] otherPlayers) { var mockPlayerPool = LocalGameControllerTestCreator.CreateMockPlayerPool(firstPlayer, otherPlayers); var localGameController = new LocalGameControllerCreator() .ChangeDice(dice) .ChangePlayerPool(mockPlayerPool) .Create(); localGameController.ErrorRaisedEvent = (ErrorDetails e) => { throw new Exception(e.Message); }; return(localGameController); }
public void Load_PlayerAndInfrastructureData_GameBoardIsAsExpected() { // Arrange Guid playerId = Guid.NewGuid(), firstOpponentId = Guid.NewGuid(), secondOpponentId = Guid.NewGuid(), thirdOpponentId = Guid.NewGuid(); var localGameController = LocalGameControllerTestCreator.CreateTestInstances().LocalGameController; GameBoard boardData = null; localGameController.GameLoadedEvent = (PlayerDataBase[] pd, GameBoard bd) => { boardData = bd; }; // Act var streamContent = "<game>" + "<players>" + "<player id=\"" + playerId + "\" name=\"" + PlayerName + "\" brick=\"5\" grain=\"\" />" + "<player id=\"" + firstOpponentId + "\" name=\"" + FirstOpponentName + "\" brick=\"6\" />" + "<player id=\"" + secondOpponentId + "\" name=\"" + SecondOpponentName + "\" brick=\"7\" />" + "<player id=\"" + thirdOpponentId + "\" name=\"" + ThirdOpponentName + "\" brick=\"8\" />" + "</players>" + "<settlements>" + "<settlement playerid=\"" + playerId + "\" location=\"" + MainSettlementOneLocation + "\" />" + "<settlement playerid=\"" + playerId + "\" location=\"" + MainSettlementTwoLocation + "\" />" + "<settlement playerid=\"" + firstOpponentId + "\" location=\"" + FirstSettlementOneLocation + "\" />" + "</settlements>" + "<roads>" + "<road playerid=\"" + playerId + "\" start=\"" + MainSettlementOneLocation + "\" end=\"" + MainRoadOneEnd + "\" />" + "</roads>" + "</game>"; var streamContentBytes = Encoding.UTF8.GetBytes(streamContent); using (var stream = new MemoryStream(streamContentBytes)) { localGameController.Load(stream); } // Assert boardData.ShouldNotBeNull(); var settlements = boardData.GetSettlementData(); settlements.Count.ShouldBe(3); settlements.ShouldContainKeyAndValue(MainSettlementOneLocation, playerId); settlements.ShouldContainKeyAndValue(MainSettlementTwoLocation, playerId); settlements.ShouldContainKeyAndValue(FirstSettlementOneLocation, firstOpponentId); var roads = boardData.GetRoadData(); roads.Length.ShouldBe(1); roads[0].ShouldBe(new Tuple <UInt32, UInt32, Guid>(MainSettlementOneLocation, MainRoadOneEnd, playerId)); }
public static TestInstances CreateTestInstances(MockDice mockNumGenerator, PlayerSetup playerSetup, IDevelopmentCardHolder developmentCardHolder, GameBoard gameBoard) { MockDice mockNumberGenerator = null; if (mockNumGenerator != null) { mockNumberGenerator = mockNumGenerator; } else { mockNumberGenerator = LocalGameControllerTestCreator.CreateMockNumberGenerator(); } MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; IPlayerFactory playerPool = null; if (playerSetup != null) { player = playerSetup.Player; firstOpponent = playerSetup.FirstOpponent; secondOpponent = playerSetup.SecondOpponent; thirdOpponent = playerSetup.ThirdOpponent; playerPool = playerSetup.PlayerPool; } else { LocalGameControllerTestCreator.CreateDefaultPlayerInstances(out player, out firstOpponent, out secondOpponent, out thirdOpponent); playerPool = LocalGameControllerTestCreator.CreateMockPlayerPool(player, firstOpponent, secondOpponent, thirdOpponent); } if (developmentCardHolder == null) { developmentCardHolder = new DevelopmentCardHolder(); } if (gameBoard == null) { gameBoard = new GameBoard(BoardSizes.Standard); } var localGameController = new LocalGameController(mockNumberGenerator, playerPool, gameBoard, developmentCardHolder); localGameController.ErrorRaisedEvent = (ErrorDetails e) => { throw new Exception(e.Message); }; var testInstances = new TestInstances(localGameController, player, firstOpponent, secondOpponent, thirdOpponent, mockNumberGenerator); return(testInstances); }
private LocalGameControllerTestCreator.TestInstances TestSetup(IDevelopmentCardHolder developmentCardHolder, GameBoard gameBoard) { var testInstances = LocalGameControllerTestCreator.CreateTestInstances(null, null, developmentCardHolder, gameBoard); testInstances.Dice.AddSequence(new[] { 8u }); LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(testInstances.LocalGameController); this.LoadPlayersByIdForCustomAsserts(testInstances.MainPlayer, testInstances.FirstOpponent, testInstances.SecondOpponent, testInstances.ThirdOpponent); return(testInstances); }
public void BuildRoadSegment_GameIsOver_MeaningfulErrorIsReceived() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 6); player.AddResources(ResourceClutch.Settlement * 3); player.AddResources(ResourceClutch.City * 4); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); localGameController.BuildRoadSegment(turnToken, 4u, 3u); localGameController.BuildRoadSegment(turnToken, 3u, 2u); localGameController.BuildRoadSegment(turnToken, 2u, 1u); localGameController.BuildRoadSegment(turnToken, 2u, 10u); localGameController.BuildSettlement(turnToken, 1); localGameController.BuildSettlement(turnToken, 3); localGameController.BuildSettlement(turnToken, 10); localGameController.BuildCity(turnToken, 1); localGameController.BuildCity(turnToken, 3); localGameController.BuildCity(turnToken, 10); localGameController.BuildCity(turnToken, 12); localGameController.BuildRoadSegment(turnToken, 1, 0); // Got 10VP, Game is over // Act localGameController.BuildRoadSegment(turnToken, LocalGameControllerTestCreator.MainRoadTwoEnd, 47); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build road segment. Game is over."); }
public void Scenario_OpponentBuildsLongerRoadThanPlayer_LongestRoadEventReturned() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); var player = testInstances.MainPlayer; var firstOpponent = testInstances.FirstOpponent; testInstances.Dice.AddSequence(new uint[] { 8, 8, 8, 8, 8 }); player.AddResources(ResourceClutch.RoadSegment * 5); firstOpponent.AddResources(ResourceClutch.RoadSegment * 6); firstOpponent.AddBuildRoadSegmentInstruction(new BuildRoadSegmentInstruction { Locations = new UInt32[] { 17, 16, 16, 27, 27, 28, 28, 29, 29, 18 } }); var actualEvents = new List <List <GameEvent> >(); localGameController.GameEvents = (List <GameEvent> e) => { actualEvents.Add(e); }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); localGameController.BuildRoadSegment(turnToken, 4, 3); localGameController.BuildRoadSegment(turnToken, 3, 2); localGameController.BuildRoadSegment(turnToken, 2, 10); localGameController.BuildRoadSegment(turnToken, 10, 9); // Act - Opponent builds longer road. localGameController.EndTurn(turnToken); // Assert var expectedEvents = new GameEvent[] { new RoadSegmentPlacedEvent(firstOpponent.Id, 17, 16), new RoadSegmentPlacedEvent(firstOpponent.Id, 16, 27), new RoadSegmentPlacedEvent(firstOpponent.Id, 27, 28), new RoadSegmentPlacedEvent(firstOpponent.Id, 28, 29), new RoadSegmentPlacedEvent(firstOpponent.Id, 29, 18), new LongestRoadBuiltEvent(firstOpponent.Id, null, player.Id) }; //actualEvents.ShouldContainExact(expectedEvents); }
public void TradeWithBank_GameIsOver_MeaningfulErrorIsReceived() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 5); player.AddResources(ResourceClutch.Settlement * 3); player.AddResources(ResourceClutch.City * 4); player.AddResources(ResourceClutch.OneBrick * 4); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); localGameController.BuildRoadSegment(turnToken, 4u, 3u); localGameController.BuildRoadSegment(turnToken, 3u, 2u); localGameController.BuildRoadSegment(turnToken, 2u, 1u); localGameController.BuildRoadSegment(turnToken, 1u, 0u); // Got 2VP for longest road (4VP) localGameController.BuildRoadSegment(turnToken, 2u, 10u); localGameController.BuildSettlement(turnToken, 3); localGameController.BuildSettlement(turnToken, 10); localGameController.BuildCity(turnToken, 3); localGameController.BuildCity(turnToken, 10); localGameController.BuildCity(turnToken, 12); localGameController.BuildCity(turnToken, 40); // Got 10VP, Game over event raised // Act localGameController.TradeWithBank(turnToken, ResourceTypes.Grain, 1, ResourceTypes.Brick); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot trade with bank. Game is over."); }
public void PlayerPlacesSettlementOffGameBoardDuringFirstSetupRound_MeaningfulErrorReceived() { var localGameController = LocalGameControllerTestCreator.CreateTestInstances() .LocalGameController; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.JoinGame(); localGameController.LaunchGame(); localGameController.StartGameSetup(); localGameController.ContinueGameSetup(100, 101); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build settlement. Location 100 is outside of board range (0 - 53)."); }
public void PlayerPlacesRoadOverEdgeOfGameBoardDuringFirstSetupRound_MeaningfulErrorIsReceived() { var localGameController = LocalGameControllerTestCreator.CreateTestInstances() .LocalGameController; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.JoinGame(); localGameController.LaunchGame(); localGameController.StartGameSetup(); localGameController.ContinueGameSetup(53, 54); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build road segment. Locations 53 and/or 54 are outside of board range (0 - 53)."); }
public void PlayerPlacesRoadWhereNoConnectionExistsDuringFirstSetupRound_MeaningfulErrorIsReceived() { var localGameController = LocalGameControllerTestCreator.CreateTestInstances() .LocalGameController; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.JoinGame(); localGameController.LaunchGame(); localGameController.StartGameSetup(); localGameController.ContinueGameSetup(28, 40); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build road segment. No direct connection between locations [28, 40]."); }
public void BuildRoadSegment_MainPlayerBuildsLongerRoadThanOpponent_LongestRoadEventRaised() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u, 8u, 8u, 8u, 8u }); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 7); var firstOpponent = testInstances.FirstOpponent; firstOpponent.AddResources(ResourceClutch.RoadSegment * 6); firstOpponent.AddBuildRoadSegmentInstruction(new BuildRoadSegmentInstruction { Locations = new UInt32[] { 17, 16, 16, 27, 27, 28, 28, 29, 29, 18 } }); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; Guid previousLongestRoadPlayerId = Guid.Empty; Guid newLongestRoadPlayerId = Guid.Empty; localGameController.LongestRoadBuiltEvent = (Guid p, Guid n) => { previousLongestRoadPlayerId = p; newLongestRoadPlayerId = n; }; localGameController.StartGamePlay(); localGameController.BuildRoadSegment(turnToken, 4, 3); localGameController.BuildRoadSegment(turnToken, 3, 2); localGameController.BuildRoadSegment(turnToken, 2, 10); localGameController.BuildRoadSegment(turnToken, 10, 9); localGameController.EndTurn(turnToken); // First opponent builds 6 road segments to take the longest road title // Build two more road segments for a new longest road of 7 localGameController.BuildRoadSegment(turnToken, 9, 8); localGameController.BuildRoadSegment(turnToken, 8, 0); // Assert previousLongestRoadPlayerId.ShouldBe(firstOpponent.Id); newLongestRoadPlayerId.ShouldBe(player.Id); }
public void BuildSettlement_GotNineVictoryPoints_EndOfGameEventRaisedWithPlayerAsWinner() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u }); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 5); player.AddResources(ResourceClutch.Settlement * 4); player.AddResources(ResourceClutch.City * 4); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; Guid winningPlayer = Guid.Empty; localGameController.GameOverEvent = (Guid g) => { winningPlayer = g; }; localGameController.StartGamePlay(); localGameController.BuildRoadSegment(turnToken, 4u, 3u); localGameController.BuildRoadSegment(turnToken, 3u, 2u); localGameController.BuildRoadSegment(turnToken, 2u, 1u); localGameController.BuildRoadSegment(turnToken, 1u, 0u); // Got 2VP for longest road (4VP) localGameController.BuildRoadSegment(turnToken, 2u, 10u); localGameController.BuildSettlement(turnToken, 3); localGameController.BuildSettlement(turnToken, 10); localGameController.BuildCity(turnToken, 3); localGameController.BuildCity(turnToken, 10); localGameController.BuildCity(turnToken, 40); // Act localGameController.BuildSettlement(turnToken, 1); // Assert winningPlayer.ShouldBe(player.Id); player.VictoryPoints.ShouldBe(10u); }
public void PlayerSelectsLocationTooCloseToComputerPlayerDuringSecondSetupRound_MeaningfulErrorIsReceived() { var localGameController = LocalGameControllerTestCreator.CreateTestInstances() .LocalGameController; ErrorDetails exception = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { exception = e; }; localGameController.JoinGame(); localGameController.LaunchGame(); localGameController.StartGameSetup(); localGameController.ContinueGameSetup(0, 1); localGameController.CompleteGameSetup(19, 18); exception.ShouldNotBeNull(); exception.Message.ShouldBe("Cannot build settlement. Too close to player '" + FirstOpponentName + "' at location " + FirstSettlementOneLocation + "."); }
public void CompleteSetupWithPlayerInSecondSlot_ExpectedPlacementsAreReturned() { var gameSetupOrder = new[] { 10u, 12u, 8u, 6u }; var mockDice = new MockDiceCreator() .AddExplicitDiceRollSequence(gameSetupOrder) .Create(); var testInstances = LocalGameControllerTestCreator.CreateTestInstances(mockDice); var firstOpponent = testInstances.FirstOpponent; var secondOpponent = testInstances.SecondOpponent; var thirdOpponent = testInstances.ThirdOpponent; var localGameController = testInstances.LocalGameController; var gameEvents = new List <GameEvent>(); localGameController.GameEvents = (List <GameEvent> e) => { gameEvents = e; }; localGameController.JoinGame(); localGameController.LaunchGame(); localGameController.StartGameSetup(); gameEvents.Count.ShouldBe(1); gameEvents[0].ShouldBe(new SetupInfrastructurePlacedEvent(firstOpponent.Id, FirstSettlementOneLocation, FirstRoadOneEnd)); gameEvents.Clear(); localGameController.ContinueGameSetup(MainSettlementOneLocation, MainRoadOneEnd); gameEvents.Count.ShouldBe(6); gameEvents[0].ShouldBe(new SetupInfrastructurePlacedEvent(secondOpponent.Id, SecondSettlementOneLocation, SecondRoadOneEnd)); gameEvents[1].ShouldBe(new SetupInfrastructurePlacedEvent(thirdOpponent.Id, ThirdSettlementOneLocation, ThirdRoadOneEnd)); gameEvents[2].ShouldBe(new SetupInfrastructurePlacedEvent(thirdOpponent.Id, ThirdSettlementTwoLocation, ThirdRoadTwoEnd)); //gameEvents[3].ShouldBe(new ResourcesCollectedEvent(thirdOpponent.Id, new[] { new ResourceCollection(ThirdSettlementTwoLocation, new ResourceClutch(0, 1, 1, 0, 1)) })); gameEvents[4].ShouldBe(new SetupInfrastructurePlacedEvent(secondOpponent.Id, SecondSettlementTwoLocation, SecondRoadTwoEnd)); //gameEvents[5].ShouldBe(new ResourcesCollectedEvent(secondOpponent.Id, new[] { new ResourceCollection(SecondSettlementTwoLocation, new ResourceClutch(0, 0, 1, 1, 1)) })); gameEvents.Clear(); localGameController.CompleteGameSetup(MainSettlementTwoLocation, MainRoadTwoEnd); gameEvents.Count.ShouldBe(3); //gameEvents[0].ShouldBe(new ResourcesCollectedEvent(testInstances.MainPlayer.Id, new[] { new ResourceCollection(MainSettlementTwoLocation, new ResourceClutch(1, 1, 0, 0, 1)) })); gameEvents[1].ShouldBe(new SetupInfrastructurePlacedEvent(firstOpponent.Id, FirstSettlementTwoLocation, FirstRoadTwoEnd)); //gameEvents[2].ShouldBe(new ResourcesCollectedEvent(firstOpponent.Id, new[] { new ResourceCollection(FirstSettlementTwoLocation, new ResourceClutch(0, 1, 1, 0, 1)) })); }
public void BuildRoadSegment_MainPlayerBuildsLongerRoadThanOpponent_VictoryPointsChangesFromOpponentToPlayer() { // Arrange var testInstances = LocalGameControllerTestCreator.CreateTestInstances(); var localGameController = testInstances.LocalGameController; LocalGameControllerTestSetup.LaunchGameAndCompleteSetup(localGameController); testInstances.Dice.AddSequence(new[] { 8u, 8u, 8u, 8u, 8u }); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 7); var firstOpponent = testInstances.FirstOpponent; firstOpponent.AddResources(ResourceClutch.RoadSegment * 6); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; Guid previousLongestRoadPlayerId = Guid.Empty; Guid newLongestRoadPlayerId = Guid.Empty; localGameController.LongestRoadBuiltEvent = (Guid p, Guid n) => { previousLongestRoadPlayerId = p; newLongestRoadPlayerId = n; }; localGameController.StartGamePlay(); localGameController.BuildRoadSegment(turnToken, 4, 3); localGameController.BuildRoadSegment(turnToken, 3, 2); localGameController.BuildRoadSegment(turnToken, 2, 10); localGameController.BuildRoadSegment(turnToken, 10, 9); localGameController.EndTurn(turnToken); localGameController.BuildRoadSegment(turnToken, 9, 8); localGameController.BuildRoadSegment(turnToken, 8, 0); // Assert player.VictoryPoints.ShouldBe(4u); firstOpponent.VictoryPoints.ShouldBe(2u); }