mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
New: Rewrite of download decision engine.
This commit is contained in:
parent
a168bdfa00
commit
5717b7f596
60 changed files with 2013 additions and 1745 deletions
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Providers.DownloadClients;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class BlackholeProviderFixture : CoreTest
|
||||
{
|
||||
private const string nzbUrl = "http://www.nzbs.com/url";
|
||||
private const string title = "some_nzb_title";
|
||||
private const string blackHoleFolder = @"d:\nzb\blackhole\";
|
||||
private const string nzbPath = @"d:\nzb\blackhole\some_nzb_title.nzb";
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.BlackholeDirectory).Returns(blackHoleFolder);
|
||||
}
|
||||
|
||||
|
||||
private void WithExistingFile()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.FileExists(nzbPath)).Returns(true);
|
||||
}
|
||||
|
||||
private void WithFailedDownload()
|
||||
{
|
||||
Mocker.GetMock<HttpProvider>().Setup(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>())).Throws(new WebException());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DownloadNzb_should_download_file_if_it_doesnt_exist()
|
||||
{
|
||||
Mocker.Resolve<BlackholeProvider>().DownloadNzb(nzbUrl, title).Should().BeTrue();
|
||||
|
||||
Mocker.GetMock<HttpProvider>().Verify(c => c.DownloadFile(nzbUrl, nzbPath),Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DownloadNzb_not_download_file_if_it_doesn_exist()
|
||||
{
|
||||
WithExistingFile();
|
||||
|
||||
Mocker.Resolve<BlackholeProvider>().DownloadNzb(nzbUrl, title).Should().BeTrue();
|
||||
|
||||
Mocker.GetMock<HttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_on_failed_download()
|
||||
{
|
||||
WithFailedDownload();
|
||||
|
||||
Mocker.Resolve<BlackholeProvider>().DownloadNzb(nzbUrl, title).Should().BeFalse();
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue