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 support #48

Closed
dmtrrk opened this issue Oct 3, 2017 · 21 comments
Closed

Stateful support #48

dmtrrk opened this issue Oct 3, 2017 · 21 comments
Assignees
Labels

Comments

@dmtrrk
Copy link
Contributor

dmtrrk commented Oct 3, 2017

Is there a plan to support stateful behavior functionality?

@StefH StefH self-assigned this Oct 4, 2017
@StefH StefH added the feature label Oct 4, 2017
@StefH
Copy link
Collaborator

StefH commented Oct 4, 2017

No plans, until your question ;-)

I'll take a look at the idea and check if this can be implemented in WireMock.net

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 4, 2017

I have implemented this functionality for in-process solution. but I can't create PR as have no permissions.
Could you give me permissions to push a new branch?

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 4, 2017

Mostly the idea is simply to add such syntax:

        _server
            .Given(Request.Create()
                .WithPath("/foo")
                .UsingGet())
            .WillSetStateTo("Test state")
            .RespondWith(Response.Create()
                .WithStatusCode(200)
                .WithBody(@"No state msg"));
        _server
            .Given(Request.Create()
                .WithPath("/foo")
                .UsingGet())
            .WhenStateIs("Test state")
            .RespondWith(Response.Create()
                .WithStatusCode(200)
                .WithBody(@"Test state msg"));

@StefH
Copy link
Collaborator

StefH commented Oct 4, 2017

What you can do is fork this project, and then build your changes there and then make a PR to this project. Or what you also can do, is zip your changes and provide this code to me.

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 4, 2017

Created a PR #49

@StefH
Copy link
Collaborator

StefH commented Oct 4, 2017

I see, currently reviewing and testing.

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 4, 2017

had to add 1 update: in case the next state is not specified - the current will not be changed (will not be set to NULL)

@StefH
Copy link
Collaborator

StefH commented Oct 5, 2017

I will look, however I'm also looking to build in support for multiple states or scenarios.

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 5, 2017

multiple states

what do you mean by multiple states? do you have any examples?

scenarios

are you talking about something similar to inScenario("To do list")?
Do you want to keep backward compatibility?

@StefH
Copy link
Collaborator

StefH commented Oct 5, 2017

Multiple states : Be able to define multiple states which will behave.

Scenarios : I think I like the original idea from wiremock.org I'm building the code based on your PR.

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 5, 2017

Multiple states : Be able to define multiple states which will behave.

I see. something like WhenState(params object[] states)?

I think I like the original idea from wiremock.org

do you plan to keep backward compatibility?

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 6, 2017

in case you decided what is the expected semantic and contract I can update PR

@StefH
Copy link
Collaborator

StefH commented Oct 6, 2017

Thanks for the offer, but currently I'm trying to build it according to my idea, I'll let you know if I need help.

Multiple states means ; multiple parallel states should be supported, like unit-test as defined below should be fine:

        [Fact]
        public async Task Should_process_request_if_equals_state_and_multiple_state_defined()
        {
            // given
            _server = FluentMockServer.Start();

            _server
                .Given(Request.Create()
                    .WithPath("/state1")
                    .UsingGet())
                .InScenario("s1")
                .WillSetStateTo("Test state 1")
                .RespondWith(Response.Create()
                    .WithBody("No state msg 1"));

            _server
                .Given(Request.Create()
                    .WithPath("/foo")
                    .UsingGet())
                .InScenario("s1")
                .WhenStateIs("Test state 1")
                .RespondWith(Response.Create()
                    .WithBody("Test state msg 1"));

            _server
                .Given(Request.Create()
                    .WithPath("/state2")
                    .UsingGet())
                .InScenario("s2")
                .WillSetStateTo("Test state 2")
                .RespondWith(Response.Create()
                    .WithBody("No state msg 2"));

            _server
                .Given(Request.Create()
                    .WithPath("/foo")
                    .UsingGet())
                .InScenario("s2")
                .WhenStateIs("Test state 2")
                .RespondWith(Response.Create()
                    .WithBody("Test state msg 2"));

            // when
            string url = "http://localhost:" + _server.Ports[0];
            var responseNoState1 = await new HttpClient().GetStringAsync(url + "/state1");
            var responseNoState2 = await new HttpClient().GetStringAsync(url + "/state2");

            var responseWithState1 = await new HttpClient().GetStringAsync(url + "/foo");
            var responseWithState2 = await new HttpClient().GetStringAsync(url + "/foo");

            // then
            Check.That(responseNoState1).Equals("No state msg 1");
            Check.That(responseWithState1).Equals("Test state msg 1");

            Check.That(responseNoState2).Equals("No state msg 2");
            Check.That(responseWithState2).Equals("Test state msg 2");
        }

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 6, 2017

looks good. will use this syntax meanwhile.
thank you

@StefH
Copy link
Collaborator

StefH commented Oct 7, 2017

See my code at https://github.com/WireMock-Net/WireMock.Net/tree/stateful-behavior

I'll extend this code to also support the JSON for this...

@StefH
Copy link
Collaborator

StefH commented Oct 7, 2017

Code merged to master, still need to add some text to wiki...

@StefH
Copy link
Collaborator

StefH commented Oct 7, 2017

WIKI --> https://github.com/WireMock-Net/WireMock.Net/wiki/Scenarios-and-States

@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 9, 2017

looks great!
do you have any plans to update the package on nuget.org?

@StefH
Copy link
Collaborator

StefH commented Oct 9, 2017

Yes, I think I can release version 1.0.2.4 on NuGet. I keep you informed here when.

@StefH
Copy link
Collaborator

StefH commented Oct 10, 2017

Done

@StefH StefH closed this as completed Oct 10, 2017
@dmtrrk
Copy link
Contributor Author

dmtrrk commented Oct 12, 2017

thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants