mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
WireMock not working as expected #323
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 @redgoose on GitHub (Jan 14, 2021).
Originally assigned to: @StefH on GitHub.
I'm trying to write some integration tests using Microsoft.AspNetCore.TestHost.TestServer and WireMock and not able to get things working as expected.
This is my test and here is the HTTP call I'm trying to mock.
Despite following this guide, my test fails and makes an outbound HTTP call.
Am I matching incorrectly? Is WireMock not meant to be used with TestServer?
Thanks in advance!
@redgoose commented on GitHub (Jan 14, 2021):
hmm... added an additional test here that doesn't use TestServer and uses the IpifyClient directly and that also fails. Any ideas?
@StefH commented on GitHub (Jan 15, 2021):
@redgoose
The WithPath is used like
"/pathabc"Did you try
WithParam(...)?See
477f3b5cd3/test/WireMock.Net.Tests/RequestTests.cs (L129)@redgoose commented on GitHub (Jan 15, 2021):
yep i tried with
Request.Create().WithParam("format", "json")as well.@StefH commented on GitHub (Jan 20, 2021):
@redgoose
I think that the http-client is not connecting to the WireMock.Net server.
(You need to send the request to
server.Urls[0])I've updated the wiki:
https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock-in-UnitTests
And here is an example:
92923a12ae/test/WireMock.Net.Tests/WireMockServerTests.cs (L268)@redgoose commented on GitHub (Feb 1, 2021):
That example doesn't make sense to me. Why are we POSTing to that url? The example in the previous revision made sense since the SUT would do something to trigger an HTTP request.
var response = _sut.DoSomething();Are you able to checkout my test app (https://github.com/redgoose/dotnet-learning) and see if you can get test
TestAPIBazto work?Also, you've introduced an undeclared variable
stringContentinto your example.@StefH commented on GitHub (Feb 1, 2021):
Example is updated to use Get and the URL is changed to
_server.Urls[0]}/foo.This does make more sense in the example.
I'll checkout your example and see if I can fix it.
@StefH commented on GitHub (Feb 1, 2021):
See PR : https://github.com/redgoose/dotnet-learning/pull/1
@redgoose commented on GitHub (Feb 2, 2021):
Thanks for your help so far. I looked at the PR and have a question. Why on this line are we matching on
/api/learning/bazwhen I'm trying to stub out the HTTP call tohttps://api.ipify.org?format=json?The logic is, GET
/api/learning/bazmakes an HTTP GET tohttps://api.ipify.org?format=json. It's that latter request I'm trying to stub out.@StefH commented on GitHub (Feb 3, 2021):
For this example it does not really matter.
If you setup a stub , and then call wiremock using the same path or query parameters ; that will match.
Also view this to get a general understanding on usage:
https://www.youtube.com/watch?v=IJa6DyJOxzk
@redgoose commented on GitHub (Feb 9, 2021):
Okay, what about this test. I'm unable to get the matching to work, do you know what the problem is?
@StefH commented on GitHub (Feb 9, 2021):
WithParam(...)See my updated PR
https://github.com/redgoose/dotnet-learning/pull/1
@redgoose commented on GitHub (Feb 10, 2021):
thanks so much for your assistance!