示例#1
0
        public async Task <IEnumerable <ICombat> > GetCombat(Guid sessionId)
        {
            ISession session = await SessionRepository.GetSessionOrThrow(sessionId)
                               .IsUserIdJoinedOrThrow(NationRepository, User.Identity.GetUserId());

            IEnumerable <ICombat> combatData = await WorldRepository.GetCombat(session.GameId, session.Round);

            return(from combat in combatData
                   where IsStillValid(session, combat)
                   orderby combat.ResolutionType ascending
                   select new Combat(combat));
        }
        public async Task IntegrationTestGetCombatByType()
        {
            // Arrange
            WorldRepository  repository        = new WorldRepository(DevelopmentStorageAccountConnectionString);
            Guid             combatId          = new Guid("B75CFB8A-727A-46C1-A952-BF2B1AFF9AD8");
            Guid             secondCombatId    = new Guid("2F366A82-A99C-4A83-BF0E-FFF8D87D94A6");
            Guid             attackingRegionId = new Guid("5EA3D204-63EA-4683-913E-C5C3609BD893");
            Guid             defendingRegionId = new Guid("6DC3039A-CC79-4CAC-B7CE-37E1B1565A6C");
            CombatTableEntry tableEntry        = new CombatTableEntry(SessionId, 1, combatId, CombatType.Invasion);

            tableEntry.SetCombatArmy(new List <ICombatArmy>
            {
                new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5),
                new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4)
            });
            CombatTableEntry secondTableEntry = new CombatTableEntry(SessionId, 1, secondCombatId, CombatType.SpoilsOfWar);

            secondTableEntry.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);

            insertOperation = TableOperation.Insert(secondTableEntry);
            await testTable.ExecuteAsync(insertOperation);

            CombatTableEntry thirdTableEntry = new CombatTableEntry(SessionId, 2, Guid.NewGuid(), CombatType.SpoilsOfWar);

            insertOperation = TableOperation.Insert(thirdTableEntry);
            await testTable.ExecuteAsync(insertOperation);

            // Act
            var results = await repository.GetCombat(SessionId, 1, CombatType.SpoilsOfWar);

            // Assert
            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Count());

            ICombat result = results.Where(combat => combat.CombatId == combatId).FirstOrDefault();

            Assert.IsNull(result);

            result = results.Where(combat => combat.CombatId == secondCombatId).FirstOrDefault();
            Assert.IsNotNull(result);
            Assert.AreEqual(CombatType.SpoilsOfWar, result.ResolutionType);
        }
        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);
        }