本文整理汇总了C#中JsonPatchDocument.ApplyUpdatesTo方法的典型用法代码示例。如果您正苦于以下问题:C# JsonPatchDocument.ApplyUpdatesTo方法的具体用法?C# JsonPatchDocument.ApplyUpdatesTo怎么用?C# JsonPatchDocument.ApplyUpdatesTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonPatchDocument
的用法示例。
在下文中一共展示了JsonPatchDocument.ApplyUpdatesTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Patch
public Car Patch(int id, JsonPatchDocument<Car> patchData)
{
// TODO: Do some validation and all that fun stuff
var carTuple = _carsCtx.GetSingle(id);
if (!carTuple.Item1)
{
var response = Request.CreateResponse(HttpStatusCode.NotFound);
throw new HttpResponseException(response);
}
patchData.ApplyUpdatesTo(carTuple.Item2);
carTuple.Item2.Id = id;
if (!_carsCtx.TryUpdate(carTuple.Item2))
{
var response = Request.CreateResponse(HttpStatusCode.NotFound);
throw new HttpResponseException(response);
}
return carTuple.Item2;
}
示例2: ApplyUpdate_MoveFromPropertyToList_EntityUpdated
public void ApplyUpdate_MoveFromPropertyToList_EntityUpdated()
{
//Arrange
var patchDocument = new JsonPatchDocument<ComplexEntity>();
var entity = new ComplexEntity
{
Bar = new SimpleEntity
{
Foo = "I am foo"
},
Norf = new List<ListEntity>
{
new ListEntity
{
Foo = new List<string> { "Element One", "Element Two", "Element Three" }
}
}
};
//Act
patchDocument.Move("/Bar/Foo", "/Norf/0/Foo/1");
patchDocument.ApplyUpdatesTo(entity);
//Assert
Assert.IsNull(entity.Bar.Foo);
Assert.AreEqual(4, entity.Norf[0].Foo.Count);
Assert.AreEqual("Element One", entity.Norf[0].Foo[0]);
Assert.AreEqual("I am foo", entity.Norf[0].Foo[1]);
Assert.AreEqual("Element Two", entity.Norf[0].Foo[2]);
Assert.AreEqual("Element Three", entity.Norf[0].Foo[3]);
}
示例3: 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]);
}
示例4: ApplyUpdate_MoveOperation_EntityUpdated
public void ApplyUpdate_MoveOperation_EntityUpdated()
{
//Arrange
var patchDocument = new JsonPatchDocument<SimpleEntity>();
var entity = new SimpleEntity { Foo = "bar", Baz = "qux" };
//Act
patchDocument.Move("Foo", "Baz");
patchDocument.ApplyUpdatesTo(entity);
//Assert
Assert.IsNull(entity.Foo);
Assert.AreEqual("bar", entity.Baz);
}
示例5: ApplyUpdate_ReplaceOperation_EntityUpdated
public void ApplyUpdate_ReplaceOperation_EntityUpdated()
{
//Arrange
var patchDocument = new JsonPatchDocument<SimpleEntity>();
var entity = new SimpleEntity { Foo = "bar" };
//Act
patchDocument.Replace("Foo", "baz");
patchDocument.ApplyUpdatesTo(entity);
//Assert
Assert.AreEqual("baz", entity.Foo);
}