public void DictionaryWithScalarKeyFormatsAsAnObject() { var dict = new DictionaryValue(new Dictionary<ScalarValue, LogEventPropertyValue> { { new ScalarValue(12), new ScalarValue(345) } }); var f = Format(dict); Assert.Equal("{\"12\":345}", f); }
public void DictionariesAreSerialisedAsObjects() { var dict = new DictionaryValue(new[] { new KeyValuePair<ScalarValue, LogEventPropertyValue>( new ScalarValue(1), new ScalarValue("hello")), new KeyValuePair<ScalarValue, LogEventPropertyValue>( new ScalarValue("world"), new SequenceValue(new [] { new ScalarValue(1.2) })) }); var e = DelegatingSink.GetLogEvent(l => l.Information("Value is {ADictionary}", dict)); var f = FormatJson(e); Assert.AreEqual("hello", (string)f.Properties.ADictionary["1"]); Assert.AreEqual(1.2, (double)f.Properties.ADictionary.world[0]); }
public void ADictionaryWithScalarKeySerializesAsAnObject() { var dictKey = Some.Int(); var dictValue = Some.Int(); var dict = new DictionaryValue(new Dictionary<ScalarValue, LogEventPropertyValue> { { new ScalarValue(dictKey), new ScalarValue(dictValue) } }); var dictProp = new LogEventProperty(Some.String(), dict); var @event = Some.InformationEvent(); @event.AddOrUpdateProperty(dictProp); var formatted = FormatToJson(@event); var expected = $"{{\"{dictKey}\":{dictValue}}}"; Assert.True(formatted.Contains(expected)); }
public void ADictionaryValueRendersAsMappingOfKeysToValues() { var dict = new DictionaryValue(new[] { new KeyValuePair<ScalarValue, LogEventPropertyValue>( new ScalarValue(1), new ScalarValue("hello")), new KeyValuePair<ScalarValue, LogEventPropertyValue>( new ScalarValue("world"), new SequenceValue(new [] { new ScalarValue(1.2) })) }); var sw = new StringWriter(); dict.Render(sw); var rendered = sw.ToString(); Assert.AreEqual("[(1: \"hello\"), (\"world\": [1.2])]", rendered); }
public void CreateEntityWithPropertiesShouldSupportAzureTableTypesForDictionary() { var messageTemplate = "{Dictionary}"; var dict1 = new DictionaryValue(new List<KeyValuePair<ScalarValue, LogEventPropertyValue>>{ new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d1k1"), new ScalarValue("d1k1v1")), new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d1k2"), new ScalarValue("d1k2v2")), new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d1k3"), new ScalarValue("d1k3v3")), }); var dict2 = new DictionaryValue(new List<KeyValuePair<ScalarValue, LogEventPropertyValue>>{ new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d2k1"), new ScalarValue("d2k1v1")), new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d2k2"), new ScalarValue("d2k2v2")), new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d2k3"), new ScalarValue("d2k3v3")), }); var dict0 = new DictionaryValue(new List<KeyValuePair<ScalarValue, LogEventPropertyValue>>{ new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d1"), dict1), new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d2"), dict2), new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue("d0"), new ScalarValue(0)) }); var properties = new List<LogEventProperty> { new LogEventProperty("Dictionary", dict0) }; var template = new MessageTemplateParser().Parse(messageTemplate); var logEvent = new Events.LogEvent(DateTime.Now, LogEventLevel.Information, null, template, properties); var entity = AzureTableStorageEntityFactory.CreateEntityWithProperties(logEvent, null, null); Assert.AreEqual(3 + properties.Count, entity.Properties.Count); Assert.AreEqual("[(\"d1\": [(\"d1k1\": \"d1k1v1\"), (\"d1k2\": \"d1k2v2\"), (\"d1k3\": \"d1k3v3\")]), (\"d2\": [(\"d2k1\": \"d2k1v1\"), (\"d2k2\": \"d2k2v2\"), (\"d2k3\": \"d2k3v3\")]), (\"d0\": 0)]", entity.Properties["Dictionary"].StringValue); }