public ClassForTests(string firstName = "", string surname = "", int age = 0, ClassForTests cc = null, double height = 0) { Friend = cc; FirstName = firstName; Surname = surname; Age = age; Height = height; }
public void SerializingFields_IfObjectHasIt() { var person = new ClassForTests("Ivan", age: 123); var printer = ObjectPrinter.For <ClassForTests>(); var s = printer.PrintToString(person); s.Should().Contain("Height"); }
public void SerializingFieldsInWayOfType_WhenSerializingItsType() { var person = new ClassForTests("Ivan", age: 123); var printer = ObjectPrinter.For <ClassForTests>() .Serializing <double>().Using(x => "Long"); var s = printer.PrintToString(person); s.Should().Contain("Long"); }
public void ExcludingAllPropertiesOfType_WhenExcluding() { var person = new ClassForTests("Ivan", "Kogut", 19); var printer = ObjectPrinter.For <ClassForTests>() .Excluding <string>(); var s = printer.PrintToString(person); s.Should().NotContain("FirstName").And.NotContain("Surname"); }
public void ExcludingProperty_WhenExcluding() { var person = new ClassForTests("Ivan", age: 123); var printer = ObjectPrinter.For <ClassForTests>() .Excluding(p => p.Age); var s = printer.PrintToString(person); s.Should().NotContain("Age"); }
public void SerializePropertyInOwnWay_WhenSerializing() { var person1 = new ClassForTests("Ivan", "Kogut", 19); var person2 = new ClassForTests("Alex", "Smelov", 19); var printer = ObjectPrinter.For <ClassForTests>() .Serializing(p => p.Age).Using(a => "A lot"); var sIvan = printer.PrintToString(person1); var sAlex = printer.PrintToString(person2); sIvan.Should().NotContain("19").And.Contain("A lot"); sAlex.Should().NotContain("19").And.Contain("A lot"); }
public void SerializeTypeInOwnWay_WhenSerializing() { var person1 = new ClassForTests("Ivan", "Kogut", 19); var person2 = new ClassForTests("Alex", "Smelov", 19); var printer = ObjectPrinter.For <ClassForTests>() .Serializing <string>().Using(x => "Vitya"); var sIvan = printer.PrintToString(person1); var sAlex = printer.PrintToString(person2); sIvan.Should().Contain("Vitya").And.NotContain("Ivan").And.NotContain("Kogut"); sAlex.Should().Contain("Vitya").And.NotContain("Alex").And.NotContain("Smelov"); }
public void NotFall_IfObjectHasRecursionLinks() { var person1 = new ClassForTests("Ivan", "Kogut", 19); var person2 = new ClassForTests("Alex", "Smelov", 19); person1.Friend = person2; person2.Friend = person1; var printer = ObjectPrinter.For <ClassForTests>(); var s = printer.PrintToString(person1); s.IndexOf("Ivan").Should().Be(s.LastIndexOf("Ivan")); s.Should().Contain("<cyclic link is detected>"); }
public void SerializeInPropertyWayDespiteTypeWay_WhenSerializingForPropertyAndType() { var person1 = new ClassForTests("Ivan", "Kogut", 19); var person2 = new ClassForTests("Alex", "Smelov", 19); var printer = ObjectPrinter.For <ClassForTests>() .Serializing <int>().Using(p => "Bullshit") .Serializing(p => p.Age).Using(p => "A lot"); var sIvan = printer.PrintToString(person1); var sAlex = printer.PrintToString(person2); sIvan.Should().NotContain("Bullshit").And.Contain("A lot"); sAlex.Should().NotContain("Bullshit").And.Contain("A lot"); }
public void CutStringProperties_WhenCutPrefix() { var person1 = new ClassForTests("Ivan", "Kogut", 19); var person2 = new ClassForTests("Alex", "Smelov", 19); var printer = ObjectPrinter.For <ClassForTests>() .Serializing(p => p.FirstName).CutPrefix(2) .Serializing(p => p.Surname).CutPrefix(3); var sIvan = printer.PrintToString(person1); var sAlex = printer.PrintToString(person2); sIvan.Should().Contain("Iv").And.NotContain("Iva"); sIvan.Should().Contain("Kog").And.NotContain("Kogu"); sAlex.Should().Contain("Al").And.NotContain("Ale"); sAlex.Should().Contain("Sme").And.NotContain("Smel"); }