|
| 1 | +using System; |
| 2 | +using System.Net.Http; |
| 3 | + |
| 4 | +using Xunit; |
| 5 | + |
| 6 | +namespace HttpClientTestHelpers.Tests |
| 7 | +{ |
| 8 | + public partial class HttpRequestMessageExtensionsTests |
| 9 | + { |
| 10 | +#nullable disable |
| 11 | + [Fact] |
| 12 | + public void HasMatchingUri_NullHttpRequestMessage_ThrowsArgumentNullException() |
| 13 | + { |
| 14 | + HttpRequestMessage sut = null; |
| 15 | + var exception = Assert.Throws<ArgumentNullException>(() => sut.HasMatchingUri("*")); |
| 16 | + Assert.Equal("httpRequestMessage", exception.ParamName); |
| 17 | + } |
| 18 | + |
| 19 | + [Fact] |
| 20 | + public void HasMatchingUri_NullPattern_ThrowsArgumentNullException() |
| 21 | + { |
| 22 | + using var sut = new HttpRequestMessage { RequestUri = new Uri("https://example.com") }; |
| 23 | + var exception = Assert.Throws<ArgumentNullException>(() => sut.HasMatchingUri(null)); |
| 24 | + Assert.Equal("pattern", exception.ParamName); |
| 25 | + } |
| 26 | +#nullable restore |
| 27 | + |
| 28 | + [Fact] |
| 29 | + public void HasMatchingUri_EmptyPattern_ReturnsFalse() |
| 30 | + { |
| 31 | + using var sut = new HttpRequestMessage { RequestUri = new Uri("https://example.com") }; |
| 32 | + |
| 33 | + Assert.False(sut.HasMatchingUri("")); |
| 34 | + } |
| 35 | + |
| 36 | + [Theory] |
| 37 | + [InlineData("*")] |
| 38 | + [InlineData("https://example.com")] |
| 39 | + [InlineData("https://example.com/")] |
| 40 | + [InlineData("https://example.com/*")] |
| 41 | + [InlineData("https://*/")] |
| 42 | + [InlineData("https://*/*")] |
| 43 | + public void HasMatchingUri_WithPatternFor_ReturnsTrue(string pattern) |
| 44 | + { |
| 45 | + using var sut = new HttpRequestMessage { RequestUri = new Uri("https://example.com") }; |
| 46 | + |
| 47 | + Assert.True(sut.HasMatchingUri(pattern)); |
| 48 | + } |
| 49 | + |
| 50 | + [Fact] |
| 51 | + public void HasMatchingUri_PatternWithMultipleWildCards_ReturnsTrue() |
| 52 | + { |
| 53 | + using var sut = new HttpRequestMessage { RequestUri = new Uri("https://example.com/api/test/value") }; |
| 54 | + |
| 55 | + Assert.True(sut.HasMatchingUri("https://*/api/*")); |
| 56 | + } |
| 57 | + |
| 58 | + [Theory] |
| 59 | + [InlineData("")] |
| 60 | + [InlineData("http://example.com")] |
| 61 | + [InlineData("http://*")] |
| 62 | + [InlineData("https://*/api/test")] |
| 63 | + public void HasMatchingUri_WithPatternThatDoesnotMatch_ReturnsFalse(string pattern) |
| 64 | + { |
| 65 | + using var sut = new HttpRequestMessage { RequestUri = new Uri("https://example.com") }; |
| 66 | + |
| 67 | + Assert.False(sut.HasMatchingUri(pattern)); |
| 68 | + } |
| 69 | + |
| 70 | + [Fact] |
| 71 | + public void HasMatchingUri_WithValidPatternIncludingQueryParameters_ReturnsTrue() |
| 72 | + { |
| 73 | + using var sut = new HttpRequestMessage { RequestUri = new Uri("https://example.com/list?id=test") }; |
| 74 | + |
| 75 | + Assert.True(sut.HasMatchingUri("*/list?id=test")); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments