Stateful support #41

Closed
opened 2025-12-29 14:21:30 +01:00 by adam · 21 comments
Owner

Originally created by @dmtrrk on GitHub (Oct 3, 2017).

Originally assigned to: @StefH on GitHub.

Is there a plan to support stateful behavior functionality?

Originally created by @dmtrrk on GitHub (Oct 3, 2017). Originally assigned to: @StefH on GitHub. Is there a plan to support [stateful behavior](http://wiremock.org/docs/stateful-behaviour/) functionality?
adam added the feature label 2025-12-29 14:21:30 +01:00
adam closed this issue 2025-12-29 14:21:30 +01:00
Author
Owner

@StefH commented on GitHub (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

@StefH commented on GitHub (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
Author
Owner

@dmtrrk commented on GitHub (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 commented on GitHub (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?
Author
Owner

@dmtrrk commented on GitHub (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"));
@dmtrrk commented on GitHub (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"));
Author
Owner

@StefH commented on GitHub (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.

@StefH commented on GitHub (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.
Author
Owner

@dmtrrk commented on GitHub (Oct 4, 2017):

Created a PR #49

@dmtrrk commented on GitHub (Oct 4, 2017): Created a PR #49
Author
Owner

@StefH commented on GitHub (Oct 4, 2017):

I see, currently reviewing and testing.

@StefH commented on GitHub (Oct 4, 2017): I see, currently reviewing and testing.
Author
Owner

@dmtrrk commented on GitHub (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)

@dmtrrk commented on GitHub (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)
Author
Owner

@StefH commented on GitHub (Oct 5, 2017):

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

@StefH commented on GitHub (Oct 5, 2017): I will look, however I'm also looking to build in support for multiple states or scenarios.
Author
Owner

@dmtrrk commented on GitHub (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?

@dmtrrk commented on GitHub (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?
Author
Owner

@StefH commented on GitHub (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.

@StefH commented on GitHub (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.
Author
Owner

@dmtrrk commented on GitHub (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 commented on GitHub (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?
Author
Owner

@dmtrrk commented on GitHub (Oct 6, 2017):

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

@dmtrrk commented on GitHub (Oct 6, 2017): in case you decided what is the expected semantic and contract I can update PR
Author
Owner

@StefH commented on GitHub (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");
        }
@StefH commented on GitHub (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: ```c# [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"); } ```
Author
Owner

@dmtrrk commented on GitHub (Oct 6, 2017):

looks good. will use this syntax meanwhile.
thank you

@dmtrrk commented on GitHub (Oct 6, 2017): looks good. will use this syntax meanwhile. thank you
Author
Owner

@StefH commented on GitHub (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 commented on GitHub (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...
Author
Owner

@StefH commented on GitHub (Oct 7, 2017):

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

@StefH commented on GitHub (Oct 7, 2017): Code merged to master, still need to add some text to wiki...
Author
Owner

@StefH commented on GitHub (Oct 7, 2017):

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

@StefH commented on GitHub (Oct 7, 2017): WIKI --> https://github.com/WireMock-Net/WireMock.Net/wiki/Scenarios-and-States
Author
Owner

@dmtrrk commented on GitHub (Oct 9, 2017):

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

@dmtrrk commented on GitHub (Oct 9, 2017): looks great! do you have any plans to update the package on nuget.org?
Author
Owner

@StefH commented on GitHub (Oct 9, 2017):

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

@StefH commented on GitHub (Oct 9, 2017): Yes, I think I can release version **1.0.2.4** on NuGet. I keep you informed here when.
Author
Owner

@StefH commented on GitHub (Oct 10, 2017):

Done

@StefH commented on GitHub (Oct 10, 2017): Done
Author
Owner

@dmtrrk commented on GitHub (Oct 12, 2017):

thanks a lot!

@dmtrrk commented on GitHub (Oct 12, 2017): thanks a lot!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#41