public async Task IntegrationTestAddCombatResults()
        {
            // Arrange
            WorldRepository  repository        = new WorldRepository(DevelopmentStorageAccountConnectionString);
            Guid             SessionId         = new Guid("2CDE3217-B8F2-4FDA-8E7A-3B6B6FA4C747");
            Guid             combatId          = new Guid("4B0286E6-6DBE-4F86-A87C-1CF776F41437");
            Guid             attackingRegionId = new Guid("4CD8D6E1-8FFE-48E1-8FE0-B89BCDD0AA96");
            Guid             defendingRegionId = new Guid("E0FE9A73-4125-4DA1-A113-25ED927EA7B4");
            CombatTableEntry combat            = new CombatTableEntry(SessionId, 1, combatId, CombatType.Invasion);

            combat.SetCombatArmy(new List <ICombatArmy>
            {
                new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 3),
                new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 2)
            });
            CombatResultTableEntry tableEntry = new CombatResultTableEntry(SessionId, combatId, new List <ICombatRoundResult>
            {
                new CombatRoundResult(
                    new List <ICombatArmyRoundResult>
                {
                    new CombatArmyRoundResult(attackingRegionId, "AttackingUser", new List <UInt32> {
                        2, 3, 4
                    }, 1),
                    new CombatArmyRoundResult(defendingRegionId, "DefendingUser", new List <UInt32> {
                        1, 1
                    }, 2),
                }
                    )
            });

            CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId);

            testTable.CreateIfNotExists();

            // Act
            await repository.AddCombatResults(SessionId, 1, new List <ICombatResult>
            {
                tableEntry
            });

            // Assert
            TableOperation operation = TableOperation.Retrieve <CombatResultTableEntry>(SessionId.ToString(), "Result_" + combatId.ToString());
            TableResult    result    = await testTable.ExecuteAsync(operation);

            Assert.IsNotNull(result.Result);
            Assert.IsInstanceOfType(result.Result, typeof(CombatResultTableEntry));
            CombatResultTableEntry resultStronglyTyped = result.Result as CombatResultTableEntry;

            AssertCombat.IsResultValid(1, combat, resultStronglyTyped);

            AssertCombat.IsArmyResult(attackingRegionId, 1, 1, resultStronglyTyped);
            AssertCombat.IsArmyResult(defendingRegionId, 1, 2, resultStronglyTyped);
        }
        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 void IntegrationTestCombatRoundResultCreateFromAzureString()
        {
            // Arrange
            String testString = "E63BC819-A1D2-4876-AE76-BBD63EBAEC99#AttackingUser#1#2#3#4@223AA4AE-AF1A-4169-A39C-3E6BA8F5B981#DefendingUser#2#1";

            // Act
            CombatRoundResult result = CombatRoundResult.CreateFromAzureString(testString);

            // Assert
            CombatResultTableEntry resultHelper = new CombatResultTableEntry(Guid.NewGuid(), Guid.NewGuid(), new List <ICombatRoundResult> {
                result
            });

            AssertCombat.IsArmyResult(new Guid("E63BC819-A1D2-4876-AE76-BBD63EBAEC99"), 1, 1, resultHelper);
            AssertCombat.IsArmyResult(new Guid("223AA4AE-AF1A-4169-A39C-3E6BA8F5B981"), 1, 2, resultHelper);
        }
        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);
        }