From 88339df298016496d814e4df7d3abdf26e84447c Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 11 Apr 2022 19:26:58 +0800 Subject: ... --- .../IntegratedTests2/HttpClientTestExtensions.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs') diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs b/BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs index cd7daf3e..48496853 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests2/HttpClientTestExtensions.cs @@ -12,7 +12,7 @@ namespace Timeline.Tests.IntegratedTests2 public static class HttpClientTestExtensions { - public static async Task TestSendAsync(this HttpClient client, HttpMethod method, string url, HttpContent? body = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, RequestSetupAsync? requestSetup = null) + public static async Task TestSendAsync(this HttpClient client, HttpMethod method, string url, HttpContent? body = null, HttpStatusCode? expectedStatusCode = null, RequestSetupAsync? requestSetup = null) { using var req = new HttpRequestMessage { @@ -23,7 +23,14 @@ namespace Timeline.Tests.IntegratedTests2 var task = requestSetup?.Invoke(req); if (task is not null) await task; var res = await client.SendAsync(req); - res.StatusCode.Should().Be(expectedStatusCode); + if (expectedStatusCode is null) + { + ((int)res.StatusCode).Should().BeGreaterThanOrEqualTo(200).And.BeLessThan(300); + } + else + { + res.StatusCode.Should().Be(expectedStatusCode.Value); + } return res; } @@ -34,13 +41,13 @@ namespace Timeline.Tests.IntegratedTests2 return body!; } - public static async Task TestJsonSendAsync(this HttpClient client, HttpMethod method, string url, object? jsonBody = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, RequestSetupAsync? requestSetup = null) + public static async Task TestJsonSendAsync(this HttpClient client, HttpMethod method, string url, object? jsonBody = null, HttpStatusCode? expectedStatusCode = null, RequestSetupAsync? requestSetup = null) { using JsonContent? reqContent = jsonBody is null ? null : JsonContent.Create(jsonBody, options: CommonJsonSerializeOptions.Options); await client.TestSendAsync(method, url, reqContent, expectedStatusCode, requestSetup); } - public static async Task TestJsonSendAsync(this HttpClient client, HttpMethod method, string url, object? jsonBody = null, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, RequestSetupAsync? requestSetup = null) + public static async Task TestJsonSendAsync(this HttpClient client, HttpMethod method, string url, object? jsonBody = null, HttpStatusCode? expectedStatusCode = null, RequestSetupAsync? requestSetup = null) { using JsonContent? reqContent = jsonBody == null ? null : JsonContent.Create(jsonBody, options: CommonJsonSerializeOptions.Options); var res = await client.TestSendAsync(method, url, reqContent, expectedStatusCode, requestSetup); -- cgit v1.2.3