mirror of
https://github.com/Radarr/Radarr
synced 2026-05-07 06:21:00 +02:00
Fix: Return empty Freebox task list instead of null
This commit is contained in:
parent
89110c2cc8
commit
64796e38ec
2 changed files with 69 additions and 1 deletions
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Download.Clients.FreeboxDownload;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class FreeboxDownloadProxyFixture : CoreTest<FreeboxDownloadProxy>
|
||||
{
|
||||
protected FreeboxDownloadSettings _settings;
|
||||
protected string _cachedHeaderKeyValue;
|
||||
protected byte[] _successfulEmptyResponseBytes;
|
||||
|
||||
protected Mock<ICached<string>> _cachedHeaderKey;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new FreeboxDownloadSettings()
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
Port = 443,
|
||||
ApiUrl = "/api/v1/",
|
||||
AppId = "someid",
|
||||
AppToken = "S0mEv3RY1oN9T0k3n"
|
||||
};
|
||||
|
||||
_cachedHeaderKeyValue = "abcdefg123456";
|
||||
|
||||
var rawSuccessfulEmptyResponse = "{ \"success\": true }";
|
||||
_successfulEmptyResponseBytes = Encoding.UTF8.GetBytes(rawSuccessfulEmptyResponse);
|
||||
|
||||
_cachedHeaderKey = Mocker.GetMock<ICached<string>>();
|
||||
Mocker.GetMock<ICacheManager>()
|
||||
.Setup(c => c.GetCache<string>(It.IsAny<Type>(), It.IsAny<string>()))
|
||||
.Returns(_cachedHeaderKey.Object);
|
||||
}
|
||||
|
||||
protected void GivenCachedHeaderKey()
|
||||
{
|
||||
_cachedHeaderKey.Setup(c => c.Find(It.IsAny<string>()))
|
||||
.Returns<string>(r => _cachedHeaderKeyValue);
|
||||
}
|
||||
|
||||
protected void GivenSuccessfulEmptyResponse()
|
||||
{
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(s => s.Execute(It.IsAny<HttpRequest>()))
|
||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), _successfulEmptyResponseBytes, statusCode: HttpStatusCode.OK));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetTasks_WithSuccessfulEmptyResponse_ShouldBeEmpty()
|
||||
{
|
||||
GivenCachedHeaderKey();
|
||||
GivenSuccessfulEmptyResponse();
|
||||
|
||||
Subject.GetTasks(_settings).Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ public List<FreeboxDownloadTask> GetTasks(FreeboxDownloadSettings settings)
|
|||
{
|
||||
var request = BuildRequest(settings).Resource("/downloads/").Build();
|
||||
|
||||
return ProcessRequest<List<FreeboxDownloadTask>>(request, settings).Result;
|
||||
return ProcessRequest<List<FreeboxDownloadTask>>(request, settings).Result ?? new ();
|
||||
}
|
||||
|
||||
private static string BuildCachedHeaderKey(FreeboxDownloadSettings settings)
|
||||
|
|
|
|||
Loading…
Reference in a new issue