public async Task TestGetCombat_WithSpoilsOfWar() { // Arrange ControllerMock primaryUser = new ControllerMock(); primaryUser.SetupDummySession(SessionGuid) .SetupDummyWorldAsTree() .SetupSessionPhase(SessionPhase.SpoilsOfWar) .SetupRegionOwnership(ControllerMockRegionRepositoryExtensions.DummyWorldRegionB, DummyUserRepository.RegisteredUserIds[1]) .SetupRegionOwnership(ControllerMockRegionRepositoryExtensions.DummyWorldRegionD, DummyUserRepository.RegisteredUserIds[2]) .SetupSpoilsOfWar(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, ControllerMockRegionRepositoryExtensions.DummyWorldRegionB, 5, ControllerMockRegionRepositoryExtensions.DummyWorldRegionD, 1); // Act IEnumerable <ICombat> result = await primaryUser.WorldController.GetCombat(SessionGuid); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.Count()); Assert.AreEqual(CombatType.SpoilsOfWar, result.First().ResolutionType); Assert.AreEqual(3, result.First().InvolvedArmies.Count()); AssertCombat.IsAttacking(ControllerMockRegionRepositoryExtensions.DummyWorldRegionB, 5, DummyUserRepository.RegisteredUserIds[1], result.First()); AssertCombat.IsAttacking(ControllerMockRegionRepositoryExtensions.DummyWorldRegionD, 1, DummyUserRepository.RegisteredUserIds[2], result.First()); AssertCombat.IsDefending(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, 0, primaryUser.OwnerId, result.First()); }
public async Task TestGetCombat_WithBorderClash() { // Arrange ControllerMock primaryUser = new ControllerMock(); primaryUser.SetupDummySession(SessionGuid) .SetupDummyWorldAsTree() .SetupSessionPhase(SessionPhase.BorderClashes) .SetupRegionOwnership(ControllerMockRegionRepositoryExtensions.DummyWorldRegionD, DummyUserRepository.RegisteredUserIds[1]) .SetupRegionTroops(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, 7) .SetupRegionTroops(ControllerMockRegionRepositoryExtensions.DummyWorldRegionD, 2) .SetupBorderClash(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, 5, ControllerMockRegionRepositoryExtensions.DummyWorldRegionD, 1); // Act IEnumerable <ICombat> result = await primaryUser.WorldController.GetCombat(SessionGuid); // Assert Assert.IsNotNull(result); Assert.AreEqual(3, result.Count()); var borderClash = result.Where(combat => combat.ResolutionType == CombatType.BorderClash).FirstOrDefault(); Assert.IsNotNull(borderClash); Assert.AreEqual(2, borderClash.InvolvedArmies.Count()); AssertCombat.IsAttacking(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, 5, primaryUser.OwnerId, borderClash); AssertCombat.IsAttacking(ControllerMockRegionRepositoryExtensions.DummyWorldRegionD, 1, DummyUserRepository.RegisteredUserIds[1], borderClash); var invasionOfA = result.Where(combat => combat.ResolutionType == CombatType.Invasion && combat.InvolvedArmies.First().OriginRegionId == ControllerMockRegionRepositoryExtensions.DummyWorldRegionA).FirstOrDefault(); Assert.IsNotNull(invasionOfA); Assert.AreEqual(1, invasionOfA.InvolvedArmies.Count()); AssertCombat.IsDefending(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, 2, primaryUser.OwnerId, invasionOfA); var invasionOfD = result.Where(combat => combat.ResolutionType == CombatType.Invasion && combat.InvolvedArmies.First().OriginRegionId == ControllerMockRegionRepositoryExtensions.DummyWorldRegionD).FirstOrDefault(); Assert.IsNotNull(invasionOfD); Assert.AreEqual(1, invasionOfD.InvolvedArmies.Count()); AssertCombat.IsDefending(ControllerMockRegionRepositoryExtensions.DummyWorldRegionD, 1, DummyUserRepository.RegisteredUserIds[1], invasionOfD); }
public async Task IntegrationTestCombatResolution_WithDirectInvasion() { // Arrange Guid validGuid = new Guid("68E4A0DC-BAB8-4C79-A6E9-D0A7494F3B45"); ControllerMock primaryUser = new ControllerMock(); primaryUser.SetupDummySession(validGuid) .SetupAddPlayer(DummyUserRepository.RegisteredUserIds[1], PlayerColour.Blue) .SetupDummyWorldAsTree(primaryUser.OwnerId) .SetupRegionOwnership(ControllerMockRegionRepositoryExtensions.DummyWorldRegionB, DummyUserRepository.RegisteredUserIds[1]) .SetupRegionTroops(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, 5) .SetupRegionTroops(ControllerMockRegionRepositoryExtensions.DummyWorldRegionB, 2) .SetupSessionPhase(SessionPhase.CombatOrders) .QueueAttack(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, ControllerMockRegionRepositoryExtensions.DummyWorldRegionB, 4) // Rig dice so that A beats B .SetupRiggedDiceResults(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, 6, 6, 6) .SetupRiggedDiceResults(ControllerMockRegionRepositoryExtensions.DummyWorldRegionB, 1, 1); // Act await ResolveAllCombat(primaryUser, validGuid); // Assert Assert.AreEqual(SessionPhase.Redeployment, primaryUser.SessionRepository.SessionMap[validGuid].PhaseType); var invasion = primaryUser.GetInvasion(ControllerMockRegionRepositoryExtensions.DummyWorldRegionB); var invasionResults = primaryUser.WorldRepository.CombatResults[invasion.CombatId]; AssertCombat.IsResultValid(1, invasion, invasionResults); AssertCombat.IsArmyResult(ControllerMockRegionRepositoryExtensions.DummyWorldRegionA, 1, 0, invasionResults); AssertCombat.IsArmyResult(ControllerMockRegionRepositoryExtensions.DummyWorldRegionB, 1, 2, invasionResults); Assert.AreEqual(primaryUser.OwnerId, primaryUser.RegionRepository.RegionData[ControllerMockRegionRepositoryExtensions.DummyWorldRegionA].OwnerId); Assert.AreEqual(1U, primaryUser.RegionRepository.RegionData[ControllerMockRegionRepositoryExtensions.DummyWorldRegionA].TroopCount); Assert.AreEqual(0U, primaryUser.RegionRepository.RegionData[ControllerMockRegionRepositoryExtensions.DummyWorldRegionA].TroopsCommittedToPhase); Assert.AreEqual(primaryUser.OwnerId, primaryUser.RegionRepository.RegionData[ControllerMockRegionRepositoryExtensions.DummyWorldRegionB].OwnerId); Assert.AreEqual(4U, primaryUser.RegionRepository.RegionData[ControllerMockRegionRepositoryExtensions.DummyWorldRegionB].TroopCount); Assert.AreEqual(0U, primaryUser.RegionRepository.RegionData[ControllerMockRegionRepositoryExtensions.DummyWorldRegionB].TroopsCommittedToPhase); }