mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Question: Same/similar fluent interface for in process and admin client API #123
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 @seanamosw on GitHub (Aug 3, 2018).
The API for stubbing and finding requests in process is done with a fluent API while using the admin client uses object construction. This can make it challenging to work with WireMock in containers or out of process.
In process:
The same with admin interface:
The more complex the request/response model the more verbose it becomes.
The difference I think stems from the builders not creating a serializable model.
Possible solutions/improvements
1. Request/Response model builders are changed to produce serializable models.
There is already code to "interpret" Request/Response/Mapping models.
Example (proposed API is not important, the idea is):
Pros
Cons
WithBody2. Two fluent interfaces, add
Givenoverload toFluentMockServerThe idea is that the current fluent interface is left intact and a second fluent interface is introduced that can create Request/Response/Mapping models.
Pros
Cons
@StefH commented on GitHub (Aug 4, 2018):
The fluent interface is mostly designed to be:
The admin REST interface can be used from any tool (postman, soapui, ...) or programming lamguage (C#, java, javascript, ...).
The current C# client interface (build with RestEase) is just a very convenient interface for developers who what to access the admin REST interface using c# & dotnet.
So option 1 would not be my preference.
And about option 2, I wonder how the fluent interface should look?
Do you mean something like:
@seanamosw commented on GitHub (Aug 4, 2018):
To clarify, this idea is sort of a middle ground with what the Java Wiremock allows. You can point the java client API at a remote Wiremock process and leverage the fluent interface against it. In their case, the API was designed to treat Wiremock as always out of process, even if it is in process.
My immediate use case is using Wiremock.Net in C# integration tests running in containers. This means Wiremock is always out of process. Typically some stub setup needs to be done at the beginning of each test and possibly verifying outbound calls were made. At the moment this needs to be done by constructing the Model objects.
It works but being able to use a fluent interface to construct the Request/Response model would be a significant quality of life improvement.
@seanamosw commented on GitHub (Aug 4, 2018):
In an ideal world, something similar to this would possible:
@StefH commented on GitHub (Aug 5, 2018):
a]
The new interface builder would have to look like:
This means that the whole code from RequestBuilders needs to be copied.
I was hoping that I could use some autogenerating for that: https://github.com/ScottLilly/FluentInterfaceCreator, but this tool is not ready yet.
So for this reason, I'll not implement this new interface builder, it's too much work and I need to keep 2 interfaces in sync.
b]
Updating the current fluent interface to understand
can be done I think, not that much changes needed.
Maybe you can form my project, start a new branch and make a PR for this?
@seanamosw commented on GitHub (Aug 5, 2018):
a. I agree, maintaining two fluent interfaces and keeping them in sync is a burden.
Without a breaking change, two fluent interfaces to achieve this would be unavoidable.
Another option that could work is adding a separate lib, eg.
WireMock.Net.ModelBuildersThat could have the fluent interface for building the request/response model builders without polluting the main library with two fluent interfaces. I'd be happy to implement and maintain that.b. I can do that.
@StefH commented on GitHub (Aug 6, 2018):
a] Maybe it's a good idea that I create this project under the https://github.com/WireMock-Net organization and give you (and me) access to that.
Also the NuGet package should be registered to both you and me if possible.
b] OK
@StefH commented on GitHub (Aug 6, 2018):
a] I did send invite to you, if you accept, I can give you access to this project.
The license is apache 2.0 ; but we can also change this into MIT? I don't know the real difference and what's better.
@seanamosw commented on GitHub (Aug 7, 2018):
Thanks.
MIT is often a go to license, simple and permissive. It doesn't have the "State Changes" clause of Apache 2.0.
@StefH commented on GitHub (Aug 7, 2018):
I've also added you as contributor to that new project.
Can this issue be closed?
(New issues or ideas can also be added to that project.)
@seanamosw commented on GitHub (Aug 7, 2018):
Yes, I think we have a way forward so any further discussion can be moved there.
@StefH commented on GitHub (Aug 9, 2020):
@seanamosw
Did you continue on the code in the
develop-branch from the https://github.com/WireMock-Net/WireMock.Net.ModelBuilders/tree/develop/ project?