Wrapr 1.0.23

There is a newer version of this package available.
See the version list below for details.
dotnet add package Wrapr --version 1.0.23                
NuGet\Install-Package Wrapr -Version 1.0.23                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Wrapr" Version="1.0.23" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Wrapr --version 1.0.23                
#r "nuget: Wrapr, 1.0.23"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Wrapr as a Cake Addin
#addin nuget:?package=Wrapr&version=1.0.23

// Install Wrapr as a Cake Tool
#tool nuget:?package=Wrapr&version=1.0.23                

Dapr Wrapr

nuget codecov stryker build status

Wrapr is a library for Dapr to start and stop a sidecar to support integration testing. It works particularly well with the In Memory pubsub component but can also be used with other components.

E2E pub/sub example

Arrange

await using var sidecar = new Sidecar("integration-test");
await sidecar.Start(with => with
    .ComponentsPath("components-path")
    .DaprGrpcPort(1234) 
    .Args("--log-level", "warn"));

await sidecar.Stop();

Use it in combination with the WebApplicationFactory or the HostBuilder to also host your web application from the test.

new HostBuilder().ConfigureWebHost(app => app
    .UseStartup<Startup>()
    .ConfigureServices(services => services.AddSingleton(service))
    .UseKestrel(options => options.ListenLocalhost(<mark>5555</mark>)))
.Build();

Act

using var client = new DaprClientBuilder()
    .UseGrpcEndpoint("http://localhost:<mark>1234</mark>")
    .Build();

await client
    .PublishEventAsync("my-pubsub", "Demo", new
    {
        Value = 1234
    });

Assert

If you really want to validate the message arrival on the controller action you probably need to stub an underlying service. Since this is an asynchronous operation by default you will need some mechanism for future completion.

I've had great success with my own "future assertion" library hypothesist.

var hypothesis = Hypothesis
    .For<int>()
    .Any(x => x == 1234);

After that you only need a stub that tests the hypothesis before you can validate it. For example using NSubstitute:

service
    .Handle(Arg.Any<int>())
    .Returns(5)
    .AndDoes(x => hypothesis.Test(x.Arg<int>()));

or with a very slim hand-rolled implementation that does exactly that:

private class TestHandler<T> : IHandler<T>
{
    private readonly IHypothesis<T> _hypothesis;

    public TestHandler(IHypothesis<T> hypothesis) => 
        _hypothesis = hypothesis;

    public Task Handle(T input) =>
        _hypothesis.Test(input);
}

Inject that stub into the service collection used by the WebApplicationFactory or HostBuilder. After that you validate the hypothesis of having received a message with specified shape:

await hypothesis
    .Validate(10.Seconds());
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.35 528 1/11/2024
1.0.32 221 10/27/2023
1.0.29 1,316 4/6/2023
1.0.25 491 9/17/2021
1.0.24 349 9/17/2021
1.0.23 318 9/17/2021
1.0.16 546 9/2/2021

1st