-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support multiple parameters in WithQuery
#460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| namespace Mockolate.Web; | ||
|
|
||
| /// <summary> | ||
| /// The value of an HTTP query parameter. | ||
| /// </summary> | ||
| public class HttpQueryParameterValue | ||
| { | ||
| private readonly string _value; | ||
|
|
||
| /// <inheritdoc cref="HttpQueryParameterValue" /> | ||
| public HttpQueryParameterValue(string value) | ||
| { | ||
| _value = value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks whether the given query parameter value matches this value. | ||
| /// </summary> | ||
| public virtual bool Matches(string parameterValue) | ||
| => _value.Equals(parameterValue); | ||
|
|
||
| /// <summary> | ||
| /// Implicitly converts a string to an <see cref="HttpQueryParameterValue" />. | ||
| /// </summary> | ||
| public static implicit operator HttpQueryParameterValue(string value) | ||
| { | ||
| return new HttpQueryParameterValue(value); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Tests/Mockolate.Tests/Web/ItExtensionsTests.IsUriTests.ForHttpsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading; | ||
| using Mockolate.Web; | ||
|
|
||
| namespace Mockolate.Tests.Web; | ||
|
|
||
| public sealed partial class ItExtensionsTests | ||
| { | ||
| public sealed partial class IsUriTests | ||
| { | ||
| public sealed class ForHttpsTests | ||
|
vbreuss marked this conversation as resolved.
Outdated
|
||
| { | ||
| [Theory] | ||
| [InlineData("http://www.aweXpect.com/foo/bar?x=123&y=234", true)] | ||
| [InlineData("HTTP://www.aweXpect.com/foo/bar?x=123&y=234", true)] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", false)] | ||
| public async Task ForHttp_ShouldVerifyHttpScheme(string uri, bool expectMatch) | ||
| { | ||
| HttpClient httpClient = Mock.Create<HttpClient>(); | ||
| httpClient.SetupMock.Method | ||
| .GetAsync(It.IsUri().ForHttp()) | ||
| .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)); | ||
|
|
||
| HttpResponseMessage result = await httpClient.GetAsync(uri, CancellationToken.None); | ||
|
|
||
| await That(result.StatusCode) | ||
| .IsEqualTo(expectMatch ? HttpStatusCode.OK : HttpStatusCode.NotImplemented); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", true)] | ||
| [InlineData("HTTPS://www.aweXpect.com/foo/bar?x=123&y=234", true)] | ||
| [InlineData("http://www.aweXpect.com/foo/bar?x=123&y=234", false)] | ||
| public async Task ForHttps_ShouldVerifyHttpsScheme(string uri, bool expectMatch) | ||
| { | ||
| HttpClient httpClient = Mock.Create<HttpClient>(); | ||
| httpClient.SetupMock.Method | ||
| .GetAsync(It.IsUri().ForHttps()) | ||
| .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)); | ||
|
|
||
| HttpResponseMessage result = await httpClient.GetAsync(uri, CancellationToken.None); | ||
|
|
||
| await That(result.StatusCode) | ||
| .IsEqualTo(expectMatch ? HttpStatusCode.OK : HttpStatusCode.NotImplemented); | ||
| } | ||
| } | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
Tests/Mockolate.Tests/Web/ItExtensionsTests.IsUriTests.WithHostTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading; | ||
| using Mockolate.Web; | ||
|
|
||
| namespace Mockolate.Tests.Web; | ||
|
|
||
| public sealed partial class ItExtensionsTests | ||
| { | ||
| public sealed partial class IsUriTests | ||
| { | ||
| public sealed class WithHostTests | ||
| { | ||
| [Theory] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", "www.awexpect.com", true)] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", "*awexpect*", true)] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", "*aweXpect*", true)] | ||
| [InlineData("http://www.aweXpect.com/foo/bar?x=123&y=234", "mockolate.com", false)] | ||
| public async Task ShouldVerifyHost(string uri, string hostPattern, bool expectMatch) | ||
| { | ||
| HttpClient httpClient = Mock.Create<HttpClient>(); | ||
| httpClient.SetupMock.Method | ||
| .GetAsync(It.IsUri().WithHost(hostPattern)) | ||
| .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)); | ||
|
|
||
| HttpResponseMessage result = await httpClient.GetAsync(uri, CancellationToken.None); | ||
|
|
||
| await That(result.StatusCode) | ||
| .IsEqualTo(expectMatch ? HttpStatusCode.OK : HttpStatusCode.NotImplemented); | ||
| } | ||
| } | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
Tests/Mockolate.Tests/Web/ItExtensionsTests.IsUriTests.WithPathTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading; | ||
| using Mockolate.Web; | ||
|
|
||
| namespace Mockolate.Tests.Web; | ||
|
|
||
| public sealed partial class ItExtensionsTests | ||
| { | ||
| public sealed partial class IsUriTests | ||
| { | ||
| public sealed class WithPathTests | ||
| { | ||
| [Theory] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", "/foo/bar", true)] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", "*foo*", true)] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", "*FOO*", true)] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", "*bar*", true)] | ||
| [InlineData("http://www.aweXpect.com/foo/bar?x=123&y=234", "*baz*", false)] | ||
| public async Task ShouldVerifyPath(string uri, string pathPattern, bool expectMatch) | ||
| { | ||
| HttpClient httpClient = Mock.Create<HttpClient>(); | ||
| httpClient.SetupMock.Method | ||
| .GetAsync(It.IsUri().WithPath(pathPattern)) | ||
| .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)); | ||
|
|
||
| HttpResponseMessage result = await httpClient.GetAsync(uri, CancellationToken.None); | ||
|
|
||
| await That(result.StatusCode) | ||
| .IsEqualTo(expectMatch ? HttpStatusCode.OK : HttpStatusCode.NotImplemented); | ||
| } | ||
| } | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
Tests/Mockolate.Tests/Web/ItExtensionsTests.IsUriTests.WithPortTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading; | ||
| using Mockolate.Web; | ||
|
|
||
| namespace Mockolate.Tests.Web; | ||
|
|
||
| public sealed partial class ItExtensionsTests | ||
| { | ||
| public sealed partial class IsUriTests | ||
| { | ||
| public sealed class WithPortTests | ||
| { | ||
| [Theory] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", 443, true)] | ||
| [InlineData("http://www.aweXpect.com/foo/bar?x=123&y=234", 80, true)] | ||
| [InlineData("https://www.aweXpect.com:8080/foo/bar?x=123&y=234", 8080, true)] | ||
| [InlineData("https://www.aweXpect.com:442/foo/bar?x=123&y=234", 443, false)] | ||
| [InlineData("https://www.aweXpect.com/foo/bar?x=123&y=234", 442, false)] | ||
| public async Task ShouldVerifyPort(string uri, int port, bool expectMatch) | ||
| { | ||
| HttpClient httpClient = Mock.Create<HttpClient>(); | ||
| httpClient.SetupMock.Method | ||
| .GetAsync(It.IsUri().WithPort(port)) | ||
| .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)); | ||
|
|
||
| HttpResponseMessage result = await httpClient.GetAsync(uri, CancellationToken.None); | ||
|
|
||
| await That(result.StatusCode) | ||
| .IsEqualTo(expectMatch ? HttpStatusCode.OK : HttpStatusCode.NotImplemented); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.