Coder Social home page Coder Social logo

verify.wolverine's Introduction

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.

verify.wolverine's People

Contributors

dependabot[bot] avatar simoncropp avatar actions-user avatar

Stargazers

Stephen Strickland avatar Sayan Maity avatar Alexander Zeitler avatar Meysam Hadeli avatar Mehdi Hadeli avatar stooboo avatar Pawel Kasperek avatar Tim Schlechter avatar Naruto avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.