Code Monkey home page Code Monkey logo

hypothesist's Introduction

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.

schema

Define

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

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

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.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.

Adapters

Some adapters wrapping around the hypothesis to make invocation convenient:

hypothesist's People

Contributors

lethek avatar riezebosch avatar roycornelissen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.