Exemplo n.º 1
0
        public void TryTraverse_ThrowsPathNotFoundException_ForNonExistingProperty()
        {
            // Arrange
            var     adapter = new DynamicObjectAdapter();
            dynamic target  = new DynamicTestObject();

            target.NestedObject = new DynamicTestObject();
            var segment = "NewProperty";
            var options = new JsonSerializerOptions();

            // Act
            var status = adapter.TryTraverse(target.NestedObject, typeof(DynamicTestObject), segment, options, out object _, out string errorMessage);

            // Assert
            Assert.False(status);
            Assert.Equal($"The target location specified by path segment '{segment}' was not found.", errorMessage);
        }
Exemplo n.º 2
0
    public void TryTraverse_ThrowsPathNotFoundException_ForNonExistingProperty()
    {
        // Arrange
        var     adapter = new DynamicObjectAdapter();
        dynamic target  = new DynamicTestObject();

        target.NestedObject = new DynamicTestObject();
        var segment  = "NewProperty";
        var resolver = new DefaultContractResolver();

        // Act
        var status = adapter.TryTraverse(target.NestedObject, segment, resolver, out object nextTarget, out string errorMessage);

        // Assert
        Assert.False(status);
        Assert.Equal($"The target location specified by path segment '{segment}' was not found.", errorMessage);
    }
Exemplo n.º 3
0
        public void TryTraverse_FindsNextTarget()
        {
            // Arrange
            var     adapter = new DynamicObjectAdapter();
            dynamic target  = new DynamicTestObject();

            target.NestedObject             = new DynamicTestObject();
            target.NestedObject.NewProperty = "A";
            var segment = "NestedObject";
            var options = new JsonSerializerOptions();

            // Act
            var status = adapter.TryTraverse(target, typeof(DynamicTestObject), segment, options, out object nextTarget, out string errorMessage);

            // Assert
            Assert.True(status);
            Assert.Null(errorMessage);
            Assert.Equal(target.NestedObject, nextTarget);
        }
Exemplo n.º 4
0
    public void TryTraverse_FindsNextTarget()
    {
        // Arrange
        var     adapter = new DynamicObjectAdapter();
        dynamic target  = new DynamicTestObject();

        target.NestedObject             = new DynamicTestObject();
        target.NestedObject.NewProperty = "A";
        var segment  = "NestedObject";
        var resolver = new DefaultContractResolver();

        // Act
        var status = adapter.TryTraverse(target, segment, resolver, out object nextTarget, out string errorMessage);

        // Assert
        Assert.True(status);
        Assert.Null(errorMessage);
        Assert.Equal(target.NestedObject, nextTarget);
    }