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);
    }
示例#2
0
        public void TryAdd_AddsNewProperty()
        {
            // Arrange
            var     adapter = new DynamicObjectAdapter();
            dynamic target  = new DynamicTestObject();
            var     segment = "NewProperty";
            var     options = new JsonSerializerOptions();

            // Act
            var status = adapter.TryAdd(target, typeof(DynamicTestObject), segment, options, "new", out string errorMessage);

            // Assert
            Assert.True(status);
            Assert.Null(errorMessage);
            Assert.Equal("new", target.NewProperty);
        }
    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);
    }
示例#4
0
        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 options = new JsonSerializerOptions();

            // Act
            var status = adapter.TryAdd(target, typeof(DynamicTestObject), segment, options, value, out string errorMessage);

            // Assert
            Assert.True(status);
            Assert.Null(errorMessage);
            Assert.Equal(value, target.List);
        }
示例#5
0
        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);
        }
示例#6
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 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);
    }