An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# Verify.Wolverine

[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true&label=)](https://github.com/orgs/VerifyTests/discussions)
[![Build status](https://img.shields.io/appveyor/build/SimonCropp/Verify-Wolverine)](https://ci.appveyor.com/project/SimonCropp/Verify-Wolverine)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.Wolverine.svg)](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.

[![Entity Framework Extensions](https://raw.githubusercontent.com/VerifyTests/Verify.Wolverine/refs/heads/main/docs/zzz.png)](https://entityframework-extensions.net/?utm_source=simoncropp&utm_medium=Verify.Wolverine)

### Developed using JetBrains IDEs

[![JetBrains logo.](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](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/).