示例#1
0
        public void Ctor_Object_SetsValue()
        {
            var expected  = new Object();
            var underTest = new DumpObject(expected);

            Assert.AreEqual(expected, underTest.Value);
        }
示例#2
0
        public void ToString_With_GetPropertyValueFailures_AddsFailureObjects()
        {
            var underTest = new DumpObject(new TestFailureClass());

            var expected = @"
TestFailureClass (1 Property)
-----------------------------
| DumpFailures = List`1 (2 Items)
|                ----------------
|                | 0: DumpObjectFailure (4 Properties)
|                |    --------------------------------
|                |    | PropertyName     = ""InstancePropertyOne""
|                |    | ErrorMessage     = ""Exception encountered while dumping property value.""
|                |    | ExceptionMessage = ""Exception has been thrown by the target of an invocation.""
|                |    | ExceptionType    = ""System.Reflection.TargetInvocationException""
|                |    --------------------------------
|                | 1: DumpObjectFailure (4 Properties)
|                |    --------------------------------
|                |    | PropertyName     = ""StaticPropertyOne""
|                |    | ErrorMessage     = ""Exception encountered while dumping property value.""
|                |    | ExceptionMessage = ""Exception has been thrown by the target of an invocation.""
|                |    | ExceptionType    = ""System.Reflection.TargetInvocationException""
|                |    --------------------------------
|                ----------------
-----------------------------
";

            var actual = "\r\n" + underTest.ToString();

            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void ToString_WithNoPadding_WithDeepNestedProperties_WritesTwoLevels_Correct()
        {
            var underTest = new DumpObject(
                new TestClass3()
            {
                One    = true,
                Two    = "Two",
                Three  = 3,
                Fourth = new TestClass2()
                {
                    First = 2.5, Second = this.GetTestClass("First", "Second", 3, false)
                }
            });

            var expected = @"
Evands.Pellucid.Terminal.Formatting.DumpHelpers.DumpObjectTests+TestClass3 (4 Properties)
-----------------------------------------------------------------------------------------
| One    = True
| Two    = ""Two""
| Three  = 3
| Fourth = Evands.Pellucid.Terminal.Formatting.DumpHelpers.DumpObjectTests+TestClass2 (2 Properties)
|          -----------------------------------------------------------------------------------------
|          | First  = 2.5
|          | Second = Evands.Pellucid.Terminal.Formatting.DumpHelpers.DumpObjectTests+TestClass (4 Properties)
|          -----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
";

            var actual = "\r\n" + underTest.ToString(2, true);

            Assert.AreEqual(expected, actual);
        }
示例#4
0
        public void Ctor_NullValue_Name_SetsValue_And_SetsName()
        {
            object expectedValue = null;
            var    expectedName  = "Test Name";
            var    underTest     = new DumpObject(null, expectedName);

            Assert.AreEqual(expectedValue, underTest.Value);
            Assert.AreEqual(expectedName, underTest.Name);
        }
示例#5
0
        public void Ctor_Object_Name_SetsValue_And_SetsName()
        {
            var expectedValue = new Object();
            var expectedName  = "Test Name";
            var underTest     = new DumpObject(expectedValue, expectedName);

            Assert.AreEqual(expectedValue, underTest.Value);
            Assert.AreEqual(expectedName, underTest.Name);
        }
示例#6
0
        public void ToString_NullValueType_ShortNames_Writes_Correct()
        {
            var underTest = new DumpObject(new Object(), null, null);
            var expected  = @"
<unknown type> (0 Properties)
";

            var actual = "\r\n" + underTest.ToString(false);

            Assert.AreEqual(expected, actual);
        }
示例#7
0
        public void Ctor_Object_Name_Type_SetsValue_And_SetsName_And_SetsType()
        {
            var expectedValue = new Object();
            var expectedName  = "Test Name";
            var expectedType  = typeof(ArgumentNullException);
            var underTest     = new DumpObject(expectedValue, expectedName, expectedType);

            Assert.AreEqual(expectedValue, underTest.Value);
            Assert.AreEqual(expectedName, underTest.Name);
            Assert.AreEqual(expectedType, underTest.ValueType);
        }
示例#8
0
        public void ToString_With_GetProperties_Failures_AddsFailureObjects()
        {
            var q = new Queue <Exception>();

            q.Enqueue(new InvalidOperationException());
            q.Enqueue(new InvalidOperationException());

            Crestron.SimplSharp.Reflection.CType.GetPropertiesExceptions = q;

            var underTest = new DumpObject(new TestFailureClass());

            var expected = @"
TestFailureClass (1 Property)
-----------------------------
| DumpFailures = List`1 (2 Items)
|                ----------------
|                | 0: DumpObjectFailure (4 Properties)
|                |    --------------------------------
|                |    | PropertyName     = """"
|                |    | ErrorMessage     = ""Exception while attempting to get the public instance properties of this object.""
|                |    | ExceptionMessage = ""Operation is not valid due to the current state of the object.""
|                |    | ExceptionType    = ""System.InvalidOperationException""
|                |    --------------------------------
|                | 1: DumpObjectFailure (4 Properties)
|                |    --------------------------------
|                |    | PropertyName     = """"
|                |    | ErrorMessage     = ""Exception while attempting to get the public static properties of this object.""
|                |    | ExceptionMessage = ""Operation is not valid due to the current state of the object.""
|                |    | ExceptionType    = ""System.InvalidOperationException""
|                |    --------------------------------
|                ----------------
-----------------------------
";

            var actual = "\r\n" + underTest.ToString();

            Crestron.SimplSharp.Reflection.CType.GetPropertiesExceptions = null;

            Assert.AreEqual(expected, actual);
        }
示例#9
0
        public void ToString_With_ListProperty_Prints_Correct()
        {
            var underTest = new DumpObject(
                new TestClassWithList()
            {
                IntList = new List <int>()
                {
                    0, 1, 2, 3
                },
                StringList = new List <string>()
                {
                    "OneItem"
                }
            });

            var expected = @"
TestClassWithList (2 Properties)
--------------------------------
| IntList    = List`1 (4 Items)
|              ----------------
|              | 0: 0
|              | 1: 1
|              | 2: 2
|              | 3: 3
|              ----------------
| StringList = List`1 (1 Item)
|              ---------------
|              | 0: ""OneItem""
|              ---------------
--------------------------------
";

            var actual = "\r\n" + underTest.ToString();

            Assert.AreEqual(expected, actual);
        }
示例#10
0
        public void ToString_WithNoPadding_WithNestedProperties_Writes_Correct()
        {
            var underTest = new DumpObject(new TestClass2()
            {
                First = 2.5, Second = this.GetTestClass("First", "Second", 3, false)
            });
            var expected = @"
TestClass2 (2 Properties)
-------------------------
| First  = 2.5
| Second = TestClass (4 Properties)
|          ------------------------
|          | FirstProperty  = ""First""
|          | SecondProperty = ""Second""
|          | ThirdProperty  = 3
|          | FourthProperty = False
|          ------------------------
-------------------------
";

            var actual = "\r\n" + underTest.ToString();

            Assert.AreEqual(expected, actual);
        }
示例#11
0
        public void ToString_With_ChildPropertySameAsSelf_Does_Not_DumpChild()
        {
            var underTest = new DumpObject(Options.Instance);

            Assert.IsFalse(underTest.ToString().Contains("Instance"));
        }