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); }
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); }
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); }
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); }
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); }
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); }
public void ToString_With_ChildPropertySameAsSelf_Does_Not_DumpChild() { var underTest = new DumpObject(Options.Instance); Assert.IsFalse(underTest.ToString().Contains("Instance")); }