public void RegisterFormatter_creates_a_function_that_emits_the_specified_property_names_and_values_for_a_specific_type() { Log.Formatters.RegisterPropertiesFormatter <SomethingWithLotsOfProperties>( 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")); }
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())); }