aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-15 01:44:48 +0800
committercrupest <crupest@outlook.com>2020-11-15 01:44:48 +0800
commitf5ccd0d9855f82e14c6b765eee6a04b22c50dc8a (patch)
tree5dc8da01f7a01e86bcacf85ac449b24ce4fac3a5 /BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs
parentc6ff19254382ff68f63cb06f39c65e7c8aaa89d7 (diff)
downloadtimeline-f5ccd0d9855f82e14c6b765eee6a04b22c50dc8a.tar.gz
timeline-f5ccd0d9855f82e14c6b765eee6a04b22c50dc8a.tar.bz2
timeline-f5ccd0d9855f82e14c6b765eee6a04b22c50dc8a.zip
...
Diffstat (limited to 'BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs')
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs47
1 files changed, 18 insertions, 29 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs b/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs
index bafb2fcf..8308eca8 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/CacheTestHelper.cs
@@ -13,9 +13,10 @@ namespace Timeline.Tests.IntegratedTests
public static async Task TestCache(HttpClient client, string getUrl)
{
EntityTagHeaderValue eTag;
+
{
var res = await client.GetAsync(getUrl);
- res.Should().HaveStatusCode(200);
+ res.StatusCode.Should().Be(HttpStatusCode.OK);
var cacheControlHeader = res.Headers.CacheControl;
cacheControlHeader.Should().NotBeNull();
cacheControlHeader!.NoCache.Should().BeTrue();
@@ -28,39 +29,27 @@ namespace Timeline.Tests.IntegratedTests
eTag = res.Headers.ETag!;
}
- {
- using var request = new HttpRequestMessage()
+ await client.TestSendAssertErrorAsync(HttpMethod.Get, getUrl,
+ expectedStatusCode: HttpStatusCode.BadRequest,
+ errorCode: ErrorCodes.Common.Header.IfNonMatch_BadFormat,
+ headerSetup: static (headers, _) =>
{
- RequestUri = new Uri(client.BaseAddress!, getUrl),
- Method = HttpMethod.Get,
- };
- request.Headers.TryAddWithoutValidation("If-None-Match", "\"dsdfd");
- var res = await client.SendAsync(request);
- await res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
- .And.HaveCommonBodyWithCodeAsync(ErrorCodes.Common.Header.IfNonMatch_BadFormat);
- }
+ headers.TryAddWithoutValidation("If-None-Match", "\"dsdfd");
+ });
- {
- using var request = new HttpRequestMessage()
+ await client.TestSendAsync(HttpMethod.Get, getUrl,
+ expectedStatusCode: HttpStatusCode.OK,
+ headerSetup: static (headers, _) =>
{
- RequestUri = new Uri(client.BaseAddress!, getUrl),
- Method = HttpMethod.Get,
- };
- request.Headers.TryAddWithoutValidation("If-None-Match", "\"aaa\"");
- var res = await client.SendAsync(request);
- res.Should().HaveStatusCode(HttpStatusCode.OK);
- }
+ headers.TryAddWithoutValidation("If-None-Match", "\"aaa\"");
+ });
- {
- using var request = new HttpRequestMessage()
+ await client.TestSendAsync(HttpMethod.Get, getUrl,
+ expectedStatusCode: HttpStatusCode.NotModified,
+ headerSetup: (headers, _) =>
{
- RequestUri = new Uri(client.BaseAddress!, getUrl),
- Method = HttpMethod.Get,
- };
- request.Headers.Add("If-None-Match", eTag.ToString());
- var res = await client.SendAsync(request);
- res.Should().HaveStatusCode(HttpStatusCode.NotModified);
- }
+ headers.Add("If-None-Match", eTag.ToString());
+ });
}
}
}