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


C# JsonPatchDocument.ApplyTo方法代码示例

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


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

示例1: WHEN_Patch2_is_applied_with_multiples_changes_THEN_sum_change_to_correct_value

 public void WHEN_Patch2_is_applied_with_multiples_changes_THEN_sum_change_to_correct_value()
 {
     var basket = JsonConvert.DeserializeObject<StockMarketOrders>(TestData.ORIGINAL_DATA);
     var patch = JsonConvert.DeserializeObject<List<Operation<StockMarketOrders>>>(TestData.PATCH_2);
     JsonPatchDocument<StockMarketOrders> doc = new JsonPatchDocument<StockMarketOrders>(patch);
     doc.ApplyTo(basket);
     var sum = basket.Select(x => x.Price).Sum();
     //expected = original sum + sum(- item source price + item new price)
     var expectedSum = 718 + (-78 + 0) + (-77 + 13) + (-22 + 27);
     Check.That(sum).IsEqualTo(expectedSum);//=581
 }
开发者ID:rhwy,项目名称:streamdataio.Net,代码行数:11,代码来源:EnsureJsonPatchWorksWithTheModel.cs

示例2: WHEN_Patch1_is_applied_THEN_sum_change_to_correct_value

 public void WHEN_Patch1_is_applied_THEN_sum_change_to_correct_value()
 {
     var basket = JsonConvert.DeserializeObject<StockMarketOrders>(TestData.ORIGINAL_DATA);
     var patch = JsonConvert.DeserializeObject<List<Operation<StockMarketOrders>>>(TestData.PATCH_1);
     JsonPatchDocument<StockMarketOrders> doc = new JsonPatchDocument<StockMarketOrders>(patch);
     doc.ApplyTo(basket);
     var sum = basket.Select(x => x.Price).Sum();
     var expectedSum = 718 - 60 + 95;
     //on patch one only one value changed from 60 to 95
     Check.That(sum).IsEqualTo(expectedSum);
 }
开发者ID:rhwy,项目名称:streamdataio.Net,代码行数:11,代码来源:EnsureJsonPatchWorksWithTheModel.cs

示例3: WHEN_Two_patches_are_applied_THEN_sum_change_to_correct_value

 public void WHEN_Two_patches_are_applied_THEN_sum_change_to_correct_value()
 {
     var basket = JsonConvert.DeserializeObject<StockMarketOrders>(TestData.ORIGINAL_DATA);
     var patch1 = JsonConvert.DeserializeObject<List<Operation<StockMarketOrders>>>(TestData.PATCH_1);
     var patch2 = JsonConvert.DeserializeObject<List<Operation<StockMarketOrders>>>(TestData.PATCH_2);
     JsonPatchDocument<StockMarketOrders> documentPatcher1 = new JsonPatchDocument<StockMarketOrders>(patch1);
     JsonPatchDocument<StockMarketOrders> documentPatcher2 = new JsonPatchDocument<StockMarketOrders>(patch2);
     documentPatcher1.ApplyTo(basket);
     documentPatcher2.ApplyTo(basket);
     var sum = basket.Select(x => x.Price).Sum();
     Check.That(sum).IsEqualTo(616);
 }
开发者ID:rhwy,项目名称:streamdataio.Net,代码行数:12,代码来源:EnsureJsonPatchWorksWithTheModel.cs

示例4: 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

示例5: ReplacePropertyInNestedObject

        public void ReplacePropertyInNestedObject()
        {
            var doc = new SimpleDTOWithNestedDTO()
            {
                IntegerValue = 1

            };

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

            patchDoc.ApplyTo(doc);

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

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

示例6: 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

示例7: 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

示例8: ReplaceNestedObject

        public void ReplaceNestedObject()
        {
            // Arrange
            var doc = new SimpleDTOWithNestedDTO()
            {
                IntegerValue = 1
            };

            var newNested = new NestedDTO() { StringProperty = "B" };

            // create patch
            var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
            patchDoc.Replace<NestedDTO>(o => o.NestedDTO, newNested);

            // Act
            patchDoc.ApplyTo(doc);

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

示例9: RemoveFromListInvalidPositionTooSmall

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

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

            // Act & Assert
            var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
            Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message);
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:16,代码来源:ObjectAdapterTests.cs

示例10: 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

示例11: MoveInList

        public void MoveInList()
        {
            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.SimpleDTO.IntegerList, 1);

            patchDoc.ApplyTo(doc);

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

示例12: CopyFromNonListToList

        public void CopyFromNonListToList()
        {
            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.Copy<int>(o => o.SimpleDTO.IntegerValue, o => o.SimpleDTO.IntegerList, 0);

            patchDoc.ApplyTo(doc);

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

示例13: AddResultsInReplace

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

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

            patchDoc.ApplyTo(doc);

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

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

示例14: Copy

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

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

            patchDoc.ApplyTo(doc);

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

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

示例15: ReplaceAtEndOfList

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

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

            patchDoc.ApplyTo(doc);


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

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


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