Code Monkey home page Code Monkey logo

Comments (21)

StefH avatar StefH commented on July 30, 2024 1

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

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

No plans, until your question ;-)

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

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

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?

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

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

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

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.

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

Created a PR #49

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

I see, currently reviewing and testing.

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

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)

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

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

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

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?

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

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.

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

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?

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

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

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

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

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

looks good. will use this syntax meanwhile.
thank you

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

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

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

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

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

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

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

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

from wiremock.net.

StefH avatar StefH commented on July 30, 2024

Done

from wiremock.net.

dmtrrk avatar dmtrrk commented on July 30, 2024

thanks a lot!

from wiremock.net.

Related Issues (20)

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.