public void TryAdd_ReplacesExistingPropertyValue() { // Arrange var adapter = new DynamicObjectAdapter(); dynamic target = new DynamicTestObject(); target.List = new List <int>() { 1, 2, 3 }; var value = new List <string>() { "stringValue1", "stringValue2" }; var segment = "List"; var resolver = new DefaultContractResolver(); // Act var status = adapter.TryAdd(target, segment, resolver, value, out string errorMessage); // Assert Assert.True(status); Assert.Null(errorMessage); Assert.Equal(value, target.List); }
public void TryAdd_AddsNewProperty() { // Arrange var adapter = new DynamicObjectAdapter(); dynamic target = new DynamicTestObject(); var segment = "NewProperty"; var resolver = new DefaultContractResolver(); // Act var status = adapter.TryAdd(target, segment, resolver, "new", out string errorMessage); // Assert Assert.True(status); Assert.Null(errorMessage); Assert.Equal("new", target.NewProperty); }
public void TryGet_GetsPropertyValue_ForExistingProperty() { // Arrange var adapter = new DynamicObjectAdapter(); dynamic target = new DynamicTestObject(); var segment = "NewProperty"; var resolver = new DefaultContractResolver(); // Act 1 var addStatus = adapter.TryAdd(target, segment, resolver, "new", out string errorMessage); // Assert 1 Assert.True(addStatus); Assert.Null(errorMessage); Assert.Equal("new", target.NewProperty); // Act 2 var getStatus = adapter.TryGet(target, segment, resolver, out object getValue, out string getErrorMessage); // Assert 2 Assert.True(getStatus); Assert.Null(getErrorMessage); Assert.Equal(getValue, target.NewProperty); }
public void TryRemove_SetsPropertyToDefaultOrNull(object value, object expectedValue) { // Arrange var adapter = new DynamicObjectAdapter(); dynamic target = new DynamicTestObject(); var segment = "NewProperty"; var resolver = new DefaultContractResolver(); // Act 1 var addStatus = adapter.TryAdd(target, segment, resolver, value, out string errorMessage); // Assert 1 Assert.True(addStatus); Assert.Null(errorMessage); Assert.Equal(value, target.NewProperty); // Act 2 var removeStatus = adapter.TryRemove(target, segment, resolver, out string removeErrorMessage); // Assert 2 Assert.True(removeStatus); Assert.Null(removeErrorMessage); Assert.Equal(expectedValue, target.NewProperty); }