public void ShouldDumpRecursiveTypes_CircularReference_Case3() { // Arrange var nestedItemB = new NestedItemB { Property = 1, Next = null, }; var nestedItemA = new NestedItemA { Property = 1, Next = nestedItemB, }; nestedItemB.Next = nestedItemA; // Act var dump = ObjectDumperConsole.Dump(nestedItemA); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{NestedItemA}\r\n" + " Next: {NestedItemB}\r\n" + " Next: null --> Circular reference detected\r\n" + " Property: 1\r\n" + " Property: 1"); }
public void ShouldDumpGenericClass_WithNestedGenericTypeArguments() { // Arrange var array2D = new string[3, 2] { { "one", "two" }, { "three", "four" }, { "five", "six" } }; var array3D = new int[, , ] { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } }; var complexDictionary = new Dictionary <string[, ], List <int[, , ]> >[1] { new Dictionary <string[, ], List <int[, , ]> > { { array2D, new List <int[, , ]> { array3D } } } }; // Act var dump = ObjectDumperConsole.Dump(complexDictionary); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("???"); }
public void ShouldDumpObject() { // Arrange var person = PersonFactory.GeneratePersons(count: 1).Single(); // Act var dump = ObjectDumperConsole.Dump(person); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{Person}\r\n" + " Name: \"Person 1\"\r\n" + " Char: ''\r\n" + " Age: 2\r\n" + " GetOnly: 11\r\n" + " Bool: false\r\n" + " Byte: 0\r\n" + " ByteArray: ...\r\n" + " 1\r\n 2\r\n 3\r\n 4\r\n" + " SByte: 0\r\n" + " Float: 0\r\n" + " Uint: 0\r\n" + " Long: 0\r\n" + " ULong: 0\r\n" + " Short: 0\r\n" + " UShort: 0\r\n" + " Decimal: 0\r\n" + " Double: 0\r\n" + " DateTime: DateTime.MinValue\r\n" + " NullableDateTime: null\r\n" + " Enum: DateTimeKind.Unspecified"); }
public void ShouldEscapeStrings() { // Arrange var expectedPerson = new Person { Name = "Boris \"The Blade\", \\GANGSTA\\ aka 'The Bullet Dodger' \a \b \f \r\nOn a new\twith tab \v \0" }; var dumpOptions = new DumpOptions { SetPropertiesOnly = true, IgnoreDefaultValues = true, MaxLevel = 1, ExcludeProperties = { "ByteArray" } }; // Act var dump = ObjectDumperConsole.Dump(expectedPerson, dumpOptions); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); // Compare generated object with input var person = new Person { Name = "Boris \"The Blade\", \\GANGSTA\\ aka \'The Bullet Dodger\' \a \b \f \r\nOn a new\twith tab \v \0" }; person.Should().BeEquivalentTo(expectedPerson); }
public void ShouldDumpExceptionAfterThrow() { // Arrange Exception ex; try { throw new KeyNotFoundException("message text"); } catch (Exception e) { ex = e; } var options = new DumpOptions { IgnoreDefaultValues = true, ExcludeProperties = { "CustomAttributes", "Module", "StackTrace", "MetadataToken" } }; // Act var dump = ObjectDumperConsole.Dump(ex, options); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); #if NETCORE dump.Should().Be( "{KeyNotFoundException}\r\n" + " TargetSite: {RuntimeMethodInfo}\r\n" + " Name: \"ShouldDumpExceptionAfterThrow\"\r\n" + " DeclaringType: ObjectDumperConsoleTests\r\n" + " ReflectedType: ObjectDumperConsoleTests\r\n" + " MemberType: MemberTypes.Method\r\n" + " IsSecurityCritical: true\r\n" + " MethodHandle: {RuntimeMethodHandle}\r\n" + " Value: {IntPtr}\r\n" + "\r\n" + " Attributes: PrivateScope | Public | HideBySig\r\n" + " CallingConvention: Standard | HasThis\r\n" + " ReturnType: void\r\n" + " ReturnTypeCustomAttributes: {RuntimeParameterInfo}\r\n" + " ParameterType: void\r\n" + " HasDefaultValue: true\r\n" + " Position: -1\r\n" + " IsHideBySig: true\r\n" + " IsPublic: true\r\n" + " Message: \"message text\"\r\n" + " Data: ...\r\n" + " Source: \"ObjectDumper.Tests\"\r\n" + " HResult: -2146232969"); #endif }
public void ShouldDumpValueOfBuiltInType(object value, string expectedOutput) { // Act var dump = ObjectDumperConsole.Dump(value); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be(expectedOutput); }
public void ShouldDumpValueTuple_Arity3() { // Arrange var valueTuple = (1, "Bill", "Gates"); // Act var dump = ObjectDumperConsole.Dump(valueTuple); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("(1, \"Bill\", \"Gates\")"); }
public void ShouldDumpEnumerable_EmptyCollection() { // Arrange var persons = new List <Person>(); // Act var dump = ObjectDumperConsole.Dump(persons); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be(""); }
public void ShouldDumpEnumerable() { // Arrange var persons = PersonFactory.GeneratePersons(count: 2); // Act var dump = ObjectDumperConsole.Dump(persons); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{System.Diagnostics.Tests.Testdata.Person}\n\r Name: \"Person 1\"\n\r Char: \n\r Age: 3\n\r GetOnly: 11\n\r Bool: False\n\r Byte: 0\n\r ByteArray: ...\n\r 1\n\r 2\n\r 3\n\r 4\n\r SByte: 0\n\r Float: 0\n\r Uint: 0\n\r Long: 0\n\r ULong: 0\n\r Short: 0\n\r UShort: 0\n\r Decimal: 0\n\r Double: 0\n\r DateTime: 01.01.0001 00:00:00\n\r NullableDateTime: null\n\r Enum: Unspecified\n\r\n\r{System.Diagnostics.Tests.Testdata.Person}\n\r Name: \"Person 2\"\n\r Char: \n\r Age: 3\n\r GetOnly: 11\n\r Bool: False\n\r Byte: 0\n\r ByteArray: ...\n\r 1\n\r 2\n\r 3\n\r 4\n\r SByte: 0\n\r Float: 0\n\r Uint: 0\n\r Long: 0\n\r ULong: 0\n\r Short: 0\n\r UShort: 0\n\r Decimal: 0\n\r Double: 0\n\r DateTime: 01.01.0001 00:00:00\n\r NullableDateTime: null\n\r Enum: Unspecified\n\r\n\r"); }
public void ShouldDumpEnum() { // Arrange var dateTimeKind = DateTimeKind.Utc; // Act var dump = ObjectDumperConsole.Dump(dateTimeKind); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("Utc"); }
public void ShouldDumpGuid() { // Arrange var guid = new Guid("024CC229-DEA0-4D7A-9FC8-722E3A0C69A3"); // Act var dump = ObjectDumperConsole.Dump(guid); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("024cc229-dea0-4d7a-9fc8-722e3a0c69a3"); }
public void ShouldDumpValueTuple_Arity0() { // Arrange var valueTuple = ValueTuple.Create(); // Act var dump = ObjectDumperConsole.Dump(valueTuple); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("()"); }
public void ShouldDumpEnumerable() { // Arrange var persons = PersonFactory.GeneratePersons(count: 2); // Act var dump = ObjectDumperConsole.Dump(persons); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{ObjectDumping.Tests.Testdata.Person}\r\n Name: \"Person 1\"\r\n Char: \r\n Age: 3\r\n GetOnly: 11\r\n Bool: False\r\n Byte: 0\r\n ByteArray: ...\r\n 1\r\n 2\r\n 3\r\n 4\r\n SByte: 0\r\n Float: 0\r\n Uint: 0\r\n Long: 0\r\n ULong: 0\r\n Short: 0\r\n UShort: 0\r\n Decimal: 0\r\n Double: 0\r\n DateTime: 01.01.0001 00:00:00\r\n NullableDateTime: null\r\n Enum: Unspecified\r\n\r\n{ObjectDumping.Tests.Testdata.Person}\r\n Name: \"Person 2\"\r\n Char: \r\n Age: 3\r\n GetOnly: 11\r\n Bool: False\r\n Byte: 0\r\n ByteArray: ...\r\n 1\r\n 2\r\n 3\r\n 4\r\n SByte: 0\r\n Float: 0\r\n Uint: 0\r\n Long: 0\r\n ULong: 0\r\n Short: 0\r\n UShort: 0\r\n Decimal: 0\r\n Double: 0\r\n DateTime: 01.01.0001 00:00:00\r\n NullableDateTime: null\r\n Enum: Unspecified\r\n\r\n"); }
public void ShouldDumpRuntimeType_BuiltInType() { // Arrange var type = typeof(string); // Act var dump = ObjectDumperConsole.Dump(type); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("string"); }
public void ShouldDumpValueTuple_WithDefaultValue() { // Arrange (int Id, string FirstName, string LastName)valueTuple = default; // Act var dump = ObjectDumperConsole.Dump(valueTuple); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("(0, null, null)"); }
public void ShouldDumpArray_OneDimensional() { // Arrange var array = new string[] { "aaa", "bbb" }; // Act var dump = ObjectDumperConsole.Dump(array); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("\"aaa\"\r\n\"bbb\""); }
public void ShouldDumpEnum_WithMultipleFlags() { // Arrange var methodAttributes = MethodAttributes.PrivateScope | MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig; // Act var dump = ObjectDumperConsole.Dump(methodAttributes); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("PrivateScope | Public | Static | HideBySig"); }
/// <summary> /// Serializes the given <see cref="element" /> to string with additional options <see cref="dumpOptions" />. /// </summary> /// <param name="element">Object to be dumped to string using the given <paramref name="dumpOptions" />.</param> /// <param name="dumpOptions">Further options to customize the dump output.</param> /// <returns></returns> public static string Dump(object element, DumpOptions dumpOptions) { if (dumpOptions == null) { dumpOptions = new DumpOptions(); } if (dumpOptions.DumpStyle == DumpStyle.Console) { return(ObjectDumperConsole.Dump(element, dumpOptions)); } return(ObjectDumperCSharp.Dump(element, dumpOptions)); }
public void ShouldDumpCultureInfo() { // Arrange var cultureInfo = new CultureInfo("de-CH"); // Act var dump = ObjectDumperConsole.Dump(cultureInfo, new DumpOptions { MaxLevel = 1 }); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().Be("de-CH"); }
public void ShouldDumpDateTime() { // Arrange var datetime = new DateTime(2000, 01, 01, 23, 59, 59); // Act var dump = ObjectDumperConsole.Dump(datetime); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("01.01.2000 23:59:59"); }
public void ShouldDumpNullableObject() { // Arrange var datetime = new DateTime?(); // Act var dump = ObjectDumperConsole.Dump(datetime); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("null"); }
public void ShouldDumpRecursiveTypes_RecursivePerson() { // Arrange var person = new RecursivePerson(); person.Parent = person; // Act var dump = ObjectDumperConsole.Dump(person); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{ObjectDumping.Tests.Testdata.RecursivePerson}\r\n Parent: { }\r\n {ObjectDumping.Tests.Testdata.RecursivePerson} <-- bidirectional reference found\r\n"); }
public void ShouldDumpRecursiveTypes_RecursivePerson() { // Arrange var person = new RecursivePerson(); person.Parent = person; // Act var dump = ObjectDumperConsole.Dump(person); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{RecursivePerson}\r\n"); }
public void ShouldDumpMultipleGenericTypes() { // Arrange var person = PersonFactory.GeneratePersons(count: 1).First(); var genericClass = new GenericClass <string, float, Person> { Prop1 = "Test", Prop2 = 123.45f, Prop3 = person }; // Act var dump = ObjectDumperConsole.Dump(genericClass); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{System.Diagnostics.Tests.Testdata.GenericClass<System.String, System.Single, System.Diagnostics.Tests.Testdata.Person>}\n\r Prop1: \"Test\"\n\r Prop2: 123.45\n\r Prop3: { }\n\r {System.Diagnostics.Tests.Testdata.Person}\n\r Name: \"Person 1\"\n\r Char: \n\r Age: 2\n\r GetOnly: 11\n\r Bool: False\n\r Byte: 0\n\r ByteArray: ...\n\r 1\n\r 2\n\r 3\n\r 4\n\r SByte: 0\n\r Float: 0\n\r Uint: 0\n\r Long: 0\n\r ULong: 0\n\r Short: 0\n\r UShort: 0\n\r Decimal: 0\n\r Double: 0\n\r DateTime: 01.01.0001 00:00:00\n\r NullableDateTime: null\n\r Enum: Unspecified\n\r"); }
public void ShouldDumpMultipleGenericTypes() { // Arrange var person = PersonFactory.GeneratePersons(count: 1).First(); var genericClass = new GenericClass <string, float, Person> { Prop1 = "Test", Prop2 = 123.45f, Prop3 = person }; // Act var dump = ObjectDumperConsole.Dump(genericClass); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{ObjectDumping.Tests.Testdata.GenericClass<System.String, System.Single, ObjectDumping.Tests.Testdata.Person>}\r\n Prop1: \"Test\"\r\n Prop2: 123.45\r\n Prop3: { }\r\n {ObjectDumping.Tests.Testdata.Person}\r\n Name: \"Person 1\"\r\n Char: \r\n Age: 2\r\n GetOnly: 11\r\n Bool: False\r\n Byte: 0\r\n ByteArray: ...\r\n 1\r\n 2\r\n 3\r\n 4\r\n SByte: 0\r\n Float: 0\r\n Uint: 0\r\n Long: 0\r\n ULong: 0\r\n Short: 0\r\n UShort: 0\r\n Decimal: 0\r\n Double: 0\r\n DateTime: 01.01.0001 00:00:00\r\n NullableDateTime: null\r\n Enum: Unspecified\r\n"); }
public void ShouldDumpRecursiveTypes_RuntimeProperties() { // Arrange var person = PersonFactory.GeneratePersons(count: 1).Single(); var properties = person.GetType().GetRuntimeProperties(); var options = new DumpOptions { MaxLevel = 2 }; // Act var dump = ObjectDumperConsole.Dump(properties, options); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); }
public void ShouldDumpEnumerable_ValueTuples() { // Arrange var persons = PersonFactory.GeneratePersons(count: 2).ToList(); var valueTuples = persons.Select(s => (s.Name, s.Age)).ToList(); // Act var dump = ObjectDumperConsole.Dump(valueTuples); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "(\"Person 1\", 3)\r\n" + "(\"Person 2\", 3)"); }
public void ShouldDumpCultureInfo() { // Arrange var cultureInfo = new CultureInfo("de-CH"); // Act var dump = ObjectDumperConsole.Dump(cultureInfo, new DumpOptions { MaxLevel = 1 }); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Contain("Name: \"de-CH\""); dump.Should().Contain("EnglishName: \"German (Switzerland)\""); }
public void ShouldDumpGenericClass_WithMultipleGenericTypeArguments() { // Arrange var person = PersonFactory.GeneratePersons(count: 1).First(); var genericClass = new GenericClass <string, float, Person> { Prop1 = "Test", Prop2 = 123.45f, Prop3 = person }; // Act var dump = ObjectDumperConsole.Dump(genericClass); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{GenericClass<string, float, Person>}\r\n" + " Prop1: \"Test\"\r\n" + " Prop2: 123.45\r\n" + " Prop3: {Person}\r\n" + " Name: \"Person 1\"\r\n" + " Char: ''\r\n" + " Age: 2\r\n" + " GetOnly: 11\r\n" + " Bool: false\r\n" + " Byte: 0\r\n" + " ByteArray: ...\r\n" + " 1\r\n" + " 2\r\n" + " 3\r\n" + " 4\r\n" + " SByte: 0\r\n" + " Float: 0\r\n" + " Uint: 0\r\n" + " Long: 0\r\n" + " ULong: 0\r\n" + " Short: 0\r\n" + " UShort: 0\r\n" + " Decimal: 0\r\n" + " Double: 0\r\n" + " DateTime: DateTime.MinValue\r\n" + " NullableDateTime: null\r\n" + " Enum: DateTimeKind.Unspecified"); }
public void ShouldOrderProperties() { // Arrange var testObject = new OrderPropertyTestObject(); var options = new DumpOptions { PropertyOrderBy = p => p.Name }; // Act var dump = ObjectDumperConsole.Dump(testObject, options); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{ObjectDumping.Tests.Testdata.OrderPropertyTestObject}\r\n A: null\r\n B: null\r\n C: null\r\n"); }