Wrapr 1.0.35

dotnet add package Wrapr --version 1.0.35
NuGet\Install-Package Wrapr -Version 1.0.35
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.35" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Wrapr --version 1.0.35
#r "nuget: Wrapr, 1.0.35"
#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.35

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

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
    .ResourcesPath("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:1234")
    .Build();

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

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 == 1111);

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

service
    .SomeMagic(Arg.Any<int>())
    .Returns(x => hypothesis.Test(x.Arg<int>()));

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

private class TestAdapter : Do
{
    private readonly IHypothesis<int> _hypothesis;

    public TestAdapter(IHypothesis<int> hypothesis) => 
        _hypothesis = hypothesis;

    Task<int> Do.SomeMagic(int 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());

You should checkout the example for the full picture.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 141 1/11/2024
1.0.32 178 10/27/2023
1.0.29 743 4/6/2023
1.0.25 458 9/17/2021
1.0.24 321 9/17/2021
1.0.23 287 9/17/2021
1.0.16 509 9/2/2021

1st