diff --git a/CHANGELOG.md b/CHANGELOG.md
index e148704..3c28f54 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,13 +4,15 @@ All notable changes to TestableHttpClient will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and
this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## [0.9] - unplanned
+## [0.9] - 2022-11-25
### Deprecated
- `Responses.NoContent()` has been deprecated, since it doesn't fit well with the rest of the API. Please use `Responses.StatusCode(HttpStatusCode.NoContent)` instead.
### Removed
- Official support for .NET Core 3.1 has been removed. This means we no longer provide a specific version for .NET Core 3.0 and we no longer test this version explicitly. Since we support .NET Standard 2.0, the library could still be used.
- TestableHttpClient.NFluent has been moved to it's own repository.
+- `HttpRequestMessageExtensions` have been made internal.
+- `HttpResponseMessageExtensions` have been removed, since it not needed for making HttpClients testable.
### Added
- Added `Responses.Route` that allows changing the response based on the url. The url supports patterns.
@@ -243,6 +245,7 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Automatically build project when pushing changes to github and when creating a pull request
- Automatically deploy to NuGet when creating a tag in github
+[0.9]: https://github.com/testablehttpclient/TestableHttpClient/compare/v0.8...v0.9
[0.8]: https://github.com/testablehttpclient/TestableHttpClient/compare/v0.7...v0.8
[0.7]: https://github.com/testablehttpclient/TestableHttpClient/compare/v0.6...v0.7
[0.6]: https://github.com/testablehttpclient/TestableHttpClient/compare/v0.5...v0.6
diff --git a/README.md b/README.md
index a93290f..ad60f16 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# TestableHttpClient
- 
+  
Creating unittest for code that uses `HttpClient` can be difficult to test. It requires a custom HttpMessageHandler or a mocked version. TestableHttpClient provides a testable version of HttpMessageHandler and several helper functions to configure the `TestableHttpHandler` and several ways to assert which requests were made.
@@ -13,9 +13,21 @@ dotnet add package TestableHttpClient
## How to use TestableHttpClient
+The following code block shows the basic use case for asserting that certain requests are made:
```csharp
-var testHandler = new TestableHttpMessageHandler();
-var httpClient = new HttpClient(testHandler); // or testHandler.CreateClient();
+TestableHttpMessageHandler testHandler = new();
+HttpClient httpClient = new(testHandler); // or testHandler.CreateClient();
+
+var result = await httpClient.GetAsync("http://httpbin.org/status/200");
+
+testHandler.ShouldHaveMadeRequestsTo("https://httpbin.org/*");
+```
+
+The default response is an empty response message with a 200 OK StatusCode, in order to return real content the response need to be configured:
+```csharp
+TestableHttpMessageHandler testHandler = new();
+testHandler.RespondWith(Responses.Json(new { Hello: "World" }));
+HttpClient httpClient = new(testHandler); // or testHandler.CreateClient();
var result = await httpClient.GetAsync("http://httpbin.org/status/200");
@@ -29,7 +41,7 @@ More examples can be found in the [IntegrationTests project](test/TestableHttpCl
TestableHttpClient is build as a netstandard2.0 library, so theoretically it can work on every .NET version that support netstandard2.0.
The following versions are being actively tested and thus supported:
-- .NET Framework 4.6 and up
+- .NET Framework 4.6, 4.7 and 4.8
- .NET 6.0
- .NET 7.0
diff --git a/src/TestableHttpClient/HttpRequestMessageExtensions.cs b/src/TestableHttpClient/HttpRequestMessageExtensions.cs
index 77c417b..bab529e 100644
--- a/src/TestableHttpClient/HttpRequestMessageExtensions.cs
+++ b/src/TestableHttpClient/HttpRequestMessageExtensions.cs
@@ -3,8 +3,7 @@
///
/// A set of static methods for checking values on a .
///
-[Obsolete("This class is not intended for public use and will be marked internal in the next release.")]
-public static class HttpRequestMessageExtensions
+internal static class HttpRequestMessageExtensions
{
///
/// Determines whether a specific HttpVersion is set on a request.
@@ -12,8 +11,7 @@ public static class HttpRequestMessageExtensions
/// A to check the correct version on.
/// The expected version.
/// true when the HttpVersion matches; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, Version httpVersion)
+ internal static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, Version httpVersion)
{
if (httpRequestMessage == null)
{
@@ -34,8 +32,7 @@ public static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, Ve
/// A to check the correct version on.
/// The expected version.
/// true when the HttpVersion matches; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, string httpVersion)
+ internal static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, string httpVersion)
{
if (httpRequestMessage == null)
{
@@ -56,8 +53,7 @@ public static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, st
/// A to check the correct method on.
/// The expected method.
/// true when the HttpMethod matches; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, HttpMethod httpMethod)
+ internal static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, HttpMethod httpMethod)
{
if (httpRequestMessage == null)
{
@@ -78,8 +74,7 @@ public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, Htt
/// A to check the correct method on.
/// The expected method.
/// true when the HttpMethod matches; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, string httpMethod)
+ internal static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, string httpMethod)
{
if (httpRequestMessage == null)
{
@@ -101,8 +96,7 @@ public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, str
/// A to check the request header on.
/// The name of the header to locate on the request.
/// true when the request contains a header with the specified name; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage, string headerName)
+ internal static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage, string headerName)
{
if (httpRequestMessage == null)
{
@@ -125,8 +119,7 @@ public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage,
/// The name of the header to locate on the request.
/// The value the header should have. Wildcard is supported.
/// true when the request contains a header with the specified name and value; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage, string headerName, string headerValue)
+ internal static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage, string headerName, string headerValue)
{
if (httpRequestMessage == null)
{
@@ -153,8 +146,7 @@ public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage,
/// A to check the content header on.
/// The name of the header to locate on the request content.
/// true when the request contains a header with the specified name; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage, string headerName)
+ internal static bool HasContentHeader(this HttpRequestMessage httpRequestMessage, string headerName)
{
if (httpRequestMessage == null)
{
@@ -182,8 +174,7 @@ public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage,
/// The name of the header to locate on the request content.
/// The value the header should have. Wildcard is supported.
/// true when the request contains a header with the specified name and value; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage, string headerName, string headerValue)
+ internal static bool HasContentHeader(this HttpRequestMessage httpRequestMessage, string headerName, string headerValue)
{
if (httpRequestMessage == null)
{
@@ -214,8 +205,7 @@ public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage,
/// A to check the correct uri on.
/// A pattern to match with the request uri, supports * as wildcards.
/// true when the request uri matches the pattern; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasMatchingUri(this HttpRequestMessage httpRequestMessage, string pattern, bool ignoreCase = true)
+ internal static bool HasMatchingUri(this HttpRequestMessage httpRequestMessage, string pattern, bool ignoreCase = true)
{
if (httpRequestMessage == null)
{
@@ -241,8 +231,7 @@ public static bool HasMatchingUri(this HttpRequestMessage httpRequestMessage, st
///
/// A to check for content.
/// true when the request has content; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasContent(this HttpRequestMessage httpRequestMessage)
+ internal static bool HasContent(this HttpRequestMessage httpRequestMessage)
{
if (httpRequestMessage == null)
{
@@ -258,8 +247,7 @@ public static bool HasContent(this HttpRequestMessage httpRequestMessage)
/// A to check the correct content on.
/// A pattern to match the request content, supports * as wildcards.
/// true when the request content matches the pattern; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasContent(this HttpRequestMessage httpRequestMessage, string pattern)
+ internal static bool HasContent(this HttpRequestMessage httpRequestMessage, string pattern)
{
if (httpRequestMessage == null)
{
@@ -292,8 +280,7 @@ public static bool HasContent(this HttpRequestMessage httpRequestMessage, string
/// A to check the correct request uir querystring on.
/// A pattern to match the request uri querystring, supports * as wildcards.
/// true when the request uri querystring matches the pattern; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasQueryString(this HttpRequestMessage httpRequestMessage, string pattern)
+ internal static bool HasQueryString(this HttpRequestMessage httpRequestMessage, string pattern)
{
if (httpRequestMessage == null)
{
diff --git a/src/TestableHttpClient/HttpRequestMessagesCheckExtensions.cs b/src/TestableHttpClient/HttpRequestMessagesCheckExtensions.cs
index 910e733..758136b 100644
--- a/src/TestableHttpClient/HttpRequestMessagesCheckExtensions.cs
+++ b/src/TestableHttpClient/HttpRequestMessagesCheckExtensions.cs
@@ -42,9 +42,7 @@ private static IHttpRequestMessagesCheck WithRequestUri(this IHttpRequestMessage
condition = $"uri pattern '{pattern}'";
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasMatchingUri(pattern, ignoreCase), expectedNumberOfRequests, condition);
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -83,9 +81,7 @@ private static IHttpRequestMessagesCheck WithQueryString(this IHttpRequestMessag
_ => $"querystring pattern '{pattern}'"
};
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasQueryString(pattern), expectedNumberOfRequests, condition);
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -117,9 +113,7 @@ private static IHttpRequestMessagesCheck WithHttpMethod(this IHttpRequestMessage
throw new ArgumentNullException(nameof(httpMethod));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasHttpMethod(httpMethod), expectedNumberOfRequests, $"HTTP Method '{httpMethod}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -151,9 +145,7 @@ private static IHttpRequestMessagesCheck WithHttpVersion(this IHttpRequestMessag
throw new ArgumentNullException(nameof(httpVersion));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasHttpVersion(httpVersion), expectedNumberOfRequests, $"HTTP Version '{httpVersion}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -187,9 +179,7 @@ private static IHttpRequestMessagesCheck WithRequestHeader(this IHttpRequestMess
throw new ArgumentNullException(nameof(headerName));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasRequestHeader(headerName), expectedNumberOfRequests, $"request header '{headerName}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -230,9 +220,7 @@ private static IHttpRequestMessagesCheck WithRequestHeader(this IHttpRequestMess
throw new ArgumentNullException(nameof(headerValue));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasRequestHeader(headerName, headerValue), expectedNumberOfRequests, $"request header '{headerName}' and value '{headerValue}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -266,9 +254,7 @@ private static IHttpRequestMessagesCheck WithContentHeader(this IHttpRequestMess
throw new ArgumentNullException(nameof(headerName));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasContentHeader(headerName), expectedNumberOfRequests, $"content header '{headerName}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -309,9 +295,7 @@ private static IHttpRequestMessagesCheck WithContentHeader(this IHttpRequestMess
throw new ArgumentNullException(nameof(headerValue));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasContentHeader(headerName, headerValue), expectedNumberOfRequests, $"content header '{headerName}' and value '{headerValue}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -343,9 +327,7 @@ private static IHttpRequestMessagesCheck WithHeader(this IHttpRequestMessagesChe
throw new ArgumentNullException(nameof(headerName));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasRequestHeader(headerName) || x.HasContentHeader(headerName), expectedNumberOfRequests, $"header '{headerName}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -384,9 +366,7 @@ private static IHttpRequestMessagesCheck WithHeader(this IHttpRequestMessagesChe
throw new ArgumentNullException(nameof(headerValue));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasRequestHeader(headerName, headerValue) || x.HasContentHeader(headerName, headerValue), expectedNumberOfRequests, $"header '{headerName}' and value '{headerValue}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -420,9 +400,7 @@ private static IHttpRequestMessagesCheck WithContent(this IHttpRequestMessagesCh
throw new ArgumentNullException(nameof(pattern));
}
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasContent(pattern), expectedNumberOfRequests, $"content '{pattern}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -472,9 +450,7 @@ private static IHttpRequestMessagesCheck WithJsonContent(this IHttpRequestMessag
var jsonString = JsonSerializer.Serialize(jsonObject, jsonSerializerOptions ?? check.Options.JsonSerializerOptions);
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasContent(jsonString) && x.HasContentHeader("Content-Type", "application/json*"), expectedNumberOfRequests, $"json content '{jsonString}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
///
@@ -511,8 +487,6 @@ private static IHttpRequestMessagesCheck WithFormUrlEncodedContent(this IHttpReq
using var content = new FormUrlEncodedContent(nameValueCollection);
var contentString = content.ReadAsStringAsync().Result;
-#pragma warning disable CS0618 // Type or member is obsolete
return check.WithFilter(x => x.HasContent(contentString) && x.HasContentHeader("Content-Type", "application/x-www-form-urlencoded*"), expectedNumberOfRequests, $"form url encoded content '{contentString}'");
-#pragma warning restore CS0618 // Type or member is obsolete
}
}
diff --git a/src/TestableHttpClient/HttpResponseMessageExtensions.cs b/src/TestableHttpClient/HttpResponseMessageExtensions.cs
deleted file mode 100644
index 0fb2071..0000000
--- a/src/TestableHttpClient/HttpResponseMessageExtensions.cs
+++ /dev/null
@@ -1,239 +0,0 @@
-namespace TestableHttpClient;
-
-///
-/// A set of static methods for checking values on a .
-///
-[Obsolete("This class is not intended for public use and will be marked internal in the next release.")]
-public static class HttpResponseMessageExtensions
-{
- ///
- /// Determines whether a specific HttpVersion is set on a response.
- ///
- /// A to check the correct version on.
- /// The expected version.
- /// true when the HttpVersion matches; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasHttpVersion(this HttpResponseMessage httpResponseMessage, Version httpVersion)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- if (httpVersion == null)
- {
- throw new ArgumentNullException(nameof(httpVersion));
- }
-
- return httpResponseMessage.Version == httpVersion;
- }
-
- ///
- /// Determines whether a specific status code is set on a response.
- ///
- /// A to check the correct version on.
- /// The expected status code.
- /// true when the status code matches; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasHttpStatusCode(this HttpResponseMessage httpResponseMessage, HttpStatusCode httpStatusCode)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- return httpResponseMessage.StatusCode == httpStatusCode;
- }
-
- ///
- /// Determines whether a specific reason phrase is set on a response.
- ///
- /// A to check the correct version on.
- /// The expected reason phrase.
- /// true when the reason phrase matches; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasReasonPhrase(this HttpResponseMessage httpResponseMessage, string reasonPhrase)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- if (reasonPhrase == null)
- {
- throw new ArgumentNullException(nameof(reasonPhrase));
- }
-
- return httpResponseMessage.ReasonPhrase == reasonPhrase;
- }
-
- ///
- /// Determines whether a specific header is set on a response.
- ///
- /// This method only checks headers in
- /// A to check the response header on.
- /// The name of the header to locate on the response.
- /// true when the response contains a header with the specified name; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasResponseHeader(this HttpResponseMessage httpResponseMessage, string headerName)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- if (string.IsNullOrEmpty(headerName))
- {
- throw new ArgumentNullException(nameof(headerName));
- }
-
- return httpResponseMessage.Headers.HasHeader(headerName);
- }
-
- ///
- /// Determines whether a specific header with a specific value is set on a response.
- ///
- /// This method only checks headers in
- /// A to check the response header on.
- /// The name of the header to locate on the response.
- /// The value the header should have. Wildcard is supported.
- /// true when the response contains a header with the specified name and value; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasResponseHeader(this HttpResponseMessage httpResponseMessage, string headerName, string headerValue)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- if (string.IsNullOrEmpty(headerName))
- {
- throw new ArgumentNullException(nameof(headerName));
- }
-
- if (string.IsNullOrEmpty(headerValue))
- {
- throw new ArgumentNullException(nameof(headerValue));
- }
-
- return httpResponseMessage.Headers.HasHeader(headerName, headerValue);
- }
-
- ///
- /// Determines whether a specific header is set on a response.
- ///
- /// This method only checks headers in
- /// A to check the content header on.
- /// The name of the header to locate on the response content.
- /// true when the response contains a header with the specified name; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasContentHeader(this HttpResponseMessage httpResponseMessage, string headerName)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- if (string.IsNullOrEmpty(headerName))
- {
- throw new ArgumentNullException(nameof(headerName));
- }
-
- if (httpResponseMessage.Content == null)
- {
- return false;
- }
-
- return httpResponseMessage.Content.Headers.HasHeader(headerName);
- }
-
- ///
- /// Determines whether a specific header with a specific value is set on a response.
- ///
- /// This method only checks headers in
- /// A to check the content header on.
- /// The name of the header to locate on the response content.
- /// The value the header should have. Wildcard is supported.
- /// true when the response contains a header with the specified name and value; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasContentHeader(this HttpResponseMessage httpResponseMessage, string headerName, string headerValue)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- if (string.IsNullOrEmpty(headerName))
- {
- throw new ArgumentNullException(nameof(headerName));
- }
-
- if (string.IsNullOrEmpty(headerValue))
- {
- throw new ArgumentNullException(nameof(headerValue));
- }
-
- if (httpResponseMessage.Content == null)
- {
- return false;
- }
-
- return httpResponseMessage.Content.Headers.HasHeader(headerName, headerValue);
- }
-
- ///
- /// Determines whether the response has content.
- ///
- /// A to check for content.
- /// true when the response has content; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasContent(this HttpResponseMessage httpResponseMessage)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- if (httpResponseMessage.Content == null)
- {
- return false;
- }
-
- var stream = httpResponseMessage.Content.ReadAsStreamAsync().Result;
- return stream.ReadByte() != -1;
- }
-
- ///
- /// Determines whether the response content matches a string pattern.
- ///
- /// A to check the correct content on.
- /// A pattern to match the response content, supports * as wildcards.
- /// true when the response content matches the pattern; otherwise, false.
- [Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
- public static bool HasContent(this HttpResponseMessage httpResponseMessage, string pattern)
- {
- if (httpResponseMessage == null)
- {
- throw new ArgumentNullException(nameof(httpResponseMessage));
- }
-
- if (pattern == null)
- {
- throw new ArgumentNullException(nameof(pattern));
- }
-
- var stringContent = string.Empty;
-
- if (httpResponseMessage.Content != null)
- {
- stringContent = httpResponseMessage.Content.ReadAsStringAsync().Result;
- }
-
- return pattern switch
- {
- "" => stringContent == pattern,
- "*" => true,
- _ => StringMatcher.Matches(stringContent, pattern),
- };
- }
-}
diff --git a/src/TestableHttpClient/PublicAPI.Shipped.txt b/src/TestableHttpClient/PublicAPI.Shipped.txt
index a93af0b..315b9a3 100644
--- a/src/TestableHttpClient/PublicAPI.Shipped.txt
+++ b/src/TestableHttpClient/PublicAPI.Shipped.txt
@@ -10,6 +10,20 @@ override TestableHttpClient.TestableHttpMessageHandler.SendAsync(System.Net.Http
TestableHttpClient.TestableHttpMessageHandlerOptions
TestableHttpClient.TestableHttpMessageHandlerOptions.JsonSerializerOptions.get -> System.Text.Json.JsonSerializerOptions!
TestableHttpClient.TestableHttpMessageHandlerOptions.TestableHttpMessageHandlerOptions() -> void
+TestableHttpClient.TestableHttpMessageHandlerOptions.RoutingOptions.get -> TestableHttpClient.RoutingOptions!
+
+TestableHttpClient.RoutingOptions
+TestableHttpClient.RoutingOptions.HostCaseInsensitive.get -> bool
+TestableHttpClient.RoutingOptions.HostCaseInsensitive.set -> void
+TestableHttpClient.RoutingOptions.PathCaseInsensitive.get -> bool
+TestableHttpClient.RoutingOptions.PathCaseInsensitive.set -> void
+TestableHttpClient.RoutingOptions.RoutingOptions() -> void
+TestableHttpClient.RoutingOptions.SchemeCaseInsensitive.get -> bool
+TestableHttpClient.RoutingOptions.SchemeCaseInsensitive.set -> void
+
+TestableHttpClient.IRoutingResponseBuilder
+TestableHttpClient.IRoutingResponseBuilder.Map(string! route, TestableHttpClient.IResponse! response) -> void
+TestableHttpClient.IRoutingResponseBuilder.MapFallBackResponse(TestableHttpClient.IResponse! fallBackResponse) -> void
TestableHttpClient.IResponse
TestableHttpClient.IResponse.ExecuteAsync(TestableHttpClient.HttpResponseContext! context, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
@@ -22,6 +36,7 @@ static TestableHttpClient.Responses.Extensions.get -> TestableHttpClient.IRespon
static TestableHttpClient.Responses.Json(object? content, string? contentType = null, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null) -> TestableHttpClient.IResponse!
static TestableHttpClient.Responses.Json(object? content, System.Net.HttpStatusCode statusCode, string? contentType = null, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null) -> TestableHttpClient.IResponse!
static TestableHttpClient.Responses.NoContent() -> TestableHttpClient.IResponse!
+static TestableHttpClient.Responses.Route(System.Action! builder) -> TestableHttpClient.IResponse!
static TestableHttpClient.Responses.SelectResponse(System.Func! selector) -> TestableHttpClient.IResponse!
static TestableHttpClient.Responses.Sequenced(params TestableHttpClient.IResponse![]! responses) -> TestableHttpClient.IResponse!
static TestableHttpClient.Responses.StatusCode(System.Net.HttpStatusCode statusCode) -> TestableHttpClient.IResponse!
@@ -59,6 +74,9 @@ TestableHttpClient.IHttpRequestMessagesCheck.WithFilter(System.Func! requestFilter, string! condition) -> TestableHttpClient.IHttpRequestMessagesCheck!
TestableHttpClient.HttpRequestMessageAssertionException
+TestableHttpClient.HttpRequestMessageAssertionException.HttpRequestMessageAssertionException() -> void
+TestableHttpClient.HttpRequestMessageAssertionException.HttpRequestMessageAssertionException(string! message) -> void
+TestableHttpClient.HttpRequestMessageAssertionException.HttpRequestMessageAssertionException(string! message, System.Exception! innerException) -> void
TestableHttpClient.HttpRequestMessagesCheckExtensions
static TestableHttpClient.HttpRequestMessagesCheckExtensions.WithContent(this TestableHttpClient.IHttpRequestMessagesCheck! check, string! pattern) -> TestableHttpClient.IHttpRequestMessagesCheck!
@@ -92,31 +110,6 @@ static TestableHttpClient.HttpRequestMessagesCheckExtensions.WithRequestUri(this
static TestableHttpClient.HttpRequestMessagesCheckExtensions.WithRequestUri(this TestableHttpClient.IHttpRequestMessagesCheck! check, string! pattern, bool ignoreCase, int expectedNumberOfRequests) -> TestableHttpClient.IHttpRequestMessagesCheck!
static TestableHttpClient.HttpRequestMessagesCheckExtensions.WithRequestUri(this TestableHttpClient.IHttpRequestMessagesCheck! check, string! pattern, int expectedNumberOfRequests) -> TestableHttpClient.IHttpRequestMessagesCheck!
-TestableHttpClient.HttpRequestMessageExtensions
-static TestableHttpClient.HttpRequestMessageExtensions.HasContent(this System.Net.Http.HttpRequestMessage! httpRequestMessage) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasContent(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! pattern) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasContentHeader(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! headerName) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasContentHeader(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! headerName, string! headerValue) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasHttpMethod(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! httpMethod) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasHttpMethod(this System.Net.Http.HttpRequestMessage! httpRequestMessage, System.Net.Http.HttpMethod! httpMethod) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasHttpVersion(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! httpVersion) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasHttpVersion(this System.Net.Http.HttpRequestMessage! httpRequestMessage, System.Version! httpVersion) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasMatchingUri(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! pattern, bool ignoreCase = true) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasQueryString(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! pattern) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasRequestHeader(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! headerName) -> bool
-static TestableHttpClient.HttpRequestMessageExtensions.HasRequestHeader(this System.Net.Http.HttpRequestMessage! httpRequestMessage, string! headerName, string! headerValue) -> bool
-
-TestableHttpClient.HttpResponseMessageExtensions
-static TestableHttpClient.HttpResponseMessageExtensions.HasContent(this System.Net.Http.HttpResponseMessage! httpResponseMessage) -> bool
-static TestableHttpClient.HttpResponseMessageExtensions.HasContent(this System.Net.Http.HttpResponseMessage! httpResponseMessage, string! pattern) -> bool
-static TestableHttpClient.HttpResponseMessageExtensions.HasContentHeader(this System.Net.Http.HttpResponseMessage! httpResponseMessage, string! headerName) -> bool
-static TestableHttpClient.HttpResponseMessageExtensions.HasContentHeader(this System.Net.Http.HttpResponseMessage! httpResponseMessage, string! headerName, string! headerValue) -> bool
-static TestableHttpClient.HttpResponseMessageExtensions.HasHttpStatusCode(this System.Net.Http.HttpResponseMessage! httpResponseMessage, System.Net.HttpStatusCode httpStatusCode) -> bool
-static TestableHttpClient.HttpResponseMessageExtensions.HasHttpVersion(this System.Net.Http.HttpResponseMessage! httpResponseMessage, System.Version! httpVersion) -> bool
-static TestableHttpClient.HttpResponseMessageExtensions.HasReasonPhrase(this System.Net.Http.HttpResponseMessage! httpResponseMessage, string! reasonPhrase) -> bool
-static TestableHttpClient.HttpResponseMessageExtensions.HasResponseHeader(this System.Net.Http.HttpResponseMessage! httpResponseMessage, string! headerName) -> bool
-static TestableHttpClient.HttpResponseMessageExtensions.HasResponseHeader(this System.Net.Http.HttpResponseMessage! httpResponseMessage, string! headerName, string! headerValue) -> bool
-
TestableHttpClient.HttpResponseMessageBuilder
TestableHttpClient.HttpResponseMessageBuilder.Build() -> System.Net.Http.HttpResponseMessage!
TestableHttpClient.HttpResponseMessageBuilder.HttpResponseMessageBuilder() -> void
@@ -131,3 +124,8 @@ TestableHttpClient.HttpResponseMessageBuilder.WithResponseHeaders(System.Action<
TestableHttpClient.HttpResponseMessageBuilder.WithStringContent(string! content) -> TestableHttpClient.HttpResponseMessageBuilder!
TestableHttpClient.HttpResponseMessageBuilder.WithStringContent(string! content, System.Text.Encoding? encoding) -> TestableHttpClient.HttpResponseMessageBuilder!
TestableHttpClient.HttpResponseMessageBuilder.WithStringContent(string! content, System.Text.Encoding? encoding, string! mediaType) -> TestableHttpClient.HttpResponseMessageBuilder!
+
+TestableHttpClient.Utils.RouteParserException
+TestableHttpClient.Utils.RouteParserException.RouteParserException() -> void
+TestableHttpClient.Utils.RouteParserException.RouteParserException(string! message) -> void
+TestableHttpClient.Utils.RouteParserException.RouteParserException(string! message, System.Exception! innerException) -> void
diff --git a/src/TestableHttpClient/PublicAPI.Unshipped.txt b/src/TestableHttpClient/PublicAPI.Unshipped.txt
index 6acb480..5f28270 100644
--- a/src/TestableHttpClient/PublicAPI.Unshipped.txt
+++ b/src/TestableHttpClient/PublicAPI.Unshipped.txt
@@ -1,20 +1 @@
-static TestableHttpClient.Responses.Route(System.Action! builder) -> TestableHttpClient.IResponse!
-TestableHttpClient.HttpRequestMessageAssertionException.HttpRequestMessageAssertionException() -> void
-TestableHttpClient.HttpRequestMessageAssertionException.HttpRequestMessageAssertionException(string! message) -> void
-TestableHttpClient.HttpRequestMessageAssertionException.HttpRequestMessageAssertionException(string! message, System.Exception! innerException) -> void
-TestableHttpClient.IRoutingResponseBuilder
-TestableHttpClient.IRoutingResponseBuilder.Map(string! route, TestableHttpClient.IResponse! response) -> void
-TestableHttpClient.IRoutingResponseBuilder.MapFallBackResponse(TestableHttpClient.IResponse! fallBackResponse) -> void
-TestableHttpClient.RoutingOptions
-TestableHttpClient.RoutingOptions.HostCaseInsensitive.get -> bool
-TestableHttpClient.RoutingOptions.HostCaseInsensitive.set -> void
-TestableHttpClient.RoutingOptions.PathCaseInsensitive.get -> bool
-TestableHttpClient.RoutingOptions.PathCaseInsensitive.set -> void
-TestableHttpClient.RoutingOptions.RoutingOptions() -> void
-TestableHttpClient.RoutingOptions.SchemeCaseInsensitive.get -> bool
-TestableHttpClient.RoutingOptions.SchemeCaseInsensitive.set -> void
-TestableHttpClient.TestableHttpMessageHandlerOptions.RoutingOptions.get -> TestableHttpClient.RoutingOptions!
-TestableHttpClient.Utils.RouteParserException
-TestableHttpClient.Utils.RouteParserException.RouteParserException() -> void
-TestableHttpClient.Utils.RouteParserException.RouteParserException(string! message) -> void
-TestableHttpClient.Utils.RouteParserException.RouteParserException(string! message, System.Exception! innerException) -> void
+
\ No newline at end of file
diff --git a/test/TestableHttpClient.Tests/HttpRequestMessageAsserterTests.cs b/test/TestableHttpClient.Tests/HttpRequestMessageAsserterTests.cs
index 977c190..b02b5d2 100644
--- a/test/TestableHttpClient.Tests/HttpRequestMessageAsserterTests.cs
+++ b/test/TestableHttpClient.Tests/HttpRequestMessageAsserterTests.cs
@@ -93,7 +93,6 @@ public void WithFilter_WithRequestExpectation_PredicateThatDoesMatchAnyRequests_
}
[Fact]
- [Obsolete("Testing obsolete code")]
public void WithFilter_WithDisposedRequestContent_DoesThrowSensibleException()
{
StringContent content = new("");
@@ -101,7 +100,7 @@ public void WithFilter_WithDisposedRequestContent_DoesThrowSensibleException()
HttpRequestMessage request = new() { Content = content };
HttpRequestMessageAsserter sut = new(new[] { request });
- var exception = Assert.Throws(() => sut.WithFilter(x => x.HasContent("test"), 1, "disposed check"));
+ var exception = Assert.Throws(() => sut.WithContent("test", 1));
Assert.Equal("Can't validate requests, because one or more requests have content that is already disposed.", exception.Message);
}
}
diff --git a/test/TestableHttpClient.Tests/HttpRequestMessageExtensionsTests/HasContent.cs b/test/TestableHttpClient.Tests/HttpRequestMessageExtensionsTests/HasContent.cs
index 3580b3a..018ced0 100644
--- a/test/TestableHttpClient.Tests/HttpRequestMessageExtensionsTests/HasContent.cs
+++ b/test/TestableHttpClient.Tests/HttpRequestMessageExtensionsTests/HasContent.cs
@@ -1,6 +1,5 @@
namespace TestableHttpClient.Tests;
-[Obsolete("Testing obsolete methods")]
public partial class HttpRequestMessageExtensionsTests
{
[Fact]
diff --git a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContent.cs b/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContent.cs
deleted file mode 100644
index 878ce6b..0000000
--- a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContent.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-namespace TestableHttpClient.Tests;
-
-[Obsolete("Testing obsolete methods")]
-public partial class HttpResponseMessageExtensionsTests
-{
-#nullable disable
- [Fact]
- public void HasContent_NullResponse_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasContent());
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-#nullable restore
-
- [Fact]
- public void HasContent_NullContent_ReturnsFalse()
- {
- using var sut = new HttpResponseMessage();
-
- Assert.False(sut.HasContent());
- }
-
- [Fact]
- public void HasContent_EmptyContent_ReturnsFalse()
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("")
- };
-
- Assert.False(sut.HasContent());
- }
-
- [Fact]
- public void HasContent_NotEmptyContent_ReturnsTrue()
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("Some Content")
- };
-
- Assert.True(sut.HasContent());
- }
-}
diff --git a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContentHeader.cs b/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContentHeader.cs
deleted file mode 100644
index 095a2c9..0000000
--- a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContentHeader.cs
+++ /dev/null
@@ -1,150 +0,0 @@
-namespace TestableHttpClient.Tests;
-
-public partial class HttpResponseMessageExtensionsTests
-{
-#nullable disable
- [Fact]
- public void HasContentHeader_NullRequest_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasContentHeader("Content-Disposition"));
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- public void HasContentHeader_NullHeaderName_ThrowsArgumentNullException(string headerName)
- {
- using var sut = new HttpResponseMessage();
-
- var exception = Assert.Throws(() => sut.HasContentHeader(headerName));
- Assert.Equal("headerName", exception.ParamName);
- }
-
- [Fact]
- public void HasContentHeader_NullRequestNonNullHeaderNameAndNonNullHeaderValue_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasContentHeader("Content-Disposition", "inline"));
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- public void HasContentHeader_NullHeaderNameAndNonNullHeaderValue_ThrowsArgumentNullException(string headerName)
- {
- using var sut = new HttpResponseMessage();
- var exception = Assert.Throws(() => sut.HasContentHeader(headerName, "inline"));
- Assert.Equal("headerName", exception.ParamName);
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- public void HasContentHeader_NonNullHeaderNameAndNullHeaderValue_ThrowsArgumentNullException(string headerValue)
- {
- using var sut = new HttpResponseMessage();
- var exception = Assert.Throws(() => sut.HasContentHeader("Content-Disposition", headerValue));
- Assert.Equal("headerValue", exception.ParamName);
- }
-#nullable restore
-
- [Fact]
- public void HasContentHeader_ExistingHeaderName_ReturnsTrue()
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("")
- };
- sut.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline");
-
- Assert.True(sut.HasContentHeader("Content-Disposition"));
- }
-
- [Theory]
- [InlineData("Host")]
- [InlineData("Content-Disposition")]
- public void HasContentHeader_NotExistingHeaderName_ReturnsFalse(string headerName)
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("")
- };
-
- Assert.False(sut.HasContentHeader(headerName));
- }
-
- [Fact]
- public void HasContentHeader_NoContent_ReturnsFalse()
- {
- using var sut = new HttpResponseMessage
- {
- Content = null
- };
-
- Assert.False(sut.HasContentHeader("Content-Disposition"));
- }
-
- [Theory]
- [InlineData("inline; filename=empty.file")]
- [InlineData("inline; *")]
- [InlineData("*; filename=empty.file")]
- [InlineData("*")]
- public void HasContentHeader_ExistingHeaderNameMatchingValue_ReturnsTrue(string value)
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("")
- };
- sut.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
- {
- FileName = "empty.file"
- };
-
- Assert.True(sut.HasContentHeader("Content-Disposition", value));
- }
-
- [Fact]
- public void HasContentHeader_NotExitingHeaderNameAndValue_ReturnsFalse()
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("")
- };
-
- Assert.False(sut.HasContentHeader("Host", "inline"));
- }
-
- [Fact]
- public void HasContentHeader_WithValue_NoContent_ReturnsFalse()
- {
- using var sut = new HttpResponseMessage
- {
- Content = null
- };
-
- Assert.False(sut.HasContentHeader("Content-Disposition", "inline"));
- }
-
- [Theory]
- [InlineData("inline; filename=emtpy.file")]
- [InlineData("inline; *")]
- [InlineData("*; filename=empty.file")]
- public void HasContentHeader_ExistingHeaderNameNotMatchingValue_ReturnsFalse(string value)
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("")
- };
- sut.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
- {
- FileName = "attachment.file"
- };
-
- Assert.False(sut.HasContentHeader("Content-Disposition", value));
- }
-}
diff --git a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContentWithPattern.cs b/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContentWithPattern.cs
deleted file mode 100644
index 2bde077..0000000
--- a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasContentWithPattern.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-namespace TestableHttpClient.Tests;
-
-public partial class HttpResponseMessageExtensionsTests
-{
-#nullable disable
- [Fact]
- public void HasContentWithPattern_NullResponse_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasContent(""));
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-
- [Fact]
- public void HasContentWithPattern_NullExpectedContent_ThrowsArgumentNullException()
- {
- using var sut = new HttpResponseMessage();
-
- var exception = Assert.Throws(() => sut.HasContent(null));
- Assert.Equal("pattern", exception.ParamName);
- }
-#nullable enable
-
- [Fact]
- public void HasContentWithPattern_NoContentAndEmptyPattern_ReturnsTrue()
- {
- using var sut = new HttpResponseMessage();
-
- Assert.True(sut.HasContent(""));
- }
-
- [Theory]
- [InlineData("")]
- [InlineData("Some text")]
- [InlineData("{\"key\":\"value\"}")]
- public void HasContentWithPattern_ExactlyMatchingStringContent_ReturnsTrue(string content)
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent(content)
- };
-
- Assert.True(sut.HasContent(content));
- }
-
- [Theory]
- [InlineData("")]
- [InlineData("Some text")]
- [InlineData("{\"key\":\"value\"}")]
- public void HasContentWithPattern_NotMatchingStringContent_ReturnsFalse(string content)
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("Example content")
- };
-
- Assert.False(sut.HasContent(content));
- }
-
- [Theory]
- [InlineData("*")]
- [InlineData("username=*&password=*")]
- [InlineData("*admin*")]
- public void HasContentWithPattern_MatchingPattern_ReturnsTrue(string pattern)
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("username=admin&password=admin")
- };
-
- Assert.True(sut.HasContent(pattern));
- }
-
- [Theory]
- [InlineData("admin")]
- [InlineData("*test*")]
- public void HasContentWithPattern_NotMatchingPattern_ReturnsFalse(string pattern)
- {
- using var sut = new HttpResponseMessage
- {
- Content = new StringContent("username=admin&password=admin")
- };
-
- Assert.False(sut.HasContent(pattern));
- }
-}
diff --git a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasHttpStatusCode.cs b/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasHttpStatusCode.cs
deleted file mode 100644
index dad4377..0000000
--- a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasHttpStatusCode.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-namespace TestableHttpClient.Tests;
-
-public partial class HttpResponseMessageExtensionsTests
-{
-#nullable disable
- [Fact]
- public void HasHttpStatusCode_WithHttpStatusCode_NullHttpResponseMessage_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasHttpStatusCode(HttpStatusCode.OK));
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-#nullable restore
-
- [Fact]
- public void HasHttpStatusCode_WithHttpStatusCode_CorrectHttpStatusCode_ReturnsTrue()
- {
- using var sut = new HttpResponseMessage(HttpStatusCode.OK);
-
- Assert.True(sut.HasHttpStatusCode(HttpStatusCode.OK));
- }
-
- [Fact]
- public void HasHttpStatusCode_WithHttpStatusCode_IncorrectHttpStatusCode_ReturnsFalse()
- {
- using var sut = new HttpResponseMessage(HttpStatusCode.BadRequest);
-
- Assert.False(sut.HasHttpStatusCode(HttpStatusCode.OK));
- }
-}
diff --git a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasHttpVersion.cs b/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasHttpVersion.cs
deleted file mode 100644
index 68d832e..0000000
--- a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasHttpVersion.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-namespace TestableHttpClient.Tests;
-
-public partial class HttpResponseMessageExtensionsTests
-{
-#nullable disable
- [Fact]
- public void HasHttpVersion_WithVersion_NullResponse_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasHttpVersion(HttpVersion.Version11));
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-
- [Fact]
- public void HasHttpVersion_WithVersion_NullVersion_ThrowsArgumentNullException()
- {
-#if NETFRAMEWORK
- using var sut = new HttpResponseMessage { Version = new Version(0, 0) };
-#else
- using var sut = new HttpResponseMessage { Version = HttpVersion.Unknown };
-#endif
-
- var exception = Assert.Throws(() => sut.HasHttpVersion(null));
- Assert.Equal("httpVersion", exception.ParamName);
- }
-#nullable restore
-
- [Fact]
- public void HasHttpVersion_WithVersion_CorrectVersion_ReturnsTrue()
- {
- using var sut = new HttpResponseMessage { Version = HttpVersion.Version11 };
-
- Assert.True(sut.HasHttpVersion(HttpVersion.Version11));
- }
-
- [Fact]
- public void HasHttpVersion_WithVersion_IncorrectVersion_ReturnsFalse()
- {
- using var sut = new HttpResponseMessage { Version = HttpVersion.Version11 };
-
- Assert.False(sut.HasHttpVersion(HttpVersion.Version10));
- }
-}
diff --git a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasReasonPhrase.cs b/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasReasonPhrase.cs
deleted file mode 100644
index 8d5b614..0000000
--- a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasReasonPhrase.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-namespace TestableHttpClient.Tests;
-
-public partial class HttpResponseMessageExtensionsTests
-{
-#nullable disable
- [Fact]
- public void HasReasonPhrase_WithReasonPhrase_NullResponse_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasReasonPhrase("OK"));
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-
- [Fact]
- public void HasReasonPhrase_WithNullReasonPhrase_ThrowsArgumentNullException()
- {
- using var sut = new HttpResponseMessage { ReasonPhrase = "OK" };
-
- var exception = Assert.Throws(() => sut.HasReasonPhrase(null));
- Assert.Equal("reasonPhrase", exception.ParamName);
- }
-#nullable restore
-
- [Theory]
- [InlineData("")]
- [InlineData("OK")]
- public void HasReasonPhrase_WithCorrectReasonPhrase_ReturnsTrue(string reasonPhrase)
- {
- using var sut = new HttpResponseMessage { ReasonPhrase = reasonPhrase };
-
- Assert.True(sut.HasReasonPhrase(reasonPhrase));
- }
-
- [Theory]
- [InlineData("")]
- [InlineData("NotFound")]
- public void HasReasonPhrase_WithIncorrectReasonPhrase_ReturnsTrue(string reasonPhrase)
- {
- using var sut = new HttpResponseMessage { ReasonPhrase = "OK" };
-
- Assert.False(sut.HasReasonPhrase(reasonPhrase));
- }
-}
diff --git a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasResponseHeader.cs b/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasResponseHeader.cs
deleted file mode 100644
index a004073..0000000
--- a/test/TestableHttpClient.Tests/HttpResponseMessageExtensionsTests/HasResponseHeader.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-namespace TestableHttpClient.Tests;
-
-public partial class HttpResponseMessageExtensionsTests
-{
-#nullable disable
- [Fact]
- public void HasResponseHeader_NullResponse_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasResponseHeader("Server"));
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- public void HasResponseHeader_NullHeaderName_ThrowsArgumentNullException(string headerName)
- {
- using var sut = new HttpResponseMessage();
-
- var exception = Assert.Throws(() => sut.HasResponseHeader(headerName));
- Assert.Equal("headerName", exception.ParamName);
- }
-
- [Fact]
- public void HasResponseHeader_NullResponseNonNullHeaderNameAndNonNullHeaderValue_ThrowsArgumentNullException()
- {
- HttpResponseMessage sut = null;
-
- var exception = Assert.Throws(() => sut.HasResponseHeader("Server", "value"));
- Assert.Equal("httpResponseMessage", exception.ParamName);
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- public void HasResponseHeader_NullHeaderNameAndNonNullHeaderValue_ThrowsArgumentNullException(string headerName)
- {
- using var sut = new HttpResponseMessage();
- var exception = Assert.Throws(() => sut.HasResponseHeader(headerName, "value"));
- Assert.Equal("headerName", exception.ParamName);
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- public void HasResponseHeader_NonNullHeaderNameAndNullHeaderValue_ThrowsArgumentNullException(string headerValue)
- {
- using var sut = new HttpResponseMessage();
- var exception = Assert.Throws(() => sut.HasResponseHeader("Server", headerValue));
- Assert.Equal("headerValue", exception.ParamName);
- }
-#nullable restore
-
- [Fact]
- public void HasRequestHeader_ExistingHeaderName_ReturnsTrue()
- {
- using var sut = new HttpResponseMessage();
- sut.Headers.Add("Server", "example server");
-
- Assert.True(sut.HasResponseHeader("Server"));
- }
-
- [Theory]
- [InlineData("Host")]
- [InlineData("Content-Type")]
- public void HasRequestHeader_NotExistingHeaderName_ReturnsFalse(string headerName)
- {
- using var sut = new HttpResponseMessage();
-
- Assert.False(sut.HasResponseHeader(headerName));
- }
-
- [Theory]
- [InlineData("example server")]
- [InlineData("example*")]
- [InlineData("*server")]
- [InlineData("*")]
- public void HasResponseHeader_ExistingHeaderNameMatchingValue_ReturnsTrue(string value)
- {
- using var sut = new HttpResponseMessage();
- sut.Headers.Add("Server", "example server");
-
- Assert.True(sut.HasResponseHeader("Server", value));
- }
-
- [Fact]
- public void HasResponseHeader_NotExitingHeaderNameAndValue_ReturnsFalse()
- {
- using var sut = new HttpResponseMessage();
-
- Assert.False(sut.HasResponseHeader("Content-Type"));
- }
-
- [Theory]
- [InlineData("example server")]
- [InlineData("example*")]
- [InlineData("*server")]
- public void HasResponseHeader_ExistingHeaderNameNotMatchingValue_ReturnsFalse(string value)
- {
- using var sut = new HttpResponseMessage();
- sut.Headers.Add("Server", "My Application");
-
- Assert.False(sut.HasResponseHeader("Server", value));
- }
-}
diff --git a/version.json b/version.json
index 220d6b2..6c43ec2 100644
--- a/version.json
+++ b/version.json
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
- "version": "0.9-beta",
+ "version": "0.9",
"versionHeightOffset": -1,
"publicReleaseRefSpec": [
"^refs/tags/v\\d+(?:\\.\\d+)?$"