diff --git a/Mockly.Specs/HttpMockSpecs.cs b/Mockly.Specs/HttpMockSpecs.cs index 4222bcd..75a8c6e 100644 --- a/Mockly.Specs/HttpMockSpecs.cs +++ b/Mockly.Specs/HttpMockSpecs.cs @@ -141,6 +141,45 @@ public async Task The_query_does_not_require_a_question_mark() response.StatusCode.Should().Be(HttpStatusCode.OK); } + [Fact] + public async Task Can_match_path_with_pipe_character() + { + // Arrange + var mock = new HttpMock(); + var key = $"{Guid.NewGuid()}|{Guid.NewGuid()}"; + + mock.ForDelete() + .WithPath($"IncomeRelations/{key}") + .RespondsWithStatus(HttpStatusCode.OK); + + // Act + var client = mock.GetClient(); + var response = await client.DeleteAsync($"https://localhost/IncomeRelations/{key}"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.OK); + } + + [Fact] + public async Task Can_match_query_with_pipe_character() + { + // Arrange + var mock = new HttpMock(); + var filter = "status=active|pending"; + + mock.ForGet() + .WithPath("api/items") + .WithQuery($"filter={filter}") + .RespondsWithStatus(HttpStatusCode.OK); + + // Act + var client = mock.GetClient(); + var response = await client.GetAsync($"https://localhost/api/items?filter={filter}"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.OK); + } + [Fact] public async Task Can_mock_get_request_with_json_response() { diff --git a/Mockly/RequestMock.cs b/Mockly/RequestMock.cs index e46880b..d30be1a 100644 --- a/Mockly/RequestMock.cs +++ b/Mockly/RequestMock.cs @@ -85,7 +85,7 @@ public async Task Matches(RequestInfo request) // Check path pattern if specified if (PathPattern != null) { - var path = request.Uri?.AbsolutePath ?? string.Empty; + var path = WebUtility.UrlDecode(request.Uri?.AbsolutePath ?? string.Empty); if (!MatchesPattern(path.TrimStart('/'), PathPattern.TrimStart('/'))) { return false;