public void Write__KeyValuePairCollection__KeysAreAligned()
        {
            var ow = new StringObjectWriter();

            var kvpc = new KeyValuePairCollection();

            kvpc.Add(new KeyValuePair("1", " "));
            kvpc.Add(new KeyValuePair("12", " "));
            kvpc.Add(new KeyValuePair("1234", " "));
            kvpc.Add(new KeyValuePair("12345", " "));
            kvpc.Add(new KeyValuePair("1234567890", " "));
            kvpc.Add(new KeyValuePair("123456789012345678901", " "));

            var r = ow.Write(kvpc);

            var expected =
                 "1\t\t\t\t\t\t:\t "
                + Environment.NewLine
                + "12\t\t\t\t\t\t:\t "
                + Environment.NewLine
                +"1234\t\t\t\t\t:\t "
                + Environment.NewLine
                + "12345\t\t\t\t\t:\t "
                + Environment.NewLine
                + "1234567890\t\t\t\t:\t "
                + Environment.NewLine
                + "123456789012345678901\t:\t ";

            Assert.AreEqual(expected, r);
        }
        public void Write__DateTime__ISO8601_WithoutTimeZone_WithoutT()
        {
            var ow = new StringObjectWriter();

            var r = ow.Write(DateTime.Parse("2013-12-30T23:24:25.1234567Z"));

            Assert.AreEqual("2013-12-30 23:24:25.1234567", r);
        }
        public void Write__EmptyString__ReturnsStringRepresentingEmptyString()
        {
            var ow = new StringObjectWriter();

            var r = ow.Write("");

            Assert.AreEqual("[EMPTY]", r);

            r = ow.Write("", emptyValue: "123");

            Assert.AreEqual("123", r);
        }
        public PatternFormatter()
        {
            Pattern = "{Event.Message}";

            TextTemplateProcessingServce = new TemplateProcessingService();
            TextTemplateProcessingServce.InternalContext.Functions.AddFunction(
                new Function(
                    "dump", 
                    (originalValue, input, parameters) => 
                    {
                        return input.DumpToString();
                    }));
            TextTemplateProcessingServce.InternalContext.Functions.AddFunction(
                new Function(
                    "dumpHtml",
                    (originalValue, input, parameters) =>
                    {
                        return input.DumpToHtml();
                    }));

            TextTemplateProcessingServce.InternalContext.Functions.AddFunction(
                new Function(
                    "dumpWithHeader",
                    (originalValue, input, parameters) =>
                    {
                        //# first describe the input
                        var inputKvpc = TypeDescriptors.Describe(input);

                        //# add KVP with header as key and input as value
                        var kvp = new KeyValuePair(parameters.First().ToString().Trim(new char[] { '\'' }),  inputKvpc);
                        
                        var result = new StringObjectWriter().Write(kvp);

                        return result;
                    }));
        }
        public void Write__KeyValuePairCollection__MultiLineValuesAreHandled()
        {
            var ow = new StringObjectWriter();

            var kvpc = new KeyValuePairCollection();

            kvpc.Add(new KeyValuePair("key", "_line1_" + Environment.NewLine + "_line2_"));
            kvpc.Add(new KeyValuePair("key_0123456", " "));

            var r = ow.Write(kvpc);

            var expected =
                 "key\t\t\t:"
                + Environment.NewLine
                + "-------------"
                + Environment.NewLine
                + "\t_line1_"
                + Environment.NewLine
                + "\t_line2_"
                + Environment.NewLine
                + "key_0123456\t:\t ";

            Assert.AreEqual(expected, r);
        }
        public void Write__Null__ReturnsStringRepresentingNullValue()
        {
            var ow = new StringObjectWriter();

            var r = ow.Write(null);

            Assert.AreEqual("[NULL]", r);

            r = ow.Write(null, "123");

            Assert.AreEqual("123", r);
        }
        public void Write__KeyValuePair_ValueMultiLineString()
        {
            var ow = new StringObjectWriter();

            var kvp = new KeyValuePair("_key_", "_line1_" + Environment.NewLine + "_line2_");

            var r = ow.Write(kvp);

            var expected =
                  "_key_\t:"
                + Environment.NewLine
                + "---------"
                + Environment.NewLine
                + "\t_line1_"
                + Environment.NewLine
                + "\t_line2_";

            Assert.AreEqual(expected, r);
        }
        public void Write__KeyValuePair_ValueIsSingleLineString()
        {
            var ow = new StringObjectWriter();

            var kvp = new KeyValuePair("_key_", "_value_");

            var r = ow.Write(kvp);

            Assert.AreEqual("_key_\t:\t_value_", r);
        }
        public void Write__KeyValuePairCollection__ValueIsKeyValuePairCollection()
        {
            var ow = new StringObjectWriter();

            var kvpc = new KeyValuePairCollection();

            var value = new KeyValuePairCollection();

            value.Add(new KeyValuePair("key_1", "value_1"));
            value.Add(new KeyValuePair("key_2", "value_2"));

            kvpc.Add("item", value);

            var r = ow.Write(kvpc);

            var expected =
                 "item\t:"
                + Environment.NewLine
                + "---------"
                + Environment.NewLine
                + "\tkey_1\t:\tvalue_1"
                + Environment.NewLine
                + "\tkey_2\t:\tvalue_2";

            Assert.AreEqual(expected, r);
        }