mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-12 05:20:35 +01:00
Fluent API for RestClient MappingModel creation #350
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @danspark on GitHub (Jul 17, 2021).
Originally assigned to: @StefH on GitHub.
Is your feature request related to a problem? Please describe.
I'm thinking about using WireMock as a container to run alongside my application during tests, and as far as I searched, looks like I have to create a mapping by instantiating a new
MappingModeldirectly.Describe the solution you'd like
I think it would be really useful for users to have an experience similar to the fluent API to used to create requests when WireMock is used on the same process. I am no expert on the library but I imagine there would be some limitations, but for simple cases like matching a request and building a response, it would be really useful, since I wouldn't have to learn two ways to configure mappings.
Describe alternatives you've considered
Build the mapping model directly.
Is your feature request supported by WireMock (java version)? Please provide details.
I'm not familiar with the java version, but as far as I researched, I couldn't find anything like that yet.
Additional context
I don't if this is something that would be interesting for the main library or maybe it would be something that the creators would want the community to develop. But if this is something that is planned or wanted, I would be glad to help as I can. But as I said, I'm no expert and I'm not sure if I would be able to cover every possible scenario the current fluent API has.
I'm building a simple example and I'll post here when I make some progress.
@StefH commented on GitHub (Jul 19, 2021):
I can build a standard FluentBuilder for all the client model objects, however this builder will be only a simple version.
Like
Will this be what you need?
@StefH commented on GitHub (Jul 20, 2021):
@danspark
See preview version on MyGet https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
WireMock.Net.RestClient.1.4.19-preview-01-ci-15231.nupkg@danspark commented on GitHub (Jul 20, 2021):
Yes! That would make the experience similar to the fluent API, I'll take a look soon. Thank you!
@StefH commented on GitHub (Aug 4, 2021):
@danspark
Did you have time to take a look yet ?
@danspark commented on GitHub (Aug 4, 2021):
Apologies for taking so long, I've been a bit busy. I took a look at the most recent version of the CI build, the API looks a little different, I don't know if it made a lot of difference. My simplest setup looked like this:
With the modification, it looks like this:
Maybe the MappingModelBuilder
WithRequestandWithResponsemethods could have an overload that asks for anAction<RequestModelBuilder>andAction<ResponseModelBuilder>? That way it could look like this:@StefH commented on GitHub (Aug 4, 2021):
You can work-around this problem by using a
FluentBuilder.ResponseModelBuilder()and then assign the value toWithResponse(...)To support your scenario, I've to see if I can update the FluentBuilder.
Can you create a new issue here? --> https://github.com/StefH/FluentBuilder
And for now, I'll merge the PR and close this issue.
In case I can implement your scenario in the FluentBuilder project, I'll post an update here and release a new WireMock.Net NuGet.