/
SentryEventTests.cs
151 lines (131 loc) · 4.41 KB
/
SentryEventTests.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
namespace Sentry.Tests.Protocol;
[UsesVerify]
public class SentryEventTests
{
[Fact]
public async Task SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
{
var ex = new Exception("exception message");
var timestamp = DateTimeOffset.MaxValue;
var id = Guid.Parse("4b780f4c-ec03-42a7-8ef8-a41c9d5621f8");
var sut = new SentryEvent(ex, timestamp, id)
{
User = new User { Id = "user-id" },
Request = new Request { Method = "POST" },
Contexts = new Contexts
{
["context_key"] = "context_value",
[".NET Framework"] = new Dictionary<string, string>
{
[".NET Framework"] = "\"v2.0.50727\", \"v3.0\", \"v3.5\"",
[".NET Framework Client"] = "\"v4.8\", \"v4.0.0.0\"",
[".NET Framework Full"] = "\"v4.8\""
}
},
Sdk = new SdkVersion { Name = "SDK-test", Version = "1.1.1" },
Environment = "environment",
Level = SentryLevel.Fatal,
Logger = "logger",
Message = new SentryMessage
{
Message = "message",
Formatted = "structured_message"
},
Modules = { { "module_key", "module_value" } },
Release = "release",
SentryExceptions = new[] { new SentryException { Value = "exception_value" } },
SentryThreads = new[] { new SentryThread { Crashed = true } },
ServerName = "server_name",
TransactionName = "transaction",
DebugImages = new List<DebugImage>()
{
new DebugImage { Type = "wasm", DebugId = "900f7d1b868432939de4457478f34720" }
},
};
sut.Sdk.AddPackage(new Package("name", "version"));
sut.AddBreadcrumb(new Breadcrumb(timestamp, "crumb"));
sut.AddBreadcrumb(new Breadcrumb(
timestamp,
"message",
"type",
new Dictionary<string, string> { { "data-key", "data-value" } },
"category",
BreadcrumbLevel.Warning));
sut.SetExtra("extra_key", "extra_value");
sut.Fingerprint = new[] { "fingerprint" };
sut.SetTag("tag_key", "tag_value");
var actualString = sut.ToJsonString();
await VerifyJson(actualString);
actualString.Should().Contain(
"\"debug_meta\":{\"images\":[" +
"{\"type\":\"wasm\",\"debug_id\":\"900f7d1b868432939de4457478f34720\"}" +
"]}");
var actual = SentryEvent.FromJson(Json.Parse(actualString));
// Assert
actual.Should().BeEquivalentTo(sut, o =>
{
// Exceptions are not deserialized
o.Excluding(x => x.Exception);
// Timestamps lose some precision when writing to JSON
o.Using<DateTimeOffset>(ctx =>
ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromMilliseconds(1))
).WhenTypeIs<DateTimeOffset>();
return o;
});
}
[Fact]
public void Ctor_Timestamp_NonDefault()
{
var evt = new SentryEvent();
Assert.NotEqual(default, evt.Timestamp);
}
[Fact]
public void Ctor_EventId_NonDefault()
{
var evt = new SentryEvent();
Assert.NotEqual(default, evt.EventId);
}
[Fact]
public void Ctor_Exception_Stored()
{
var e = new Exception();
var evt = new SentryEvent(e);
Assert.Same(e, evt.Exception);
}
[Fact]
public void SentryThreads_Getter_NotNull()
{
var evt = new SentryEvent();
Assert.NotNull(evt.SentryThreads);
}
[Fact]
public void SentryThreads_SetToNUll_Getter_NotNull()
{
var evt = new SentryEvent
{
SentryThreads = null
};
Assert.NotNull(evt.SentryThreads);
}
[Fact]
public void SentryExceptions_Getter_NotNull()
{
var evt = new SentryEvent();
Assert.NotNull(evt.SentryExceptions);
}
[Fact]
public void SentryExceptions_SetToNUll_Getter_NotNull()
{
var evt = new SentryEvent
{
SentryExceptions = null
};
Assert.NotNull(evt.SentryExceptions);
}
[Fact]
public void Modules_Getter_NotNull()
{
var evt = new SentryEvent();
Assert.NotNull(evt.Modules);
}
}