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

Closed
opened 2025-12-29 08:27:19 +01:00 by adam · 5 comments
Owner

Originally created by @antero-lukkonen on GitHub (Dec 20, 2021).

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) );`
Originally created by @antero-lukkonen on GitHub (Dec 20, 2021). **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)](https://www.wiremock.org)? 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. ``` c# 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) );` ```
adam added the feature label 2025-12-29 08:27:19 +01:00
adam closed this issue 2025-12-29 08:27:19 +01:00
Author
Owner

@StefH commented on GitHub (Dec 25, 2021):

@antero-lukkonen
Do you mean code like this?

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

@StefH commented on GitHub (Dec 25, 2021): @antero-lukkonen Do you mean code like this? https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Serialization/MappingConverter.cs
Author
Owner

@StefH commented on GitHub (Feb 6, 2022):

@antero-lukkonen
is this what you mean?

@StefH commented on GitHub (Feb 6, 2022): @antero-lukkonen is this what you mean?
Author
Owner

@antero-lukkonen commented on GitHub (Feb 7, 2022):

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 commented on GitHub (Feb 7, 2022): 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.
Author
Owner

@StefH commented on GitHub (Dec 22, 2022):

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

@StefH commented on GitHub (Dec 22, 2022): @antero-lukkonen I think this is the same request as https://github.com/WireMock-Net/WireMock.Net/issues/867 ?
Author
Owner

@StefH commented on GitHub (Jan 7, 2023):

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

@StefH commented on GitHub (Jan 7, 2023): https://github.com/WireMock-Net/WireMock.Net/pull/869
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#393