Skip to content

VerifyTests/Verify.Wolverine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Verify.Wolverine

Discussions Build status NuGet Status

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.

NuGet package

https://nuget.org/packages/Verify.Wolverine/

Usage

[ModuleInitializer]
public static void Init() =>
    VerifyWolverine.Initialize();

snippet source | anchor

Handler

Given the handler:

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.

[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:

{
  Sent: [
    {
      Message: {
        Property: Property Value
      }
    }
  ]
}

snippet source | anchor

AddInvokeResult

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);
    }
}

snippet source | anchor

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);
}

snippet source | anchor

Icon

Wolverine designed by Phạm Thanh Lộc from The Noun Project.

About

Adds Verify support for verifying Wolverine via a custom test context.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages