You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using the assertions .WithQueryParamValue in my UnitTests but I noticed that it's not comparing the whole value for the "value", instead it's using a regex pattern to match if the value is present on the Request Uri, however this can leads to false-positives as it's not checking the exact value.
I'm showing it with two unit tests:
[Test]
public async Task ShouldFail()
{
using (var httpFake = new HttpTest())
{
var request = await "http://www.uol.com.br/?code=UNIT_TEST".GetStringAsync();
httpFake
.ShouldHaveCalled("*http://www.uol.com.br*")
.WithQueryParamValue("code", "UNIT");
}
}
[Test]
public async Task ShouldPass()
{
using (var httpFake = new HttpTest())
{
var request = await "http://www.uol.com.br/?code=UNIT_TEST".GetStringAsync();
httpFake
.ShouldHaveCalled("*http://www.uol.com.br*")
.WithQueryParamValue("code", "UNIT_TEST");
}
}
First one should Fail as it's not matching the exact value.
I didn't check it further but I believe the issue is in:
private bool QueryParamMatches(QueryParameter qp, string name, object value)
{
if (qp.Name != name)
return false;
if (value is string pattern)
return this.MatchesPattern(qp.Value?.ToString(), pattern);
return qp.Value?.ToString() == value?.ToString();
}
Because you're validating using a Regex pattern before validating if the value is exactly the same.
The text was updated successfully, but these errors were encountered:
RoggerFabri
changed the title
.WithParamValue skips whole value when it's a string
.WithParamValue skips whole value when it's a string leads to false-positive
Apr 29, 2019
RoggerFabri
changed the title
.WithParamValue skips whole value when it's a string leads to false-positive
.WithParamValue skips exact value when it's a string and leads to false-positive
Apr 29, 2019
Thanks for reporting. Closely related to #323. I'm not calling either a bug but I am convinced that the behavior should change. I'll get this done in 3.0.
I've been using the assertions .WithQueryParamValue in my UnitTests but I noticed that it's not comparing the whole value for the "value", instead it's using a regex pattern to match if the value is present on the Request Uri, however this can leads to false-positives as it's not checking the exact value.
I'm showing it with two unit tests:
First one should Fail as it's not matching the exact value.
I didn't check it further but I believe the issue is in:
Because you're validating using a Regex pattern before validating if the value is exactly the same.
The text was updated successfully, but these errors were encountered: