public void TryGet_ThrowsPathNotFoundException_ForNonExistingProperty() { // Arrange var adapter = new DynamicObjectAdapter(); dynamic target = new DynamicTestObject(); var segment = "NewProperty"; var options = new JsonSerializerOptions(); // Act var getStatus = adapter.TryGet(target, typeof(DynamicTestObject), segment, options, out object getValue, out string getErrorMessage); // Assert Assert.False(getStatus); Assert.Null(getValue); Assert.Equal($"The target location specified by path segment '{segment}' was not found.", getErrorMessage); }
public void TryGet_GetsPropertyValue_ForExistingProperty() { // Arrange var adapter = new DynamicObjectAdapter(); dynamic target = new DynamicTestObject(); var segment = "NewProperty"; var options = new JsonSerializerOptions(); // Act 1 var addStatus = adapter.TryAdd(target, typeof(DynamicTestObject), segment, options, "new", out string errorMessage); // Assert 1 Assert.True(addStatus); Assert.Null(errorMessage); Assert.Equal("new", target.NewProperty); // Act 2 var getStatus = adapter.TryGet(target, typeof(DynamicTestObject), segment, options, out object getValue, out string getErrorMessage); // Assert 2 Assert.True(getStatus); Assert.Null(getErrorMessage); Assert.Equal(getValue, 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); }