public void SimplifyScalarReplacesXmlInvalidChars()
        {
            // Arrange
            var input = new ScalarValue("some<allowed>words&inbetween");
            var sut   = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, null);

            // Assert
            Assert.Equal("some&lt;allowed&gt;words&amp;inbetween", result);
        }
        public void SimplifyDictionaryReplacesXmlInvalidCharsInKey()
        {
            // Arrange
            var input = new DictionaryValue(new List <KeyValuePair <ScalarValue, LogEventPropertyValue> >
            {
                new KeyValuePair <ScalarValue, LogEventPropertyValue>(new ScalarValue("some<allowed>words&inbetween"), new ScalarValue("Value1"))
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions();
            var sut     = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<dictionary><item key='some&lt;allowed&gt;words&amp;inbetween'>Value1</item></dictionary>", result);
        }
        public void SimplifySequenceReplacesXmlInvalidCharsInValue()
        {
            // Arrange
            var input = new SequenceValue(new List <LogEventPropertyValue>
            {
                new ScalarValue("some<allowed>words&inbetween")
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions();
            var sut     = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<sequence><item>some&lt;allowed&gt;words&amp;inbetween</item></sequence>", result);
        }
        public void SimplifyStructureRendersElements()
        {
            // Arrange
            var input = new StructureValue(new List <LogEventProperty>
            {
                new LogEventProperty("Key1", new ScalarValue("Value1")),
                new LogEventProperty("Key2", new ScalarValue(2))
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions();
            var sut     = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<structure type=''><property key='Key1'>Value1</property><property key='Key2'>2</property></structure>", result);
        }
        public void SimplifyDictionaryRendersElements()
        {
            // Arrange
            var input = new DictionaryValue(new List <KeyValuePair <ScalarValue, LogEventPropertyValue> >
            {
                new KeyValuePair <ScalarValue, LogEventPropertyValue>(new ScalarValue("Key1"), new ScalarValue("Value1")),
                new KeyValuePair <ScalarValue, LogEventPropertyValue>(new ScalarValue("Key2"), new ScalarValue(2))
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions();
            var sut     = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<dictionary><item key='Key1'>Value1</item><item key='Key2'>2</item></dictionary>", result);
        }
        public void SimplifySequenceRendersElements()
        {
            // Arrange
            var input = new SequenceValue(new List <LogEventPropertyValue>
            {
                new ScalarValue("Value1"),
                new ScalarValue(2)
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions();
            var sut     = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<sequence><item>Value1</item><item>2</item></sequence>", result);
        }
        public void SimplifyStructureFixesElementNamesIfUsePropertyKeyAsElementNameIsTrue()
        {
            // Arrange
            var input = new StructureValue(new List <LogEventProperty>
            {
                new LogEventProperty("xml Key With Space", new ScalarValue("Value1"))
            }, "5structure\ttype");
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions {
                UsePropertyKeyAsElementName = true
            };
            var sut = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<x5structure_type><xxml_Key_With_Space>Value1</xxml_Key_With_Space></x5structure_type>", result);
        }
        public void SimplifyDictionaryHandlesOptionUsePropertyKeyAsElementName()
        {
            // Arrange
            var input = new DictionaryValue(new List <KeyValuePair <ScalarValue, LogEventPropertyValue> >
            {
                new KeyValuePair <ScalarValue, LogEventPropertyValue>(new ScalarValue("Key1"), new ScalarValue("Value1")),
                new KeyValuePair <ScalarValue, LogEventPropertyValue>(new ScalarValue("Key2"), new ScalarValue(2))
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions {
                UsePropertyKeyAsElementName = true
            };
            var sut = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<dictionary><Key1>Value1</Key1><Key2>2</Key2></dictionary>", result);
        }
        public void SimplifyStructureHandlesOptionOmitStructureContainerElement()
        {
            // Arrange
            var input = new StructureValue(new List <LogEventProperty>
            {
                new LogEventProperty("Key1", new ScalarValue("Value1")),
                new LogEventProperty("Key2", new ScalarValue(2))
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions {
                OmitStructureContainerElement = true
            };
            var sut = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<property key='Key1'>Value1</property><property key='Key2'>2</property>", result);
        }
        public void SimplifyStructureHandlesOptionUsePropertyKeyAsElementName()
        {
            // Arrange
            var input = new StructureValue(new List <LogEventProperty>
            {
                new LogEventProperty("Key1", new ScalarValue("Value1")),
                new LogEventProperty("Key2", new ScalarValue(2))
            }, "structuretype");
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions {
                UsePropertyKeyAsElementName = true
            };
            var sut = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<structuretype><Key1>Value1</Key1><Key2>2</Key2></structuretype>", result);
        }
        public void SimplifySequenceUsesCustomItemElementName()
        {
            // Arrange
            var input = new SequenceValue(new List <LogEventPropertyValue>
            {
                new ScalarValue("Value1"),
                new ScalarValue("Value2")
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions {
                ItemElementName = "element"
            };
            var sut = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<sequence><element>Value1</element><element>Value2</element></sequence>", result);
        }
        public void SimplifySequenceHandlesOptionOmitSequenceContainerElement()
        {
            // Arrange
            var input = new SequenceValue(new List <LogEventPropertyValue>
            {
                new ScalarValue("Value1"),
                new ScalarValue("Value2")
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions {
                OmitSequenceContainerElement = true
            };
            var sut = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<item>Value1</item><item>Value2</item>", result);
        }
        public void SimplifyDictionaryHandlesOptionOmitDictionaryContainerElement()
        {
            // Arrange
            var input = new DictionaryValue(new List <KeyValuePair <ScalarValue, LogEventPropertyValue> >
            {
                new KeyValuePair <ScalarValue, LogEventPropertyValue>(new ScalarValue("Key1"), new ScalarValue("Value1")),
                new KeyValuePair <ScalarValue, LogEventPropertyValue>(new ScalarValue("Key2"), new ScalarValue("Value2"))
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions {
                OmitDictionaryContainerElement = true
            };
            var sut = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<item key='Key1'>Value1</item><item key='Key2'>Value2</item>", result);
        }
        public void SimplifyStructureHandlesOptionOmitElementIfEmpty()
        {
            // Arrange
            var input = new StructureValue(new List <LogEventProperty>
            {
                new LogEventProperty("Key1", new ScalarValue(string.Empty)),
                new LogEventProperty("Key2", new ScalarValue("Value2")),
                new LogEventProperty("Key3", new ScalarValue(null))
            });
            var options = new Serilog.Sinks.MSSqlServer.ColumnOptions.PropertiesColumnOptions {
                OmitElementIfEmpty = true
            };
            var sut = new XmlPropertyFormatter();

            // Act
            var result = sut.Simplify(input, options);

            // Assert
            Assert.Equal("<structure type=''><property key='Key2'>Value2</property></structure>", result);
        }