本文整理汇总了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
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}