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 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); }
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 UseYearOfPlentyCard_UseCardPurchasedInSameTurn_MeaningfulErrorIsReceived() { // Arrange var yearOfPlentyCard = new YearOfPlentyDevelopmentCard(); var testInstances = this.TestSetupWithExplictDevelopmentCards(yearOfPlentyCard); var localGameController = testInstances.LocalGameController; testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; DevelopmentCard purchasedDevelopmentCard = null; localGameController.DevelopmentCardPurchasedEvent = (DevelopmentCard d) => { purchasedDevelopmentCard = d; }; localGameController.StartGamePlay(); localGameController.BuyDevelopmentCard(turnToken); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; // Act localGameController.UseYearOfPlentyCard(turnToken, (YearOfPlentyDevelopmentCard)purchasedDevelopmentCard, ResourceTypes.Brick, ResourceTypes.Brick); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot use development card that has been purchased this turn."); }
public void BuildCity_OnLocationThatIsEmpty_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(ResourceClutch.City); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); // Act localGameController.BuildCity(turnToken, 0); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build city. No settlement at location 0."); }
public void BuildCity_OnExistingCityBelongingToPlayer_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(ResourceClutch.City * 2); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); localGameController.BuildCity(turnToken, MainSettlementOneLocation); // Act localGameController.BuildCity(turnToken, MainSettlementOneLocation); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build city. There is already a city at location " + MainSettlementOneLocation + " that belongs to you."); }
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 + "'."); }
public void PlayerSelectsLocationTooCloseToComputerPlayerDuringFirstSetupRound_MeaningfulErrorIsReceived() { var mockDice = new MockDiceCreator() .AddExplicitDiceRollSequence(new uint[] { 10, 12, 8, 6 }) .Create(); MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; this.CreateDefaultPlayerInstances(out player, out firstOpponent, out secondOpponent, out thirdOpponent); var localGameController = this.CreateLocalGameController(mockDice, player, firstOpponent, secondOpponent, thirdOpponent); ErrorDetails exception = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { exception = e; }; localGameController.JoinGame(); localGameController.LaunchGame(); localGameController.StartGameSetup(); localGameController.ContinueGameSetup(19u, 1u); exception.ShouldNotBeNull(); exception.Message.ShouldBe("Cannot build settlement. Too close to player '" + FirstOpponentName + "' at location " + FirstSettlementOneLocation + "."); }
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 UseYearOfPlentyCard_UseDevelopmentCardMoreThanOnce_MeaningfulErrorIsReceived() { // Arrange var yearOfPlentyCard = new YearOfPlentyDevelopmentCard(); var testInstances = this.TestSetupWithExplictDevelopmentCards(yearOfPlentyCard); var localGameController = testInstances.LocalGameController; testInstances.Dice.AddSequenceWithRepeatingRoll(null, 6); testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Buy the year of plenty card localGameController.BuyDevelopmentCard(turnToken); localGameController.EndTurn(turnToken); // Play the same year of plenty card each turn for the next two turns localGameController.UseYearOfPlentyCard(turnToken, yearOfPlentyCard, ResourceTypes.Brick, ResourceTypes.Brick); localGameController.EndTurn(turnToken); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; // Act localGameController.UseYearOfPlentyCard(turnToken, yearOfPlentyCard, ResourceTypes.Brick, ResourceTypes.Brick); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot play the same development card more than once."); }
public void TradeWithBank_PaymentIsWrong_MeaningfulErrorIsReceived(Int32 paymentCount, Int32 receivingCount) { // Arrange var bankId = Guid.NewGuid(); var testInstances = this.TestSetupWithExplictGameBoard(bankId, new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.OneBrick * paymentCount); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.ResourcesTransferredEvent = (ResourceTransactionList r) => { throw new Exception("ResourcesTransferredEvent should not be called."); }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); // Act localGameController.TradeWithBank(turnToken, ResourceTypes.Grain, receivingCount, ResourceTypes.Brick); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot complete trade with bank: Need to pay " + (receivingCount * 4) + " brick for " + receivingCount + " grain. Only paying " + paymentCount + "."); }
public void BuildRoadSegment_OnExistingRoadSegment_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(new ResourceClutch(1, 0, 1, 0, 0)); localGameController.LongestRoadBuiltEvent = (Guid pid, Guid nid) => { throw new NotImplementedException(); }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; PlayerDataBase playerData = null; //localGameController.RoadSegmentBuiltEvent = (PlayerDataBase p) => { playerData = p; }; localGameController.StartGamePlay(); // Act localGameController.BuildRoadSegment(turnToken, MainRoadOneEnd, MainSettlementOneLocation); // Assert Assert.Fail("Fail"); playerData.ShouldBeNull(); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build road segment. Road segment between " + MainRoadOneEnd + " and " + MainSettlementOneLocation + " already exists."); }
public void BuildRoadSegment_NoDirectConnection_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(new ResourceClutch(1, 0, 1, 0, 0)); localGameController.LongestRoadBuiltEvent = (Guid pid, Guid nid) => { throw new NotImplementedException(); }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Act localGameController.BuildRoadSegment(turnToken, MainRoadOneEnd, 0); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build road segment. No direct connection between locations [4, 0]."); }
public void UseKnightCard_UseKnightDevelopmentCardAndTryToMoveRobberToSameSpot_MeaningfulErrorIsReceived() { // Arrange var knightCard = new KnightDevelopmentCard(); var testInstances = this.TestSetup(knightCard); var localGameController = testInstances.LocalGameController; testInstances.Dice.AddSequenceWithRepeatingRoll(null, 6); testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; DevelopmentCard purchasedDevelopmentCard = null; localGameController.DevelopmentCardPurchasedEvent = (DevelopmentCard d) => { purchasedDevelopmentCard = d; }; localGameController.StartGamePlay(); localGameController.BuyDevelopmentCard(turnToken); localGameController.EndTurn(turnToken); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; // Act localGameController.UseKnightCard(turnToken, (KnightDevelopmentCard)purchasedDevelopmentCard, 0); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot place robber back on present hex (0)."); }
public void UseKnightCard_IdParameterDoesNotMatchWithAnyPlayerOnHex_MeaningfulErrorIsReceived() { // Arrange var knightCard = new KnightDevelopmentCard(); var testInstances = this.TestSetup(knightCard); var localGameController = testInstances.LocalGameController; testInstances.Dice.AddSequence(new uint[] { 8, 8, 8, 8 }); testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Buy the knight cards localGameController.BuyDevelopmentCard(turnToken); localGameController.EndTurn(turnToken); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; // Act localGameController.UseKnightCard(turnToken, knightCard, HexWithTwoPlayerSettlements, testInstances.MainPlayer.Id); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Player Id (" + testInstances.MainPlayer.Id + ") does not match with any players on hex " + HexWithTwoPlayerSettlements + "."); }
public void UseKnightCard_NewRobberHexIsOutOfBounds_MeaningfulErrorIsReceived() { // Arrange var knightCard = new KnightDevelopmentCard(); var testInstances = this.TestSetup(knightCard); var localGameController = testInstances.LocalGameController; testInstances.Dice.AddSequence(new uint[] { 8, 8, 8, 8 }); testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; DevelopmentCard purchasedDevelopmentCard = null; localGameController.DevelopmentCardPurchasedEvent = (DevelopmentCard d) => { purchasedDevelopmentCard = d; }; localGameController.StartGamePlay(); localGameController.BuyDevelopmentCard(turnToken); localGameController.EndTurn(turnToken); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; // Act localGameController.UseKnightCard(turnToken, (KnightDevelopmentCard)purchasedDevelopmentCard, GameBoards.GameBoard.StandardBoardHexCount); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot move robber to hex 19 because it is out of bounds (0.. 18)."); }
public void BuyDevelopmentCard_NoMoreDevelopmentCards_MeaningfulErrorIsReceived() { // Arrange var testInstances = this.TestSetup(); testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard * 26); var localGameController = testInstances.LocalGameController; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); for (var i = 25; i > 0; i--) { localGameController.BuyDevelopmentCard(turnToken); } // Act localGameController.BuyDevelopmentCard(turnToken); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot buy development card. No more cards available"); }
public void TradeWithBank_RequestedCountIsWrong_MeaningfulErrorIsReceived(Int32 receivingCount) { // Arrange var testInstances = this.TestSetup(); var localGameController = testInstances.LocalGameController; var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.OneBrick * 4); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.ResourcesTransferredEvent = (ResourceTransactionList r) => { throw new Exception("ResourcesTransferredEvent should not be called."); }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.StartGamePlay(); // Act localGameController.TradeWithBank(turnToken, ResourceTypes.Grain, receivingCount, ResourceTypes.Brick); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot complete trade with bank: Receiving count must be positive. Was " + receivingCount + "."); }
public void BuildCity_TurnTokenNotCorrect_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Act localGameController.BuildCity(new GameToken(), 3); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Turn token not recognised."); }
public void BuildSettlement_ToCloseToOpponentSettlement_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(ResourceClutch.RoadSegment * 7); player.AddResources(ResourceClutch.Settlement); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); var roadSegmentDetails = new UInt32[] { 4, 3, 3, 2, 2, 1, 1, 0, 0, 8, 8, 9, 9, 19 }; for (var index = 0; index < roadSegmentDetails.Length; index += 2) { localGameController.BuildRoadSegment(turnToken, roadSegmentDetails[index], roadSegmentDetails[index + 1]); } // Act localGameController.BuildSettlement(turnToken, 19); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build settlement. Too close to player '" + FirstOpponentName + "' at location 18."); }
public void BuildCity_OnExistingSettlementBelongingToOpponent_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(ResourceClutch.City); bool 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, FirstSettlementOneLocation); // Assert cityBuilt.ShouldBeFalse(); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build city. Location " + FirstSettlementOneLocation + " is owned by player '" + FirstOpponentName + "'."); }
public void BuildSettlement_NotConnectedToExistingRoad_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(ResourceClutch.RoadSegment); player.AddResources(ResourceClutch.Settlement); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); localGameController.BuildRoadSegment(turnToken, 4, 3); // Act localGameController.BuildSettlement(turnToken, 2); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build settlement. Location 2 not connected to existing road."); }
public void LaunchGame_LaunchGameWithoutJoining_MeaningfulErrorIsReceived() { var localGameController = new LocalGameControllerCreator().Create(); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.LaunchGame(); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot call 'LaunchGame' without joining game."); }
public void CompleteGameSetup_CallOutOfSequence_MeaningfulErrorIsReceived() { var localGameController = new LocalGameControllerCreator().Create(); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.CompleteGameSetup(0u, 1u); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot call 'CompleteGameSetup' until 'ContinueGameSetup' has completed."); }
public void UseYearOfPlentyCard_GameIsOver_MeaningfulErrorIsReceived() { // Arrange var testInstances = this.TestSetupWithExplictGameBoard(Guid.Empty, new YearOfPlentyDevelopmentCard(), new MockGameBoardWithNoResourcesCollected()); var localGameController = testInstances.LocalGameController; testInstances.Dice.AddSequenceWithRepeatingRoll(null, 6); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 5); player.AddResources(ResourceClutch.Settlement * 3); player.AddResources(ResourceClutch.City * 4); player.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; YearOfPlentyDevelopmentCard yearOfPlentyCard = null; localGameController.DevelopmentCardPurchasedEvent = (DevelopmentCard d) => { yearOfPlentyCard = (YearOfPlentyDevelopmentCard)d; }; localGameController.StartGamePlay(); localGameController.BuyDevelopmentCard(turnToken); localGameController.EndTurn(turnToken); 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.UseYearOfPlentyCard(turnToken, yearOfPlentyCard, ResourceTypes.Brick, ResourceTypes.Grain); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot use year of plenty card. Game is over."); }
public void BuildCity_AllCitiesAreBuilt_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(ResourceClutch.RoadSegment * 4); player.AddResources(ResourceClutch.Settlement * 3); player.AddResources(ResourceClutch.City * 5); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { if (errorDetails != null) { throw new Exception("Error already raised: " + errorDetails.Message); } errorDetails = e; }; localGameController.StartGamePlay(); localGameController.BuildCity(turnToken, MainSettlementOneLocation); localGameController.BuildCity(turnToken, MainSettlementTwoLocation); localGameController.BuildRoadSegment(turnToken, 4, 3); localGameController.BuildRoadSegment(turnToken, 4, 5); localGameController.BuildSettlement(turnToken, 3); localGameController.BuildCity(turnToken, 3); localGameController.BuildSettlement(turnToken, 5); localGameController.BuildCity(turnToken, 5); localGameController.BuildRoadSegment(turnToken, 3, 2); localGameController.BuildRoadSegment(turnToken, 2, 1); localGameController.BuildSettlement(turnToken, 1); // Act localGameController.BuildCity(turnToken, 1); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build city. All cities already built."); }
public void BuildSettlement_AllSettlementsAreBuilt_MeaningfulErrorIsReceived() { // Arrange MockDice mockDice = null; MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstOpponent, out secondOpponent, out thirdOpponent); mockDice.AddSequence(new[] { 8u }); player.AddResources(ResourceClutch.Settlement * 3); player.AddResources(ResourceClutch.RoadSegment * 7); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { if (errorDetails != null) { // Ensure that the error details are only received once. throw new Exception("Already received error details"); } errorDetails = e; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); var roadSegmentDetails = new UInt32[] { 4, 3, 3, 2, 2, 1, 1, 0, 0, 8, 8, 7, 7, 17 }; for (var index = 0; index < roadSegmentDetails.Length; index += 2) { localGameController.BuildRoadSegment(turnToken, roadSegmentDetails[index], roadSegmentDetails[index + 1]); } localGameController.BuildSettlement(turnToken, 3); localGameController.BuildSettlement(turnToken, 1); localGameController.BuildSettlement(turnToken, 8); // Act localGameController.BuildSettlement(turnToken, 17); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot build settlement. All settlements already built."); }
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 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 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]."); }