Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/MockHttp/Extensions/HttpRequestMatcherExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ internal static class HttpRequestMatcherExtensions
/// <returns><see langword="true" /> if all <paramref name="matchers" /> match the <paramref name="requestContext" />.</returns>
public static async Task<bool> AllAsync(this IEnumerable<IAsyncHttpRequestMatcher> matchers, MockHttpRequestContext requestContext)
{
bool hasMatchedAll = true;
foreach (IAsyncHttpRequestMatcher m in matchers)
{
if (await m.IsMatchAsync(requestContext).ConfigureAwait(false))
if (!await m.IsMatchAsync(requestContext).ConfigureAwait(false))
{
continue;
return false;
}

hasMatchedAll = false;
}

return hasMatchedAll;
return true;
}

/// <summary>
Expand Down
19 changes: 19 additions & 0 deletions test/MockHttp.Json.Tests/JsonRequestMatchingExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net;
using System.Text;
using FluentAssertions;
using MockHttp.FluentAssertions;
using MockHttp.Json.Newtonsoft;
using Newtonsoft.Json;
Expand Down Expand Up @@ -34,6 +35,24 @@ public async Task Given_json_content_matching_request_when_matching_should_be_tr
// Assert
response.Should().HaveStatusCode(HttpStatusCode.OK);
}

[Fact]
public async Task Given_not_a_json_content_matching_request_and_a_different_request_uri_when_matching_should_not_test_others_matcher()
{
var obj = new TestClass { SomeProperty = "value" };

_httpMock
.When(m => m
.RequestUri("/users")
.JsonContent(obj))
.Respond(HttpStatusCode.OK);

// Act
Func<Task> act = () => _httpClient.PostAsync("http://0.0.0.0", new StringContent("test=test", Encoding.UTF8, "application/x-www-form-urlencoded"));

// Assert
await act.Should().NotThrowAsync<System.Text.Json.JsonException>();
}

[Theory]
[InlineData(true)]
Expand Down