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 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 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 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 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 ShouldDumpNestedObjects() { // Arrange var persons = PersonFactory.GeneratePersons(count: 2).ToList(); var organization = new Organization { Name = "superdev gmbh", Persons = persons }; // Act var dump = ObjectDumperConsole.Dump(organization); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{System.Diagnostics.Tests.Testdata.Organization}\n\r Name: \"superdev gmbh\"\n\r Persons: ...\n\r {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 ShouldDumpNestedObjects() { // Arrange var persons = PersonFactory.GeneratePersons(count: 2).ToList(); var organization = new Organization { Name = "superdev gmbh", Persons = persons }; // Act var dump = ObjectDumperConsole.Dump(organization); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{ObjectDumping.Tests.Testdata.Organization}\r\n Name: \"superdev gmbh\"\r\n Persons: ...\r\n {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 ShouldExcludeProperties() { // Arrange var testObject = new TestObject(); var options = new DumpOptions { ExcludeProperties = { "Id", "NonExistent" } }; // Act var dump = ObjectDumperConsole.Dump(testObject, options); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{ObjectDumping.Tests.Testdata.TestObject}\r\n NullableDateTime: null\r\n"); }
public void ShouldDumpRecursiveTypes() { // Arrange var person = PersonFactory.GeneratePersons(count: 1).First(); 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(); dump.Should().Contain("<-- bidirectional reference found"); }
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"); }
public void ShouldDumpArray_TwoDimensional() { // Arrange var array = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } }; // Act var dump = ObjectDumperConsole.Dump(array); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("???"); }
public void ShouldDumpDictionary() { // Arrange var dictionary = new Dictionary <int, string> { { 1, "Value1" }, { 2, "Value2" }, { 3, "Value3" } }; // Act var dump = ObjectDumperConsole.Dump(dictionary); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("[1, Value1]\r\n[2, Value2]\r\n[3, Value3]\r\n"); }
public void ShouldDumpObject_WithDumpOptions() { // Arrange var person = PersonFactory.GetPersonThomas(); var options = new DumpOptions { IndentChar = '\t', IndentSize = 1, SetPropertiesOnly = true }; // Act var dump = ObjectDumperConsole.Dump(person, options); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{System.Diagnostics.Tests.Testdata.Person}\n\r Name: \"Thomas\"\n\r Char: \n\r Age: 30\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 ShouldDumpObject_WithNullFieldsAndProperties() { // Arrange var myObject = new My.TestObject2 { body = null, Body = null, name = null, Name = null, }; // Act var dump = ObjectDumperConsole.Dump(myObject); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{My.TestObject2}\r\n body: null\r\n name: null\r\n Body: null\r\n Name: null\r\n"); }
public void ShouldDumpObject_WithDumpOptions() { // Arrange var person = PersonFactory.GetPersonThomas(); var options = new DumpOptions { IndentChar = '\t', IndentSize = 1, SetPropertiesOnly = true }; // Act var dump = ObjectDumperConsole.Dump(person, options); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{ObjectDumping.Tests.Testdata.Person}\r\n Name: \"Thomas\"\r\n Char: \r\n Age: 30\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 ShouldDumpObjectWithMaxLevel() { // Arrange var persons = PersonFactory.GeneratePersons(count: 2).ToList(); var organization = new Organization { Name = "superdev gmbh", Persons = persons }; var options = new DumpOptions { MaxLevel = 1 }; // Act var dump = ObjectDumperConsole.Dump(organization, options); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be("{ObjectDumping.Tests.Testdata.Organization}\r\n Name: \"superdev gmbh\"\r\n Persons: ...\r\n"); }
public void ShouldDumpExpandoObject() { // Arrange dynamic expandoObject = new ExpandoObject(); expandoObject.IntProperty = 10; expandoObject.StringProperty = "hello"; expandoObject.DoubleProperty = 3.14d; // Act string dump = ObjectDumperConsole.Dump(expandoObject); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{ \"IntProperty\", 10 }\r\n" + "{ \"StringProperty\", \"hello\" }\r\n" + "{ \"DoubleProperty\", 3.14 }"); }
public void ShouldDumpStruct() { // Arrange var x509ChainStatusStruct = new System.Security.Cryptography.X509Certificates.X509ChainStatus { Status = System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError, StatusInformation = "Test status" }; // Act var dump = ObjectDumperConsole.Dump(x509ChainStatusStruct); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{X509ChainStatus}\r\n" + " Status: X509ChainStatusFlags.NoError\r\n" + " StatusInformation: \"Test status\""); }
public void ShouldDumpException() { // Arrange var ex = new KeyNotFoundException("message text"); var options = new DumpOptions { IgnoreDefaultValues = true }; // Act var dump = ObjectDumperConsole.Dump(ex, options); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{KeyNotFoundException}\r\n" + " Message: \"message text\"\r\n" + " Data: ...\r\n" + " HResult: -2146232969"); }
public void ShouldDumpAnonymousObject() { // Arrange var dynamicObject = new { IntProperty = 10, StringProperty = "hello", DoubleProperty = 3.14d, }; // Act var dump = ObjectDumperConsole.Dump(dynamicObject); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{AnonymousObject}\r\n" + " IntProperty: 10\r\n" + " StringProperty: \"hello\"\r\n" + " DoubleProperty: 3.14"); }
public void ShouldDumpObject_WithDumpOptions() { // Arrange var person = PersonFactory.GeneratePersons(count: 1).Single(); var options = new DumpOptions { IndentChar = '\t', IndentSize = 1, SetPropertiesOnly = true }; // Act var dump = ObjectDumperConsole.Dump(person, options); // 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"+ " 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 ShouldDumpRecursiveTypes_CircularReference_Case1() { // Arrange var person = new RecursivePerson(); person.Parent = person; var dumpOptions = new DumpOptions { IgnoreDefaultValues = false }; // Act var dump = ObjectDumperConsole.Dump(person, dumpOptions); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{RecursivePerson}\r\n" + " Id: 0\r\n" + " Parent: null --> Circular reference detected"); }
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" + " Member: null --> Circular reference detected\r\n" + " Position: -1\r\n" + " ReturnParameter: null --> Circular reference detected\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 ShouldDumpMailMessage() { // Arrange var mailmessage = new MailMessage("*****@*****.**", "*****@*****.**", "Subject", "Body"); // Act var dump = ObjectDumperConsole.Dump(mailmessage); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{MailMessage}\r\n" + " From: {MailAddress}\r\n" + " DisplayName: \"\"\r\n" + " User: \"sender\"\r\n" + " Host: \"mail.com\"\r\n" + " Address: \"[email protected]\"\r\n" + " Sender: null\r\n" + " ReplyTo: null\r\n" + " ReplyToList: ...\r\n" + " To: ...\r\n" + " {MailAddress}\r\n" + " DisplayName: \"\"\r\n" + " User: \"receiver\"\r\n" + " Host: \"mail.com\"\r\n" + " Address: \"[email protected]\"\r\n" + " Bcc: ...\r\n" + " CC: ...\r\n" + " Priority: MailPriority.Normal\r\n" + " DeliveryNotificationOptions: DeliveryNotificationOptions.None\r\n" + " Subject: \"Subject\"\r\n" + " SubjectEncoding: null\r\n" + " Headers: ...\r\n" + " HeadersEncoding: null\r\n" + " Body: \"Body\"\r\n" + #if NET452 " BodyEncoding: {ASCIIEncoding}\r\n" + #else " BodyEncoding: {ASCIIEncodingSealed}\r\n" + #endif " IsSingleByte: true\r\n" + #if NETCOREAPP3_1_OR_GREATER || NET5_0_OR_GREATER " Preamble: \"{NotSupportedException: Specified method is not supported.}\"\r\n" + #endif " BodyName: \"us-ascii\"\r\n" + " EncodingName: \"US-ASCII\"\r\n" + " HeaderName: \"us-ascii\"\r\n" + " WebName: \"us-ascii\"\r\n" + " WindowsCodePage: 1252\r\n" + " IsBrowserDisplay: false\r\n" + " IsBrowserSave: false\r\n" + " IsMailNewsDisplay: true\r\n" + " IsMailNewsSave: true\r\n" + " EncoderFallback: {EncoderReplacementFallback}\r\n" + " DefaultString: \"?\"\r\n" + " MaxCharCount: 1\r\n" + " DecoderFallback: {DecoderReplacementFallback}\r\n" + " DefaultString: \"?\"\r\n" + " MaxCharCount: 1\r\n" + " IsReadOnly: true\r\n" + " CodePage: 20127\r\n" + " BodyTransferEncoding: TransferEncoding.Unknown\r\n" + " IsBodyHtml: false\r\n" + " Attachments: ...\r\n" + " AlternateViews: ..."); }
public void ShouldDumpNestedObjects() { // Arrange var persons = PersonFactory.GeneratePersons(count: 2).ToList(); var organization = new Organization { Name = "superdev gmbh", Persons = persons }; // Act var dump = ObjectDumperConsole.Dump(organization); // Assert this.testOutputHelper.WriteLine(dump); dump.Should().NotBeNull(); dump.Should().Be( "{Organization}\r\n" + " Name: \"superdev gmbh\"\r\n" + " Persons: ...\r\n" + " {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: DateTime.MinValue\r\n" + " NullableDateTime: null\r\n" + " Enum: DateTimeKind.Unspecified\r\n" + " {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: DateTime.MinValue\r\n" + " NullableDateTime: null\r\n" + " Enum: DateTimeKind.Unspecified\r\n" + " IsAfterCollection: true"); }