-
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example of Snapshot tests for catching broken contract in events
- Loading branch information
1 parent
9842d4c
commit ef8d994
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ting/EventsSnapshotTests.ShoppingCartConfirmed_WithCompleteData_IsCompatible.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
ShoppingCartId: Guid_1, | ||
ClientId: anonymised, | ||
ConfirmedAt: DateTimeOffset_1 | ||
} |
4 changes: 4 additions & 0 deletions
4
.../EventsSnapshotTests.ShoppingCartConfirmed_WithOnlyRequiredData_IsCompatible.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
ShoppingCartId: Guid_1, | ||
ConfirmedAt: DateTimeOffset_1 | ||
} |
34 changes: 34 additions & 0 deletions
34
Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/EventsSnapshotTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace EventsVersioning.Tests.SnapshotTesting; | ||
|
||
public class EventsSnapshotTests | ||
{ | ||
private record ShoppingCartConfirmed( | ||
Guid ShoppingCartId, | ||
string? ClientId, | ||
DateTimeOffset ConfirmedAt | ||
); | ||
|
||
[Fact] | ||
public Task ShoppingCartConfirmed_WithCompleteData_IsCompatible() | ||
{ | ||
var @event = new ShoppingCartConfirmed(Guid.NewGuid(), "Oskar Dudycz", DateTimeOffset.UtcNow); | ||
return Verify(@event); | ||
} | ||
|
||
[Fact] | ||
public Task ShoppingCartConfirmed_WithOnlyRequiredData_IsCompatible() | ||
{ | ||
var @event = new ShoppingCartConfirmed(Guid.NewGuid(), null, DateTimeOffset.UtcNow); | ||
return Verify(@event); | ||
} | ||
} | ||
// note this is optional, if you really need to | ||
// This is just showing that you can | ||
public static class StaticSettingsUsage | ||
{ | ||
[ModuleInitializer] | ||
public static void Initialize() => | ||
VerifierSettings.AddScrubber(text => text.Replace("Oskar Dudycz", "anonymised")); | ||
} |