Skip to content

Commit 7d88da8

Browse files
committed
Mark types and methods obsolete that should be internal or are going to be removed.
1 parent a7d8a3e commit 7d88da8

File tree

16 files changed

+73
-5
lines changed

16 files changed

+73
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1010
- `TestableHttpMessageHandler.RespondWith(Func<HttpRequestMessage, HttpResponseMessage>)` had been deprecated, it's functionality is replaced by IResponse.
1111
- `RespondWith(this TestableHttpMessageHandler, HttpResponseMessage)` has been deprecated, the response is modified with every call, so it doesn't work reliably and is different from how HttpClientHandler works, which creates a HttpResponseMessage for every request.
1212
- `HttpResponseMessageBuilder` and `RespondWith(this TestableHttpMessageHandler, HttpResponseMessageBuilder)` has been deprecated, it's functionality can be replaced with ConfiguredResponse or a custom IResponse.
13+
- `HttpRequestMessageExtensions` and `HttpResponseMessageExtensions` were introduced as extensions for easier assertion. However, these types are intended for internal use and will be made internal next release.
14+
- TestableHttpClient.NFluent is deprecated and will be removed in the next version.
1315

1416
### Added
1517
- `CreateClient` now accepts `DelegateHandlers` in order to chain Handlers. The InnerHandler property of each handler is set automatically and the `TestableHttpMessageHandler` is automatically set as the last handler. This is showcased with Polly in the integration tests.

src/TestableHttpClient.NFluent/HttpResponseMessageChecks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// <summary>
44
/// A set of NFluent checks to validate <see cref="HttpResponseMessage"/>s.
55
/// </summary>
6+
[Obsolete("These NFluent extensions are no longer supported and will be removed.")]
67
public static class HttpResponseMessageChecks
78
{
89
/// <summary>

src/TestableHttpClient.NFluent/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# TestableHttpClient.NFluent
22

3+
## Status
4+
The NFluent extensions for TestableHttpClient are being deprecated and will no longer ship with the next version of the library.
5+
6+
---
7+
38
In integration tests, asserting HttpResponseMessages can be a real challenge, especially since error messages are sometimes not very clear. NFluent is known for giving clear error messages.
49
`TestableHttpClient.NFluent` is designed to make it easier to check `HttpResponseMessage`s and `TestableHttpClient`s and give clear error messages.
510

src/TestableHttpClient.NFluent/TestableHttpClientChecks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// <summary>
44
/// A set of NFluent checks to check <see cref="TestableHttpMessageHandler"/>.
55
/// </summary>
6+
[Obsolete("These NFluent extensions are no longer supported and will be removed.")]
67
public static class TestableHttpClientChecks
78
{
89
/// <summary>

src/TestableHttpClient/HttpRequestMessageExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// <summary>
44
/// A set of static methods for checking values on a <see cref="HttpRequestMessage"/>.
55
/// </summary>
6+
[Obsolete("This class is not intended for public use and will be marked internal in the next release.")]
67
public static class HttpRequestMessageExtensions
78
{
89
/// <summary>
@@ -11,6 +12,7 @@ public static class HttpRequestMessageExtensions
1112
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct version on.</param>
1213
/// <param name="httpVersion">The expected version.</param>
1314
/// <returns>true when the HttpVersion matches; otherwise, false.</returns>
15+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
1416
public static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, Version httpVersion)
1517
{
1618
if (httpRequestMessage == null)
@@ -32,6 +34,7 @@ public static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, Ve
3234
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct version on.</param>
3335
/// <param name="httpVersion">The expected version.</param>
3436
/// <returns>true when the HttpVersion matches; otherwise, false.</returns>
37+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
3538
public static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, string httpVersion)
3639
{
3740
if (httpRequestMessage == null)
@@ -53,6 +56,7 @@ public static bool HasHttpVersion(this HttpRequestMessage httpRequestMessage, st
5356
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct method on.</param>
5457
/// <param name="httpMethod">The expected method.</param>
5558
/// <returns>true when the HttpMethod matches; otherwise, false.</returns>
59+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
5660
public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, HttpMethod httpMethod)
5761
{
5862
if (httpRequestMessage == null)
@@ -74,6 +78,7 @@ public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, Htt
7478
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct method on.</param>
7579
/// <param name="httpMethod">The expected method.</param>
7680
/// <returns>true when the HttpMethod matches; otherwise, false.</returns>
81+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
7782
public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, string httpMethod)
7883
{
7984
if (httpRequestMessage == null)
@@ -96,6 +101,7 @@ public static bool HasHttpMethod(this HttpRequestMessage httpRequestMessage, str
96101
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the request header on.</param>
97102
/// <param name="headerName">The name of the header to locate on the request.</param>
98103
/// <returns>true when the request contains a header with the specified name; otherwise, false.</returns>
104+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
99105
public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage, string headerName)
100106
{
101107
if (httpRequestMessage == null)
@@ -119,6 +125,7 @@ public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage,
119125
/// <param name="headerName">The name of the header to locate on the request.</param>
120126
/// <param name="headerValue">The value the header should have. Wildcard is supported.</param>
121127
/// <returns>true when the request contains a header with the specified name and value; otherwise, false.</returns>
128+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
122129
public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage, string headerName, string headerValue)
123130
{
124131
if (httpRequestMessage == null)
@@ -146,6 +153,7 @@ public static bool HasRequestHeader(this HttpRequestMessage httpRequestMessage,
146153
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the content header on.</param>
147154
/// <param name="headerName">The name of the header to locate on the request content.</param>
148155
/// <returns>true when the request contains a header with the specified name; otherwise, false.</returns>
156+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
149157
public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage, string headerName)
150158
{
151159
if (httpRequestMessage == null)
@@ -174,6 +182,7 @@ public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage,
174182
/// <param name="headerName">The name of the header to locate on the request content.</param>
175183
/// <param name="headerValue">The value the header should have. Wildcard is supported.</param>
176184
/// <returns>true when the request contains a header with the specified name and value; otherwise, false.</returns>
185+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
177186
public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage, string headerName, string headerValue)
178187
{
179188
if (httpRequestMessage == null)
@@ -205,6 +214,7 @@ public static bool HasContentHeader(this HttpRequestMessage httpRequestMessage,
205214
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct uri on.</param>
206215
/// <param name="pattern">A pattern to match with the request uri, supports * as wildcards.</param>
207216
/// <returns>true when the request uri matches the pattern; otherwise, false.</returns>
217+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
208218
public static bool HasMatchingUri(this HttpRequestMessage httpRequestMessage, string pattern, bool ignoreCase = true)
209219
{
210220
if (httpRequestMessage == null)
@@ -231,6 +241,7 @@ public static bool HasMatchingUri(this HttpRequestMessage httpRequestMessage, st
231241
/// </summary>
232242
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check for content.</param>
233243
/// <returns>true when the request has content; otherwise, false.</returns>
244+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
234245
public static bool HasContent(this HttpRequestMessage httpRequestMessage)
235246
{
236247
if (httpRequestMessage == null)
@@ -247,6 +258,7 @@ public static bool HasContent(this HttpRequestMessage httpRequestMessage)
247258
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct content on.</param>
248259
/// <param name="pattern">A pattern to match the request content, supports * as wildcards.</param>
249260
/// <returns>true when the request content matches the pattern; otherwise, false.</returns>
261+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
250262
public static bool HasContent(this HttpRequestMessage httpRequestMessage, string pattern)
251263
{
252264
if (httpRequestMessage == null)
@@ -280,6 +292,7 @@ public static bool HasContent(this HttpRequestMessage httpRequestMessage, string
280292
/// <param name="httpRequestMessage">A <see cref="HttpRequestMessage"/> to check the correct request uir querystring on.</param>
281293
/// <param name="pattern">A pattern to match the request uri querystring, supports * as wildcards.</param>
282294
/// <returns>true when the request uri querystring matches the pattern; otherwise, false.</returns>
295+
[Obsolete("This method is not intended for public use and will be marked internal in the next release.")]
283296
public static bool HasQueryString(this HttpRequestMessage httpRequestMessage, string pattern)
284297
{
285298
if (httpRequestMessage == null)

src/TestableHttpClient/HttpRequestMessagesCheckExtensions.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace TestableHttpClient;
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace TestableHttpClient;
24

35
public static class HttpRequestMessagesCheckExtensions
46
{
@@ -40,7 +42,9 @@ private static IHttpRequestMessagesCheck WithRequestUri(this IHttpRequestMessage
4042
condition = $"uri pattern '{pattern}'";
4143
}
4244

45+
#pragma warning disable CS0618 // Type or member is obsolete
4346
return check.WithFilter(x => x.HasMatchingUri(pattern, ignoreCase), expectedNumberOfRequests, condition);
47+
#pragma warning restore CS0618 // Type or member is obsolete
4448
}
4549

4650
/// <summary>
@@ -79,7 +83,9 @@ private static IHttpRequestMessagesCheck WithQueryString(this IHttpRequestMessag
7983
_ => $"querystring pattern '{pattern}'"
8084
};
8185

86+
#pragma warning disable CS0618 // Type or member is obsolete
8287
return check.WithFilter(x => x.HasQueryString(pattern), expectedNumberOfRequests, condition);
88+
#pragma warning restore CS0618 // Type or member is obsolete
8389
}
8490

8591
/// <summary>
@@ -111,7 +117,9 @@ private static IHttpRequestMessagesCheck WithHttpMethod(this IHttpRequestMessage
111117
throw new ArgumentNullException(nameof(httpMethod));
112118
}
113119

120+
#pragma warning disable CS0618 // Type or member is obsolete
114121
return check.WithFilter(x => x.HasHttpMethod(httpMethod), expectedNumberOfRequests, $"HTTP Method '{httpMethod}'");
122+
#pragma warning restore CS0618 // Type or member is obsolete
115123
}
116124

117125
/// <summary>
@@ -143,7 +151,9 @@ private static IHttpRequestMessagesCheck WithHttpVersion(this IHttpRequestMessag
143151
throw new ArgumentNullException(nameof(httpVersion));
144152
}
145153

154+
#pragma warning disable CS0618 // Type or member is obsolete
146155
return check.WithFilter(x => x.HasHttpVersion(httpVersion), expectedNumberOfRequests, $"HTTP Version '{httpVersion}'");
156+
#pragma warning restore CS0618 // Type or member is obsolete
147157
}
148158

149159
/// <summary>
@@ -177,7 +187,9 @@ private static IHttpRequestMessagesCheck WithRequestHeader(this IHttpRequestMess
177187
throw new ArgumentNullException(nameof(headerName));
178188
}
179189

190+
#pragma warning disable CS0618 // Type or member is obsolete
180191
return check.WithFilter(x => x.HasRequestHeader(headerName), expectedNumberOfRequests, $"request header '{headerName}'");
192+
#pragma warning restore CS0618 // Type or member is obsolete
181193
}
182194

183195
/// <summary>
@@ -218,7 +230,9 @@ private static IHttpRequestMessagesCheck WithRequestHeader(this IHttpRequestMess
218230
throw new ArgumentNullException(nameof(headerValue));
219231
}
220232

233+
#pragma warning disable CS0618 // Type or member is obsolete
221234
return check.WithFilter(x => x.HasRequestHeader(headerName, headerValue), expectedNumberOfRequests, $"request header '{headerName}' and value '{headerValue}'");
235+
#pragma warning restore CS0618 // Type or member is obsolete
222236
}
223237

224238
/// <summary>
@@ -252,7 +266,9 @@ private static IHttpRequestMessagesCheck WithContentHeader(this IHttpRequestMess
252266
throw new ArgumentNullException(nameof(headerName));
253267
}
254268

269+
#pragma warning disable CS0618 // Type or member is obsolete
255270
return check.WithFilter(x => x.HasContentHeader(headerName), expectedNumberOfRequests, $"content header '{headerName}'");
271+
#pragma warning restore CS0618 // Type or member is obsolete
256272
}
257273

258274
/// <summary>
@@ -293,7 +309,9 @@ private static IHttpRequestMessagesCheck WithContentHeader(this IHttpRequestMess
293309
throw new ArgumentNullException(nameof(headerValue));
294310
}
295311

312+
#pragma warning disable CS0618 // Type or member is obsolete
296313
return check.WithFilter(x => x.HasContentHeader(headerName, headerValue), expectedNumberOfRequests, $"content header '{headerName}' and value '{headerValue}'");
314+
#pragma warning restore CS0618 // Type or member is obsolete
297315
}
298316

299317
/// <summary>
@@ -325,7 +343,9 @@ private static IHttpRequestMessagesCheck WithHeader(this IHttpRequestMessagesChe
325343
throw new ArgumentNullException(nameof(headerName));
326344
}
327345

346+
#pragma warning disable CS0618 // Type or member is obsolete
328347
return check.WithFilter(x => x.HasRequestHeader(headerName) || x.HasContentHeader(headerName), expectedNumberOfRequests, $"header '{headerName}'");
348+
#pragma warning restore CS0618 // Type or member is obsolete
329349
}
330350

331351
/// <summary>
@@ -364,7 +384,9 @@ private static IHttpRequestMessagesCheck WithHeader(this IHttpRequestMessagesChe
364384
throw new ArgumentNullException(nameof(headerValue));
365385
}
366386

387+
#pragma warning disable CS0618 // Type or member is obsolete
367388
return check.WithFilter(x => x.HasRequestHeader(headerName, headerValue) || x.HasContentHeader(headerName, headerValue), expectedNumberOfRequests, $"header '{headerName}' and value '{headerValue}'");
389+
#pragma warning restore CS0618 // Type or member is obsolete
368390
}
369391

370392
/// <summary>
@@ -398,7 +420,9 @@ private static IHttpRequestMessagesCheck WithContent(this IHttpRequestMessagesCh
398420
throw new ArgumentNullException(nameof(pattern));
399421
}
400422

423+
#pragma warning disable CS0618 // Type or member is obsolete
401424
return check.WithFilter(x => x.HasContent(pattern), expectedNumberOfRequests, $"content '{pattern}'");
425+
#pragma warning restore CS0618 // Type or member is obsolete
402426
}
403427

404428
/// <summary>
@@ -447,7 +471,10 @@ private static IHttpRequestMessagesCheck WithJsonContent(this IHttpRequestMessag
447471
}
448472

449473
var jsonString = JsonSerializer.Serialize(jsonObject, jsonSerializerOptions ?? check.Options.JsonSerializerOptions);
474+
475+
#pragma warning disable CS0618 // Type or member is obsolete
450476
return check.WithFilter(x => x.HasContent(jsonString) && x.HasContentHeader("Content-Type", "application/json*"), expectedNumberOfRequests, $"json content '{jsonString}'");
477+
#pragma warning restore CS0618 // Type or member is obsolete
451478
}
452479

453480
/// <summary>
@@ -484,6 +511,8 @@ private static IHttpRequestMessagesCheck WithFormUrlEncodedContent(this IHttpReq
484511
using var content = new FormUrlEncodedContent(nameValueCollection);
485512
var contentString = content.ReadAsStringAsync().Result;
486513

514+
#pragma warning disable CS0618 // Type or member is obsolete
487515
return check.WithFilter(x => x.HasContent(contentString) && x.HasContentHeader("Content-Type", "application/x-www-form-urlencoded*"), expectedNumberOfRequests, $"form url encoded content '{contentString}'");
516+
#pragma warning restore CS0618 // Type or member is obsolete
488517
}
489518
}

0 commit comments

Comments
 (0)