public void CreateForMembers_emits_the_specified_property_names_and_values_for_a_specific_type()
            {
                var formatter = PlainTextFormatter <SomethingWithLotsOfProperties> .CreateForMembers(
                    o => o.DateProperty,
                    o => o.StringProperty);

                var s = new SomethingWithLotsOfProperties
                {
                    DateProperty   = DateTime.MinValue,
                    StringProperty = "howdy"
                }.ToDisplayString(formatter);

                s.Should().Contain("DateProperty: 0001-01-01 00:00:00Z");
                s.Should().Contain("StringProperty: howdy");
                s.Should().NotContain("IntProperty");
                s.Should().NotContain("BoolProperty");
                s.Should().NotContain("UriProperty");
            }
Example #2
0
        public virtual void GenerateFor_creates_a_function_that_emits_the_specified_property_names_and_values_for_a_specific_type()
        {
            Formatter <SomethingWithLotsOfProperties> .RegisterForMembers(
                o => o.DateProperty,
                o => o.StringProperty);

            var s = new SomethingWithLotsOfProperties
            {
                DateProperty   = DateTime.MinValue,
                StringProperty = "howdy"
            }.ToDisplayString();

            s.Should().Contain("DateProperty: 0001-01-01 00:00:00Z");
            s.Should().Contain("StringProperty: howdy");
            s.Should().NotContain("IntProperty");
            s.Should().NotContain("BoolProperty");
            s.Should().NotContain("UriProperty");
        }
Example #3
0
        public virtual void GenerateFor_creates_a_function_that_emits_the_specified_property_names_and_values_for_a_specific_type()
        {
            Formatter<SomethingWithLotsOfProperties>.RegisterForMembers(
                o => o.DateProperty,
                o => o.StringProperty);

            var s = new SomethingWithLotsOfProperties
            {
                DateProperty = DateTime.MinValue,
                StringProperty = "howdy"
            }.ToLogString();

            Assert.That(s, Contains.Substring("DateProperty = 0001-01-01 00:00:00Z"));
            Assert.That(s, Contains.Substring("StringProperty = howdy"));
            Assert.That(s, !Contains.Substring("IntProperty"));
            Assert.That(s, !Contains.Substring("BoolProperty"));
            Assert.That(s, !Contains.Substring("UriProperty"));
        }
Example #4
0
        public void Generated_formatters_can_be_registered_for_types_not_known_until_runtime()
        {
            var obj = new SomethingWithLotsOfProperties
            {
                BoolProperty   = true,
                DateProperty   = DateTime.Now,
                IntProperty    = 42,
                StringProperty = "oh hai",
                UriProperty    = new Uri("http://blammo.com")
            };
            var reference = Formatter <SomethingWithLotsOfProperties> .GenerateForAllMembers();

            var writer = new StringWriter();

            reference(obj, writer);

            Formatter.RegisterForAllMembers(typeof(SomethingWithLotsOfProperties));

            obj.ToDisplayString().Should().Be(writer.ToString());
        }
Example #5
0
        public void Generated_formatters_can_be_registered_for_types_not_known_until_runtime()
        {
            var obj = new SomethingWithLotsOfProperties
            {
                BoolProperty = true,
                DateProperty = DateTime.Now,
                IntProperty = 42,
                StringProperty = "oh hai",
                UriProperty = new Uri("http://blammo.com")
            };
            var reference = Formatter<SomethingWithLotsOfProperties>.GenerateForAllMembers();
            var writer = new StringWriter();
            reference(obj, writer);

            Formatter.RegisterForAllMembers(typeof (SomethingWithLotsOfProperties));
            
            Assert.That(obj.ToLogString(),
                        Is.EqualTo(writer.ToString()));
        }