forked from datalust/seq-extensions-logging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionDataEnricherTests.cs
More file actions
47 lines (40 loc) · 1.32 KB
/
ExceptionDataEnricherTests.cs
File metadata and controls
47 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Seq.Extensions.Logging;
using Serilog.Events;
using Tests.Support;
using Xunit;
namespace Tests.Seq.Extensions.Logging;
public class ExceptionDataEnricherTests
{
[Fact]
public void WhenNoDataIsPresentNoPropertyIsAdded()
{
var enricher = new ExceptionDataEnricher();
var exception = new Exception();
var evt = Some.ErrorEvent(exception);
enricher.Enrich(evt, Some.PropertyValueFactory());
Assert.Empty(evt.Properties);
}
[Fact]
public void WhenDataIsPresentThePropertyIsAdded()
{
var enricher = new ExceptionDataEnricher();
var exception = new Exception
{
Data =
{
["A"] = 42,
["B"] = "Hello"
}
};
var evt = Some.ErrorEvent(exception);
enricher.Enrich(evt, Some.PropertyValueFactory());
Assert.Single(evt.Properties);
var data = evt.Properties["ExceptionData"];
var value = Assert.IsType<StructureValue>(data);
Assert.Equal(2, value.Properties.Count);
var a = Assert.IsType<ScalarValue>(value.Properties.Single(p => p.Name == "A").Value);
Assert.Equal(42, a.Value);
var b = Assert.IsType<ScalarValue>(value.Properties.Single(p => p.Name == "B").Value);
Assert.Equal("Hello", b.Value);
}
}