예제 #1
0
 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;
 }
예제 #2
0
        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");
        }
예제 #3
0
        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");
        }
예제 #4
0
        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");
        }
예제 #5
0
        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");
        }
예제 #6
0
        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");
        }
예제 #7
0
        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");
        }
예제 #8
0
        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>");
        }
예제 #9
0
        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");
        }
예제 #10
0
        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");
        }