public void RemoveNestedProperty_FromDynamicObject() { // Arrange dynamic dynamicTestObject = new DynamicTestObject(); dynamicTestObject.Test = new DynamicTestObject(); dynamicTestObject.Test.AnotherTest = "A"; var patchDoc = new JsonPatchDocument(); patchDoc.Remove("Test"); // Act patchDoc.ApplyTo(dynamicTestObject); dynamicTestObject.TryGetValue("Test", out object valueFromDictionary); // Assert Assert.Null(valueFromDictionary); }
public void MoveToNonExistingProperty_InDynamicObject_ShouldAddNewProperty() { // Arrange dynamic dynamicTestObject = new DynamicTestObject(); dynamicTestObject.StringProperty = "A"; var patchDoc = new JsonPatchDocument(); patchDoc.Move("StringProperty", "AnotherStringProperty"); // Act patchDoc.ApplyTo(dynamicTestObject); dynamicTestObject.TryGetValue("StringProperty", out object valueFromDictionary); // Assert Assert.Equal("A", dynamicTestObject.AnotherStringProperty); Assert.Null(valueFromDictionary); }
public void MovePropertyValue_FromDynamicObject_ToTypedObject() { // Arrange dynamic dynamicTestObject = new DynamicTestObject(); dynamicTestObject.StringProperty = "A"; dynamicTestObject.SimpleObject = new SimpleObject() { AnotherStringProperty = "B" }; var patchDoc = new JsonPatchDocument(); patchDoc.Move("StringProperty", "SimpleObject/AnotherStringProperty"); // Act patchDoc.ApplyTo(dynamicTestObject); dynamicTestObject.TryGetValue("StringProperty", out object valueFromDictionary); // Assert Assert.Equal("A", dynamicTestObject.SimpleObject.AnotherStringProperty); Assert.Null(valueFromDictionary); }