-
-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fluent API for RestClient MappingModel creation #621
Comments
I can build a standard FluentBuilder for all the client model objects, however this builder will be only a simple version. Like var matcher = FluentBuilder.MatcherModel()
.WithName("n")
.WithPattern("p")
.Build(); Will this be what you need? |
See preview version on MyGet https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
|
Yes! That would make the experience similar to the fluent API, I'll take a look soon. Thank you! |
@danspark |
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: var response = await _api.PostMappingAsync(new MappingModel {
Request = new RequestModel {
Url = "*"
},
Response = new ResponseModel {
StatusCode = (int)statusCode
}
}); With the modification, it looks like this: var requestBuilder = new FluentBuilder.MappingModelBuilder()
.WithRequest(new RequestModel {
Path = "*"
})
.WithResponse(new ResponseModel {
StatusCode = (int)statusCode
}).Build(); Maybe the MappingModelBuilder var requestBuilder = new FluentBuilder.MappingModelBuilder()
.WithRequest(b => b.WithPath("*"))
.WithResponse(b => b.WithStatusCode((int) statusCode)}).Build(); |
You can work-around this problem by using a To support your scenario, I've to see if I can update the 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. |
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
MappingModel
directly.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.
The text was updated successfully, but these errors were encountered: