2012-03-07 05:53:49 +03:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common;
|
2013-02-19 09:01:03 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
2012-03-07 05:53:49 +03:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2012-03-07 10:34:26 +03:00
|
|
|
using NzbDrone.Test.Common;
|
2012-03-07 05:53:49 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 08:44:06 +03:00
|
|
|
public class BannerProviderTest : CoreTest
|
2012-03-07 05:53:49 +03:00
|
|
|
{
|
|
|
|
private Series _series;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2012-03-07 10:34:26 +03:00
|
|
|
WithTempAsAppPath();
|
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
_series = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.SeriesId = 12345)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var path = @"C:\Windows\Temp";
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.CreateDirectory(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WithSuccessfulDownload()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WithFailedDownload()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
.Throws(new WebException("Failed to download file (Mocked)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Download_should_return_true_when_banner_is_downloaded_successfully()
|
|
|
|
{
|
|
|
|
WithSuccessfulDownload();
|
2012-03-07 23:37:36 +03:00
|
|
|
var result = Mocker.Resolve<BannerProvider>().Download(_series);
|
2012-03-07 05:53:49 +03:00
|
|
|
result.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Download_should_return_false_when_banner_download_fails()
|
|
|
|
{
|
|
|
|
WithFailedDownload();
|
2012-03-07 23:37:36 +03:00
|
|
|
var result = Mocker.Resolve<BannerProvider>().Download(_series);
|
2012-03-07 05:53:49 +03:00
|
|
|
result.Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Delete_should_delete_banner_file_when_it_exists()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.FileExists(It.IsAny<string>()))
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFile(It.IsAny<string>()));
|
|
|
|
|
|
|
|
var result = Mocker.Resolve<BannerProvider>().Delete(1);
|
|
|
|
result.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Delete_should_return_true_even_when_file_sint_deleted()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.FileExists(It.IsAny<string>()))
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
var result = Mocker.Resolve<BannerProvider>().Delete(1);
|
|
|
|
result.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Delete_should_return_false_when_file_fails_to_delete()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.FileExists(It.IsAny<string>()))
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFile(It.IsAny<string>()))
|
|
|
|
.Throws(new SystemException("File not found."));
|
|
|
|
|
|
|
|
var result = Mocker.Resolve<BannerProvider>().Delete(1);
|
|
|
|
result.Should().BeFalse();
|
2012-03-07 10:34:26 +03:00
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2012-03-07 05:53:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|