public void NonCompiledBuilderThrowsOnStringify()
        {
            var target  = new A();
            var builder = new ToStringBuilder <A>()
                          .Include(a => a.Prop);

            builder.Stringify(target);
        }
        public void NonPrimitiveValueTypes()
        {
            var target  = new G();
            var builder = new ToStringBuilder <G>()
                          .IncludeAllPublic()
                          .Compile();

            var result = builder.Stringify(target);

            Assert.That(result, Contains.Substring("01/01/2010 01:01:01"));
        }
        public void ChildObjects()
        {
            var target  = new F();
            var builder = new ToStringBuilder <F>()
                          .Include(f => f.ChildObject)
                          .Compile();

            var result = builder.Stringify(target);

            Assert.That(result, Is.EqualTo("F{ChildObject:E{PublicField:0,_privateField:1}}"));
        }
        public void IncludeAllPublic()
        {
            var target = new D();

            var builder = new ToStringBuilder <D>()
                          .IncludeAllPublic()
                          .Compile();

            var result = builder.Stringify(target);

            Assert.That(result, Is.EqualTo("D{" +
                                           "PublicField:0," +
                                           "PublicProperty:0" +
                                           "}"));
        }
        public void BuilderReuse()
        {
            var target = new C();

            var builder = new ToStringBuilder <C>()
                          .Include(c => c.Int)
                          .Compile();

            for (int i = 0; i < 10; i++)
            {
                target.Int = i;
                var result = builder.Stringify(target);
                Assert.That(result, Is.EqualTo("C{Int:" + i + "}"));
            }
        }
        public void BasicFormatting()
        {
            var target = new A {
                Prop = "A Property Value", Field = "A Field Value"
            };

            var builder = new ToStringBuilder <A>()
                          .Include(a => a.Field)
                          .Include(a => a.Prop)
                          .Compile();

            var result = builder.Stringify(target);

            Assert.That(result, Is.EqualTo("A{Field:\"A Field Value\",Prop:\"A Property Value\"}"));
        }
        public void MultiLineFormatting()
        {
            var target = new A {
                Prop = "A Property Value", Field = "A Field Value"
            };

            var builder = new ToStringBuilder <A>()
                          .MultiLine(true)
                          .Include(a => a.Field)
                          .Include(a => a.Prop)
                          .Compile();

            var result = builder.Stringify(target);

            Assert.That(result, Is.EqualTo("A\r\n{\r\n  Field:\"A Field Value\",\r\n  Prop:\"A Property Value\"\r\n}"));
        }
        public void NotQuotingStrings()
        {
            var target = new A {
                Prop = "A Property Value", Field = "A Field Value"
            };

            var builder = new ToStringBuilder <A>()
                          .QuoteStrings(false)
                          .Include(a => a.Field)
                          .Include(a => a.Prop)
                          .Compile();

            var result = builder.Stringify(target);

            Assert.That(result, Is.EqualTo("A{Field:A Field Value,Prop:A Property Value}"));
        }
        public void OrderAlphabetically()
        {
            var target = new B();

            var builder = new ToStringBuilder <B>()
                          .OrderAlphabetically(true)
                          .Include(b => b.Short)
                          .Include(b => b.Byte)
                          .Include(b => b.SByte)
                          .Include(b => b.Char)

                          .Compile();

            var result = builder.Stringify(target);

            Assert.That(result, Is.EqualTo("B{" +
                                           "Byte:1," +
                                           "Char:'c'," +
                                           "SByte:1," +
                                           "Short:1" +
                                           "}"));
        }
        public void BuilderConcurrentUse()
        {
            var builder = new ToStringBuilder <C>()
                          .Include(c => c.Int)
                          .Compile();

            Action task = () =>
            {
                var target = new C();
                for (int i = 0; i < 10000; i++)
                {
                    target.Int = i;
                    var result = builder.Stringify(target);
                    Assert.That(result, Is.EqualTo("C{Int:" + i + "}"));
                }
            };

            var taskA = Task.Factory.StartNew(task);
            var taskB = Task.Factory.StartNew(task);
            var taskC = Task.Factory.StartNew(task);

            Task.WaitAll(taskA, taskB, taskC);
        }
        public void Primitives()
        {
            var target = new B();

            var builder = new ToStringBuilder <B>()
                          .Include(b => b.Byte)
                          .Include(b => b.SByte)
                          .Include(b => b.Char)
                          .Include(b => b.Short)
                          .Include(b => b.UShort)
                          .Include(b => b.Int)
                          .Include(b => b.UInt)
                          .Include(b => b.Long)
                          .Include(b => b.ULong)
                          .Include(b => b.Float)
                          .Include(b => b.Double)
                          .Include(b => b.Decimal)
                          .Compile();

            var result = builder.Stringify(target);

            Assert.That(result, Is.EqualTo("B{" +
                                           "Byte:1," +
                                           "SByte:1," +
                                           "Char:'c'," +
                                           "Short:1," +
                                           "UShort:1," +
                                           "Int:1," +
                                           "UInt:1," +
                                           "Long:1," +
                                           "ULong:1," +
                                           "Float:1.1," +
                                           "Double:1.1," +
                                           "Decimal:1.1" +
                                           "}"));
        }
 public override string ToString()
 {
     return(ToStringBuilder.Stringify(this));
 }