mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Wikipage Update for Admin REST Api + Fluent Model Builder #485
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 @R0boC0p on GitHub (Feb 16, 2023).
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 Apito build a request and send it over to theIWireMockAdminApiinstance 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
MappingModelBuilderhttps://github.com/WireMock-Net/WireMock.Net/issues/867 which is what I was trying to leverage, to create an interface which replicates what theWireMockServeris 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.RestClientNuget package. I ended up pulling too much interfaces and abstractions from theWireMock Projectinto 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.
@StefH commented on GitHub (Feb 16, 2023):
@R0boC0p
I understand your question.
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:
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
@StefH commented on GitHub (Feb 18, 2023):
@R0boC0p
I started with an implementation.
See PR https://github.com/WireMock-Net/WireMock.Net/pull/890
This can be used like:
Preview version (
1.5.16-ci-17023) can be tested.(https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)
@StefH commented on GitHub (Feb 20, 2023):
@R0boC0p Did you have time to test this preview version?
@R0boC0p commented on GitHub (Feb 23, 2023):
@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
UsingGet/UsingPostmethods, and all parameters seem to have acceptedobjectandstringonly. Also theWithStatusCodewas missing a type. Would have preferred some strong typing there, as it's too easy to get something wrong by accident.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
HttpStatusCodethat could be easily added to theRequestModelBuilderlike you did with theUsingxxx()I guess?Btw, are the nugets of this branch to be targeted against
net7.0only? I had some troubles there, as I am still using net6.0 and found that I couldn't use them without jumping through some hoops.@StefH commented on GitHub (Feb 23, 2023):
Preview version (1.5.16-ci-17054) can be tested which includes some more methods.
I'll merge to master and create a new NuGet release.
(You can always create a PR to add more methods.)