Esempio n. 1
0
        public void XmlLayout_PropertiesElementNameFormat_RenderTrickyDictionary()
        {
            // Arrange
            var xmlLayout = new XmlLayout()
            {
                Elements = { new XmlLayout("message", "${message}") },
                PropertiesElementName         = "{0}",
                PropertiesElementKeyAttribute = "",
                IncludeAllProperties          = true,
                MaxRecursionLimit             = 10,
            };

            var logEventInfo = new LogEventInfo
            {
                Message = "Monster massage"
            };
            IDictionary <object, object> testDictionary = new Internal.TrickyTestDictionary();

            testDictionary.Add("key1", 13);
            testDictionary.Add("key 2", 1.3m);
            logEventInfo.Properties["nlogPropertyKey"] = testDictionary;

            // Act
            var result = xmlLayout.Render(logEventInfo);

            // Assert
            const string expected = @"<logevent><message>Monster massage</message><nlogPropertyKey><key1>13</key1><key_2>1.3</key_2></nlogPropertyKey></logevent>";

            Assert.Equal(expected, result);
        }
Esempio n. 2
0
        public void SerializeTrickyDict_Test()
        {
            IDictionary <object, object> dictionary = new Internal.TrickyTestDictionary();

            dictionary.Add("key1", 13);
            dictionary.Add("key 2", 1.3m);
            var actual = SerializeObject(dictionary);

            Assert.Equal("{\"key1\":13,\"key 2\":1.3}", actual);
        }