Use modern HttpClient

(cherry picked from commit 402f8b296f17bf161824ec5ff40d67d036d00d94)
This commit is contained in:
ta264
2021-11-10 21:59:08 +00:00
parent 5f946c0aa3
commit cef15887a4
39 changed files with 372 additions and 318 deletions
@@ -1,5 +1,6 @@
using System.Linq;
using System.Net;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using FluentAssertions;
using NUnit.Framework;
@@ -8,25 +9,30 @@ namespace NzbDrone.Integration.Test
[TestFixture]
public class IndexHtmlFixture : IntegrationTest
{
private HttpClient _httpClient = new HttpClient();
[Test]
public void should_get_index_html()
{
var text = new WebClient().DownloadString(RootUrl);
var request = new HttpRequestMessage(HttpMethod.Get, RootUrl);
var response = _httpClient.Send(request);
var text = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
text.Should().NotBeNullOrWhiteSpace();
}
[Test]
public void index_should_not_be_cached()
{
var client = new WebClient();
_ = client.DownloadString(RootUrl);
var request = new HttpRequestMessage(HttpMethod.Get, RootUrl);
var response = _httpClient.Send(request);
var headers = client.ResponseHeaders;
var headers = response.Headers;
headers.Get("Cache-Control").Split(',').Select(x => x.Trim())
.Should().BeEquivalentTo("no-store, no-cache".Split(',').Select(x => x.Trim()));
headers.Get("Pragma").Should().Be("no-cache");
headers.Get("Expires").Should().Be("-1");
headers.CacheControl.NoStore.Should().BeTrue();
headers.CacheControl.NoCache.Should().BeTrue();
headers.Pragma.Should().Contain(new NameValueHeaderValue("no-cache"));
response.Content.Headers.Expires.Should().BeBefore(DateTime.UtcNow);
}
}
}