Skip to content

Commit 03605b2

Browse files
Copilotdennisdoomen
andcommitted
Fix WithBody to support multi-line request bodies
- Added RegexOptions.Singleline to StringExtensions.MatchesWildcard - Added test for multi-line body matching with wildcard patterns - All 107 tests pass Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
1 parent fc2bb30 commit 03605b2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Mockly.Specs/HttpMockSpecs.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,36 @@ public async Task Can_match_body_against_a_wildcard_pattern()
480480
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
481481
}
482482

483+
[Fact]
484+
public async Task Can_match_multi_line_body_against_a_wildcard_pattern()
485+
{
486+
// Arrange
487+
var mock = new HttpMock();
488+
489+
mock.ForPost()
490+
.WithPath("/api/test")
491+
.WithBody("*<entity>*<condition*value=\"0\"*")
492+
.RespondsWithStatus(HttpStatusCode.NoContent);
493+
494+
var client = mock.GetClient();
495+
496+
// Act
497+
var response = await client.PostAsync("https://localhost/api/test",
498+
new StringContent(
499+
"""
500+
<fetch>
501+
<entity>
502+
<filter>
503+
<condition attribute="statecode" operator="eq" value="0"/>
504+
</filter>
505+
</entity>
506+
</fetch>
507+
"""));
508+
509+
// Assert
510+
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
511+
}
512+
483513
[Fact]
484514
public async Task Can_match_the_body_against_a_json_string_ignoring_layout()
485515
{

Mockly/Common/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static bool MatchesWildcard(this string text, string wildcardPattern)
2323
.Replace("\\*", ".*")
2424
.Replace("\\?", ".");
2525

26-
return Regex.IsMatch(text, regexPattern, RegexOptions.IgnoreCase);
26+
return Regex.IsMatch(text, regexPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
2727
}
2828

2929
/// <summary>

0 commit comments

Comments
 (0)