public void WhenObjectContainsCyclicReferences_ThenNoStackoverflowExceptionIsThrown()
        {
            // Arrange
            var exception = new CyclicException
            {
                MyObject = new MyObject(),
            };

            exception.MyObject.Foo        = "bar";
            exception.MyObject.Reference  = exception.MyObject;
            exception.MyObject.Reference2 = exception.MyObject;

            // Act
            var result       = new ExceptionPropertiesBag(new Exception());
            var destructurer = new ReflectionBasedDestructurer(10);

            destructurer.Destructure(exception, result, EmptyDestructurer());

            // Assert
            var myObject = (Dictionary <string, object>)result.GetResultDictionary()["MyObject"];

            Assert.Equal("bar", myObject["Foo"]);
            Assert.Equal(myObject["$id"], ((Dictionary <string, object>)myObject["Reference"])["$ref"]);
            Assert.Equal(myObject["$id"], ((Dictionary <string, object>)myObject["Reference2"])["$ref"]);
            Assert.Equal("1", myObject["$id"]);
        }
Esempio n. 2
0
        public void When_object_contains_cyclic_references_then_no_stackoverflow_exception_is_thrown()
        {
            // Arrange
            var exception = new CyclicException
            {
                MyObject = new MyObject()
            };

            exception.MyObject.Foo        = "bar";
            exception.MyObject.Reference  = exception.MyObject;
            exception.MyObject.Reference2 = exception.MyObject;

            // Act
            var result       = new Dictionary <string, object>();
            var destructurer = new ReflectionBasedDestructurer(new List <string>());

            destructurer.Destructure(exception, result, null);

            // Assert
            var myObject = (Dictionary <string, object>)result["MyObject"];

            Assert.Equal("bar", myObject["Foo"]);
            Assert.Equal(myObject["$id"], ((Dictionary <string, object>)myObject["Reference"])["$ref"]);
            Assert.Equal(myObject["$id"], ((Dictionary <string, object>)myObject["Reference2"])["$ref"]);
            Assert.Equal("1", myObject["$id"]);
        }