コード例 #1
0
        public void ConflictSettingsSerializeTest()
        {
            string id = Guid.NewGuid().ToString();

            CosmosConflictProperties conflictSettings = new CosmosConflictProperties()
            {
                Id            = id,
                OperationKind = Cosmos.OperationKind.Create,
                ResourceType  = typeof(CosmosStoredProcedureProperties)
            };

            Conflict conflict = new Conflict()
            {
                Id            = id,
                OperationKind = OperationKind.Create,
                ResourceType  = typeof(StoredProcedure)
            };

            string cosmosSerialized = SettingsContractTests.CosmosSerialize(conflictSettings);
            string directSerialized = SettingsContractTests.DirectSerialize(conflict);

            // Swap de-serialize and validate
            CosmosConflictProperties conflictDeserSettings = SettingsContractTests.CosmosDeserialize <CosmosConflictProperties>(directSerialized);
            Conflict conflictDeser = SettingsContractTests.DirectDeSerialize <Conflict>(cosmosSerialized);

            Assert.AreEqual(conflictDeserSettings.Id, conflictDeser.Id);
            Assert.AreEqual((int)conflictDeserSettings.OperationKind, (int)conflictDeser.OperationKind);
            Assert.AreEqual(typeof(StoredProcedure), conflictDeser.ResourceType);
            Assert.AreEqual(typeof(CosmosStoredProcedureProperties), conflictDeserSettings.ResourceType);
            Assert.AreEqual(conflictDeserSettings.Id, conflict.Id);
        }
コード例 #2
0
        public void ConflictsSettingsDefaults()
        {
            CosmosConflictProperties conflictSettings = new CosmosConflictProperties();

            Assert.IsNull(conflictSettings.ResourceType);
            Assert.AreEqual(Cosmos.OperationKind.Invalid, conflictSettings.OperationKind);
            Assert.IsNull(conflictSettings.Id);

            SettingsContractTests.TypeAccessorGuard(typeof(CosmosConflictProperties), "Id", "OperationKind", "ResourceType", "SourceResourceId");
        }
コード例 #3
0
        public void ReadConflictContentDeserializesContent()
        {
            CosmosContainerCore container = CosmosConflictTests.GetMockedContainer((request, cancellationToken) => {
                return(TestHandler.ReturnSuccess());
            });

            JObject someJsonObject = new JObject();

            someJsonObject["id"]      = Guid.NewGuid().ToString();
            someJsonObject["someInt"] = 2;

            CosmosConflictProperties conflictSettings = new CosmosConflictProperties();

            conflictSettings.Content = someJsonObject.ToString();

            Assert.AreEqual(someJsonObject.ToString(), container.GetConflicts().ReadConflictContent <JObject>(conflictSettings).ToString());
        }
コード例 #4
0
        public void ConflictSettingsDeSerializeTest()
        {
            string conflictResponsePayload = @"{
                 id: 'Conflict1',
                 operationType: 'Replace',
                 resourceType: 'trigger'
                }";

            CosmosConflictProperties conflictSettings = SettingsContractTests.CosmosDeserialize <CosmosConflictProperties>(conflictResponsePayload);
            Conflict conflict = SettingsContractTests.DirectDeSerialize <Conflict>(conflictResponsePayload);

            Assert.AreEqual(conflict.Id, conflictSettings.Id);
            Assert.AreEqual((int)conflictSettings.OperationKind, (int)conflict.OperationKind);
            Assert.AreEqual(typeof(Trigger), conflict.ResourceType);
            Assert.AreEqual(typeof(CosmosTriggerProperties), conflictSettings.ResourceType);

            Assert.AreEqual("Conflict1", conflictSettings.Id);
        }
コード例 #5
0
        public async Task CosmosConflictsStreamIteratorBuildsSettings()
        {
            string conflictResponsePayload = @"{ 'Data':[{
                 id: 'Conflict1',
                 operationType: 'Replace',
                 resourceType: 'trigger'
                }]}";

            CosmosClient mockClient = MockCosmosUtil.CreateMockCosmosClient(
                (cosmosClientBuilder) => cosmosClientBuilder.WithConnectionModeDirect());

            CosmosContainer container    = mockClient.GetContainer("database", "container");
            FeedIterator    feedIterator = container.GetConflicts().GetConflictsStreamIterator();

            TestHandler testHandler = new TestHandler((request, cancellationToken) =>
            {
                Assert.AreEqual(OperationType.ReadFeed, request.OperationType);
                Assert.AreEqual(ResourceType.Conflict, request.ResourceType);
                CosmosResponseMessage handlerResponse = TestHandler.ReturnSuccess().Result;
                MemoryStream stream = new MemoryStream();
                StreamWriter writer = new StreamWriter(stream);
                writer.Write(conflictResponsePayload);
                writer.Flush();
                stream.Position = 0;

                handlerResponse.Content = stream;
                return(Task.FromResult(handlerResponse));
            });

            mockClient.RequestHandler.InnerHandler = testHandler;
            CosmosResponseMessage streamResponse = await feedIterator.FetchNextSetAsync();

            Collection <CosmosConflictProperties> response = new CosmosJsonSerializerCore().FromStream <CosmosFeedResponseUtil <CosmosConflictProperties> >(streamResponse.Content).Data;

            Assert.AreEqual(1, response.Count());

            CosmosConflictProperties responseSettings = response.FirstOrDefault();

            Assert.IsNotNull(responseSettings);

            Assert.AreEqual("Conflict1", responseSettings.Id);
            Assert.AreEqual(Cosmos.OperationKind.Replace, responseSettings.OperationKind);
            Assert.AreEqual(typeof(CosmosTriggerProperties), responseSettings.ResourceType);
        }
コード例 #6
0
        public async Task DeleteSendsCorrectPayload()
        {
            const string expectedId = "something";

            Cosmos.PartitionKey partitionKey = new Cosmos.PartitionKey("pk");
            Uri expectedRequestUri           = new Uri($"/dbs/conflictsDb/colls/conflictsColl/conflicts/{expectedId}", UriKind.Relative);
            CosmosContainerCore container    = CosmosConflictTests.GetMockedContainer((request, cancellationToken) => {
                Assert.AreEqual(OperationType.Delete, request.OperationType);
                Assert.AreEqual(ResourceType.Conflict, request.ResourceType);
                Assert.AreEqual(expectedRequestUri, request.RequestUri);
                return(TestHandler.ReturnSuccess());
            });

            CosmosConflictProperties conflictSettings = new CosmosConflictProperties();

            conflictSettings.Id = expectedId;

            await container.GetConflicts().DeleteConflictAsync(partitionKey, conflictSettings);
        }
コード例 #7
0
        public async Task ReadCurrentGetsCorrectRID()
        {
            const string expectedRID = "something";

            Cosmos.PartitionKey partitionKey = new Cosmos.PartitionKey("pk");
            // Using "test" as container name because the Mocked DocumentClient has it hardcoded
            Uri expectedRequestUri        = new Uri($"dbs/conflictsDb/colls/test/docs/{expectedRID}", UriKind.Relative);
            CosmosContainerCore container = CosmosConflictTests.GetMockedContainer((request, cancellationToken) => {
                Assert.AreEqual(OperationType.Read, request.OperationType);
                Assert.AreEqual(ResourceType.Document, request.ResourceType);
                Assert.AreEqual(expectedRequestUri, request.RequestUri);
                return(TestHandler.ReturnSuccess());
            });

            CosmosConflictProperties conflictSettings = new CosmosConflictProperties();

            conflictSettings.SourceResourceId = expectedRID;

            await container.GetConflicts().ReadCurrentAsync <JObject>(partitionKey, conflictSettings);
        }