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.GetBestFormatterFor <Node>();

                var output = node.ToDisplayString(formatter);

                output.Should().Contain("1.1");
                output.Should().Contain("1.2");
                output.Should().Contain("1.3");
            }
            public void Static_properties_are_not_written()
            {
                var formatter = PlainTextFormatter.GetBestFormatterFor <Widget>();

                new Widget().ToDisplayString(formatter)
                .Should().NotContain(nameof(SomethingAWithStaticProperty.StaticProperty));
            }
            public void ValueTuple_values_are_formatted()
            {
                var tuple = (123, "Hello", Enumerable.Range(1, 3));

                var formatter = PlainTextFormatter.GetBestFormatterFor(tuple.GetType());

                var formatted = tuple.ToDisplayString(formatter);

                formatted.Should().Be("( 123, Hello, [ 1, 2, 3 ] )");
            }
            public void Enums_are_formatted_using_their_names()
            {
                var formatter = PlainTextFormatter.GetBestFormatterFor(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.GetBestFormatterFor(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.GetBestFormatterFor(typeof(object[]));

                var writer = new StringWriter();

                formatter.Format(new object[] { 1, null, 3 }, writer);

                writer.ToString().Should().Be("[ 1, <null>, 3 ]");
            }
            public void TimeSpan_is_not_destructured()
            {
                var formatter = PlainTextFormatter.GetBestFormatterFor(typeof(TimeSpan));

                var writer = new StringWriter();

                var timespan = 25.Milliseconds();

                formatter.Format(timespan, writer);

                writer.ToString().Should().Be(timespan.ToString());
            }
            public void Properies_of_System_Type_instances_are_not_expanded()
            {
                var formatter = PlainTextFormatter.GetBestFormatterFor(typeof(Type));

                var writer = new StringWriter();

                formatter.Format(typeof(string), writer);

                writer.ToString()
                .Should()
                .Be("System.String");
            }
            public void ReadOnlyMemory_of_int_is_formatted_like_a_int_array()
            {
                var formatter = PlainTextFormatter.GetBestFormatterFor(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 ]");
            }
Ejemplo n.º 10
0
            public void ReadOnlyMemory_of_char_is_formatted_like_a_string()
            {
                var formatter = PlainTextFormatter.GetBestFormatterFor(typeof(ReadOnlyMemory <char>));

                ReadOnlyMemory <char> readOnlyMemory = "Hi!".AsMemory();

                var writer = new StringWriter();

                formatter.Format(readOnlyMemory, writer);

                writer.ToString().Should().Be("Hi!");
            }
Ejemplo n.º 11
0
            public void Anonymous_types_are_automatically_fully_formatted()
            {
                var ints = new[] { 3, 2, 1 };

                var obj = new { ints, count = ints.Length };

                var formatter = PlainTextFormatter.GetBestFormatterFor(obj.GetType());

                var output = obj.ToDisplayString(formatter);

                output.Should().Be("{ ints: [ 3, 2, 1 ], count: 3 }");
            }
Ejemplo n.º 12
0
            public void It_expands_properties_of_structs()
            {
                var id = new EntityId("the typename", "the id");

                var formatter = PlainTextFormatter.GetBestFormatterFor(id.GetType());

                var formatted = id.ToDisplayString(formatter);

                formatted.Should()
                .Contain("TypeName: the typename")
                .And
                .Contain("Id: the id");
            }
Ejemplo n.º 13
0
            public void Type_specific_formatter_is_preferred_over_generic_formatter()
            {
                // There is a specific default formatter registered for ReadOnlyMemory<char>, check
                // it is selected
                var formatter = PlainTextFormatter.GetBestFormatterFor(typeof(ReadOnlyMemory <char>));

                formatter.GetType().Should().Be(typeof(PlainTextFormatter <ReadOnlyMemory <char> >));
                formatter.Type.Should().Be(typeof(ReadOnlyMemory <char>));

                var formatter2 = PlainTextFormatter.GetBestFormatterFor(typeof(ReadOnlyMemory <int>));

                formatter2.Type.Should().Be(typeof(ReadOnlyMemory <>));
            }
Ejemplo n.º 14
0
            public void Formatter_expands_properties_of_ExpandoObjects()
            {
                dynamic expando = new ExpandoObject();

                expando.Name  = "socks";
                expando.Parts = null;

                var formatter = PlainTextFormatter.GetBestFormatterFor <ExpandoObject>();

                var expandoString = ((object)expando).ToDisplayString(formatter);

                expandoString.Should().Be("{ Name: socks, Parts: <null> }");
            }
Ejemplo n.º 15
0
            public void Formatter_expands_IEnumerable()
            {
                var list = new List <string> {
                    "this", "that", "the other thing"
                };

                var formatter = PlainTextFormatter.GetBestFormatterFor(list.GetType());

                var formatted = list.ToDisplayString(formatter);

                formatted.Should()
                .Be("[ this, that, the other thing ]");
            }
Ejemplo n.º 16
0
            public void Create_creates_a_formatter_that_emits_the_property_names_and_values_for_a_specific_type()
            {
                var formatter = PlainTextFormatter.GetBestFormatterFor <Widget>();

                var writer = new StringWriter();

                formatter.Format(new Widget {
                    Name = "Bob"
                }, writer);

                var s = writer.ToString();

                s.Should().Contain("Name: Bob");
            }
Ejemplo n.º 17
0
            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.GetBestFormatterFor(widget.GetType());

                widget.Invoking(w => w.ToDisplayString(formatter)).Should().NotThrow();
            }
Ejemplo n.º 18
0
            public void It_expands_fields_of_objects()
            {
                var formatter = PlainTextFormatter.GetBestFormatterFor <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: ");
            }
Ejemplo n.º 19
0
            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.GetBestFormatterFor(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();
            }
Ejemplo n.º 20
0
            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.GetBestFormatterFor <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> } ]");
            }
Ejemplo n.º 21
0
            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.GetBestFormatterFor <Widget>();

                // this should not throw
                var s = widget.ToDisplayString(formatter);

                s.Should()
                .Contain("hello")
                .And
                .NotContain("{ h },{ e }");
            }
Ejemplo n.º 22
0
 public void Non_generic_GetBestFormatter_uses_default_formatter_for_object()
 {
     PlainTextFormatter.GetBestFormatterFor(typeof(Widget))
     .Should()
     .BeOfType <PlainTextFormatter <object> >();
 }
Ejemplo n.º 23
0
 public void GetBestFormatter_for_List_uses_default_formatter_for_enumerable()
 {
     PlainTextFormatter.GetBestFormatterFor(typeof(List <int>))
     .Should()
     .BeOfType <PlainTextFormatter <IEnumerable> >();
 }