public void Static_properties_are_not_written() { var formatter = PlainTextFormatter.GetPreferredFormatterFor <Widget>(); new Widget().ToDisplayString(formatter) .Should().NotContain(nameof(SomethingAWithStaticProperty.StaticProperty)); }
public void Formatter_iterates_IEnumerable_property_when_its_actual_type_is_an_array_of_objects() { var node = new Node { Id = "1", Nodes = new[] { new Node { Id = "1.1" }, new Node { Id = "1.2" }, new Node { Id = "1.3" }, } }; var formatter = PlainTextFormatter.GetPreferredFormatterFor <Node>(); var output = node.ToDisplayString(formatter); output.Should().Contain("1.1"); output.Should().Contain("1.2"); output.Should().Contain("1.3"); }
public void Formatter_truncates_expansion_of_IEnumerable() { Formatter.ListExpansionLimit = 3; var formatter = PlainTextFormatter.GetPreferredFormatterFor <IEnumerable <int> >(); var formatted = InfiniteSequence().ToDisplayString(formatter); formatted.Should().Contain("[ number 9, number 9, number 9 ... (more) ]");
public void Enums_are_formatted_using_their_names() { var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(FileAccess)); var writer = new StringWriter(); formatter.Format(FileAccess.ReadWrite, writer); writer.ToString().Should().Be("ReadWrite"); }
public void Formatter_iterates_IEnumerable_property_when_its_actual_type_is_an_array_of_structs() { var ints = new[] { 1, 2, 3, 4, 5 }; var formatter = PlainTextFormatter.GetPreferredFormatterFor(ints.GetType()); ints.ToDisplayString(formatter) .Should() .Be("[ 1, 2, 3, 4, 5 ]"); }
public void It_shows_null_items_in_the_sequence_as_null() { var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(object[])); var writer = new StringWriter(); formatter.Format(new object[] { 1, null, 3 }, writer); writer.ToString().Should().Be("[ 1, <null>, 3 ]"); }
public void ValueTuple_values_are_formatted() { var tuple = (123, "Hello", Enumerable.Range(1, 3)); var formatter = PlainTextFormatter.GetPreferredFormatterFor(tuple.GetType()); var formatted = tuple.ToDisplayString(formatter); formatted.Should().Be("( 123, Hello, [ 1, 2, 3 ] )"); }
public void Anonymous_types_are_automatically_fully_formatted() { var ints = new[] { 3, 2, 1 }; var obj = new { ints, count = ints.Length }; var formatter = PlainTextFormatter.GetPreferredFormatterFor(obj.GetType()); var output = obj.ToDisplayString(formatter); output.Should().Be("{ ints: [ 3, 2, 1 ], count: 3 }"); }
public void Strings_with_escaped_sequences_are_preserved() { var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(string)); var value = "hola! \n \t \" \" ' ' the joy of escapes! and white space "; var writer = new StringWriter(); formatter.Format(value, writer); writer.ToString().Should().Be(value); }
public void TimeSpan_is_not_destructured() { var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(TimeSpan)); var writer = new StringWriter(); var timespan = 25.Milliseconds(); formatter.Format(timespan, writer); writer.ToString().Should().Be(timespan.ToString()); }
public void When_Zero_properties_available_to_choose_just_ToString_is_used() { var formatter = PlainTextFormatter.GetPreferredFormatterFor <Dummy.DummyWithNoProperties>(); var writer = new StringWriter(); formatter.Format(new Dummy.DummyWithNoProperties(), writer); var s = writer.ToString(); s.Should().Be("Dummy.DummyWithNoProperties"); }
public void ReadOnlyMemory_of_char_is_formatted_like_a_string() { var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(ReadOnlyMemory <char>)); ReadOnlyMemory <char> readOnlyMemory = "Hi!".AsMemory(); var writer = new StringWriter(); formatter.Format(readOnlyMemory, writer); writer.ToString().Should().Be("Hi!"); }
public void It_emits_a_default_maximum_number_of_properties() { var formatter = PlainTextFormatter.GetPreferredFormatterFor <Dummy.DummyClassWithManyProperties>(); var writer = new StringWriter(); formatter.Format(new Dummy.DummyClassWithManyProperties(), writer); var s = writer.ToString(); s.Should().Be("{ Dummy.DummyClassWithManyProperties: X1: 1, X2: 2, X3: 3, X4: 4, X5: 5, X6: 6, X7: 7, X8: 8, X9: 9, X10: 10, X11: 11, X12: 12, X13: 13, X14: 14, X15: 15, X16: 16, X17: 17, X18: 18, X19: 19, X20: 20, .. }"); }
public void ReadOnlyMemory_of_int_is_formatted_like_a_int_array() { var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(ReadOnlyMemory <int>)); var readOnlyMemory = new ReadOnlyMemory <int>(new[] { 1, 2, 3 }); var writer = new StringWriter(); formatter.Format(readOnlyMemory, writer); writer.ToString().Should().Be("[ 1, 2, 3 ]"); }
public void Properies_of_System_Type_instances_are_not_expanded() { var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(Type)); var writer = new StringWriter(); formatter.Format(typeof(string), writer); writer.ToString() .Should() .Be("System.String"); }
public void Formatter_expands_IEnumerable() { var list = new List <string> { "this", "that", "the other thing" }; var formatter = PlainTextFormatter.GetPreferredFormatterFor(list.GetType()); var formatted = list.ToDisplayString(formatter); formatted.Should() .Be("[ this, that, the other thing ]"); }
public void It_expands_properties_of_structs() { var id = new EntityId("the typename", "the id"); var formatter = PlainTextFormatter.GetPreferredFormatterFor(id.GetType()); var formatted = id.ToDisplayString(formatter); formatted.Should() .Contain("TypeName: the typename") .And .Contain("Id: the id"); }
public void Formatter_expands_properties_of_ExpandoObjects() { dynamic expando = new ExpandoObject(); expando.Name = "socks"; expando.Parts = null; var formatter = PlainTextFormatter.GetPreferredFormatterFor <ExpandoObject>(); var expandoString = ((object)expando).ToDisplayString(formatter); expandoString.Should().Be("{ Name: socks, Parts: <null> }"); }
public void Recursive_formatter_calls_do_not_cause_exceptions() { var widget = new Widget(); widget.Parts = new List <Part> { new Part { Widget = widget } }; var formatter = PlainTextFormatter.GetPreferredFormatterFor(widget.GetType()); widget.Invoking(w => w.ToDisplayString(formatter)).Should().NotThrow(); }
public void PlainTextFormatter_returns_plain_for_BigInteger() { var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(BigInteger)); var writer = new StringWriter(); var instance = BigInteger.Parse("78923589327589332402359"); formatter.Format(instance, writer); writer.ToString() .Should() .Be("78923589327589332402359"); }
public void It_emits_the_property_names_and_values_for_a_specific_type() { var formatter = PlainTextFormatter.GetPreferredFormatterFor <Widget>(); var writer = new StringWriter(); formatter.Format(new Widget { Name = "Bob" }, writer); var s = writer.ToString(); s.Should().Contain("Name: Bob"); }
public void It_emits_a_configurable_maximum_number_of_properties() { var formatter = PlainTextFormatter.GetPreferredFormatterFor <Dummy.DummyClassWithManyProperties>(); PlainTextFormatter.MaxProperties = 1; var writer = new StringWriter(); formatter.Format(new Dummy.DummyClassWithManyProperties(), writer); var s = writer.ToString(); s.Should().Be("{ Dummy.DummyClassWithManyProperties: X1: 1, .. }"); }
public void When_Zero_properties_chosen_just_ToString_is_used() { var formatter = PlainTextFormatter.GetPreferredFormatterFor <Dummy.DummyClassWithManyProperties>(); PlainTextFormatter.MaxProperties = 0; var writer = new StringWriter(); formatter.Format(new Dummy.DummyClassWithManyProperties(), writer); var s = writer.ToString(); s.Should().Be("Dummy.DummyClassWithManyProperties"); }
public void It_expands_fields_of_objects() { var formatter = PlainTextFormatter.GetPreferredFormatterFor <SomeStruct>(); var today = DateTime.Today; var tomorrow = DateTime.Today.AddDays(1); var id = new SomeStruct { DateField = today, DateProperty = tomorrow }; var output = id.ToDisplayString(formatter); output.Should().Contain("DateField: "); output.Should().Contain("DateProperty: "); }
public void Formatter_truncates_expansion_of_ICollection() { var list = new List <string>(); for (var i = 1; i < 11; i++) { list.Add("number " + i); } Formatter.ListExpansionLimit = 4; var formatter = PlainTextFormatter.GetPreferredFormatterFor(typeof(ICollection)); var formatted = list.ToDisplayString(formatter); formatted.Contains("number 1").Should().BeTrue(); formatted.Contains("number 4").Should().BeTrue(); formatted.Should().NotContain("number 5"); formatted.Should().Contain("6 more"); }
public void Formatter_truncates_expansion_of_long_IDictionary() { var list = new Dictionary <string, int>(); for (var i = 1; i < 11; i++) { list.Add("number " + i, i); } Formatter.ListExpansionLimit = 4; var formatter = PlainTextFormatter.GetPreferredFormatterFor(list.GetType()); var formatted = list.ToDisplayString(formatter); formatted.Contains("number 1").Should().BeTrue(); formatted.Contains("number 4").Should().BeTrue(); formatted.Should().NotContain("number 5"); formatted.Contains("6 more").Should().BeTrue(); }
public void Formatter_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 formatter = PlainTextFormatter.GetPreferredFormatterFor <List <Widget> >(); var formatted = list.ToDisplayString(formatter); formatted.Should().Be("[ { Microsoft.DotNet.Interactive.Formatting.Tests.Widget: Name: widget x, Parts: <null> }, { Microsoft.DotNet.Interactive.Formatting.Tests.Widget: Name: widget y, Parts: <null> }, { Microsoft.DotNet.Interactive.Formatting.Tests.Widget: Name: widget z, Parts: <null> } ]"); }
public void Formatter_does_not_expand_string() { var widget = new Widget { Name = "hello" }; widget.Parts = new List <Part> { new Part { Widget = widget } }; var formatter = PlainTextFormatter.GetPreferredFormatterFor <Widget>(); // this should not throw var s = widget.ToDisplayString(formatter); s.Should() .Contain("hello") .And .NotContain("{ h },{ e }"); }