public async Task IntegrationTestResetDiscardedCards() { // Arrange NationRepository repository = new NationRepository(DevelopmentStorageAccountConnectionString); SessionRepository sessionRepository = new SessionRepository(DevelopmentStorageAccountConnectionString); Guid validGuid = new Guid("0FC802DC-2F1B-4D0B-B1B4-E6BD88E5550D"); Guid dummyRegionGuid = new Guid("EAB48F5F-F268-45BE-B42D-936DE39CDD09"); String dummyUserId = "DummyUserId"; await sessionRepository.SetupSession(validGuid, dummyUserId); CardTableEntry ownedCard = await sessionRepository.SetupAddCard(validGuid, dummyRegionGuid, CardTableEntry.State.Discarded, dummyUserId, 3); var dataTable = SessionRepository.GetTableForSessionData(TableClient, validGuid); // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(sessionRepository.GetTableForSessionData(validGuid))) { await repository.ResetDiscardedCards(batchOperation, validGuid); } // Assert var operation = TableOperation.Retrieve <CardTableEntry>(validGuid.ToString(), "Card_" + dummyRegionGuid); var result = await dataTable.ExecuteAsync(operation); CardTableEntry resultStronglyTyped = result.Result as CardTableEntry; Assert.AreEqual(CardTableEntry.State.Unowned, resultStronglyTyped.OwnerState); Assert.AreEqual(String.Empty, resultStronglyTyped.OwnerId); }
public async Task IntegrationTestSetAvailableReinforcements_WithMultipleUsers() { // Arrange NationRepository repository = new NationRepository(DevelopmentStorageAccountConnectionString); SessionRepository sessionRepository = new SessionRepository(DevelopmentStorageAccountConnectionString); Guid validGuid = new Guid("B59C5710-F3B3-4AAB-983D-9899ADEB4F28"); String dummyUserId = "DummyUserId"; String secondDummyUserId = "DummyUserId2"; await sessionRepository.SetupSession(validGuid, dummyUserId); await sessionRepository.SetupAddPlayer(validGuid, secondDummyUserId); var dataTable = SessionRepository.GetTableForSessionData(TableClient, validGuid); // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(sessionRepository.GetTableForSessionData(validGuid))) { repository.SetAvailableReinforcements(batchOperation, validGuid, dummyUserId, "*", 10U); repository.SetAvailableReinforcements(batchOperation, validGuid, secondDummyUserId, "*", 20U); } // Assert var operation = TableOperation.Retrieve <NationTableEntry>(validGuid.ToString(), "Nation_" + dummyUserId); var result = await dataTable.ExecuteAsync(operation); NationTableEntry resultPlayerStronglyTyped = result.Result as NationTableEntry; Assert.AreEqual(10U, resultPlayerStronglyTyped.AvailableReinforcements); operation = TableOperation.Retrieve <NationTableEntry>(validGuid.ToString(), "Nation_" + secondDummyUserId); result = await dataTable.ExecuteAsync(operation); resultPlayerStronglyTyped = result.Result as NationTableEntry; Assert.AreEqual(20U, resultPlayerStronglyTyped.AvailableReinforcements); }
public async Task IntegrationTestSetCardOwner() { // Arrange NationRepository repository = new NationRepository(DevelopmentStorageAccountConnectionString); SessionRepository sessionRepository = new SessionRepository(DevelopmentStorageAccountConnectionString); Guid validGuid = new Guid("745C4DEB-2C66-4AC5-900E-27BA0C82BB0F"); Guid dummyRegionGuid = new Guid("8C60947F-F7E5-4153-B43C-4B19D8CBE2CF"); String dummyUserId = "DummyUserId"; await sessionRepository.SetupSession(validGuid, dummyUserId); CardTableEntry ownedCard = await sessionRepository.SetupAddCard(validGuid, dummyRegionGuid, CardTableEntry.State.Unowned, String.Empty, 3); var dataTable = SessionRepository.GetTableForSessionData(TableClient, validGuid); // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(sessionRepository.GetTableForSessionData(validGuid))) { repository.SetCardOwner(batchOperation, validGuid, dummyRegionGuid, dummyUserId, ownedCard.CurrentEtag); } // Assert var operation = TableOperation.Retrieve <CardTableEntry>(validGuid.ToString(), "Card_" + dummyRegionGuid); var result = await dataTable.ExecuteAsync(operation); CardTableEntry resultStronglyTyped = result.Result as CardTableEntry; Assert.AreEqual(CardTableEntry.State.Owned, resultStronglyTyped.OwnerState); Assert.AreEqual(dummyUserId, resultStronglyTyped.OwnerId); }
public async Task IntegrationTestSetCardDiscarded() { // CHANGE GUIDS // Arrange NationRepository repository = new NationRepository(DevelopmentStorageAccountConnectionString); SessionRepository sessionRepository = new SessionRepository(DevelopmentStorageAccountConnectionString); Guid validGuid = new Guid("C6EA373B-63E8-481D-894C-9051F6710771"); Guid dummyRegionGuid = new Guid("7D194EC9-59ED-494F-8F77-9ED4B26F75FA"); String dummyUserId = "DummyUserId"; await sessionRepository.SetupSession(validGuid, dummyUserId); CardTableEntry ownedCard = await sessionRepository.SetupAddCard(validGuid, dummyRegionGuid, CardTableEntry.State.Owned, dummyUserId, 3); var dataTable = SessionRepository.GetTableForSessionData(TableClient, validGuid); // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(sessionRepository.GetTableForSessionData(validGuid))) { repository.SetCardDiscarded(batchOperation, validGuid, dummyRegionGuid, ownedCard.CurrentEtag); } // Assert var operation = TableOperation.Retrieve <CardTableEntry>(validGuid.ToString(), "Card_" + dummyRegionGuid); var result = await dataTable.ExecuteAsync(operation); CardTableEntry resultStronglyTyped = result.Result as CardTableEntry; Assert.AreEqual(CardTableEntry.State.Discarded, resultStronglyTyped.OwnerState); Assert.AreEqual(dummyUserId, resultStronglyTyped.OwnerId); }
public async Task IntegrationTestOrderAttack() { // Arrange CommandQueue repository = new CommandQueue(DevelopmentStorageAccountConnectionString); Guid targetRegionGuid = new Guid("8449A25B-363D-4F01-B3D9-7EF8C5D42047"); // Act Guid operationGuid; using (IBatchOperationHandle batchOperation = new BatchOperationHandle(CommandTable)) { operationGuid = await repository.OrderAttack(batchOperation, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 5U); } // Assert var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + RegionGuid.ToString() + "_" + targetRegionGuid.ToString()); var result = await CommandTable.ExecuteAsync(operation); CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry; Assert.IsNotNull(queuedCommand); Assert.AreEqual(operationGuid, queuedCommand.OperationId); Assert.AreEqual(SessionGuid, queuedCommand.SessionId); Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId); Assert.AreEqual(CommandQueueMessageType.Attack, queuedCommand.MessageType); Assert.AreEqual(RegionGuid, queuedCommand.SourceRegion); Assert.AreEqual("DummyEtag", queuedCommand.SourceRegionEtag); Assert.AreEqual(targetRegionGuid, queuedCommand.TargetRegion); Assert.AreEqual(5U, queuedCommand.NumberOfTroops); }
public async Task IntegrationTestOrderAttack_MergeWithExisting() { // Arrange CommandQueue repository = new CommandQueue(DevelopmentStorageAccountConnectionString); Guid targetRegionGuid = new Guid("7E3BCD95-EB8B-4401-A987-F613A3428676"); Guid initialOperationId = Guid.NewGuid(); CommandQueueTableEntry newCommand = CommandQueueTableEntry.CreateAttackMessage(initialOperationId, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 5U); CommandTable.Execute(TableOperation.Insert(newCommand)); // Act Guid operationGuid; using (IBatchOperationHandle batchOperation = new BatchOperationHandle(CommandTable)) { operationGuid = await repository.OrderAttack(batchOperation, SessionGuid, SessionPhaseGuid, RegionGuid, "DummyEtag", targetRegionGuid, 4U); } // Assert var operation = TableOperation.Retrieve <CommandQueueTableEntry>(SessionGuid.ToString(), "Command_" + RegionGuid.ToString() + "_" + targetRegionGuid.ToString()); var result = await CommandTable.ExecuteAsync(operation); CommandQueueTableEntry queuedCommand = result.Result as CommandQueueTableEntry; Assert.IsNotNull(queuedCommand); Assert.AreEqual(operationGuid, queuedCommand.OperationId); Assert.AreNotEqual(operationGuid, initialOperationId); Assert.AreEqual(SessionGuid, queuedCommand.SessionId); Assert.AreEqual(SessionPhaseGuid, queuedCommand.PhaseId); Assert.AreEqual(CommandQueueMessageType.Attack, queuedCommand.MessageType); Assert.AreEqual(RegionGuid, queuedCommand.SourceRegion); Assert.AreEqual("DummyEtag", queuedCommand.SourceRegionEtag); Assert.AreEqual(targetRegionGuid, queuedCommand.TargetRegion); Assert.AreEqual(9U, queuedCommand.NumberOfTroops); }
public async Task IntegrationTestGetRegions() { // Arrange RegionRepository repository = new RegionRepository(DevelopmentStorageAccountConnectionString, String.Empty); Guid dummySessionId = new Guid("74720766-452A-40AD-8A61-FEF07E8573C9"); Guid dummyRegionId = new Guid("CBDF6EBE-5F91-4ADF-AC30-D149D8E5F8EB"); Guid secondDummyRegionId = new Guid("336312D8-F219-4C9B-B3FE-F4B39602E28D"); Guid dummyContinentId = new Guid("DE167712-0CE6-455C-83EA-CB2A6936F1BE"); TableClient.SetupSessionDataTable(dummySessionId); using (IBatchOperationHandle batchOperation = new BatchOperationHandle(SessionRepository.GetTableForSessionData(TableClient, dummySessionId))) { repository.CreateRegion(batchOperation, dummySessionId, dummyRegionId, dummyContinentId, "DummyRegion", new List <Guid>(), 0); repository.CreateRegion(batchOperation, dummySessionId, secondDummyRegionId, dummyContinentId, "DummyRegion2", new List <Guid>(), 0); } // Act IEnumerable <IRegionData> regionData = await repository.GetRegions(dummySessionId); // Assert Assert.IsNotNull(regionData); Assert.IsTrue(regionData.Count() >= 2, "Expected at least two regions"); Assert.AreEqual(1, regionData.Where(region => region.RegionId == dummyRegionId).Count()); Assert.AreEqual(1, regionData.Where(region => region.RegionId == secondDummyRegionId).Count()); }
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 IntegrationTestCreateRegion() { // Arrange RegionRepository repository = new RegionRepository(DevelopmentStorageAccountConnectionString, String.Empty); Guid dummySessionId = new Guid("74720766-452A-40AD-8A61-FEF07E8573C9"); Guid dummyRegionId = new Guid("024D1E45-EF34-4AB1-840D-79229CCDE8C3"); Guid dummyContinentId = new Guid("DE167712-0CE6-455C-83EA-CB2A6936F1BE"); List <Guid> dummyConnections = new List <Guid> { new Guid("0533203F-13F2-4863-B528-17F53D279E19"), new Guid("4A9779D0-0727-4AD9-AD66-17AE9AF9BE02") }; var dataTable = TableClient.SetupSessionDataTable(dummySessionId); // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(SessionRepository.GetTableForSessionData(TableClient, dummySessionId))) { repository.CreateRegion(batchOperation, dummySessionId, dummyRegionId, dummyContinentId, "DummyRegion", dummyConnections, 3); } // Assert TableOperation operation = TableOperation.Retrieve <RegionTableEntry>(dummySessionId.ToString(), "Region_" + dummyRegionId.ToString()); TableResult result = await dataTable.ExecuteAsync(operation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(RegionTableEntry)); RegionTableEntry resultStronglyTyped = result.Result as RegionTableEntry; Assert.AreEqual(dummySessionId, resultStronglyTyped.SessionId); Assert.AreEqual(dummyRegionId, resultStronglyTyped.RegionId); Assert.AreEqual(dummyContinentId, resultStronglyTyped.ContinentId); Assert.AreEqual("DummyRegion", resultStronglyTyped.Name); Assert.AreEqual(String.Empty, resultStronglyTyped.OwnerId); Assert.AreEqual(3U, resultStronglyTyped.CardValue); Assert.AreEqual(0, resultStronglyTyped.StoredTroopCount); Assert.IsTrue(resultStronglyTyped.ETag.Length > 0); Assert.IsTrue(resultStronglyTyped.ConnectedRegions.Contains(dummyConnections[0])); TableOperation cardOperation = TableOperation.Retrieve <CardTableEntry>(dummySessionId.ToString(), "Card_" + dummyRegionId.ToString()); result = await dataTable.ExecuteAsync(cardOperation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(CardTableEntry)); CardTableEntry cardStronglyTyped = result.Result as CardTableEntry; Assert.AreEqual(dummySessionId, cardStronglyTyped.SessionId); Assert.AreEqual(dummyRegionId, cardStronglyTyped.RegionId); Assert.AreEqual(3U, cardStronglyTyped.Value); Assert.AreEqual(String.Empty, cardStronglyTyped.OwnerId); Assert.AreEqual(CardTableEntry.State.Unowned, cardStronglyTyped.OwnerState); }
public async Task IntegrationTestStressTestAttacks() { var primaryUser = new ControllerAzure(DevelopmentStorageAccountConnectionString, @"WorldData\FullWorldDefinition.xml"); var secondaryUser = new ControllerAzure(DevelopmentStorageAccountConnectionString, @"WorldData\FullWorldDefinition.xml", DummyUserRepository.RegisteredUserIds[1]); // Start new session var sessionDetails = await primaryUser.GameController.PostStartNewSession(Core.PlayerColour.Black); await secondaryUser.GameController.PostJoinSession(sessionDetails.GameId, Core.PlayerColour.Green); // Assert all players in session var playersInSession = await primaryUser.GameController.GetPlayers(sessionDetails.GameId); Assert.AreEqual(2, playersInSession.Count()); // Start game (with primary user) sessionDetails = await primaryUser.GameController.GetSession(sessionDetails.GameId); await primaryUser.GameController.PostAdvanceNextPhase(sessionDetails.GameId, sessionDetails.PhaseId, true); // Ensure primary user has enough troops for the test using (IBatchOperationHandle batchOperation = new BatchOperationHandle(primaryUser.AzureSessionRepository.GetTableForSessionData(sessionDetails.GameId))) { primaryUser.AzureNationRepository.SetAvailableReinforcements(batchOperation, sessionDetails.GameId, primaryUser.OwnerId, "*", 2000); } // Deploy initial troops for primary user await Controllers.IntegrationTest.RandomlyDeployReinforcements(primaryUser.GameController, primaryUser.NationController, primaryUser.WorldController, primaryUser.RegionController, sessionDetails.GameId, primaryUser.OwnerId); // Move into combat phase (with primary user) sessionDetails = await primaryUser.GameController.GetSession(sessionDetails.GameId); await primaryUser.GameController.PostAdvanceNextPhase(sessionDetails.GameId, sessionDetails.PhaseId, true); // Attempt to issue 1000 random attack orders for primary user UInt32 numberOfAttacks = await Controllers.IntegrationTest.BulkRandomlyAttack(primaryUser.GameController, primaryUser.WorldController, primaryUser.AzureRegionRepository, primaryUser.AzureSessionRepository, sessionDetails.GameId, primaryUser.OwnerId, 1, 1000); Assert.AreNotEqual(0, numberOfAttacks); // Move into resolution phase (with primary user) sessionDetails = await primaryUser.GameController.GetSession(sessionDetails.GameId); await primaryUser.GameController.PostAdvanceNextPhase(sessionDetails.GameId, sessionDetails.PhaseId, true); // Resolve combat await Controllers.IntegrationTest.ResolveAllCombat(primaryUser.GameController, sessionDetails.GameId); }
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 IntegrationTestRemoveCommands() { // Arrange CommandQueue repository = new CommandQueue(DevelopmentStorageAccountConnectionString); Guid sessionId = Guid.NewGuid(); CloudTable randomCommandTable = CommandQueue.GetCommandQueueTableForSession(TableClient, sessionId); randomCommandTable.CreateIfNotExists(); Guid attackId; Guid attackSecondId; Guid secondRegionId = Guid.NewGuid(); using (IBatchOperationHandle batchOperation = new BatchOperationHandle(randomCommandTable)) { attackId = await repository.OrderAttack(batchOperation, sessionId, sessionId, sessionId, String.Empty, sessionId, 0); attackSecondId = await repository.OrderAttack(batchOperation, sessionId, sessionId, sessionId, String.Empty, secondRegionId, 0); } var queuedAttacks = await repository.GetQueuedCommands(sessionId, sessionId); // Act using (BatchOperationHandle handle = new BatchOperationHandle(randomCommandTable)) { repository.RemoveCommands(handle, new List <ICommandQueueMessage> { queuedAttacks.Where(attack => attack.OperationId == attackId).First() }); } // Assert var tableQuery = from entity in randomCommandTable.CreateQuery <CommandQueueTableEntry>() select entity; var tableData = tableQuery.ToList(); Assert.AreEqual(1, tableData.Count); CommandQueueTableEntry result = tableData.First(); Assert.AreEqual(attackSecondId, result.OperationId); }
public async Task IntegrationTestAssignRegionOwnership() { // Arrange RegionRepository repository = new RegionRepository(DevelopmentStorageAccountConnectionString, String.Empty); Guid dummySessionId = new Guid("7C76A14F-DA7F-4AEC-9AF4-DDC77C6122CD"); Guid dummyRegionId = new Guid("CBDF6EBE-5F91-4ADF-AC30-D149D8E5F8EB"); Guid secondDummyRegionId = new Guid("336312D8-F219-4C9B-B3FE-F4B39602E28D"); Guid dummyContinentId = new Guid("DE167712-0CE6-455C-83EA-CB2A6936F1BE"); TableClient.SetupSessionDataTable(dummySessionId); using (IBatchOperationHandle batchOperation = new BatchOperationHandle(SessionRepository.GetTableForSessionData(TableClient, dummySessionId))) { repository.CreateRegion(batchOperation, dummySessionId, dummyRegionId, dummyContinentId, "DummyRegion", new List <Guid>(), 0); repository.CreateRegion(batchOperation, dummySessionId, secondDummyRegionId, dummyContinentId, "DummyRegion2", new List <Guid>(), 0); } // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(SessionRepository.GetTableForSessionData(TableClient, dummySessionId))) { repository.AssignRegionOwnership(batchOperation, dummySessionId, new Dictionary <Guid, OwnershipChange> { { dummyRegionId, new OwnershipChange("DummyUser", 10) }, { secondDummyRegionId, new OwnershipChange("DummyUser2", 20) } }); } // Assert IEnumerable <IRegionData> regionData = await repository.GetRegions(dummySessionId); Assert.IsNotNull(regionData); Assert.AreEqual(2, regionData.Count()); Assert.AreEqual("DummyUser", regionData.Where(region => region.RegionId == dummyRegionId).First().OwnerId); Assert.AreEqual(10U, regionData.Where(region => region.RegionId == dummyRegionId).First().TroopCount); Assert.AreEqual(0U, regionData.Where(region => region.RegionId == dummyRegionId).First().TroopsCommittedToPhase); Assert.AreEqual("DummyUser2", regionData.Where(region => region.RegionId == secondDummyRegionId).First().OwnerId); Assert.AreEqual(20U, regionData.Where(region => region.RegionId == secondDummyRegionId).First().TroopCount); Assert.AreEqual(0U, regionData.Where(region => region.RegionId == secondDummyRegionId).First().TroopsCommittedToPhase); }
public async Task IntegrationTestGetRegion() { // Arrange RegionRepository repository = new RegionRepository(DevelopmentStorageAccountConnectionString, String.Empty); Guid dummySessionId = new Guid("74720766-452A-40AD-8A61-FEF07E8573C9"); Guid dummyRegionId = new Guid("89B6BDF0-83B7-42F1-B216-7DFFB8D11EA2"); Guid dummyContinentId = new Guid("DE167712-0CE6-455C-83EA-CB2A6936F1BE"); List <Guid> dummyConnections = new List <Guid> { new Guid("0533203F-13F2-4863-B528-17F53D279E19"), new Guid("4A9779D0-0727-4AD9-AD66-17AE9AF9BE02") }; TableClient.SetupSessionDataTable(dummySessionId); using (IBatchOperationHandle batchOperation = new BatchOperationHandle(SessionRepository.GetTableForSessionData(TableClient, dummySessionId))) { repository.CreateRegion(batchOperation, dummySessionId, dummyRegionId, dummyContinentId, "DummyRegion", dummyConnections, 0); } // Act IRegionData regionData = await repository.GetRegion(dummySessionId, dummyRegionId); // Assert Assert.IsNotNull(regionData); Assert.AreEqual(dummySessionId, regionData.SessionId); }
internal static async Task <UInt32> BulkRandomlyAttack(GameController game, WorldController world, RegionRepository regionRepository, SessionRepository sessionRepository, Guid sessionId, String ownerId, UInt32 troopCount, UInt32 numberOfAttacks) { ISession session = await game.GetSession(sessionId); // Get owned regions List <CommandQueueTableEntry> attacksToQueue = new List <CommandQueueTableEntry>(); IEnumerable <Guid> ownedRegions = await GetCurrentlyOwnedRegions(world, sessionId, ownerId); IEnumerable <IRegionData> worldRegionList = await regionRepository.GetRegions(sessionId); Dictionary <Guid, IRegionData> worldRegionLookup = worldRegionList.ToDictionary(region => region.RegionId); UInt32 numberOfRequestedAttacks = numberOfAttacks; // Create attack table entries foreach (Guid ownedRegionId in ownedRegions) { IRegionData details = worldRegionLookup[ownedRegionId]; if (details.TroopCount > 1 && numberOfAttacks > 0) { foreach (Guid adjacentRegionId in details.ConnectedRegions) { IRegionData targetDetails = worldRegionLookup[adjacentRegionId]; UInt32 troopsInRegionToAttackWith = details.TroopCount - 1; if (targetDetails.OwnerId != ownerId) { UInt32 troopsToAttackWith = Math.Min(details.TroopCount - 1, troopCount); attacksToQueue.Add(CommandQueueTableEntry.CreateAttackMessage(Guid.NewGuid(), session.GameId, session.PhaseId, details.RegionId, details.CurrentEtag, targetDetails.RegionId, troopsToAttackWith)); troopsInRegionToAttackWith -= troopsToAttackWith; numberOfAttacks -= 1; } if (numberOfAttacks == 0 || troopsInRegionToAttackWith == 0) { break; } } } if (numberOfAttacks == 0) { break; } } // Batch insert operations using (BatchOperationHandle batchOperation = new BatchOperationHandle(sessionRepository.GetTableForSessionData(sessionId))) { for (int counter = 0; counter < attacksToQueue.Count; ++counter) { batchOperation.BatchOperation.Insert(attacksToQueue[counter]); if (batchOperation.RemainingCapacity == 0) { await batchOperation.CommitBatch(); } } } // End attack phase await game.PostEndPhase(session.GameId, session.PhaseId); return(numberOfRequestedAttacks - numberOfAttacks); }