コード例 #1
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)));
        }
コード例 #2
0
        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));
        }
コード例 #3
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"));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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 }"));
        }
コード例 #6
0
        public void RegisterPropertiesFormatter_for_string_does_nothing()
        {
            var formatter = new FormatterSet();

            formatter.RegisterPropertiesFormatter <string>();

            Assert.That(formatter.Format("hello"),
                        Is.EqualTo("hello"));
        }
コード例 #7
0
        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()));
        }
コード例 #8
0
        public void Static_properties_are_not_written()
        {
            var formatter = new FormatterSet();

            formatter.RegisterPropertiesFormatter <BoundaryTests.NestedWidget>();

            Assert.That(formatter.Format(new Widget()),
                        !Contains.Substring("StaticProperty"));
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        public void RegisterPropertiesFormatter_for_string_does_nothing()
        {
            var formatter = new FormatterSet();
            formatter.RegisterPropertiesFormatter<string>();

            Assert.That(formatter.Format("hello"),
                        Is.EqualTo("hello"));
        }
コード例 #11
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        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()));
        }
コード例 #12
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        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)));
        }
コード例 #13
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        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"));
        }
コード例 #14
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        public void Static_properties_are_not_written()
        {
            var formatter = new FormatterSet();
            formatter.RegisterPropertiesFormatter<BoundaryTests.NestedWidget>();

            Assert.That(formatter.Format(new Widget()),
                        !Contains.Substring("StaticProperty"));
        }
コード例 #15
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        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));
        }
コード例 #16
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        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 }"));
        }
コード例 #17
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        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));
        }
コード例 #18
0
ファイル: FormatterSetTests.cs プロジェクト: wli3/Its.Log
        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"));
        }