public void FormatterSet_recursively_formats_types_within_IEnumerable() { var list = new List <Widget> { new Widget { Name = "widget x" }, new Widget { Name = "widget y" }, new Widget { Name = "widget z" } }; var formatted = new FormatterSet() .RegisterFormatter <Widget>( w => w.Name + ", Parts: " + (w.Parts == null ? "0" : w.Parts.Count.ToString())) .Format(list); Console.WriteLine(formatted); Assert.That(formatted, Is.EqualTo("{ widget x, Parts: 0, widget y, Parts: 0, widget z, Parts: 0 }")); }
public void Exceptions_always_get_properties_formatters() { var exception = new ReflectionTypeLoadException( new[] { typeof(FileStyleUriParser), typeof(AssemblyKeyFileAttribute) }, new Exception[] { new EventLogInvalidDataException() }); var formatter = new FormatterSet(); var message = formatter.Format(exception); Assert.That(message, Contains.Substring("ReflectionTypeLoadException")); Assert.That(message, Contains.Substring("FileStyleUriParser")); Assert.That(message, Contains.Substring("AssemblyKeyFileAttribute")); Assert.That(message, Contains.Substring("EventLogInvalidDataException")); }
public void Anonymous_types_are_automatically_fully_formatted() { var formatter = new FormatterSet(); var ints = new[] { 3, 2, 1 }; var output = formatter.Format(new { ints, count = ints.Count() }); Assert.That(output, Is.EqualTo("{ ints = { 3, 2, 1 } | count = 3 }")); }
public void Default_formatter_for_Type_displays_only_the_name() { var formatter = new FormatterSet(); Assert.That(formatter.Format(GetType()), Is.EqualTo(GetType().Name)); Assert.That(formatter.Format(typeof(FormatterSetTests)), Is.EqualTo(typeof(FormatterSetTests).Name)); }
public void Custom_formatter_for_Type_can_be_registered() { var formatter = new FormatterSet(); formatter.RegisterFormatter <Type>(t => t.GUID.ToString()); Assert.That(formatter.Format(GetType()), Is.EqualTo(GetType().GUID.ToString())); }
public void Default_formatter_for_null_Nullable_indicates_null() { var formatter = new FormatterSet(); int?nullable = null; var output = formatter.Format(nullable); Assert.That(output, Is.EqualTo(formatter.Format <object>(null))); }
public void Static_properties_are_not_written() { var formatter = new FormatterSet(); formatter.RegisterPropertiesFormatter <BoundaryTests.NestedWidget>(); Assert.That(formatter.Format(new Widget()), !Contains.Substring("StaticProperty")); }
public void CreatePropertiesFormatter_does_not_include_autoproperty_backing_fields() { var formatter = new FormatterSet().CreatePropertiesFormatter <Node>(true); var output = formatter(new Node()); Assert.That(output, !Contains.Substring("<Nodes>k__BackingField")); Assert.That(output, !Contains.Substring("<NodesArray>k__BackingField")); }
public void RegisterPropertiesFormatter_for_string_does_nothing() { var formatter = new FormatterSet(); formatter.RegisterPropertiesFormatter <string>(); Assert.That(formatter.Format("hello"), Is.EqualTo("hello")); }
public void CreatePropertiesFormatter_can_include_internal_properties() { var formatter = new FormatterSet().CreatePropertiesFormatter <Node>(true); var output = formatter(new Node { Id = "6" }); Assert.That(output, Contains.Substring("InternalId = 6")); }
public void FormatterSet_expands_IEnumerable() { var list = new List <string> { "this", "that", "the other thing" }; var formatted = new FormatterSet().Format(list); Assert.That(formatted, Is.EqualTo("{ this, that, the other thing }")); }
public void CreateFormatter_throws_when_an_expression_is_not_a_MemberExpression() { var formatter = new FormatterSet(); var ex = Assert.Throws <ArgumentException>(() => formatter.CreateFormatterFor <SomethingWithLotsOfProperties>( o => o.DateProperty.ToShortDateString(), o => o.StringProperty)); Assert.That(ex.Message, Contains.Substring("o => o.DateProperty.ToShortDateString()")); }
public void CreateFormatter_throws_when_an_expression_is_not_a_MemberExpression() { var formatter = new FormatterSet(); var ex = Assert.Throws<ArgumentException>(() => formatter.CreateFormatterFor<SomethingWithLotsOfProperties>( o => o.DateProperty.ToShortDateString(), o => o.StringProperty)); Assert.That(ex.Message, Contains.Substring("o => o.DateProperty.ToShortDateString()")); }
public void CreatePropertiesFormatter_expands_properties_of_structs() { var func = new FormatterSet().CreatePropertiesFormatter <EntityId>(); var id = new EntityId("the typename", "the id"); var value = func(id); Console.WriteLine(value); Assert.That(value, Contains.Substring("TypeName = the typename")); Assert.That(value, Contains.Substring("Id = the id")); }
public void When_Clear_is_called_then_default_formatters_are_immediately_reregistered() { var formatterSet = new FormatterSet(); var logEntry = new LogEntry("hola!"); var before = formatterSet.Format(logEntry); formatterSet.RegisterFormatter <LogEntry>(e => "hello!"); Assert.That(formatterSet.Format(logEntry), Is.Not.EqualTo(before)); formatterSet.Clear(); Assert.That(formatterSet.Format(logEntry), Is.EqualTo(before)); }
public void CreatePropertiesFormatter_expands_fields_of_objects() { var func = new FormatterSet().CreatePropertiesFormatter <SomeStruct>(); var today = DateTime.Today; var tomorrow = DateTime.Today.AddDays(1); var id = new SomeStruct { DateField = today, DateProperty = tomorrow }; var value = func(id); Console.WriteLine(value); Assert.That(value, Contains.Substring("DateField = ")); Assert.That(value, Contains.Substring("DateProperty = ")); }
public void FormatterSet_truncates_expansion_of_long_IEnumerable() { var list = new List <string>(); for (var i = 1; i < 11; i++) { list.Add("number " + i); } var formatterSet = new FormatterSet { ListExpansionLimit = 4 }; var formatted = formatterSet.Format(list); Console.WriteLine(formatted); Assert.IsTrue(formatted.Contains("number 1")); Assert.IsTrue(formatted.Contains("number 4")); Assert.IsFalse(formatted.Contains("number 5")); Assert.IsTrue(formatted.Contains("6 more")); }
public void Custom_formatter_for_Type_can_be_registered() { var formatter = new FormatterSet(); formatter.RegisterFormatter<Type>(t => t.GUID.ToString()); Assert.That(formatter.Format(GetType()), Is.EqualTo(GetType().GUID.ToString())); }
public void CreatePropertiesFormatter_expands_properties_of_structs() { var func = new FormatterSet().CreatePropertiesFormatter<EntityId>(); var id = new EntityId("the typename", "the id"); var value = func(id); Console.WriteLine(value); Assert.That(value, Contains.Substring("TypeName = the typename")); Assert.That(value, Contains.Substring("Id = the id")); }
public void FormatterSet_recursively_formats_types_within_IEnumerable() { var list = new List<Widget> { new Widget { Name = "widget x" }, new Widget { Name = "widget y" }, new Widget { Name = "widget z" } }; var formatted = new FormatterSet() .RegisterFormatter<Widget>( w => w.Name + ", Parts: " + (w.Parts == null ? "0" : w.Parts.Count.ToString())) .Format(list); Console.WriteLine(formatted); Assert.That(formatted, Is.EqualTo("{ widget x, Parts: 0, widget y, Parts: 0, widget z, Parts: 0 }")); }
public void Default_formatter_for_null_Nullable_indicates_null() { var formatter = new FormatterSet(); int? nullable = null; var output = formatter.Format(nullable); Assert.That(output, Is.EqualTo(formatter.Format<object>(null))); }
public void FormatterSet_truncates_expansion_of_long_IEnumerable() { var list = new List<string>(); for (var i = 1; i < 11; i++) { list.Add("number " + i); } var formatterSet = new FormatterSet { ListExpansionLimit = 4 }; var formatted = formatterSet.Format(list); Console.WriteLine(formatted); Assert.IsTrue(formatted.Contains("number 1")); Assert.IsTrue(formatted.Contains("number 4")); Assert.IsFalse(formatted.Contains("number 5")); Assert.IsTrue(formatted.Contains("6 more")); }
public void When_Clear_is_called_then_default_formatters_are_immediately_reregistered() { var formatterSet = new FormatterSet(); var logEntry = new LogEntry("hola!"); var before = formatterSet.Format(logEntry); formatterSet.RegisterFormatter<LogEntry>(e => "hello!"); Assert.That(formatterSet.Format(logEntry), Is.Not.EqualTo(before)); formatterSet.Clear(); Assert.That(formatterSet.Format(logEntry), Is.EqualTo(before)); }
public void FormatterSet_expands_IEnumerable() { var list = new List<string> { "this", "that", "the other thing" }; var formatted = new FormatterSet().Format(list); Assert.That(formatted, Is.EqualTo("{ this, that, the other thing }")); }
public void Default_formatter_for_Type_displays_only_the_name() { var formatter = new FormatterSet(); Assert.That(formatter.Format(GetType()), Is.EqualTo(GetType().Name)); Assert.That(formatter.Format(typeof (FormatterSetTests)), Is.EqualTo(typeof (FormatterSetTests).Name)); }
public void Static_properties_are_not_written() { var formatter = new FormatterSet(); formatter.RegisterPropertiesFormatter<BoundaryTests.NestedWidget>(); Assert.That(formatter.Format(new Widget()), !Contains.Substring("StaticProperty")); }
public void CreatePropertiesFormatter_expands_fields_of_objects() { var func = new FormatterSet().CreatePropertiesFormatter<SomeStruct>(); var today = DateTime.Today; var tomorrow = DateTime.Today.AddDays(1); var id = new SomeStruct { DateField = today, DateProperty = tomorrow }; var value = func(id); Console.WriteLine(value); Assert.That(value, Contains.Substring("DateField = ")); Assert.That(value, Contains.Substring("DateProperty = ")); }
public void Exceptions_always_get_properties_formatters() { var exception = new ReflectionTypeLoadException( new[] { typeof (FileStyleUriParser), typeof (AssemblyKeyFileAttribute) }, new Exception[] { new EventLogInvalidDataException() }); var formatter = new FormatterSet(); var message = formatter.Format(exception); Assert.That(message, Contains.Substring("ReflectionTypeLoadException")); Assert.That(message, Contains.Substring("FileStyleUriParser")); Assert.That(message, Contains.Substring("AssemblyKeyFileAttribute")); Assert.That(message, Contains.Substring("EventLogInvalidDataException")); }
public void CreatePropertiesFormatter_does_not_include_autoproperty_backing_fields() { var formatter = new FormatterSet().CreatePropertiesFormatter<Node>(true); var output = formatter(new Node()); Assert.That(output, !Contains.Substring("<Nodes>k__BackingField")); Assert.That(output, !Contains.Substring("<NodesArray>k__BackingField")); }
public void RegisterPropertiesFormatter_for_string_does_nothing() { var formatter = new FormatterSet(); formatter.RegisterPropertiesFormatter<string>(); Assert.That(formatter.Format("hello"), Is.EqualTo("hello")); }
public void CreatePropertiesFormatter_can_include_internal_properties() { var formatter = new FormatterSet().CreatePropertiesFormatter<Node>(true); var output = formatter(new Node { Id = "6" }); Assert.That(output, Contains.Substring("InternalId = 6")); }