当前位置: 首页>>代码示例>>C#>>正文


C# JsonPatchDocument.Add方法代码示例

本文整理汇总了C#中JsonPatchDocument.Add方法的典型用法代码示例。如果您正苦于以下问题:C# JsonPatchDocument.Add方法的具体用法?C# JsonPatchDocument.Add怎么用?C# JsonPatchDocument.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonPatchDocument的用法示例。


在下文中一共展示了JsonPatchDocument.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddToListInListInvalidPositionTooLarge

        public void AddToListInListInvalidPositionTooLarge()
        {
            var doc = new SimpleDTOWithNestedDTO()
            {
                ListOfSimpleDTO = new List<SimpleDTO>()
                {
                     new SimpleDTO()
                     {
                        IntegerList = new List<int>() { 1, 2, 3 }
                     }
                }
            };
            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("ListOfSimpleDTO/20/IntegerList/0", 4);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);

            var exception = Assert.Throws<JsonPatchException>(() =>
            {
                deserialized.ApplyTo(doc);
            });
            Assert.Equal(
                "The property at path '/ListOfSimpleDTO/20/IntegerList/0' could not be added.",
                exception.Message);
        }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:27,代码来源:AddTypedOperationTests.cs

示例2: Add_InvalidPath_ThrowsJsonPatchParseException

        public void Add_InvalidPath_ThrowsJsonPatchParseException()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument<SimpleEntity>();

            //Act
            patchDocument.Add("FooMissing", "bar");
        }
开发者ID:bradodarb,项目名称:JsonPatch,代码行数:8,代码来源:JsonPatchDocumentTests.cs

示例3: CreateAServiceOnAkamai_UsingDefaults

        public async Task CreateAServiceOnAkamai_UsingDefaults()
        {
            Trace.WriteLine("Looking for a CDN flavor provided by Akamai...");
            var flavors = await _cdnService.ListFlavorsAsync();
            var flavor = flavors.FirstOrDefault(x => x.Providers.Any(p => string.Equals(p.Name, "Akamai", StringComparison.OrdinalIgnoreCase)));
            Assert.NotNull(flavor);
            var akamaiFlavor = flavor.Id;
            Trace.WriteLine(string.Format("Found the {0} flavor", akamaiFlavor));

            Trace.WriteLine("Creating a CDN service using defaults for anything I can omit...");
            var domains = new[] {new ServiceDomain("mirror.example.com")};
            var origins = new[] {new ServiceOrigin("example.com")};
            var serviceDefinition = new ServiceDefinition("ci-test", akamaiFlavor, domains, origins);
            var serviceId = await _cdnService.CreateServiceAsync(serviceDefinition);
            Trace.WriteLine(string.Format("Service was created: {0}", serviceId));

            try
            {
                Trace.WriteLine("Waiting for the service to be deployed...");
                var service = await _cdnService.WaitForServiceDeployedAsync(serviceId, progress: new Progress<bool>(x => Trace.WriteLine("...")));

                Trace.WriteLine("Verifying service matches the requested definition...");
                Assert.Equal("ci-test", service.Name);
                Assert.Equal(serviceDefinition.FlavorId, service.FlavorId);

                Assert.Equal(serviceDefinition.Origins.Count, service.Origins.Count());
                Assert.Equal(serviceDefinition.Origins.First().Origin, service.Origins.First().Origin);

                Assert.Equal(serviceDefinition.Domains.Count, service.Domains.Count());
                Assert.Equal(serviceDefinition.Domains.First().Domain, service.Domains.First().Domain);

                Trace.WriteLine("Updating the service...");
                var patch = new JsonPatchDocument<ServiceDefinition>();
                patch.Replace(x => x.Name, "ci-test2");
                var intranetOnly = new ServiceRestriction("intranet", new[] {new ServiceRestrictionRule("intranet", "intranet.example.com")});
                patch.Add(x => x.Restrictions, intranetOnly, 0);
                await _cdnService.UpdateServiceAsync(serviceId, patch);

                Trace.WriteLine("Waiting for the service changes to be deployed...");
                service = await _cdnService.WaitForServiceDeployedAsync(serviceId, progress: new Progress<bool>(x => Trace.WriteLine("...")));

                Trace.WriteLine("Verifying service matches updated definition...");
                Assert.Equal("ci-test2", service.Name);
                Assert.Equal(JsonConvert.SerializeObject(intranetOnly), JsonConvert.SerializeObject(service.Restrictions.First()));

                Trace.WriteLine("Purging all assets on service");
                await _cdnService.PurgeCachedAssetsAsync(serviceId);
            }
            finally
            {
                Trace.WriteLine("Cleaning up any test data...");

                Trace.WriteLine("Removing the service...");
                _cdnService.DeleteService(serviceId);
                _cdnService.WaitForServiceDeleted(serviceId);
                Trace.WriteLine("The service was cleaned up sucessfully.");
            }
        }
开发者ID:ravikamachi,项目名称:openstack.net,代码行数:58,代码来源:ServiceTests.cs

示例4: InvalidPathWithDotShouldThrowException

 public void InvalidPathWithDotShouldThrowException()
 {
     JsonPatchDocument patchDoc = new JsonPatchDocument();
     var exception = Assert.Throws<JsonPatchException>(() =>
     {
         patchDoc.Add("NewInt.Test", 1);
     });
     Assert.Equal(
        "The provided string 'NewInt.Test' is an invalid path.",
         exception.Message);
 }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:11,代码来源:PatchDocumentTests.cs

示例5: Add_ValidPath_OperationAdded

        public void Add_ValidPath_OperationAdded()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument<SimpleEntity>();

            //Act
            patchDocument.Add("Foo", "bar");

            //Assert
            Assert.AreEqual(1, patchDocument.Operations.Count);
            Assert.AreEqual(JsonPatchOperationType.add, patchDocument.Operations.Single().Operation);
        }
开发者ID:bradodarb,项目名称:JsonPatch,代码行数:12,代码来源:JsonPatchDocumentTests.cs

示例6: AddToList

        public void AddToList()
        {
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            JsonPatchDocument<SimpleDTO> patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<int>(o => o.IntegerList, 4, 0);

            patchDoc.ApplyTo(doc);

            Assert.Equal(new List<int>() { 4, 1, 2, 3 }, doc.IntegerList);
        }
开发者ID:Drakraq,项目名称:JsonPatch,代码行数:15,代码来源:ObjectAdapterTests.cs

示例7: AddNewProperty

        public void AddNewProperty()
        {
            dynamic obj = new ExpandoObject();
            obj.Test = 1;

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("NewInt", 1);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);

            deserialized.ApplyTo(obj);

            Assert.Equal(1, obj.NewInt);
            Assert.Equal(1, obj.Test);
        }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:17,代码来源:AddOperationTests.cs

示例8: AddResultsShouldReplace

        public void AddResultsShouldReplace()
        {
            // Arrange
            var doc = new SimpleDTO()
            {
                StringProperty = "A"
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<string>(o => o.StringProperty, "B");

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal("B", doc.StringProperty);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:18,代码来源:ObjectAdapterTests.cs

示例9: AddResultsShouldReplace

        public void AddResultsShouldReplace()
        {
            var doc = new SimpleDTO()
            {
                StringProperty = "A"
            };

            // create patch
            JsonPatchDocument<SimpleDTO> patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<string>(o => o.StringProperty, "B");

            patchDoc.ApplyTo(doc);

            var s = new Operations.Operation();

            Assert.Equal("B", doc.StringProperty);
          
        }
开发者ID:Drakraq,项目名称:JsonPatch,代码行数:18,代码来源:ObjectAdapterTests.cs

示例10: AddResultsShouldReplaceWithSerialization

        public void AddResultsShouldReplaceWithSerialization()
        {
            var doc = new SimpleDTO()
            {
                StringProperty = "A"
            };

            // create patch
            JsonPatchDocument<SimpleDTO> patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Add<string>(o => o.StringProperty, "B");


            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
            
            deserialized.ApplyTo(doc);

            Assert.Equal("B", doc.StringProperty);

        }
开发者ID:Drakraq,项目名称:JsonPatch,代码行数:20,代码来源:ObjectAdapterTests.cs

示例11: AddToListNegativePosition

        public void AddToListNegativePosition()
        {
            var doc = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("IntegerList/-1", 4);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);

            var exception = Assert.Throws<JsonPatchException>(() =>
            {
                deserialized.ApplyTo(doc);
            });
            Assert.Equal(
               "For operation 'add' on array property at path '/IntegerList/-1', the index is negative.",
                exception.Message);
        }
开发者ID:leloulight,项目名称:JsonPatch,代码行数:22,代码来源:AddTypedOperationTests.cs

示例12: AddNewPropertyShouldFailIfRootIsNotAnExpandoObject

        public void AddNewPropertyShouldFailIfRootIsNotAnExpandoObject()
        {
            dynamic doc = new
            {
                Test = 1
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("NewInt", 1);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);

            var exception = Assert.Throws<JsonPatchException>(() =>
            {
                deserialized.ApplyTo(doc);
            });
            Assert.Equal(
                "The property at path '/NewInt' could not be added.",
                exception.Message);
        }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:22,代码来源:AddOperationTests.cs

示例13: AddToListInList

        public void AddToListInList()
        {
            var doc = new SimpleDTOWithNestedDTO()
            {
                ListOfSimpleDTO = new List<SimpleDTO>()
                {
                     new SimpleDTO()
                     {
                         IntegerList = new List<int>() { 1, 2, 3 }
                     }
                }
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("ListOfSimpleDTO/0/IntegerList/0", 4);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);

            deserialized.ApplyTo(doc);
            Assert.Equal(new List<int>() { 4, 1, 2, 3 }, doc.ListOfSimpleDTO[0].IntegerList);
        }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:23,代码来源:AddTypedOperationTests.cs

示例14: AddNewPropertyToAnonymousObjectShouldFail

        public void AddNewPropertyToAnonymousObjectShouldFail()
        {
            dynamic doc = new
            {
                Test = 1
            };

            dynamic valueToAdd = new { IntValue = 1, StringValue = "test", GuidValue = Guid.NewGuid() };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Add("ComplexProperty", valueToAdd);

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);

            var exception = Assert.Throws<JsonPatchException>(() =>
            {
                deserialized.ApplyTo(doc);
            });
            Assert.Equal(
                "The property at path '/ComplexProperty' could not be added.",
                exception.Message);
        }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:24,代码来源:AddOperationTests.cs

示例15: AddResultsInReplaceWithSerialization

        public void AddResultsInReplaceWithSerialization()
        {
            // Arrange
            var doc = new SimpleDTOWithNestedDTO()
            {
                SimpleDTO = new SimpleDTO()
                {
                    StringProperty = "A"
                }
            };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Add<string>(o => o.SimpleDTO.StringProperty, "B");

            var serialized = JsonConvert.SerializeObject(patchDoc);
            var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);

            // Act
            deserialized.ApplyTo(doc);

            // Assert
            Assert.Equal("B", doc.SimpleDTO.StringProperty);
        }
开发者ID:slideroom,项目名称:JsonPatch,代码行数:24,代码来源:NestedObjectTests.cs


注:本文中的JsonPatchDocument.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。