Hypothesist 3.0.91

dotnet add package Hypothesist --version 3.0.91                
NuGet\Install-Package Hypothesist -Version 3.0.91                
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="Hypothesist" Version="3.0.91" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hypothesist --version 3.0.91                
#r "nuget: Hypothesist, 3.0.91"                
#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 Hypothesist as a Cake Addin
#addin nuget:?package=Hypothesist&version=3.0.91

// Install Hypothesist as a Cake Tool
#tool nuget:?package=Hypothesist&version=3.0.91                

nuget codecov stryker build status

Hypothesist

The "future" assertion library for .NET, promise!

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.

v3

See the docs for the changed API since v3.

Rx

See some notes on using System.Linq.Async and FluentAssertions.

Usage

schema

Define

Define your hypothesis with an observer, an experiment, an a time constraint. Feed the observer with samples and validate the hypothesis:

var observer = Observer.For<int>();

Test

You feed the observer with data:

await observer.Add(3);

For example with an injected stub:

var service = Substitute.For<SomeInjectable>();
service
    .When(x => x.Demo(Arg.Any<int>()))
    .Do(x => observer.Add(x.Arg<int>()));

or with a hand-rolled implementation:

class TestAdapter(Observer<int> observer) : SomeInjectable
{
    public Task Demo(int data) =>
        observer.Add(data);
}

var service = new TestAdapter(observer);

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

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

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

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

Just checkout the available adapters for more information!

Validate

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

await hypothesis
    .On(observer)
    .Timebox(1.Seconds());
    .Any()
    .Match(1234)
    .Validate();

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.

AtMost

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

Adapters

Some adapters wrapping around the hypothesis to make invocation convenient:

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 (5)

Showing the top 5 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.

Hypothesist.ServiceBus

Test your hypothesis easily with a ServiceBusProcessor.

Hypothesist.AspNet

Plugin the hypothesis as a middleware into aspnet to validate requests and responses.

Hypothesist.EF

Plugin the hypothesis as a handler into Entity Framework to validate entity events.

GitHub repositories (3)

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

Repository Stars
mehdihadeli/food-delivery-microservices
🍔 A practical and imaginary food delivery microservices, built with .Net 8, MassTransit, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
Eventuous/eventuous
Event Sourcing library for .NET
mehdihadeli/food-delivery-modular-monolith
🌭 A practical and imaginary food and grocery delivery modular monolith, built with .Net 8, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
Version Downloads Last updated
3.0.91 901 3/8/2024
3.0.89 256 3/8/2024
3.0.88 1,795 1/11/2024
2.2.72 549 11/23/2023
2.2.71 278 11/23/2023
2.2.66 601 11/6/2023
2.2.64 274 11/6/2023
2.2.63 297 11/2/2023
2.1.62 281 11/2/2023
2.1.61 259 11/2/2023
2.1.60 264 11/1/2023
2.1.55 2,265 3/2/2023
2.1.52 588 3/2/2023
2.1.50 1,326 1/31/2023
2.1.49 600 1/27/2023
2.1.44 711 12/5/2022
2.1.39 666 11/30/2022
2.0.30 13,692 2/4/2022
2.0.28 919 2/4/2022
2.0.23 1,484 11/1/2021
2.0.22 955 9/14/2021
2.0.20 585 9/14/2021
2.0.17 594 9/13/2021
2.0.16 701 9/13/2021
2.0.12 2,008 6/10/2021
2.0.11 400 6/8/2021
1.3.1 415 6/2/2021