public Move ( string from, string path ) : |
||
from | string | source location |
path | string | target location |
return |
public void MovePropertyValue_ForExpandoObject_WithCustomNamingStrategy() { // Arrange var contractResolver = new DefaultContractResolver { NamingStrategy = new TestNamingStrategy() }; dynamic targetObject = new ExpandoObject(); targetObject.customStringProperty = "A"; targetObject.customAnotherStringProperty = "B"; var patchDocument = new JsonPatchDocument(); patchDocument.Move("StringProperty", "AnotherStringProperty"); patchDocument.ContractResolver = contractResolver; // Act patchDocument.ApplyTo(targetObject); var cont = targetObject as IDictionary <string, object>; cont.TryGetValue("customStringProperty", out var valueFromDictionary); // Assert Assert.Equal("A", targetObject.customAnotherStringProperty); Assert.Null(valueFromDictionary); }
public void Move_FallsbackToPropertyName_WhenJsonPropertyAttributeName_IsEmpty() { // Arrange var patchDocument = new JsonPatchDocument <JsonPropertyWithNoPropertyName>(); // Act patchDocument.Move(m => m.StringProperty, m => m.StringProperty2); // Assert var fromPath = patchDocument.Operations.First().from; Assert.Equal("/StringProperty", fromPath); var toPath = patchDocument.Operations.First().path; Assert.Equal("/StringProperty2", toPath); }
public void Move_WithExpression_FallsbackToPropertyName_WhenJsonPropertyName_IsEmpty() { // Arrange var patchDoc = new JsonPatchDocument <JsonPropertyWithNoPropertyName>(); patchDoc.Move(m => m.StringProperty, m => m.StringProperty2); var serialized = JsonConvert.SerializeObject(patchDoc); // Act var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument <JsonPropertyWithNoPropertyName> >(serialized); // Assert var fromPath = deserialized.Operations.First().from; Assert.Equal("/StringProperty", fromPath); var toPath = deserialized.Operations.First().path; Assert.Equal("/StringProperty2", toPath); }