WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

Allow to create MappingModel from c# to be able to configure local and remote mocks similarly

Open antero-lukkonen opened this issue 4 years ago • 3 comments

Is your feature request related to a problem? Please describe. I am proposing an API extension, where i could use the fluent syntax of defining Mappings, so that i can work with within unit-test and remote server mocks the same way. I would define the mappings with fluent syntax and could share them.

Describe the solution you'd like See additional context for rough examples.

Describe alternatives you've considered Right now it is possible to achieve the same with interfaces that accept MappingModel, so this would be a convenience feature only.

Is your feature request supported by WireMock (java version)? Please provide details. It seems to me to be an interface concern only.

Additional context

Maybe the below code will help understanding what i am after. That i could achieve the same result with both approaches.

var server = WireMockServer.Start();

     
            server
                .Given(
                    Request.Create().WithPath("/hi"))
                .RespondWith(
                    Response.Create().WithBody("there"));
            
            var fluentMappings = server.MappingModels.ToList();

            var declaredMappings = new[] {
                new MappingModel {
                    Request = new RequestModel()
                    {
                        Path  = "/hi"
                    },
                    Response = new ResponseModel()
                    {
                        Body = "there"
                    }
                }
            };

            await api.PostMappingsAsync(new MappingConverter().ToMappingModel(fluentMappings) );`

antero-lukkonen avatar Dec 20 '21 13:12 antero-lukkonen

@antero-lukkonen Do you mean code like this?

https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Serialization/MappingConverter.cs

StefH avatar Dec 25 '21 10:12 StefH

@antero-lukkonen is this what you mean?

StefH avatar Feb 06 '22 10:02 StefH

I am so sorry for disappearing. Yes indeed something like this. I found this in the codebase but it is internal.

Because i had been using WireMock previously in unit-testing context and had a use-case where i wanted it to run as a stand-alone server, i naturally started to describe my mock responses in the fluent syntax and then found that there is no way to configure a remote server using admin api in such way.

The fluent syntax goes well with other popular mocking tools like moq and other frameworks we use in asp.net so it is a common paradigm, whereas the Rest model based specification, while it certainly works, is a bit awkward and does not allow reuse if you want to share these setups between local and remotes.

antero-lukkonen avatar Feb 07 '22 07:02 antero-lukkonen

@antero-lukkonen I think this is the same request as https://github.com/WireMock-Net/WireMock.Net/issues/867 ?

StefH avatar Dec 22 '22 11:12 StefH

https://github.com/WireMock-Net/WireMock.Net/pull/869

StefH avatar Jan 07 '23 08:01 StefH