Adds Verify support for verifying Wolverine via a custom test context.
See Milestones for release notes.
Uses the same pattern as the Wolverine TestMessageContext with some additions:
- All messaging parameters, eg DeliveryOptions and timeout, can be asserted.
- Support for
IMessageBus.InvokeAsync<T>
via AddInvokeResult.
https://nuget.org/packages/Verify.Wolverine/
[ModuleInitializer]
public static void Init() =>
VerifyWolverine.Initialize();
Given the handler:
public class Handler(IMessageBus context)
{
public ValueTask Handle(Message message) =>
context.SendAsync(new Response("Property Value"));
}
Pass in instance of RecordingMessageContext
in to the Handle
method and then Verify
that instance.
[Fact]
public async Task HandlerTest()
{
var context = new RecordingMessageContext();
var handler = new Handler(context);
await handler.Handle(new Message("value"));
await Verify(context);
}
Will result in:
{
Sent: [
{
Message: {
Property: Property Value
}
}
]
}
When using Request/Reply via IMessageBus.InvokeAsync<T>
the message context is required to supply the "Reply" part. This can be one using RecordingMessageContext.AddInvokeResult<T>
.
For example, given the handler:
public class Handler(IMessageBus context)
{
public async Task Handle(Message message)
{
var request = new Request(message.Property);
var response = await context.InvokeAsync<Response>(request);
Trace.WriteLine(response.Property);
}
}
The result can be set:
[Fact]
public async Task HandlerTest()
{
var context = new RecordingMessageContext();
context.AddInvokeResult<Response>(
message =>
{
var request = (Request) message;
return new Response(request.Property);
});
var handler = new Handler(context);
await handler.Handle(new Message("value"));
await Verify(context);
}
Wolverine designed by Phạm Thanh Lộc from The Noun Project.