Skip to content

Commit 5ed1373

Browse files
#140: Add Exception tests & Docs
1 parent b3c493c commit 5ed1373

13 files changed

+338
-3
lines changed

docs/docs/library/verify-extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ The reson it doesn't emit the formatted message or exception message by default
7575
* Verify the [LogLevel](verify/log-level.md)
7676
* Verify the [CategoryName](verify/category-name.md)
7777
* Verify the log [Message](verify/message.md)
78+
* Verify [Exceptions](verify/exception.md)
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
layout: default
3+
title: Verify Logs - Eceptions
4+
---
5+
6+
# Verifying Exeptions
7+
8+
There are three settings:
9+
* `None`: Does not verify any exceptions.
10+
* `Message`: Verifies the exception message. This can cause brittle tests as the message may contain nondeterministic information.
11+
* `Type`: Verifies the exception type.
12+
* `StackTrace`: Verifies the stack trace of the exception. This can cause brittle tests as code moves around, is refactored, packages updated, etc.
13+
* `IncludeInnerExceptions`: Recursively verifies the inner exceptions.
14+
15+
Each of these settings are flags and can be joined together like the example below.
16+
17+
The default value is `Type` and `IncludeInnerExceptions`.
18+
19+
```csharp
20+
public async Task VerifyWarningLogsAreEmittedCorrectlyTestAsync()
21+
{
22+
// ... Code that produces logs
23+
24+
VerifySettings verifySettings = new VerifySettings()
25+
.AddCapturedLogs(new LoggingCaptureVerifySettings()
26+
{
27+
Exception = ExceptionSetting.Message | ExceptionSetting.Type | ExceptionSetting.IncludeInnerExceptions,
28+
});
29+
30+
await Verifier.Verify(logs, verifySettings);
31+
}
32+
```
33+
34+
## Example output
35+
36+
### None
37+
38+
```
39+
[
40+
{
41+
Sequence: 0,
42+
LogLevel: Error,
43+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
44+
MessageTemplate: Am error happened that resulted in an exception being thrown.
45+
}
46+
]
47+
```
48+
49+
### Message
50+
51+
```
52+
[
53+
{
54+
Sequence: 0,
55+
LogLevel: Error,
56+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
57+
MessageTemplate: Am error happened that resulted in an exception being thrown.,
58+
Exception: {
59+
Message: This is the application exception, it contains an inner exception.
60+
}
61+
}
62+
]
63+
```
64+
65+
### Type
66+
67+
```
68+
[
69+
{
70+
Sequence: 0,
71+
LogLevel: Error,
72+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
73+
MessageTemplate: An error happened that resulted in an exception being thrown.,
74+
Exception: {
75+
Type: System.ApplicationException
76+
}
77+
}
78+
]
79+
```
80+
81+
### StackTrace
82+
83+
```
84+
[
85+
{
86+
Sequence: 0,
87+
LogLevel: Error,
88+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
89+
MessageTemplate: An error happened that resulted in an exception being thrown.,
90+
Exception: {
91+
StackTrace:
92+
at Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests.DoTheThing() in {ProjectDirectory}Verify/VerifyExceptionSettingTests.cs:line 60
93+
at Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests.VerifyMessageSettingAsync(ExceptionSetting setting) in {ProjectDirectory}Verify/VerifyExceptionSettingTests.cs:line 33
94+
}
95+
}
96+
]
97+
```
98+
99+
Note here that Verify has detected the project directory in the output and replaced it with `{ProjectDirectoy}` so that it doesn't break on other team members' machines or on build servers.
100+
101+
### IncludeInnerExceptions
102+
103+
```
104+
[
105+
{
106+
Sequence: 0,
107+
LogLevel: Error,
108+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
109+
MessageTemplate: An error happened that resulted in an exception being thrown.,
110+
Exception: {
111+
InnerException: {}
112+
}
113+
}
114+
]
115+
```
116+
117+
This setting on its own isn't very useful.
118+
119+
### All: Type, Message, StackTrace, IncludeInnerExceptions
120+
121+
```
122+
[
123+
{
124+
Sequence: 0,
125+
LogLevel: Error,
126+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
127+
MessageTemplate: An error happened that resulted in an exception being thrown.,
128+
Exception: {
129+
Type: System.ApplicationException,
130+
Message: This is the application exception, it contains an inner exception.,
131+
StackTrace:
132+
at Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests.DoTheThing() in {ProjectDirectory}Verify/VerifyExceptionSettingTests.cs:line 61
133+
at Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests.VerifyMessageSettingAsync(ExceptionSetting setting) in {ProjectDirectory}Verify/VerifyExceptionSettingTests.cs:line 34,
134+
InnerException: {
135+
Type: System.InvalidOperationException,
136+
Message: Boo! You performed an invalid operation.,
137+
StackTrace:
138+
at Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests.PerformThePartOfTheTaskThatActuallyBreaks() in {ProjectDirectory}Verify/VerifyExceptionSettingTests.cs:line 68
139+
at Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests.DoTheThing() in {ProjectDirectory}Verify/VerifyExceptionSettingTests.cs:line 57
140+
}
141+
}
142+
}
143+
]
144+
```

docs/scripts/contributors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
This is a list of all the contributors to this repository in ascending order by the contributor name.
44

5-
**Colin Mackay** contributed 353 commits from Saturday, 26 September, 2020 @ 20:26:19 +00:00 to Thursday, 21 March, 2024 @ 22:10:09 +00:00.
5+
**Colin Mackay** contributed 355 commits from Saturday, 26 September, 2020 @ 20:26:19 +00:00 to Sunday, 24 March, 2024 @ 19:37:12 +00:00.
66

77
**dependabot[bot]** contributed 59 commits from Wednesday, 14 October, 2020 @ 19:13:43 +00:00 to Monday, 26 February, 2024 @ 14:54:09 +00:00.
88

99
**StravaigBot** contributed 28 commits from Monday, 14 December, 2020 @ 19:28:09 +00:00 to Tuesday, 27 February, 2024 @ 21:50:14 +00:00.
1010

1111
## Summary
1212

13-
:octocat: 440 commits in total.
13+
:octocat: 442 commits in total.
1414

1515
:date: From Saturday, 26 September, 2020 @ 20:26:19 +00:00.
1616

17-
:date: Until Thursday, 21 March, 2024 @ 22:10:09 +00:00.
17+
:date: Until Sunday, 24 March, 2024 @ 19:37:12 +00:00.
1818

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
Sequence: 0,
4+
LogLevel: Error,
5+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
6+
MessageTemplate: An error happened that resulted in an exception being thrown.,
7+
Exception: {
8+
InnerException: {}
9+
}
10+
}
11+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
Sequence: 0,
4+
LogLevel: Error,
5+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
6+
MessageTemplate: An error happened that resulted in an exception being thrown.,
7+
Exception: {
8+
Message: This is the application exception, it contains an inner exception.,
9+
InnerException: {
10+
Message: Boo! You performed an invalid operation.
11+
}
12+
}
13+
}
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
Sequence: 0,
4+
LogLevel: Error,
5+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
6+
MessageTemplate: An error happened that resulted in an exception being thrown.,
7+
Exception: {
8+
Message: This is the application exception, it contains an inner exception.
9+
}
10+
}
11+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
Sequence: 0,
4+
LogLevel: Error,
5+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
6+
MessageTemplate: An error happened that resulted in an exception being thrown.
7+
}
8+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
Sequence: 0,
4+
LogLevel: Error,
5+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
6+
MessageTemplate: An error happened that resulted in an exception being thrown.,
7+
Exception: {
8+
StackTrace:
9+
at Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests.DoTheThing() in {ProjectDirectory}Verify/VerifyExceptionSettingTests.cs:line 61
10+
at Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests.VerifyMessageSettingAsync(ExceptionSetting setting) in {ProjectDirectory}Verify/VerifyExceptionSettingTests.cs:line 34
11+
}
12+
}
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
Sequence: 0,
4+
LogLevel: Error,
5+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
6+
MessageTemplate: An error happened that resulted in an exception being thrown.,
7+
Exception: {
8+
Type: System.ApplicationException,
9+
InnerException: {
10+
Type: System.InvalidOperationException
11+
}
12+
}
13+
}
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
Sequence: 0,
4+
LogLevel: Error,
5+
CategoryName: Stravaig.Extensions.Logging.Diagnostics.Tests.Verify.VerifyExceptionSettingTests,
6+
MessageTemplate: An error happened that resulted in an exception being thrown.,
7+
Exception: {
8+
Type: System.ApplicationException,
9+
Message: This is the application exception, it contains an inner exception.,
10+
InnerException: {
11+
Type: System.InvalidOperationException,
12+
Message: Boo! You performed an invalid operation.
13+
}
14+
}
15+
}
16+
]

0 commit comments

Comments
 (0)