https://github.com/verifytests/verify.wolverine
Adds Verify support for verifying Wolverine via a custom test context.
https://github.com/verifytests/verify.wolverine
Last synced: 3 months ago
JSON representation
Adds Verify support for verifying Wolverine via a custom test context.
- Host: GitHub
- URL: https://github.com/verifytests/verify.wolverine
- Owner: VerifyTests
- License: mit
- Created: 2022-12-12T09:40:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-14T11:25:12.000Z (about 1 year ago)
- Last Synced: 2025-04-14T12:30:18.690Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 446 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license.txt
Awesome Lists containing this project
README
#
Verify.Wolverine
[](https://github.com/orgs/VerifyTests/discussions)
[](https://ci.appveyor.com/project/SimonCropp/Verify-Wolverine)
[](https://www.nuget.org/packages/Verify.Wolverine/)
Adds [Verify](https://github.com/VerifyTests/Verify) support for verifying [Wolverine](https://github.com/JasperFx/wolverine) via a custom test context.
Uses the same pattern as the [Wolverine TestMessageContext](https://wolverine.netlify.app/guide/testing.html#testmessagecontext) with some additions:
* All messaging parameters, eg DeliveryOptions and timeout, can be asserted.
* Support for `IMessageBus.InvokeAsync` via [AddInvokeResult](#addinvokeresult).
**See [Milestones](../../milestones?state=closed) for release notes.**
## Sponsors
### Entity Framework Extensions
[Entity Framework Extensions](https://entityframework-extensions.net/?utm_source=simoncropp&utm_medium=Verify.Wolverine) is a major sponsor and is proud to contribute to the development this project.
[](https://entityframework-extensions.net/?utm_source=simoncropp&utm_medium=Verify.Wolverine)
### Developed using JetBrains IDEs
[](https://jb.gg/OpenSourceSupport)
## NuGet
* https://nuget.org/packages/Verify.Wolverine
## Usage
```cs
[ModuleInitializer]
public static void Init() =>
VerifyWolverine.Initialize();
```
snippet source | anchor
## Handler
Given the handler:
```cs
public class Handler(IMessageBus context)
{
public ValueTask Handle(Message message) =>
context.SendAsync(new Response("Property Value"));
}
```
snippet source | anchor
## Test
Pass in instance of `RecordingMessageContext` in to the `Handle` method and then `Verify` that instance.
```cs
[Fact]
public async Task HandlerTest()
{
var context = new RecordingMessageContext();
var handler = new Handler(context);
await handler.Handle(new Message("value"));
await Verify(context);
}
```
snippet source | anchor
Will result in:
```txt
{
Sent: [
{
Message: {
Property: Property Value
}
}
]
}
```
snippet source | anchor
### AddInvokeResult
When using [Request/Reply](https://wolverine.netlify.app/guide/messaging/message-bus.html#request-reply) via `IMessageBus.InvokeAsync` the message context is required to supply the "Reply" part. This can be one using `RecordingMessageContext.AddInvokeResult`.
For example, given the handler:
```cs
public class Handler(IMessageBus context)
{
public async Task Handle(Message message)
{
var request = new Request(message.Property);
var response = await context.InvokeAsync(request);
Trace.WriteLine(response.Property);
}
}
```
snippet source | anchor
The result can be set:
```cs
[Fact]
public async Task HandlerTest()
{
var context = new RecordingMessageContext();
context.AddInvokeResult(
message =>
{
var request = (Request) message;
return new Response(request.Property);
});
var handler = new Handler(context);
await handler.Handle(new Message("value"));
await Verify(context);
}
```
snippet source | anchor
## Icon
[Wolverine](https://thenounproject.com/term/wolverine/3386573/) designed by [Phạm Thanh Lộc](https://thenounproject.com/thanhloc1009/) from [The Noun Project](https://thenounproject.com/).