示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        public async Task IntegrationTestGetCards()
        {
            // Arrange
            NationRepository  repository        = new NationRepository(DevelopmentStorageAccountConnectionString);
            SessionRepository sessionRepository = new SessionRepository(DevelopmentStorageAccountConnectionString);
            Guid   validGuid        = new Guid("03ECAE31-CB33-4537-9E22-FE1A68BFFA08");
            Guid   dummyRegionAGuid = new Guid("FD28529F-011D-42F5-B9B2-0F7AEA80CB8A");
            Guid   dummyRegionBGuid = new Guid("A05EBB51-1BAA-4E4E-B43E-7E30EB89F5C7");
            Guid   dummyRegionCGuid = new Guid("21B47511-8376-44F1-835D-41FF3BD1A860");
            String dummyUserId      = "DummyUserId";
            await sessionRepository.SetupSession(validGuid, dummyUserId);

            CardTableEntry ownedCard = await sessionRepository.SetupAddCard(validGuid, dummyRegionAGuid, CardTableEntry.State.Owned, dummyUserId, 3);

            await sessionRepository.SetupAddCard(validGuid, dummyRegionBGuid, CardTableEntry.State.Unowned, String.Empty, 5);

            await sessionRepository.SetupAddCard(validGuid, dummyRegionCGuid, CardTableEntry.State.Discarded, dummyUserId, 7);

            // Act
            IEnumerable <ICardData> ownedCards = await repository.GetCards(validGuid, dummyUserId);

            // Assert
            Assert.IsNotNull(ownedCards);
            Assert.AreEqual(1, ownedCards.Count());
            Assert.AreEqual(dummyUserId, ownedCards.First().OwnerId);
            Assert.AreEqual(dummyRegionAGuid, ownedCards.First().RegionId);
            Assert.AreEqual(3U, ownedCards.First().Value);
            Assert.AreEqual(ownedCard.ETag, ownedCards.First().CurrentEtag);
        }
示例#5
0
        private void SetCardInternal(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Guid regionId, CardTableEntry.State newState, String newOwnerId, String currentEtag)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Get the session data table
            CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            // Create a DynamicTableEntity so that we can do a partial update of this table (a merge)
            DynamicTableEntity cardEntry = CardTableEntry.CreateDynamicTableEntity(sessionId, regionId, currentEtag);

            CardTableEntry.SetOwner(cardEntry, newState, newOwnerId);
            batchOperationHandle.BatchOperation.Merge(cardEntry);
        }
        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);
        }
        static internal async Task <CardTableEntry> SetupAddCard(this SessionRepository repository, Guid sessionId, Guid regionId, CardTableEntry.State initialState, String ownerId, UInt32 value)
        {
            var dataTable = repository.GetTableForSessionData(sessionId);

            CardTableEntry newCardEntry = new CardTableEntry(sessionId, regionId);

            newCardEntry.ValueRaw      = (Int32)value;
            newCardEntry.OwnerId       = ownerId;
            newCardEntry.OwnerStateRaw = (Int32)initialState;

            TableOperation insertOperation = TableOperation.InsertOrReplace(newCardEntry);
            await dataTable.ExecuteAsync(insertOperation);

            return(newCardEntry);
        }
示例#8
0
        public void CreateRegion(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Guid regionId, Guid continentId, String name, IEnumerable <Guid> connectedRegions, UInt32 cardValue)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Create a new table entry
            RegionTableEntry newRegion = new RegionTableEntry(sessionId, regionId, continentId, name, cardValue);

            newRegion.IsValid();
            newRegion.SetConnectedRegions(connectedRegions);
            batchOperationHandle.BatchOperation.Insert(newRegion);

            // Create a new card for this region
            CardTableEntry newCard = new CardTableEntry(sessionId, regionId);

            newCard.IsValid();
            newCard.ValueRaw = (Int32)cardValue;
            batchOperationHandle.BatchOperation.Insert(newCard);
        }