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


C# JsonPatchDocument.Remove方法代码示例

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


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

示例1: Remove_InvalidPath_ThrowsJsonPatchParseException

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

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

示例2: Remove_ValidPath_OperationAdded

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

            //Act
            patchDocument.Remove("Foo");

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

示例3: RemoveFromList

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

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Remove("IntegerList/2");

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

            deserialized.ApplyTo(doc);

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

示例4: NestedRemove

        public void NestedRemove()
        {
            dynamic doc = new ExpandoObject();
            doc.SimpleDTO = new SimpleDTO()
            {
                StringProperty = "A"
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Remove("SimpleDTO/StringProperty");

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

            deserialized.ApplyTo(doc);
            Assert.Equal(null, doc.SimpleDTO.StringProperty);
        }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:18,代码来源:RemoveOperationTests.cs

示例5: NestedRemoveFromEndOfList

        public void NestedRemoveFromEndOfList()
        {
            dynamic doc = new ExpandoObject();
            doc.SimpleDTO = new SimpleDTO()
            {
                IntegerList = new List<int>() { 1, 2, 3 }
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Remove("SimpleDTO/IntegerList/-");

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

            deserialized.ApplyTo(doc);
            Assert.Equal(new List<int>() { 1, 2 }, doc.SimpleDTO.IntegerList);
        }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:18,代码来源:RemoveOperationTests.cs

示例6: RemovePropertyFromExpandoObject

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

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Remove("Test");

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

            deserialized.ApplyTo(obj);

            var cont = obj as IDictionary<string, object>;
            object valueFromDictionary;

            cont.TryGetValue("Test", out valueFromDictionary);
            Assert.Null(valueFromDictionary);
        }
开发者ID:leloulight,项目名称:JsonPatch,代码行数:20,代码来源:RemoveOperationTests.cs

示例7: RemovePropertyShouldFailIfItDoesntExist

        public void RemovePropertyShouldFailIfItDoesntExist()
        {
            dynamic doc = new ExpandoObject();
            doc.Test = 1;

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Remove("NonExisting");

            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 '/NonExisting' could not be removed.",
                exception.Message);
        }
开发者ID:leloulight,项目名称:JsonPatch,代码行数:20,代码来源:RemoveOperationTests.cs

示例8: RemovePropertyShouldFailIfRootIsAnonymous

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

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Remove("Test");

            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 '/Test' could not be updated.",
                exception.Message);
        }
开发者ID:leloulight,项目名称:JsonPatch,代码行数:22,代码来源:RemoveOperationTests.cs

示例9: RemoveFromListInvalidPositionTooLarge

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

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Remove("IntegerList/3");

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

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

示例10: RemoveFromListInvalidPositionTooSmallWithSerialization

        public void RemoveFromListInvalidPositionTooSmallWithSerialization()
        {

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

            // create patch
            JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, -1);

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


            Assert.Throws<JsonPatchException>(() => { deserialized.ApplyTo(doc); });

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

示例11: RemoveFromListInvalidPositionTooSmall

        public void RemoveFromListInvalidPositionTooSmall()
        {

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

            // create patch
            JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, -1);


            Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });

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

示例12: RemoveWithSerialization

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

            // create patch
            JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Remove<string>(o => o.SimpleDTO.StringProperty);

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


            deserialized.ApplyTo(doc);

            Assert.Equal(null, doc.SimpleDTO.StringProperty);

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

示例13: Remove

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

            // create patch
            JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Remove<string>(o => o.SimpleDTO.StringProperty);

            patchDoc.ApplyTo(doc);

            Assert.Equal(null, doc.SimpleDTO.StringProperty);

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

示例14: RemoveFromListInvalidPositionTooLarge

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

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, 3);

            // Act & Assert
            var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
            Assert.Equal(
                "For operation 'remove' on array property at path '/simpledto/integerlist/3', the index is " +
                    "larger than the array size.",
                exception.Message);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:22,代码来源:NestedObjectTests.cs

示例15: Remove

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

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Remove<string>(o => o.StringProperty);

            // Act
            patchDoc.ApplyTo(doc);

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


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