Skip to content
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

HandlebarsRegistrationCallback not fired #433

Closed
jantanis opened this issue Mar 2, 2020 · 10 comments
Closed

HandlebarsRegistrationCallback not fired #433

jantanis opened this issue Mar 2, 2020 · 10 comments
Labels

Comments

@jantanis
Copy link

jantanis commented Mar 2, 2020

WireMock.Handlebars.zip

See attached reproduction project. Start and go to http:https://localhost:5001/datasets

HandlebarsRegistrationCallback is not fired, so I can't register custom handlebar extensions.

@StefH
Copy link
Collaborator

StefH commented Mar 2, 2020

This is because you already use the WithCallback() in the response, and this means that the "UseTransformer" is not called anymore, and also the HandlebarsRegistrationCallback is not done anymore. (This is current behavior in de the code.)

@jantanis
Copy link
Author

jantanis commented Mar 2, 2020

Does this mean that you cannot use Handlebars if you use WithCallback()? If so I would really like this as a feature.

@StefH StefH added the feature label Mar 2, 2020
@StefH
Copy link
Collaborator

StefH commented Mar 2, 2020

I see your point.

You want to use code like this?

private static ResponseMessage DataSetCallback(RequestMessage arg)
{
	return new ResponseMessage
	{
        BodyData = new BodyData
        {
            BodyAsJson = new
            {
                Test = "test: {{request.url}}"
            }
        },
		StatusCode = 200
	};
}

@jantanis
Copy link
Author

jantanis commented Mar 2, 2020

Yes. Now I've implemented Handlebars myself in the callback function, but I'm missing the Wiremock handlebar extensions. If only I have access to the handlebars context (IHandebars) of Wiremock I'm good to go. Right now there is no way for me to achieve this.

@StefH
Copy link
Collaborator

StefH commented Mar 2, 2020

I've made a preview fix (can be found via MyGet) : WireMock.Net.1.1.9-ci-12788. This one should fire the HandlebarsRegistrationCallback.

@jantanis
Copy link
Author

jantanis commented Mar 3, 2020

Yes, that works. But is it not possible to expose the IHandlebars on the WireMockServer? I require that context somewhere else too. As I see it every request registers the handlebars again, that isn't really necessary right?

@StefH
Copy link
Collaborator

StefH commented Mar 3, 2020

Correct, the factory only needs to be created once, no need to create that for every response. I'll check if that's easy to change.

And where do you need that IHandlebars ? Would it help if this was maybe available in callback?

@jantanis
Copy link
Author

jantanis commented Mar 3, 2020

I managed to complete what I wanted by assigning the IHandlebars in the callback to a static property. I can now use this property wherever I want. I think the best way to do this is to init IHandlebars using the factory on startup and then expose it for everything to use. Now you have to await 1 transform cycle to have it working.

@StefH
Copy link
Collaborator

StefH commented Mar 4, 2020

I'm looking into the code to do some changes, but the HandlebarsRegistrationCallback is still fired with each response because every response gets a fresh handlebars-context. I'm not sure if I can change this.

For now, I'll just fix your bug that the HandlebarsRegistrationCallback was never fired when using WithCallback

You can create a new issue with the specific issue, or try to make PR yourself.

Linking #435 ...

@StefH
Copy link
Collaborator

StefH commented Mar 5, 2020

closing...

@StefH StefH closed this as completed Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants