public void ObjectPrinter_ShouldExcludeTypeFromSerialization()
        {
            var expected = string.Join(Environment.NewLine, "Person", "\tId = 00000000-0000-0000-0000-000000000000",
                                       "\tName = John Smith", "\tHeight = 13,37")
                           + Environment.NewLine;

            personPrinter.Excluding <int>();

            personPrinter.PrintToString(person).Should().Be(expected);
        }
        public void ObjectPrinter_ShouldSerializeObjectsWithEnumerations()
        {
            var expected = string.Join(Environment.NewLine, "MyObjectWithEnumerables",
                                       "\tArray = Int32[]",
                                       "\t\t[0] = 1",
                                       "\t\t[1] = 2",
                                       "\t\t[2] = 3",
                                       "\tListOfComplexObjects = List`1",
                                       "\t\t[0] = Person",
                                       "\t\t\tId = 00000000-0000-0000-0000-000000000000",
                                       "\t\t\tName = John Smith",
                                       "\t\t\tHeight = 13,37",
                                       "\t\t\tAge = 69",
                                       "\t\t[1] = Person",
                                       "\t\t\tId = 00000000-0000-0000-0000-000000000000",
                                       "\t\t\tName = John Smith",
                                       "\t\t\tHeight = 13,37",
                                       "\t\t\tAge = 69",
                                       "\tDictionary = Dictionary`2",
                                       "\t\t[0] = [Somebody once told me, the world is gonna roll me]",
                                       "\t\t[1] = [I ain't the sharpest, tool in the shed]"
                                       )
                           + Environment.NewLine;

            myObjectWithEnumerablesPrinter.PrintToString(myObjectWithEnumerables).Should().Be(expected);
        }
        public void ObjectPrinter_ShouldSerializePropertiesAlternatively()
        {
            var expected = string.Join(Environment.NewLine, "MyCustomObject", "\tJustAField = 1337",
                                       "\tStringProperty = string (это строковое свойство)",
                                       "\tAnotherStringProperty = another string",
                                       "\tPerson = Person",
                                       "\t\tId = 00000000-0000-0000-0000-000000000000",
                                       "\t\tName = John Smith",
                                       "\t\tHeight = 13,37",
                                       "\t\tAge = 69")
                           + Environment.NewLine;

            myCustomObjectPrinter.Printing(e => e.StringProperty).Using(e => e + " (это строковое свойство)");

            myCustomObjectPrinter.PrintToString(myCustomObject).Should().Be(expected);
        }
Exemplo n.º 4
0
        public void ObjectPrinter_SyntaxSugar_CanBeUsedLikeCommonMethods()
        {
            var firstLine  = _printer.PrintToString(_person);
            var secondLine = _person.PrintToString();

            firstLine.Should().Be(secondLine);
        }
Exemplo n.º 5
0
        public void RecursiveLinksShouldNotBeBreakingApp()
        {
            var config = new PrintingConfig <PathNode>();

            var printed = config.PrintToString(pathNodeWithRecursiveLinks);

            AssertPrinting(printed, new[] { "Recursive link" }, new string[0]);
        }
Exemplo n.º 6
0
        public void SameObjectsAreNotRecursiveLinks()
        {
            var config = new PrintingConfig <PathNode>();

            var printed = config.PrintToString(pathNode);

            AssertPrinting(printed, new string[0], new[] { "Recursive link" });
        }
Exemplo n.º 7
0
        public void NullShouldBePrintCorrect()
        {
            var config = new PrintingConfig <Dictionary <int, int> >();

            var printed = config.PrintToString(null);

            AssertPrinting(printed, new[] { "null" }, new string[0]);
        }
Exemplo n.º 8
0
        public void Print_Default()
        {
            var expectedResult =
                $"Person{newLine}	Id = 00000000-0000-0000-0000-000000000000{newLine}	Name = Alexander{newLine}	Height = 188,9{newLine}	Age = 19{newLine}";

            printer
            .PrintToString(person)
            .Should().Be(expectedResult);
        }
Exemplo n.º 9
0
        public void PrintToString_NotThrowsNullReferenceException_IfPropertyIsNull()
        {
            printer = printer
                      .SetAlternateSerialize(x => x.Name, x => null)
                      .SetTrimming(x => x.Name, 4);
            Action act = () => printer.PrintToString(person);

            act.Should().NotThrow <NullReferenceException>();
        }
Exemplo n.º 10
0
        public void ObjectPrinter_WithoutConfigs_ReturnRightLinesCount()
        {
            var       result             = printer.PrintToString(testPerson);
            var       linesCount         = result.Split('\n', StringSplitOptions.RemoveEmptyEntries).Length;
            const int expectedLinesCount = 5;

            linesCount.Should().Be(expectedLinesCount);
        }
Exemplo n.º 11
0
        public void StringMustBeCropped()
        {
            var config = new PrintingConfig <Person>();

            config.Select <string>().CropTo(2);

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "Je" }, new[] { "ff" });
        }
Exemplo n.º 12
0
        public void AlternateSerializeWayByType()
        {
            var config = new PrintingConfig <Person>();

            config.Select <int>().SetSerializeWay(value => $"This is int: {value}");

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "This is int:" }, new string[0]);
        }
Exemplo n.º 13
0
        public void ExcludePropertyByName()
        {
            var config = new PrintingConfig <Person>();

            config.Exclude(x => x.Age);

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "Id" }, new[] { "Age" });
        }
Exemplo n.º 14
0
        public void ExcludePropertyByType()
        {
            var config = new PrintingConfig <Person>();

            config.Exclude <int>();

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "Name", "SleptToday" }, new[] { "Age", "Id" });
        }
Exemplo n.º 15
0
        public void SpecificCulture()
        {
            var config = new PrintingConfig <Person>();

            config.Select <double>().SetCulture(specificCulture);

            person.Height = double.NaN;
            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "https://habr.com/ru/news/t/526412/" }, new string[0]);
        }
Exemplo n.º 16
0
        public void AlternateSerializeWayByName()
        {
            var config = new PrintingConfig <Person>();

            config.Select(x => x.Width).SetSerializeWay(value => "Secret number");
            config.Select(x => x.Height).SetSerializeWay(value => $"Around {Math.Round(value, 0)}");

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "Secret number", "Around 33" }, new[] { "99" });
        }
Exemplo n.º 17
0
        public void PrintPerson_WithoutConfiguration()
        {
            var result =
                $"Person{_newLine}\tId = {Guid.Empty}{_newLine}\tName = Legion{_newLine}\tHeight = 160{_newLine}\tAge = 13{_newLine}"
                .ToHashSet(_newLine);

            _printer.PrintToString(_person)
            .ToHashSet(_newLine)
            .Should()
            .BeEquivalentTo(result);
        }
Exemplo n.º 18
0
        public void CanBePrintEnumerable()
        {
            var config = new PrintingConfig <List <int> >();
            var list   = new List <int>()
            {
                1, 99, 2
            };
            var expectedString = "[ 1, 99, 2 ]";

            var printed = config.PrintToString(list);

            AssertPrinting(printed, new[] { expectedString }, new string[0]);
        }
        public void ObjectPrinter_TzarPrintingCycleReference()
        {
            var tzar1 = new Tzar("Serega", 18);
            var tzar2 = new Tzar("Kolya", 74);
            var tzar3 = new Tzar("Ekaterina", 45);

            tzar1.PreviousTzar = tzar2;
            tzar1.NextTzar     = tzar3;
            tzar2.PreviousTzar = tzar1;
            var printer = new PrintingConfig <Tzar>();
            var str     = printer.PrintToString(tzar1);

            str.Should()
            .Be(
                "Tzar\r\n	Age = 18\r\n	Name = Serega\r\n	PreviousTzar = Tzar\r\n		Age = 74\r\n		Name = Kolya\r\n		NextTzar = null\r\n		Id = 1\r\n	NextTzar = Tzar\r\n		Age = 45\r\n		Name = Ekaterina\r\n		PreviousTzar = null\r\n		NextTzar = null\r\n		Id = 2\r\n	Id = 0\r\n");
        }
Exemplo n.º 20
0
        public void CanBePrintDictionary()
        {
            var config     = new PrintingConfig <Dictionary <string, string> >();
            var dictionary = new Dictionary <string, string>()
            {
                { "hello", "world" },
                { "1", "2" }
            };
            var expectedStrings = new List <string>()
            {
                "{ hello: world }", "{ 1: 2 }"
            };

            var printed = config.PrintToString(dictionary);

            AssertPrinting(printed, expectedStrings, new string[0]);
        }
        public void PrintToString_ContainsAllProperties_WhenGetsNoAdditionProperties()
        {
            var printing = printer.PrintToString(person);

            foreach (var property in GetProperties(person))
            {
                printing.Should()
                .Contain(property.Name);
            }

            GetProperties(person).Should().OnlyContain(x => printing.Contains(x.Name));
        }
Exemplo n.º 22
0
        public void PrintToString_PrintingAll_IfHasNoConfig()
        {
            var heightToString = person.Height.ToString(CultureInfo.CurrentCulture);

            printer.PrintToString(person).Should().Be("Person\r\n" +
                                                      "\tId = 00000000-0000-0000-0000-000000000000\r\n" +
                                                      "\tName = Alex\r\n" +
                                                      $"\tHeight = {heightToString}\r\n" +
                                                      "\tAge = 19\r\n" +
                                                      "\tFriend = null\r\n" +
                                                      "\tFriend2 = null\r\n" +
                                                      "\tSurname = Brown\r\n" +
                                                      "\tCodes = null\r\n" +
                                                      "\tPasswords = null\r\n");
        }
Exemplo n.º 23
0
 public void ObjectPrinter_null_StingWithNull()
 {
     printer.PrintToString(null).Should().Be("null");
 }
Exemplo n.º 24
0
 public void PrintToString_PrintingPropertyByAlternateSerializing()
 {
     printer = printer.SetAlternateSerialize(x => x.Name, x => x + "!!");
     printer.PrintToString(person).Should().Contain($"{nameof(person.Name)} = Alex!!");
 }
Exemplo n.º 25
0
 public void PrintToString_NotPrintingType_IfTypeExcluded()
 {
     printer = printer.Excluding <int>();
     printer.PrintToString(person).Should().NotContain(nameof(person.Age));
 }
Exemplo n.º 26
0
 public void PrintToString_PrintingWithCulture_IfCultureWasSet()
 {
     printer = printer.SetCulture <double>(CultureInfo.InvariantCulture);
     printer.PrintToString(person).Should().Contain($"{nameof(person.Height)} = 1.85");
 }
Exemplo n.º 27
0
 public void PrintToString_NotPrintingField_IfFieldExcluded()
 {
     printer = printer.Excluding(x => x.Surname);
     printer.PrintToString(person).Should().NotContain(nameof(person.Surname));
 }
Exemplo n.º 28
0
 public void PrintEverything()
 {
     printer.PrintToString(Me).Should()
     .Contain("Age = 20")
     .And.Contain("Height = 150,5")
     .And.Contain("Name = Natasha")
     .And.Contain("Surname = Smit")
     .And.Contain("Parent = ")
     .And.Contain("Name = Anthony")
     .And.Contain("Age = 40")
     .And.Contain("Height = 200,001");
 }
Exemplo n.º 29
0
 public void PrintToString_NotPrintingProperty_IfPropertyExcluded()
 {
     printer = printer.Excluding(x => x.Height);
     printer.PrintToString(person).Should().NotContain(nameof(person.Height));
 }
Exemplo n.º 30
0
 public void PrintToString_PrintingFieldByAlternateSerializing()
 {
     printer = printer.SetAlternateSerialize(x => x.Surname, x => x + "!!");
     printer.PrintToString(person).Should().Contain($"{nameof(person.Surname)} = Brown!!");
 }