-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Question: Same/similar fluent interface for in process and admin client API #172
Comments
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, ...). 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: var requestModel = new RequestModel
{
// manually define all properties here in code
};
var responseModel = new ResponseModel
{
// manually define all properties here in code
};
var server = FluentMockServer.Start();
server.Given(requestModel).RespondWith(responseModel); |
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. |
In an ideal world, something similar to this would possible: var requestModel =
Request.Create()
.UsingGet()
.WithUrl("/test");
var responseModel =
Response.Create()
.WithStatusCode(200);
await admin.PostMappingAsync(new MappingModel
{
Request = requestModel,
Response = responseModel
});
// being able to use the same fluent interface between remote and in process
server.Given(requestModel).RespondWith(responseModel); |
a] var requestModel =
RequestModelBuilder.Create()
.UsingGet()
.WithUrl("/test")
.Build(); 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] server.Given(requestModel).RespondWith(responseModel); 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? |
a. I agree, maintaining two fluent interfaces and keeping them in sync is a burden. Another option that could work is adding a separate lib, eg. b. I can do that. |
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 |
a] I did send invite to you, if you accept, I can give you access to this project. |
Thanks. |
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.) |
Yes, I think we have a way forward so any further discussion can be moved there. |
@seanamosw |
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
WithBody
2. Two fluent interfaces, add
Given
overload toFluentMockServer
The 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
The text was updated successfully, but these errors were encountered: