-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Wikipage Update for Admin REST Api + Fluent Model Builder #886
Comments
@R0boC0p You actually want to have a Fluent interface which mimics the same builder pattern for WireMockServer for the JSON Rest ClientModels. This functionality is not yet present. However, there are some auto-generated builders present in WireMock.Net.Abstractions which use https://github.com/StefH/FluentBuilder and can be used to create the models in a fluent way. I think it should be possible to create a builder for the WireMock.Net.Abstractions project. In basic, your interface looks ok: public interface IAdminMappingRequestBuilder
{
IEnumerable<MappingModel> GetMappingModels();
IRespondWithAProvider Given(IRequestBuilder request);
IAdminMappingRequestBuilder Given(
Action<IRequestBuilder> request,
Action<IResponseBuilder> response,
Action<IRespondWithAProvider> provider = null);
Task<StatusModel> BuildAndSendAsync();
} However for the implementation you cannot use the "MappingBuilder" because that one is server-side only. So if you build an extension /new project this should only reference the WireMock.Net.Abstractions project |
I started with an implementation. This can be used like: var api = RestClient.For<IWireMockAdminApi>("http://localhost:9091");
var mappingBuilder = api.GetMappingBuilder();
mappingBuilder.Given(m => m
.WithTitle("This is my title 1")
.WithRequest(req => req
.UsingGet()
.WithPath("/bla1")
)
.WithResponse(rsp => rsp
.WithBody("x1")
.WithHeaders(h => h.Add("h1", "v1"))
)
);
mappingBuilder.Given(m => m
.WithTitle("This is my title 2")
.WithRequest(req => req
.UsingGet()
.WithPath("/bla2")
)
.WithResponse(rsp => rsp
.WithBody("x2")
.WithHeaders(h => h.Add("h2", "v2"))
)
);
var result = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false); Preview version ( (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions) |
@R0boC0p Did you have time to test this preview version? |
@StefH Hi, sorry for the late reply. Been off work for a couple of days.
I have seen these builders but did not use them, as there was a lack of like
I have just checked your preview version and from what I can tell it works as expected. Thank you for that. I think there is just a lack of some types like Btw, are the nugets of this branch to be targeted against |
Preview version (1.5.16-ci-17054) can be tested which includes some more methods. (You can always create a PR to add more methods.) |
Hi @StefH , I already approach you using Gitter, but I cannot reply on there anymore for whatever reasons.
I must have formulated my question oddly and caused some confusion, so here I go again...
Former Question:
Can I use the
Fluent Api
to build a request and send it over to theIWireMockAdminApi
instance as my WireMock is running remotely inside another docker container?Self-Answer:
You answered me to use the RestApi. Yes, but it's about the fluent bit.
I have seen that there are already several questions, which are relating to what I have asked. So I apologize if I am bugging you with this over again. Example
You recently exposed the
MappingModelBuilder
#867 which is what I was trying to leverage, to create an interface which replicates what theWireMockServer
is currently able to do usingGiven()
call.I tried to be helpful, fork your repository, and provide a solution to ship an extension along the
WireMock.Net.RestClient
Nuget package. I ended up pulling too much interfaces and abstractions from theWireMock Project
into theWiremock Abstractions Project
. It wasn't a simple change anymore, which you presumingly wouldn't have accepted, as it was just too invasive.Suggestion:
Maybe I still have just overseen something, but I ended up writing an extension, which you could propose on your WikiPage if you like?
It supposed to replicate the same usage as the
WireMockServer.Given()
:Usage:
Usage 2:
Final Thought:
Please excuse my approach if it is a bit blue-eyed or I found a solution for a non existent issue. It really took me some time to figure how to do it. Perhaps if there is an explicit example on the Wiki how to properly handle FluentApi using the ResClient, using whatever approach, people will stop asking/looking for it. Potential time saver.
Thanks for your great work!
All the best.
The text was updated successfully, but these errors were encountered: