Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stateful behavior #49

Closed
wants to merge 3 commits into from
Closed

Conversation

dmtrrk
Copy link
Contributor

@dmtrrk dmtrrk commented Oct 4, 2017

This PR adds stateful behavior similar to wiremock.
By default there are no changes in semantic. All previous code will work without any changes.
There are 2 methods added in IRespondWithAProvider interface:
IRespondWithAProvider WhenStateIs(object state); - defined mapping will be processed only in case the current state is equals to specified.
IRespondWithAProvider WillSetStateTo(object state); - In case the concrete mapping was selected and executed with the success, the current state will be changed to the specified.

All states are per server. The default state is null so for the entry request it is not required to specify WhenStateIs.
Both methods can be used together or separately.
Dynamic typing is used over generics, so state is of object type.

Usage example:

  1. This mock will be executed only for the default state (as entry point).
    Once this mapping is executed, the state will be changed to Test state, so it will not be executed the next time.
        _server
            .Given(Request.Create()
                .WithPath("/foo")
                .UsingGet())
            .WillSetStateTo("Test state")
            .RespondWith(Response.Create()
                .WithStatusCode(200)
                .WithBody(@"No state msg"));
  1. This mapping will be executed when the current state is Test state.
        _server
            .Given(Request.Create()
                .WithPath("/foo")
                .UsingGet())
            .WhenStateIs("Test state")
            .RespondWith(Response.Create()
                .WithStatusCode(200)
                .WithBody(@"Test state msg"));

@dmtrrk dmtrrk mentioned this pull request Oct 4, 2017
@StefH StefH closed this Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants