-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
False positive on _httpTest.ShouldHaveCalled() #323
Comments
This is a tough call. I'm inclined to agree with you about how it probably should work, but this would be a breaking change that could affect lots of people. I can also kind of see a counter-argument for something like query strings. If your code calls test.ShouldHaveCalled("https://api.com/endpoint"); Some might say yes. If I had it to do all over again, I'd probably say no, just put a I'll keep this open. Maybe there should just be a new method like |
Here's how I resolved the issue (with Fluent Assertions): public static HttpCallAssertion ShouldHaveExactCall(this HttpTest test, string exactUrl)
{
test.CallLog.First().FlurlRequest.Url.ToString().Should().Be(exactUrl);
return new HttpCallAssertion(test.CallLog);
} The reason I needed to match exact URLs was because I had two distinct endpoints using( var test = new HttpTest() ){
var response = await "https://test.com/v2/users"
.PutJsonAsync(new {foo="hi"});
test.ShouldHaveCalled("https://test.com/v2/user");
"test should not pass".Dump();
} Infact, Good thing I caught this, because some API calls to |
This one's finally ready! As a side-note, the same simple wildcard matching is used for other things like asserting query parameters, headers, and response bodies. This will affect all of them, but I'm a little bit lenient in the case of |
Now available to test: https://www.nuget.org/packages/Flurl.Http/3.0.0-pre2 |
Thanks a bunch Todd! :) I think this is going to really help! |
Just need to leave a note here that this change destroyed all of the testing I was previously doing with Flurl, and my tests now have to be extremely tightly coupled to implementations because of it -- instead of setting up a service with a URL base and then checking to ensure that it was used, testing now requires that you know the exact URL eventually resolved by that service implementation internally. A |
Not true and supported by tests. Are you sure the trailing slash isn't the problem? |
It would be strange for that to be a problem. |
@Kesmy Sorry for the delay on this, been very short on time in the last couple months. I think this issue was left open by mistake but before I close it I want to understand if there's still an issue. If you're suggesting that |
I don't know if it's intended behavior, but it got me sidetracked a bit and I had to make special checking that would be avoided if this worked as expected.
I ran into the issue that when confirming that a url was called, the
HttpTest
library doesn't compare if the urls are equal but only if the test url is in the called url. Even though there are no wildcards.Calling
/something
and/something/1/else/3
are very different things, but the test sees them as equivalent.To recreated - this test will pass:
.csproj
The text was updated successfully, but these errors were encountered: