public void Creates_array_of_complex() { Complex2[] complexes = { new Complex2 { N1 = "Hello", N2 = "World" }, new Complex2 { N1 = "Hallo", N2 = "Welt" }, }; var result = _reflector.GetDObject(complexes, 5); var expected = new DArray(); var dcomplex1 = new DComplex("MiP.ObjectDump.Tests.Reflection.ReflectorTests+Complex2", null); var dcomplex2 = new DComplex("MiP.ObjectDump.Tests.Reflection.ReflectorTests+Complex2", null); dcomplex1.AddProperty("N1", new DValue("Hello")); dcomplex1.AddProperty("N2", new DValue("World")); dcomplex2.AddProperty("N1", new DValue("Hallo")); dcomplex2.AddProperty("N2", new DValue("Welt")); expected.Add(dcomplex1); expected.Add(dcomplex2); expected.TypeHeader = "Complex2[] (2 items)"; expected.AddColumns(new[] { "N1", "N2" }); result.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering().IncludingAllRuntimeProperties()); }
public void Creates_complex_with_properties() { var result = _reflector.GetDObject(new Complex1 { Name_f = "Hello", Name_p = "World", Number_f = 17, Number_p = 42 }, 5); DComplex expected = new DComplex("MiP.ObjectDump.Tests.Reflection.ReflectorTests+Complex1", null); expected.AddProperty(nameof(Complex1.Name_f), new DValue("Hello")); // fields will always be before properties expected.AddProperty(nameof(Complex1.Number_f), new DValue("17")); expected.AddProperty(nameof(Complex1.Name_p), new DValue("World")); expected.AddProperty(nameof(Complex1.Number_p), new DValue("42")); result.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering().IncludingAllRuntimeProperties()); }
public void Creates_complex_with_cyclic_references() { var four = new Complex4(); var five = new Complex5 { Four = four }; four.Five = five; var result = _reflector.GetDObject(four, 5); var expected = new DComplex("MiP.ObjectDump.Tests.Reflection.ReflectorTests+Complex4", null); var fiveExpected = new DComplex("MiP.ObjectDump.Tests.Reflection.ReflectorTests+Complex5", null); expected.AddProperty("Five", fiveExpected); fiveExpected.AddProperty("Four", new CyclicReference("MiP.ObjectDump.Tests.Reflection.ReflectorTests+Complex4", Check_if_its_a_Guid)); result.Should().BeEquivalentTo(expected, o => o.IncludingAllRuntimeProperties() .Using <string>(IsGuid) .When(m => m.RuntimeType == typeof(string) && m.SelectedMemberInfo.Name == nameof(CyclicReference.Reference) && m.SelectedMemberInfo.DeclaringType == typeof(CyclicReference)) ); }
public void Creates_complex_and_catches_exceptions_when_reading_properties() { var result = _reflector.GetDObject(new Complex3(), 5); var expected = new DComplex("MiP.ObjectDump.Tests.Reflection.ReflectorTests+Complex3", null); string systemInvalidoperationexceptionThisIsExpected = "System.InvalidOperationException: This is expected!*"; expected.AddProperty("Throws", new DError(systemInvalidoperationexceptionThisIsExpected)); expected.AddProperty("Name", new DValue("Hello")); result.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering().IncludingAllRuntimeProperties() // only match first part of the exception string .Using <string>(a => StringMatching(a, systemInvalidoperationexceptionThisIsExpected)) .WhenTypeIs <string>() ); }