Hypothesist 2.0.30

.NET Core 3.1
Install-Package Hypothesist -Version 2.0.30
dotnet add package Hypothesist --version 2.0.30
<PackageReference Include="Hypothesist" Version="2.0.30" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hypothesist --version 2.0.30
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Hypothesist, 2.0.30"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hypothesist as a Cake Addin
#addin nuget:?package=Hypothesist&version=2.0.30

// Install Hypothesist as a Cake Tool
#tool nuget:?package=Hypothesist&version=2.0.30
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

nuget codecov stryker build status

Hypothesist

The future assertion library for .NET.

This library is there to help you do assertions on events that are about to happen in the near future. For example, when building integration tests for a subscriber on a service bus.

schema

Define

Define your hypothesis with an experiment, time constraint and test:

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

Test

You test your hypothesis by providing samples:

await hypothesis.Test(sample);

For example with an injected stub:

var service = Substitute.For<IDemoService>();
service
    .When(x => x.Demo(Arg.Any<Data>()))
    .Do(x => hypothesis.Test(x.Arg<Data>()));

or with a hand-rolled implementation:

class TestService : IDemoService
{
    private readonly IHypothesis<Data> _hypothesis;

    public TestService(IHypothesis<Data> hypothesis) => 
        _hypothesis = hypothesis;

    public Task Demo(Data data) =>
        _hypothesis.Test(data);
}

var service = new TestService(hypothesis);

or with the consumer factory Hypothesist.MassTransit when using MassTransit:

cfg.ReceiveEndpoint("...", x => x.Consumer(hypothesis.AsConsumer));

or with the handler factory Hypothesist.Rebus when using Rebus:

using var activator = new BuiltinHandlerActivator()
    .Register(hypothesis.AsHandler);

Validate

You validate if your hypothesis holds true for the supplied samples during the specified time window.

await hypothesis.Validate(15.Seconds()); // <-- using TimeSpan extension from FluentAssertions

But somewhere in between you've fired off the eventing mechanism that ultimately invokes the injected service.

Experiments

The two parts of the hypothesis are the experiment and a time constraint.

Any

Validates that at least one item matches the assertion, meaning the experiment stops when this item is observed.

All

Validates that all items that are observed during the experiment matches the assertion.

Remark: having no items observed during the time window also means the hypothesis holds true;

First

Validates that the first item that is observed matches the assertion.

Single

Validates that exactly one item is observed that matches the assertion.

Remark: having other items not matching the assert means the hypothesis still holds true.

Exactly

Validates that exactly the given number of occurrences is observed that matches the assertion within the given timeframe.

AtLeast

Validates that at least the given number of occurrences is observed that matches the assertion.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Hypothesist:

Package Downloads
Hypothesist.MassTransit

Plugin the hypothesis as a consumer into MassTransit to validate message arrival.

Hypothesist.Rebus

Plugin the hypothesis as a handler into Rebus to validate message arrival.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Hypothesist:

Repository Stars
Eventuous/eventuous
Minimalistic Event Sourcing library for .NET
mehdihadeli/ecommerce-microservices
🛍️ A practical e-commerce microservices sample, built with C#, .Net Core, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
Version Downloads Last updated
2.0.30 1,782 2/4/2022
2.0.28 119 2/4/2022
2.0.23 570 11/1/2021
2.0.22 554 9/14/2021
2.0.20 169 9/14/2021
2.0.17 202 9/13/2021
2.0.16 297 9/13/2021
2.0.12 1,533 6/10/2021
2.0.11 177 6/8/2021
1.3.1 147 6/2/2021

🤟