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 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_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_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 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 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 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_AddToRoadShorterThanFiveSegments_LongestRoadEventNotRaised(UInt32[] roadLocations) { // 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 }); var roadCount = roadLocations.Length / 2; var brickCount = roadCount; var lumberCount = roadCount; player.AddResources(new ResourceClutch(brickCount, 0, lumberCount, 0, 0)); Boolean longestRoadBuiltEventRaised = false; localGameController.LongestRoadBuiltEvent = (Guid pid, Guid nid) => { longestRoadBuiltEventRaised = true; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Act for (var index = 0; index < roadLocations.Length; index += 2) { localGameController.BuildRoadSegment(turnToken, roadLocations[index], roadLocations[index + 1]); } // Assert longestRoadBuiltEventRaised.ShouldBeFalse(); }
public void BuildRoadSegment_ValidScenario_RoadSegmentBuiltEventRaised() { // 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)); PlayerDataBase playerDataBase = null; //localGameController.RoadSegmentBuiltEvent = (PlayerDataBase p) => { playerDataBase = p; }; GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Act localGameController.BuildRoadSegment(turnToken, 4u, 3u); // Assert //playerDataBase.ShouldNotBeNull(); Assert.Fail("Fail"); }
public void BuildCity_OnExistingSettlementBelongingToPlayer_CityBuiltEventRaised() { // 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); 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.ShouldBeTrue(); errorDetails.ShouldBeNull(); }
public TestInstances(LocalGameController localGameController, MockPlayer player, MockComputerPlayer firstOpponent, MockComputerPlayer secondOpponent, MockComputerPlayer thirdOpponent, MockDice dice) { this.MainPlayer = player; this.FirstOpponent = firstOpponent; this.SecondOpponent = secondOpponent; this.ThirdOpponent = thirdOpponent; this.Dice = dice; this.LocalGameController = localGameController; }
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); }
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."); }
protected LocalGameController CreateLocalGameControllerAndCompleteGameSetup(out MockDice mockDice, out MockPlayer player, out MockComputerPlayer firstOpponent, out MockComputerPlayer secondOpponent, out MockComputerPlayer thirdOpponent) { mockDice = this.CreateMockDice(); this.CreateDefaultPlayerInstances(out player, out firstOpponent, out secondOpponent, out thirdOpponent); var localGameController = this.CreateLocalGameController(mockDice, player, firstOpponent, secondOpponent, thirdOpponent); localGameController.JoinGame(); localGameController.LaunchGame(); localGameController.StartGameSetup(); localGameController.ContinueGameSetup(MainSettlementOneLocation, MainRoadOneEnd); localGameController.CompleteGameSetup(MainSettlementTwoLocation, MainRoadTwoEnd); return(localGameController); }
public void StartOfMainPlayerTurn_TurnTokenReceived() { // Arrange MockDice mockDice = null; Guid id = Guid.Empty; MockPlayer player; MockComputerPlayer firstComputerPlayer, secondComputerPlayer, thirdComputerPlayer; var localGameController = this.CreateLocalGameControllerAndCompleteGameSetup(out mockDice, out player, out firstComputerPlayer, out secondComputerPlayer, out thirdComputerPlayer); mockDice.AddSequence(new[] { 8u }); // Act GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Assert turnToken.ShouldNotBeNull(); }
public static TestInstances CreateTestInstances(MockDice mockNumGenerator) { return(LocalGameControllerTestCreator.CreateTestInstances(mockNumGenerator, null, null, null)); }