Skip to content

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

License

Notifications You must be signed in to change notification settings

VerifyTests/Verify.Wolverine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

764 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Verify.Wolverine

Discussions Build status NuGet Status

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

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.

See Milestones for release notes.

Sponsors

Entity Framework Extensions

Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.

Entity Framework Extensions

NuGet

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

 

Contributors 4

  •  
  •  
  •  
  •  

Languages