示例#1
0
        public void TryRemove_ThrowsPathNotFoundException_ForNonExistingProperty()
        {
            // Arrange
            var     adapter = new DynamicObjectAdapter();
            dynamic target  = new DynamicTestObject();
            var     segment = "NewProperty";
            var     options = new JsonSerializerOptions();

            // Act
            var removeStatus = adapter.TryRemove(target, typeof(DynamicTestObject), segment, options, out string removeErrorMessage);

            // Assert
            Assert.False(removeStatus);
            Assert.Equal($"The target location specified by path segment '{segment}' was not found.", removeErrorMessage);
        }
示例#2
0
        public void TryRemove_SetsPropertyToDefaultOrNull(object value, object expectedValue)
        {
            // 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, value, out string errorMessage);

            // Assert 1
            Assert.True(addStatus);
            Assert.Null(errorMessage);
            Assert.Equal(value, target.NewProperty);

            // Act 2
            var removeStatus = adapter.TryRemove(target, typeof(DynamicTestObject), segment, options, out string removeErrorMessage);

            // Assert 2
            Assert.True(removeStatus);
            Assert.Null(removeErrorMessage);
            Assert.Equal(expectedValue, 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);
    }