mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
New Feature: Load & Register Custom IHandlebars Transformers from any assembly (dll) #200
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 @muzammilkm on GitHub (Aug 16, 2019).
WireMock StandAlone could accept dll paths to load & register custom IHandlebars Transformer from them. So that response template transformed output can easily tested out in browser without a lots for debugging.
@StefH commented on GitHub (Aug 16, 2019):
Why would you need IHandlebars transformers? The whole idea from Handlebars is that you can define the transformation in plain text.
@muzammilkm commented on GitHub (Aug 17, 2019):
Ahh.. sorry for confusion.
What i meant was, right now we have Register Transformation Helper via Settings & can only be used while running unit tests or Create a copy of "Standalone" & then copy these helpers. Working with multiple project would be difficult.
If you could provide an interface that we can implement once & provide away for these libraries to be loaded in "Standalone", so that i would be easy for the QA's or anyone to run standalone and test json mapping.
@StefH commented on GitHub (Aug 17, 2019):
The
StandAloneAppis just a simple library which converts/parses commandline arguments into settings, and then just starts the Mock Server.You always need a console app (.net framework or .net core) to really start and run the server.
I think I makes more sense to create a WireMock.CommandLineParser NuGet which just converts arguments into a settings file.
And then you can just add the handlebars to that settings and then start using
public static FluentMockServer Start([NotNull] IFluentMockServerSettings settings)Would that be an option?
@muzammilkm commented on GitHub (Aug 24, 2019):
Yes, i have built CommandLine dotnet tool which read arguments like mapping folder and port. This tool can be installed from nuget & run via commad line. I made this tool generic so, that any team can install start writing json mapping files for their own testing.
I work well, but few teams will have there own Custom Handlebars part of the json mapping files which they want to see how it is rendering. That's where i was thinking of
If there was an interface within wiremock.net which contains method "register custom handlebars" and pass list of object of above type interface. This way i can take one more arguments for "xxx.dll" either with cmdline load & create instances of interface or passon the dll to WireMock.Net to load & instantiate.
Hope this add some clarity ???
@StefH commented on GitHub (Aug 24, 2019):
There is a HandlebarsRegistrationCallback method defined in the settings interface: https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Settings/IFluentMockServerSettings.cs#L121
With this callback you could load your own dll's and register the Custom Handlebars from the teams.
Would this help you?
@muzammilkm commented on GitHub (Aug 24, 2019):
I guess you are asking to impl "IFluentMockServerSettings" in multiple application & load those dll in cmd,
Below what i am thinking should be & this sort of interface should be in Wiremock where any one can implement.
This is Impl within any ones test suit.
Usage:
With this sort of setup, Now i can load given dll, Dynamically instantiate "IHandleBarTransformer" type within this assembly & pass on to settings. This way we would have one CmdLine tool any one can pass argument to control the behavior of the tool.
Hope i am making sense ?
I could also create separate package with above interface & ask everyone to implement & load. But i feel this interface should be part of WireMock.Net.
@StefH commented on GitHub (Aug 25, 2019):
The HandlebarsRegistrationCallback can be used by anyone who wants to register it's own Handlebars helpers.
So in your case this should be enough for your requirements, see code sample below:
@muzammilkm commented on GitHub (Aug 25, 2019):
Yes, that correct. But for that
i would need an
IHandleBarTransformerinterface first in 'WireMock.Net'.Next step, I just want to property of
List<IHandleBarTransformer>inFluentMockServerSettings, so that i can pass it & internally WireMock.Net can register them Instead of usingHandlebarsRegistrationCallback.Next step, WireMock.Net can auto load of type
IHandleBarTransformerinterface@StefH commented on GitHub (Aug 25, 2019):
I still don't see why you would need the interface to be defined in WireMock.
See this examplehttps://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs#L56
Where I just did define the interface in my console app.
@muzammilkm commented on GitHub (Aug 25, 2019):
We have different teams who would be using WireMock.Net in there Test Projects and each team would have there own custom Handlebar transformer within there project.
If they want to create many mapping files & see how it renders for preview in browser, the only option they have is each team create another separate "console" project and run the console project to preview while working on json files.
I want to avoid this & create single wiremock tool for all of them & they will pass "test.project.dll" argument. With which i can load & register helper using interface. If this interface is available in WireMock.Net then everybody would impl & i could dynamically load & register.
@StefH commented on GitHub (Feb 14, 2020):
Hello @muzammilkm is this still an issue for you or your team?
@muzammilkm commented on GitHub (Feb 14, 2020):
closing this.