1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Core.Test/ProviderTests/DownloadProviderTest.cs

125 lines
4.7 KiB
C#
Raw Normal View History

using System;
using FizzWare.NBuilder;
using Moq;
2011-06-03 00:06:46 +03:00
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
2011-05-28 22:23:35 +03:00
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
// ReSharper disable InconsistentNaming
2011-05-28 22:23:35 +03:00
namespace NzbDrone.Core.Test.ProviderTests
{
[TestFixture]
2011-11-13 10:27:16 +03:00
public class DownloadProviderTest : CoreTest
{
[Test]
public void Download_report_should_send_to_sab_add_to_history_mark_as_grabbed()
{
2011-12-15 07:15:53 +03:00
WithStrictMocker();
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();
const string sabTitle = "My fake sab title";
2011-12-15 07:15:53 +03:00
Mocker.GetMock<SabProvider>()
.Setup(s => s.IsInQueue(It.IsAny<EpisodeParseResult>()))
.Returns(false);
2011-12-15 07:15:53 +03:00
Mocker.GetMock<SabProvider>()
.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-12-15 07:15:53 +03:00
Mocker.GetMock<HistoryProvider>()
.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>()
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)));
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>()
.Setup(c => c.MarkEpisodeAsFetched(12));
2011-12-15 07:15:53 +03:00
Mocker.GetMock<EpisodeProvider>()
.Setup(c => c.MarkEpisodeAsFetched(99));
2011-12-15 07:15:53 +03:00
Mocker.GetMock<ExternalNotificationProvider>()
.Setup(c => c.OnGrab(It.IsAny<string>()));
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-12-15 07:15:53 +03:00
Mocker.VerifyAllMocks();
}
}
2011-05-28 22:23:35 +03:00
}