mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Help converting a slightly more complex Wiremock.org template #417
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 @mattisking on GitHub (Apr 29, 2022).
Originally assigned to: @StefH on GitHub.
I'm experimenting using this instead of wiremock.org and am doing some POC stuff. I've hit a couple of problems with Body matching using XPath, and I could use some guidance on how to accomplish the response request->response items and dynamically created response parts. I have a template here (cnp.json
config.zip
)
and a partially converted one along with what to post.
https://localhost:9443/vap/communicator/online
The current issue is that my XPath matching rules both have to fail for it to fail to match, but I need ANY rule to cause it to fail. As it stands, if I change one of the values in the post but not the second it still says it's a match. Also, any help with building the response would be great.
cnp.json
@StefH commented on GitHub (Apr 30, 2022):
@mattisking
So in your case, this mapping should only match if both Matchers are matching.
And currently WireMock.Net works like : any are matching.
Correct?
@mattisking commented on GitHub (Apr 30, 2022):
That’s correct. It’s doing an OR match and I need an AND match.
some test cases I’ll need to set 5 or more AND matches.
I also started on building the response. Using one of the examples I was looking at the random data generator which seems to work when using BodyAsJson, but there’s no BodyAsXml option and just using Body doesn’t seem to work? (I forgot how much a pain namespaces in Xml are.) This is an external service I’m mocking. Our services are Json based but I can’t control this one.
@StefH commented on GitHub (Apr 30, 2022):
Sometimes the logic in WireMock.Net uses an
or, sometimes it uses anaverage. I guess I need to verify the logic from all matchers so that these behave the same. What would be the best default behavior? Using anororandoraverage?I think you can use templating for that, also for a body as a string or xml. See https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating.
@mattisking commented on GitHub (Apr 30, 2022):
As long as there is a way to change it between OR and AND (or average) I’m not sure that it matters. But from a logical perspective, if each item in the config is a “Matcher” of some sort I would personally expect it must follow all the matches to match. That’s my personal belief. If this is the way it works today, however, changing it might break it for others if they update in the future… that might be more a pain then me adjusting these templates out of the gate.
{{Random Type='Text' Min=17 Max=17 UseNumber=true UseSpecial=false UseLetter=false UseSpace=false UseNullValues=false UseUppercase=false UseLowercase=false}}
I also got the XPath.SelectSingleNode to work for me eventually, as well as eventually finding DateTime.Now as additional HandleBar.Net Helpers. So, just getting matching working the way I need is all I lack right now. Thank you.
@StefH commented on GitHub (May 14, 2022):
@mattisking
I'll take a look on how to correctly implement the OR and AND matching. I keep you posted here.
@StefH commented on GitHub (May 17, 2022):
https://github.com/WireMock-Net/WireMock.Net/pull/755
@StefH commented on GitHub (May 18, 2022):
@mattisking
I've implemented this functionality for path,url,clientip and body matchers.
See preview version:
1.4.42-ci-16200(https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)It can be used like:
@StefH commented on GitHub (May 20, 2022):
@mattisking
Did you have to test this new functionality?
@mattisking commented on GitHub (May 20, 2022):
I will be testing it this weekend. Overwhelmed with a large release the past few days. Thanks a lot for looking into this.
@StefH commented on GitHub (May 20, 2022):
@mattisking Thank your very much.
@mattisking commented on GitHub (May 23, 2022):
So far this is working well. I've tried out a couple of scenarios and I'll go ahead and bang out a few more from our scripts.
@StefH commented on GitHub (May 24, 2022):
I'll just keep this open for now, in case you encounter other issues.
If there are no problems for a week, I'll merge and create a new version.
@StefH commented on GitHub (Jun 2, 2022):
@mattisking
Did you encounter any issues?
@mattisking commented on GitHub (Jun 4, 2022):
Not so far. I appreciate the effort. I like wiremock and in this case you’ve really added some nice additions. Now we should build on wiremock studio 😉
@StefH commented on GitHub (Jun 9, 2022):
@mattisking I'll merge the PR and create a new version (1.5.0)
wiremock studio ? You mean a version for this WireMock.NET ?
@mattisking commented on GitHub (Jun 11, 2022):
Yes I just mean that the open source wiremock studio isn’t bad and is a decent editor. One of the things I’m working to accomplish is to empower our QA people with tools to build their own mocks for their test cases. That’s a stretch goal. I’m more than capable of editing template files.
@StefH commented on GitHub (Jun 11, 2022):
Maybe a good use case to build this in .net Maui 😀