question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ForCallsTo and ShouldHaveCalled should "pass" when query not specified but actual call contains one

See original GitHub issue

Hi,

(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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tmeniercommented, Apr 28, 2021

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.

0reactions
tmeniercommented, May 4, 2021

Published to NuGet in Flurl.Http 3.1.0

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found