public void TryParse_should_parse_and_move_offset_ignoring_case()
        {
            var offset = 3;

            FragmentHelpers.TryParse <LevelFragment>("%l", "%d %L", ref offset).Should().NotBeNull();
            offset.Should().Be(5);
        }
        public void TryParse_should_throw_exception_if_fragment_is_null()
        {
            var offset = 3;

            new Action(() => FragmentHelpers.TryParse <LevelFragment>(null, "%d %l", ref offset)).Should().Throw <Exception>();
            offset.Should().Be(3);
        }
        public void TryParse_should_not_parse_if_wrong_fragment()
        {
            var offset = 3;

            FragmentHelpers.TryParse <LevelFragment>("%?", "%d %l", ref offset).Should().BeNull();
            offset.Should().Be(3);
        }
        public void TryParse_should_not_parse_if_wrong_offset_is_given()
        {
            var offset = 4;

            FragmentHelpers.TryParse <LevelFragment>("%l", "%d %l", ref offset).Should().BeNull();
            offset.Should().Be(4);
        }
        public void TryParse_should_not_parse_if_format_is_null()
        {
            var offset = 3;

            FragmentHelpers.TryParse <LevelFragment>("%l", null, ref offset).Should().BeNull();
            offset.Should().Be(3);
        }
        public void TryWriteProperty_should_not_write_if_event_has_no_properties()
        {
            var writer = new StringWriter();

            FragmentHelpers.TryWriteProperty(null, null, writer);
            writer.ToString().Should().BeEmpty();
        }
        public void TryWriteProperty_should_write_property_without_format()
        {
            const string propName = "name";
            const int    value    = 123;

            var writer = new StringWriter();
            var le     = LogEvent().WithProperty(propName, value);
            var prop   = FragmentHelpers.GetPropertyOrNull(le, propName);

            FragmentHelpers.TryWriteProperty(prop, null, writer);
            writer.ToString().Should().Be(value.ToString());
        }
        public void TryWriteProperty_should_write_property_with_format()
        {
            const string propName = "name";
            const string format   = "yyyy-MM-dd";
            var          value    = DateTime.Now;

            var writer = new StringWriter();
            var le     = LogEvent().WithProperty(propName, value);
            var prop   = FragmentHelpers.GetPropertyOrNull(le, propName);

            FragmentHelpers.TryWriteProperty(prop, format, writer);
            writer.ToString().Should().Be(value.ToString(format));
        }
        private static void WriteProperties(IReadOnlyDictionary <string, object> properties, TextWriter writer)
        {
            if (properties == null || properties.Count == 0)
            {
                return;
            }

            writer.Write("[properties: ");

            var i = 0;

            foreach (var pair in properties)
            {
                writer.Write(pair.Key);
                writer.Write(" = ");
                FragmentHelpers.TryWriteProperty(pair.Value, null, writer);
                if (++i < properties.Count)
                {
                    writer.Write(", ");
                }
            }

            writer.Write("]");
        }
 public void Render(LogEvent @event, TextWriter writer) =>
 FragmentHelpers.TryWriteProperty(FragmentHelpers.GetPropertyOrNull(@event, property), format, writer);
 public static ExceptionFragment TryParse(string value, ref int offset) =>
 FragmentHelpers.TryParse <ExceptionFragment>(Text, value, ref offset);
 public static PropertiesFragment TryParse(string value, ref int offset) =>
 FragmentHelpers.TryParse <PropertiesFragment>(Text, value, ref offset);
Exemplo n.º 13
0
 public static LevelFragment TryParse(string value, ref int offset) =>
 FragmentHelpers.TryParse <LevelFragment>(Text, value, ref offset);
        public void GetPropertyOrNull_shoult_return_null_if_event_has_no_properties()
        {
            var le = LogEvent();

            FragmentHelpers.GetPropertyOrNull(le, "name").Should().BeNull();
        }
        public void GetPropertyOrNull_shoult_return_null_if_given_wrong_property_name()
        {
            var le = LogEvent().WithProperty("name", 123);

            FragmentHelpers.GetPropertyOrNull(le, "wrong name").Should().BeNull();
        }
        public void GetPropertyOrNull_shoult_return_value()
        {
            var le = LogEvent().WithProperty("name", 123);

            FragmentHelpers.GetPropertyOrNull(le, "name").Should().Be(123);
        }
 public bool HasValue(LogEvent @event) => FragmentHelpers.GetPropertyOrNull(@event, property) != null;
Exemplo n.º 18
0
 public static MessageFragment TryParse(string value, ref int offset) =>
 FragmentHelpers.TryParse <MessageFragment>(Text, value, ref offset);
Exemplo n.º 19
0
 public static NewLineFragment TryParse(string value, ref int offset) =>
 FragmentHelpers.TryParse <NewLineFragment>(Text, value, ref offset);