ForCallsTo and ShouldHaveCalled should "pass" when query not specified but actual call contains one
See original GitHub issueHi,
(Great library, thank you!)
Problem
It was unclear for a few minutes why the following test was failing. The problem is that ForCallsTo("*/endpoint")
in this case should be ForCallsTo("*/endpoint*")
in order for the urlPattern
to match the query parameters that have been added as a result of SetQueryParam
in the Act
portion of the code.
// This test currently fails:
// Expected string length 7 but was 0. Strings differ at index 0.
// Expected: "success"
// But was: <string.Empty>
[Test]
public async Task Should_match_ForCallsTo_using_WithQueryParam()
{
// Arrange
HttpTest.ForCallsTo("*/endpoint")
.WithQueryParam("a", "b")
.RespondWith("success");
// Act
var result = await "https://example.com/endpoint"
.SetQueryParam("a", "b")
.GetStringAsync();
// Assert
Assert.AreEqual("success", result);
}
In comparison, this test passes OK:
[Test]
public async Task Does_match_ForCallsTo_using_WithQueryParam_when_asterisk_is_used_at_end_of_ForCallsTo_urlPattern()
{
// Arrange
HttpTest.ForCallsTo("*/endpoint*")
.WithQueryParam("a", "b")
.RespondWith("success");
// Act
var result = await "https://example.com/endpoint"
.SetQueryParam("a", "b")
.GetStringAsync();
// Assert
Assert.AreEqual("success", result);
}
Discussion
I’m wondering if Should_match_ForCallsTo_using_WithQueryParam
should pass when the WithQueryParam
has been called in the arrange/setup code, without needing a trailing asterisk in the ForCallsTo
which felt redundant, because I was trying to match the SetQueryParam
calls in the executing code.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Flurl
ForCallsTo and ShouldHaveCalled should "pass" when query not specified but actual call contains one... Hi, (Great library, thank you!)
Read more >Testable HTTP
Once an HttpTest is created and any specific responses are queued, simply call into a test subject. When the SUT makes an HTTP...
Read more >platform/libcore
When used + * in a method, the call to {@code open} should occur just ... If the VM does not have a...
Read more >249 Aer Lingus Reviews - Check Before Flying
I was told to get verification that is was not repairable as well as supply an original receipt for the luggage. You would...
Read more >Wheres the customer support Telstra
Is there no email or online form option to contact customer support? All I want to do is query a couple of charges...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m hoping to get input from the community on whether this should wait until the next major version (it’s technically breaking), or if it’s reasonable to call it a bug fix and do it now.
Published to NuGet in Flurl.Http 3.1.0