public void ApplyTo_Model_Test1() { // Arrange var model = new ObjectWithJObject { CustomData = JObject.FromObject(new { Email = "*****@*****.**", Name = "Bar" }) }; var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("test", "/CustomData/Email", null, "*****@*****.**")); patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Name", null, "Bar Baz")); // Act & Assert Assert.Throws <JsonPatchException>(() => patch.ApplyTo(model)); }
public void ApplyTo_Model_Add_Null() { // Arrange var model = new ObjectWithJObject(); var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Name", null, null)); // Act patch.ApplyTo(model); // Assert Assert.Equal(JTokenType.Null, model.CustomData["Name"].Type); }
public void ApplyTo_Model_Add() { // Arrange var model = new ObjectWithJObject(); var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Name", null, "Foo")); // Act patch.ApplyTo(model); // Assert Assert.Equal("Foo", model.CustomData["Name"].Value <string>()); }
public void ApplyTo_Model_Remove() { // Arrange var model = new ObjectWithJObject { CustomData = JObject.FromObject(new { FirstName = "Foo", LastName = "Bar" }) }; var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("remove", "/CustomData/LastName", null)); // Act patch.ApplyTo(model); // Assert Assert.False(model.CustomData.ContainsKey("LastName")); }
public void ApplyTo_Model_Copy() { // Arrange var model = new ObjectWithJObject { CustomData = JObject.FromObject(new { Email = "*****@*****.**" }) }; var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("copy", "/CustomData/UserName", "/CustomData/Email")); // Act patch.ApplyTo(model); // Assert Assert.Equal("*****@*****.**", model.CustomData["UserName"].Value <string>()); }
public void ApplyTo_Model_Replace_Null() { // Arrange var model = new ObjectWithJObject { CustomData = JObject.FromObject(new { Email = "*****@*****.**", Name = "Bar" }) }; var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("replace", "/CustomData/Email", null, null)); // Act patch.ApplyTo(model); // Assert Assert.Equal(JTokenType.Null, model.CustomData["Email"].Type); }
public void ApplyTo_Array_Add() { // Arrange var model = new ObjectWithJObject { CustomData = JObject.FromObject(new { Emails = new[] { "*****@*****.**" } }) }; var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Emails/-", null, "*****@*****.**")); // Act patch.ApplyTo(model); // Assert Assert.Equal("*****@*****.**", model.CustomData["Emails"][1].Value <string>()); }
public void ApplyTo_Model_Test2() { // Arrange var model = new ObjectWithJObject { CustomData = JObject.FromObject(new { Email = "*****@*****.**", Name = "Bar" }) }; var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("test", "/CustomData/Email", null, "*****@*****.**")); patch.Operations.Add(new Operation <ObjectWithJObject>("add", "/CustomData/Name", null, "Bar Baz")); // Act patch.ApplyTo(model); // Assert Assert.Equal("Bar Baz", model.CustomData["Name"].Value <string>()); }
public void ApplyTo_Model_Move() { // Arrange var model = new ObjectWithJObject { CustomData = JObject.FromObject(new { FirstName = "Bar" }) }; var patch = new JsonPatchDocument <ObjectWithJObject>(); patch.Operations.Add(new Operation <ObjectWithJObject>("move", "/CustomData/LastName", "/CustomData/FirstName")); // Act patch.ApplyTo(model); // Assert Assert.False(model.CustomData.ContainsKey("FirstName")); Assert.Equal("Bar", model.CustomData["LastName"].Value <string>()); }