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


C# JsonPatchDocument.Move方法代码示例

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


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

示例1: MoveFromListToEndOfList

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

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Move("IntegerList/0", "IntegerList/-");

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

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

示例2: MoveFomListToNonList

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

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Move("IntegerList/0", "IntegerValue");

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

            deserialized.ApplyTo(doc);

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

示例3: Move

        public void Move()
        {
            var doc = new SimpleDTO()
            {
                StringProperty = "A",
                AnotherStringProperty = "B"
            };

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Move("StringProperty", "AnotherStringProperty");

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

            deserialized.ApplyTo(doc);

            Assert.Equal("A", doc.AnotherStringProperty);
            Assert.Equal(null, doc.StringProperty);
        }
开发者ID:leloulight,项目名称:JsonPatch,代码行数:20,代码来源:MoveTypedOperationTests.cs

示例4: MoveToNonExisting

        public void MoveToNonExisting()
        {
            dynamic doc = new ExpandoObject();
            doc.StringProperty = "A";

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Move("StringProperty", "AnotherStringProperty");

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

            deserialized.ApplyTo(doc);

            Assert.Equal("A", doc.AnotherStringProperty);

            var cont = doc as IDictionary<string, object>;
            object valueFromDictionary;
            cont.TryGetValue("StringProperty", out valueFromDictionary);
            Assert.Null(valueFromDictionary);
        }
开发者ID:leloulight,项目名称:JsonPatch,代码行数:21,代码来源:MoveOperationTests.cs

示例5: Move_ArrayIndexes_OperationAdded

        public void Move_ArrayIndexes_OperationAdded()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument<ArrayEntity>();

            //Act
            patchDocument.Move("Foo/5", "Foo/2");

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

示例6: MoveToEndOfList

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

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTO>();
            patchDoc.Move<int>(o => o.IntegerValue, o => o.IntegerList);

            // Act
            patchDoc.ApplyTo(doc);

            // Assert
            Assert.Equal(0, doc.IntegerValue);
            Assert.Equal(new List<int>() { 1, 2, 3, 5 }, doc.IntegerList);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:20,代码来源:ObjectAdapterTests.cs

示例7: MoveInListWithSerialization

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

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

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

            deserialized.ApplyTo(doc);

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

示例8: MoveToEndOfList

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

            // create patch
            JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Move<int>(o => o.SimpleDTO.IntegerValue, o => o.SimpleDTO.IntegerList);

            patchDoc.ApplyTo(doc);

            Assert.Equal(0, doc.IntegerValue);

            Assert.Equal(new List<int>() { 1, 2, 3, 5 }, doc.SimpleDTO.IntegerList);

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

示例9: MoveFomListToNonListBetweenHierarchy

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

            // create patch
            JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Move<int>(o => o.SimpleDTO.IntegerList, 0, o => o.IntegerValue);

            patchDoc.ApplyTo(doc);

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

示例10: MoveWithSerialization

        public void MoveWithSerialization()
        {
            var doc = new SimpleDTOWithNestedDTO()
            {
                SimpleDTO = new SimpleDTO()
                {
                    StringProperty = "A",
                    AnotherStringProperty = "B"
                }
            };

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

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

            Assert.Equal("A", doc.SimpleDTO.AnotherStringProperty);
            Assert.Equal(null, doc.SimpleDTO.StringProperty);
        }
开发者ID:Drakraq,项目名称:JsonPatch,代码行数:22,代码来源:ObjectAdapterTestsOnNested.cs

示例11: Move_ValidPaths_OperationAdded

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

            //Act
            patchDocument.Move("Foo", "Baz");

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

示例12: ApplyUpdate_MoveListElement_EntityUpdated

        public void ApplyUpdate_MoveListElement_EntityUpdated()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument<ListEntity>();
            var entity = new ListEntity
            {
                Foo = new List<string> { "Element One", "Element Two", "Element Three" }
            };

            //Act
            patchDocument.Move("/Foo/2", "/Foo/1");
            patchDocument.ApplyUpdatesTo(entity);

            //Assert
            Assert.AreEqual(3, entity.Foo.Count);
            Assert.AreEqual("Element One", entity.Foo[0]);
            Assert.AreEqual("Element Three", entity.Foo[1]);
            Assert.AreEqual("Element Two", entity.Foo[2]);
        }
开发者ID:bradodarb,项目名称:JsonPatch,代码行数:19,代码来源:JsonPatchDocumentTests.cs

示例13: Move_InvalidDestinationPath_ThrowsJsonPatchParseException

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

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

示例14: NestedMoveToEndOfList

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

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Move("Nested/IntegerValue", "Nested/IntegerList/-");

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

            deserialized.ApplyTo(doc);

            Assert.Equal(0, doc.Nested.IntegerValue);
            Assert.Equal(new List<int>() { 1, 2, 3, 5 }, doc.Nested.IntegerList);
        }
开发者ID:aspnet,项目名称:JsonPatch,代码行数:21,代码来源:MoveOperationTests.cs

示例15: MoveTypedToDynamic

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

            // create patch
            JsonPatchDocument patchDoc = new JsonPatchDocument();
            patchDoc.Move("SimpleDTO/AnotherStringProperty", "StringProperty");

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

            deserialized.ApplyTo(doc);

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


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