2011-05-24 07:12:54 +03:00
|
|
|
using System;
|
2011-11-14 03:22:18 +03:00
|
|
|
|
2011-05-24 07:12:54 +03:00
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using Moq;
|
2011-06-03 00:06:46 +03:00
|
|
|
using NUnit.Framework;
|
2011-05-24 07:12:54 +03:00
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-01-29 02:53:14 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-05-24 07:12:54 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
2011-05-28 22:23:35 +03:00
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-06-04 04:56:53 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-05-24 07:12:54 +03:00
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-28 22:23:35 +03:00
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-05-24 07:12:54 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2011-11-13 10:27:16 +03:00
|
|
|
public class DownloadProviderTest : CoreTest
|
2011-05-24 07:12:54 +03:00
|
|
|
{
|
|
|
|
[Test]
|
2011-07-04 02:04:57 +03:00
|
|
|
public void Download_report_should_send_to_sab_add_to_history_mark_as_grabbed()
|
2011-05-24 07:12:54 +03:00
|
|
|
{
|
2011-12-15 07:15:53 +03:00
|
|
|
WithStrictMocker();
|
2011-05-24 07:12:54 +03:00
|
|
|
var parseResult = Builder<EpisodeParseResult>.CreateNew()
|
2011-06-22 04:12:20 +03:00
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.DVD, false))
|
|
|
|
.Build();
|
2011-06-22 05:41:06 +03:00
|
|
|
|
2011-06-22 04:12:20 +03:00
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
2011-10-23 08:39:14 +03:00
|
|
|
.TheFirst(1).With(s => s.EpisodeId = 12)
|
|
|
|
.TheNext(1).With(s => s.EpisodeId = 99)
|
|
|
|
.All().With(s => s.SeriesId = 5)
|
2011-06-22 04:12:20 +03:00
|
|
|
.Build();
|
|
|
|
|
2011-05-24 07:12:54 +03:00
|
|
|
|
|
|
|
const string sabTitle = "My fake sab title";
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<SabProvider>()
|
2012-01-20 08:37:08 +03:00
|
|
|
.Setup(s => s.IsInQueue(It.IsAny<EpisodeParseResult>()))
|
2011-05-24 07:12:54 +03:00
|
|
|
.Returns(false);
|
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<SabProvider>()
|
2011-05-24 07:12:54 +03:00
|
|
|
.Setup(s => s.AddByUrl(parseResult.NzbUrl, sabTitle))
|
|
|
|
.Returns(true);
|
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<SabProvider>()
|
2011-05-28 22:23:35 +03:00
|
|
|
.Setup(s => s.GetSabTitle(parseResult))
|
|
|
|
.Returns(sabTitle);
|
2011-05-24 07:12:54 +03:00
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<HistoryProvider>()
|
2011-06-22 05:15:39 +03:00
|
|
|
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5)));
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<HistoryProvider>()
|
2011-06-22 05:15:39 +03:00
|
|
|
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)));
|
2011-05-24 07:12:54 +03:00
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2011-06-22 04:12:20 +03:00
|
|
|
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(episodes);
|
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2011-07-04 02:04:57 +03:00
|
|
|
.Setup(c => c.MarkEpisodeAsFetched(12));
|
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2011-07-04 02:04:57 +03:00
|
|
|
.Setup(c => c.MarkEpisodeAsFetched(99));
|
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.GetMock<ExternalNotificationProvider>()
|
2011-07-29 04:02:21 +03:00
|
|
|
.Setup(c => c.OnGrab(It.IsAny<string>()));
|
|
|
|
|
2012-01-29 02:53:14 +03:00
|
|
|
Mocker.GetMock<ConfigProvider>()
|
|
|
|
.Setup(c => c.DownloadClient)
|
|
|
|
.Returns(DownloadClientType.Sabnzbd);
|
|
|
|
|
|
|
|
Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
|
|
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Download_report_should_download_nzb_add_to_history_mark_as_grabbed()
|
|
|
|
{
|
|
|
|
WithStrictMocker();
|
|
|
|
var parseResult = Builder<EpisodeParseResult>.CreateNew()
|
|
|
|
.With(c => c.Quality = new Quality(QualityTypes.DVD, false))
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
.TheFirst(1).With(s => s.EpisodeId = 12)
|
|
|
|
.TheNext(1).With(s => s.EpisodeId = 99)
|
|
|
|
.All().With(s => s.SeriesId = 5)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
const string sabTitle = "My fake sab title";
|
|
|
|
Mocker.GetMock<BlackholeProvider>()
|
|
|
|
.Setup(s => s.DownloadNzb(It.IsAny<EpisodeParseResult>(), sabTitle))
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
Mocker.GetMock<SabProvider>()
|
|
|
|
.Setup(s => s.GetSabTitle(parseResult))
|
|
|
|
.Returns(sabTitle);
|
|
|
|
|
|
|
|
Mocker.GetMock<HistoryProvider>()
|
|
|
|
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5)));
|
|
|
|
Mocker.GetMock<HistoryProvider>()
|
|
|
|
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)));
|
|
|
|
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(episodes);
|
|
|
|
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(c => c.MarkEpisodeAsFetched(12));
|
|
|
|
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(c => c.MarkEpisodeAsFetched(99));
|
|
|
|
|
|
|
|
Mocker.GetMock<ExternalNotificationProvider>()
|
|
|
|
.Setup(c => c.OnGrab(It.IsAny<string>()));
|
|
|
|
|
|
|
|
Mocker.GetMock<ConfigProvider>()
|
|
|
|
.Setup(c => c.DownloadClient)
|
|
|
|
.Returns(DownloadClientType.Blackhole);
|
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
2011-05-24 07:12:54 +03:00
|
|
|
|
2011-12-15 07:15:53 +03:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-05-24 07:12:54 +03:00
|
|
|
}
|
|
|
|
}
|
2011-05-28 22:23:35 +03:00
|
|
|
}
|