public async Task IntegrationTestAddArmyToCombat() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); Guid combatId = new Guid("0DAAF6DD-E1D6-42BA-B3ED-749BB7652C8E"); Guid attackingRegionId = new Guid("5EA3D204-63EA-4683-913E-C5C3609BD893"); Guid attacking2RegionId = new Guid("E0675161-4192-4C33-B8BB-3B6D763725E2"); Guid attacking3RegionId = new Guid("CA563328-5743-4EC0-AA39-D7978DE44872"); Guid defendingRegionId = new Guid("6DC3039A-CC79-4CAC-B7CE-37E1B1565A6C"); CombatTableEntry tableEntry = new CombatTableEntry(SessionId, 1, combatId, CombatType.MassInvasion); tableEntry.SetCombatArmy(new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); TableOperation insertOperation = TableOperation.Insert(tableEntry); await testTable.ExecuteAsync(insertOperation); // Act using (BatchOperationHandle batchOperation = new BatchOperationHandle(testTable)) { repository.AddArmyToCombat(batchOperation, tableEntry, new List <ICombatArmy> { new CombatArmy(attacking2RegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 6), new CombatArmy(attacking3RegionId, "AttackingUser2", Core.CombatArmyMode.Attacking, 3) }); } // Assert TableOperation operation = TableOperation.Retrieve <CombatTableEntry>(SessionId.ToString(), "Combat_" + combatId.ToString()); TableResult result = await testTable.ExecuteAsync(operation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(CombatTableEntry)); CombatTableEntry resultStronglyTyped = result.Result as CombatTableEntry; Assert.AreEqual(SessionId, resultStronglyTyped.SessionId); Assert.AreEqual(combatId, resultStronglyTyped.CombatId); Assert.AreEqual(1, resultStronglyTyped.Round); Assert.AreEqual(CombatType.MassInvasion, resultStronglyTyped.ResolutionType); Assert.AreEqual(4, resultStronglyTyped.InvolvedArmies.Count()); AssertCombat.IsAttacking(attackingRegionId, 5, "AttackingUser", resultStronglyTyped); AssertCombat.IsAttacking(attacking2RegionId, 6, "AttackingUser", resultStronglyTyped); AssertCombat.IsAttacking(attacking3RegionId, 3, "AttackingUser2", resultStronglyTyped); AssertCombat.IsDefending(defendingRegionId, 4, "DefendingUser", resultStronglyTyped); }
public async Task IntegrationTestGetCombatWithMultipleRounds() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); Guid combatId = new Guid("3233BE80-37BA-4FBD-B07B-BB18F6E47FEE"); Guid attackingRegionId = new Guid("5EA3D204-63EA-4683-913E-C5C3609BD893"); Guid defendingRegionId = new Guid("6DC3039A-CC79-4CAC-B7CE-37E1B1565A6C"); CombatTableEntry tableEntry = new CombatTableEntry(SessionId, 5, combatId, CombatType.Invasion); tableEntry.SetCombatArmy(new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); TableOperation insertOperation = TableOperation.Insert(tableEntry); await testTable.ExecuteAsync(insertOperation); CombatTableEntry otherRoundTableEntry = new CombatTableEntry(SessionId, 2, Guid.NewGuid(), CombatType.Invasion); insertOperation = TableOperation.Insert(otherRoundTableEntry); await testTable.ExecuteAsync(insertOperation); // Act var results = await repository.GetCombat(SessionId, 5); // Assert Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); ICombat result = results.Where(combat => combat.CombatId == combatId).FirstOrDefault(); Assert.IsNotNull(result); Assert.AreEqual(combatId, result.CombatId); Assert.AreEqual(CombatType.Invasion, result.ResolutionType); Assert.AreEqual(2, result.InvolvedArmies.Count()); AssertCombat.IsAttacking(attackingRegionId, 5, "AttackingUser", result); AssertCombat.IsDefending(defendingRegionId, 4, "DefendingUser", result); }
public async Task IntegrationTestAddCombat() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); Guid attackingRegionId = new Guid("4CD8D6E1-8FFE-48E1-8FE0-B89BCDD0AA96"); Guid defendingRegionId = new Guid("E0FE9A73-4125-4DA1-A113-25ED927EA7B4"); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(testTable)) { repository.AddCombat(batchOperation, SessionId, 2, new List <Tuple <CombatType, IEnumerable <ICombatArmy> > > { Tuple.Create <CombatType, IEnumerable <ICombatArmy> >(CombatType.MassInvasion, new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }) }); } // Assert IEnumerable <ICombat> combatList = await repository.GetCombat(SessionId, 2); Assert.IsNotNull(combatList); Assert.AreEqual(1, combatList.Count()); ICombat combat = combatList.First(); Assert.IsInstanceOfType(combat, typeof(CombatTableEntry)); CombatTableEntry resultStronglyTyped = combat as CombatTableEntry; Assert.AreEqual(SessionId, resultStronglyTyped.SessionId); Assert.IsNotNull(resultStronglyTyped.CombatId); Assert.AreEqual(CombatType.MassInvasion, resultStronglyTyped.ResolutionType); Assert.AreEqual(2, resultStronglyTyped.InvolvedArmies.Count()); AssertCombat.IsAttacking(attackingRegionId, 5, "AttackingUser", resultStronglyTyped); AssertCombat.IsDefending(defendingRegionId, 4, "DefendingUser", resultStronglyTyped); }
public async Task IntegrationTestCombatTableEntrySerialise() { // Arrange Guid combatId = new Guid("5C161C2F-3982-45B8-8FCE-9D7F609AB012"); Guid attackingRegionId = new Guid("4CD8D6E1-8FFE-48E1-8FE0-B89BCDD0AA96"); Guid defendingRegionId = new Guid("E0FE9A73-4125-4DA1-A113-25ED927EA7B4"); CombatTableEntry tableEntry = new CombatTableEntry(SessionId, 1, combatId, CombatType.Invasion); List <ICombatArmy> armies = new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }; tableEntry.SetCombatArmy(armies); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); // Act TableOperation insertOperation = TableOperation.Insert(tableEntry); await testTable.ExecuteAsync(insertOperation); // Assert TableOperation operation = TableOperation.Retrieve <CombatTableEntry>(SessionId.ToString(), "Combat_" + combatId.ToString()); TableResult result = await testTable.ExecuteAsync(operation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(CombatTableEntry)); CombatTableEntry resultStronglyTyped = result.Result as CombatTableEntry; Assert.AreEqual(SessionId, resultStronglyTyped.SessionId); Assert.AreEqual(combatId, resultStronglyTyped.CombatId); Assert.AreEqual(1, resultStronglyTyped.Round); Assert.AreEqual(CombatType.Invasion, resultStronglyTyped.ResolutionType); Assert.AreEqual(2, resultStronglyTyped.InvolvedArmies.Count()); AssertCombat.IsAttacking(attackingRegionId, 5, "AttackingUser", resultStronglyTyped); AssertCombat.IsDefending(defendingRegionId, 4, "DefendingUser", resultStronglyTyped); }