diff options
author | crupest <crupest@outlook.com> | 2020-03-13 18:09:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-13 18:09:50 +0800 |
commit | b20c488a9b02807cfa117b10dd8906271af03614 (patch) | |
tree | 23167ac72ad2a0a878eacbfec7fdd9b8b4a81c55 /Timeline.Tests/Helpers/CacheTestHelper.cs | |
parent | d51954c2eaf07769e045270a02c19e46e01fe73f (diff) | |
parent | 5edffd0242a16e9866a1f4e9f1e1d2ff4e549d2c (diff) | |
download | timeline-b20c488a9b02807cfa117b10dd8906271af03614.tar.gz timeline-b20c488a9b02807cfa117b10dd8906271af03614.tar.bz2 timeline-b20c488a9b02807cfa117b10dd8906271af03614.zip |
Merge pull request #71 from crupest/cache
Add cache support for timeline post data.
Diffstat (limited to 'Timeline.Tests/Helpers/CacheTestHelper.cs')
-rw-r--r-- | Timeline.Tests/Helpers/CacheTestHelper.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Timeline.Tests/Helpers/CacheTestHelper.cs b/Timeline.Tests/Helpers/CacheTestHelper.cs new file mode 100644 index 00000000..b3709a28 --- /dev/null +++ b/Timeline.Tests/Helpers/CacheTestHelper.cs @@ -0,0 +1,64 @@ +using FluentAssertions;
+using System;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Threading.Tasks;
+using Timeline.Models.Http;
+
+namespace Timeline.Tests.Helpers
+{
+ public static class CacheTestHelper
+ {
+ public static async Task TestCache(HttpClient client, string getUrl)
+ {
+ EntityTagHeaderValue eTag;
+ {
+ var res = await client.GetAsync(getUrl);
+ res.Should().HaveStatusCode(200);
+ var cacheControlHeader = res.Headers.CacheControl;
+ cacheControlHeader.NoCache.Should().BeTrue();
+ cacheControlHeader.NoStore.Should().BeFalse();
+ cacheControlHeader.Private.Should().BeTrue();
+ cacheControlHeader.Public.Should().BeFalse();
+ cacheControlHeader.MustRevalidate.Should().BeTrue();
+ cacheControlHeader.MaxAge.Should().NotBeNull().And.Be(TimeSpan.FromDays(14));
+ eTag = res.Headers.ETag;
+ }
+
+ {
+ using var request = new HttpRequestMessage()
+ {
+ RequestUri = new Uri(client.BaseAddress, getUrl),
+ Method = HttpMethod.Get,
+ };
+ request.Headers.TryAddWithoutValidation("If-None-Match", "\"dsdfd");
+ var res = await client.SendAsync(request);
+ res.Should().HaveStatusCode(HttpStatusCode.BadRequest)
+ .And.HaveCommonBody(ErrorCodes.Common.Header.IfNonMatch_BadFormat);
+ }
+
+ {
+ using var request = new HttpRequestMessage()
+ {
+ 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);
+ }
+
+ {
+ using var request = new HttpRequestMessage()
+ {
+ 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);
+ }
+ }
+ }
+}
|