Wrapr 1.0.29
See the version list below for details.
dotnet add package Wrapr --version 1.0.29
NuGet\Install-Package Wrapr -Version 1.0.29
<PackageReference Include="Wrapr" Version="1.0.29" />
paket add Wrapr --version 1.0.29
#r "nuget: Wrapr, 1.0.29"
// Install Wrapr as a Cake Addin #addin nuget:?package=Wrapr&version=1.0.29 // Install Wrapr as a Cake Tool #tool nuget:?package=Wrapr&version=1.0.29
Dapr Wrapr
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 | Versions 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. |
-
net5.0
- CliWrap (>= 3.6.0)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.3)
- System.Linq.Async (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1st