public void Can_create_with_lambda() { DateTime startTime = DateTime.Now.AddMilliseconds(-100); var metric = DynamicMetric.From(() => (DateTime.Now - startTime).TotalMilliseconds); Assert.That(metric.Value, Is.EqualTo(100d).Within(5)); }
public void Many_meric_and_dynamic_metric() { var evt = new LogEventInfo("Test", "App") { Metrics = { ["M1"] = 1, ["M2"] = 2 }, DynamicMetrics = { ["D1"] = DynamicMetric.From(() => 1), ["D2"] = DynamicMetric.From(() => 2) } }; var expected = new Dictionary <string, double> { ["App.M1"] = 1, ["App.M2"] = 2, ["App.D1"] = 1, ["App.D2"] = 2 }; Assert.That(evt.GetQualifiedMetrics(), Is.EquivalentTo(expected)); }
public void Should_throw_when_add_whitespace_key() { Assert.Throws <ArgumentException>(() => { var evt = new LogEventInfo("Test"); evt.DynamicMetrics.Add("", DynamicMetric.From(() => 1d)); }); }
public void Should_throw_when_add_key_value_pair_with_whitespace_key() { Assert.Throws <ArgumentException>(() => { var evt = new LogEventInfo("Test"); evt.DynamicMetrics.Add(new KeyValuePair <string, DynamicMetric>("", DynamicMetric.From(() => 1d))); }); }
public void Can_add_using_object_initializer_syntax() { var evt = new LogEventInfo("Test") { DynamicMetrics = { ["M1"] = DynamicMetric.From(() => 1d) } }; Assert.That(evt.DynamicMetrics["M1"].Value, Is.EqualTo(1d)); }
public void One_dynamic_has_Prefix() { var evt = new LogEventInfo("Test", "App") { DynamicMetrics = { ["M1"] = DynamicMetric.From(() => 1) } }; var expected = new Dictionary <string, double> { ["App.M1"] = 1 }; Assert.That(evt.GetQualifiedMetrics(), Is.EquivalentTo(expected)); }