public void PreventDoublePrinting()
        {
            var sut = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = new SomeList <object>
                {
                    new SomeStruct {
                        Num = 1
                    },
                    new SomeStruct {
                        Num = 1
                    }
                }
            };
            var          actual   = sut.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = SomeList`1@16 [\n" +
                                    "      SomeStruct@1 {\n" +
                                    "         Num = 1,\n" +
                                    "      },\n" +
                                    "      {--> SomeStruct@1},\n" +
                                    "   },\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void Nested_WithThrowingToString()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = new ClassWithThrowingToString()
            }.ToStringReflection();

            Assert.That(actual.StartsWith("ToString reflection failed for 'ClassWithNesting@1': a cause\n"));
            Assert.That(
                actual.Contains("at KaVE.Commons.Tests.Utils.ToStringUtilsTest.ClassWithThrowingToString.ToString()"));
        }
        public void NestedStringIsPrintedAsString()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = "a"
            }.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = \"a\",\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void Nested_Struct()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = new SomeStruct()
            }.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = KaVE.Commons.Tests.Utils.ToStringUtilsTest+SomeStruct,\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void Nested_Null()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = null
            }.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = null,\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void RecursionPrevension()
        {
            var sut = new ClassWithNesting {
                HashCode = 1
            };

            sut.Nested = sut;
            var          actual   = sut.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = {--> ClassWithNesting@1},\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void LongNestedString()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = new string('x', 129)
            }.ToStringReflection();
            var expected = string.Format(
                "ClassWithNesting@1 {{\n" +
                "   HashCode = 1,\n" +
                "   Nested = \"{0}... (cut)\",\n" +
                "}}",
                new string('x', 128));

            Assert.AreEqual(expected, actual);
        }
        public void NestedStringInEnumerableIsPrintedAsString()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = new SomeList <object> {
                    "a"
                }
            }.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = SomeList`1@16 [\n" +
                                    "      \"a\",\n" +
                                    "   ],\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void RecursionPrevensionInEnumerables()
        {
            var someList = new SomeList <object>();
            var sut      = new ClassWithNesting {
                HashCode = 1, Nested = someList
            };

            someList.Add(sut);
            var          actual   = sut.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = SomeList`1@16 [\n" +
                                    "      {--> ClassWithNesting@1},\n" +
                                    "   ],\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void Nested_Array()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = new[] { 1, 2, 3 }
            }.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = [\n" +
                                    "      1,\n" +
                                    "      2,\n" +
                                    "      3,\n" +
                                    "   ],\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void Nested_Enumerable()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = new SomeList <int> {
                    1, 2, 3
                }
            }.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = SomeList`1@16 [\n" +
                                    "      1,\n" +
                                    "      2,\n" +
                                    "      3,\n" +
                                    "   ],\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
        public void Nested_EnumerableWithNull()
        {
            var actual = new ClassWithNesting
            {
                HashCode = 1,
                Nested   = new SomeList <object> {
                    new ClassWithToString(), null
                }
            }.ToStringReflection();
            const string expected = "ClassWithNesting@1 {\n" +
                                    "   HashCode = 1,\n" +
                                    "   Nested = SomeList`1@16 [\n" +
                                    "      {\n" +
                                    "         XYZ\n" +
                                    "      },\n" +
                                    "      null,\n" +
                                    "   ],\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
 protected bool Equals(ClassWithNesting other)
 {
     return(HashCode == other.HashCode && Equals(Nested, other.Nested));
 }