Пример #1
0
        public void ShouldCreateDefaultFormat()
        {
            var format   = ObjectFormat.CreateDefault();
            var toString = format.Compile(AccountMembers);

            Assert.That(toString, Is.Not.Null);

            Assert.That(
                toString(new Account(42, "James", null)),
                Is.EqualTo("Account(Id: \"42\", Name: \"James\")")
                );
        }
Пример #2
0
        public void ShouldUseDefaultToStringFunctionWhenOneWasNotProvidedExplicitly()
        {
            var toString = ObjectFormat.CreateDefault()
                           .Compile(AccountMembers.Select(am =>
                                                          new MemberContext <Func <object, string> >(am.Member, null, ContextSource.Implicit)
                                                          ));

            Assert.That(
                toString(new Account(42, "James")),
                Is.EqualTo("Account(Id: \"42\", Name: \"James\", Phones: \"System.String[]\")")
                );
        }
Пример #3
0
        public void ShouldAlwaysCreateNewInstanceOfDefaultFormat()
        {
            var firstFormat = ObjectFormat.CreateDefault()
                              .AddFlags(MemberPerLine)
                              .ObjectMemberNamePrefixAndSuffix("<", ">");

            var firstToString = firstFormat.Compile(AccountMembers);

            var secondFormat   = ObjectFormat.CreateDefault();
            var secondToString = secondFormat.Compile(AccountMembers);

            Assert.That(firstFormat, Is.Not.SameAs(secondFormat));
            Assert.That(firstToString, Is.Not.SameAs(secondToString));
            Assert.That(secondToString(new Account(42, "James", null)),
                        Is.EqualTo("Account(Id: \"42\", Name: \"James\")"));
        }