New: Async HttpClient

(cherry picked from commit 0feee191462dd3e5dde66e476e8b4b46a85ec4f0)
This commit is contained in:
Bogdan
2023-07-16 21:07:31 +03:00
parent 29118cda45
commit 1f95bcae4e
58 changed files with 680 additions and 555 deletions
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;
using NUnit.Framework;
@@ -103,8 +104,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
protected void GivenSuccessfulDownload()
{
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[1000]));
.Setup(s => s.GetAsync(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => Task.FromResult(new HttpResponse(r, new HttpHeader(), new byte[1000])));
Mocker.GetMock<IHadoukenProxy>()
.Setup(s => s.AddTorrentUri(It.IsAny<HadoukenSettings>(), It.IsAny<string>()))
@@ -196,13 +197,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
}
[Test]
public void Download_should_return_unique_id()
public async Task Download_should_return_unique_id()
{
GivenSuccessfulDownload();
var remoteBook = CreateRemoteBook();
var id = Subject.Download(remoteBook, CreateIndexer());
var id = await Subject.Download(remoteBook, CreateIndexer());
id.Should().NotBeNullOrEmpty();
}
@@ -277,7 +278,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
}
[Test]
public void Download_from_magnet_link_should_return_hash_uppercase()
public async Task Download_from_magnet_link_should_return_hash_uppercase()
{
var remoteBook = CreateRemoteBook();
@@ -286,13 +287,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
Mocker.GetMock<IHadoukenProxy>()
.Setup(v => v.AddTorrentUri(It.IsAny<HadoukenSettings>(), It.IsAny<string>()));
var result = Subject.Download(remoteBook, CreateIndexer());
var result = await Subject.Download(remoteBook, CreateIndexer());
Assert.IsFalse(result.Any(c => char.IsLower(c)));
}
[Test]
public void Download_from_torrent_file_should_return_hash_uppercase()
public async Task Download_from_torrent_file_should_return_hash_uppercase()
{
var remoteBook = CreateRemoteBook();
@@ -300,7 +301,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
.Setup(v => v.AddTorrentFile(It.IsAny<HadoukenSettings>(), It.IsAny<byte[]>()))
.Returns("hash");
var result = Subject.Download(remoteBook, CreateIndexer());
var result = await Subject.Download(remoteBook, CreateIndexer());
Assert.IsFalse(result.Any(c => char.IsLower(c)));
}