示例#1
0
        public void WhenObjectContainsCyclicReferencesInList_ThenRecursiveDestructureIsImmediatelyStopped()
        {
            // Arrange
            var cyclic = new MyObjectEnumerable
            {
                Foo = "Cyclic"
            };

            cyclic.Reference = cyclic;
            var exception = new CyclicException2
            {
                MyObjectEnumerable = new MyObjectEnumerable()
            };

            exception.MyObjectEnumerable.Foo       = "bar";
            exception.MyObjectEnumerable.Reference = cyclic;

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

            destructurer.Destructure(exception, result, null);

            // Assert
            var myObject = (List <object>)result.GetResultDictionary()["MyObjectEnumerable"];

            // exception.MyObjectEnumerable[0] is still list
            var firstLevelList = Assert.IsType <List <object> >(myObject[0]);

            // exception.MyObjectEnumerable[0][0] we notice that we would again destructure "cyclic"
            var secondLevelList = Assert.IsType <Dictionary <string, object> >(firstLevelList[0]);

            Assert.Equal("Cyclic reference", secondLevelList["$ref"]);
        }
示例#2
0
        public void When_object_contains_cyclic_references_in_list_then_recursive_destructure_is_immediately_stopped()
        {
            // Arrange
            var cyclic = new MyObjectEnumerable
            {
                Foo = "Cyclic"
            };

            cyclic.Reference = cyclic;
            var exception = new CyclicException2
            {
                MyObjectEnumerable = new MyObjectEnumerable()
            };

            exception.MyObjectEnumerable.Foo       = "bar";
            exception.MyObjectEnumerable.Reference = cyclic;

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

            destructurer.Destructure(exception, result, null);

            // Assert
            var myObject = (List <object>)result["MyObjectEnumerable"];

            // exception.MyObjectEnumerable[0] is still list
            var firstLevelList = Assert.IsType <List <object> >(myObject[0]);

            // exception.MyObjectEnumerable[0][0] we notice that we would again destructure "cyclic"
            var secondLevelList = Assert.IsType <Dictionary <string, object> >(firstLevelList[0]);

            Assert.Equal("Cyclic reference", secondLevelList["$ref"]);
        }