mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
How can I assign a value to a data variable #518
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 @Dunga999 on GitHub (May 29, 2023).
How can I assign a value to a variable that I can use latter when templating.
Looking for examples I came with something like:
But I can't make it work. Somehow #assign is not recognized.
Is this the correct way to do it?
By the way, You have made a great tool.
Thank you
@StefH commented on GitHub (May 30, 2023):
I don't know if "#assign" works.
But you can also just define a Data field with some static data.
See this issue for more details
https://github.com/WireMock-Net/WireMock.Net/issues/892
@Dunga999 commented on GitHub (May 30, 2023):
Yes, I have crossed that option, but I need a more dynamic (not static) data.
My full need is that I'm receiving a request with an ID and with that ID I need to query a DB to gather specific data for the response.
My issue is how to pass this dynamic data when templating.
@StefH commented on GitHub (May 30, 2023):
If you have an ID in the request parameter or body, you can use get that value and return it in the response.
See also
https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating
@StefH commented on GitHub (Jun 13, 2023):
@Dunga999
Does my proposed solution work for you?
@Dunga999 commented on GitHub (Jun 13, 2023):
Hi @StefH,
Thanks for the follow up.
As I said, I need to handle dynamic data, so your solution didn't directly attend my needs, but pointed me a way to handle the requirement.
I created an helper to save the dynamic data in the Data field so I could access it in the templating.
I think I didn't gave you the full view of the dynamic data requirement, but I implemented something like this:
Being, "save" and "query" the helpers I created.
Again, thank you for the suggestion and for this amazing tool