1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00
Radarr/NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs
2013-02-15 16:52:46 -08:00

103 lines
3.2 KiB
C#

using System;
using System.IO;
using System.Linq;
using System.Net;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
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;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class BannerProviderTest : SqlCeTest
{
private Series _series;
[SetUp]
public void Setup()
{
WithTempAsAppPath();
_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();
var result = Mocker.Resolve<BannerProvider>().Download(_series);
result.Should().BeTrue();
}
[Test]
public void Download_should_return_false_when_banner_download_fails()
{
WithFailedDownload();
var result = Mocker.Resolve<BannerProvider>().Download(_series);
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();
ExceptionVerification.ExpectedWarns(1);
}
}
}