Wrapr 1.0.35
dotnet add package Wrapr --version 1.0.35
NuGet\Install-Package Wrapr -Version 1.0.35
<PackageReference Include="Wrapr" Version="1.0.35" />
paket add Wrapr --version 1.0.35
#r "nuget: Wrapr, 1.0.35"
// 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
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 | Versions 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. |
-
.NETStandard 2.1
- CliWrap (>= 3.6.4)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- 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