2011-05-22 16:53:21 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-20 23:42:17 +00:00
|
|
|
|
|
2011-05-24 00:44:44 +00:00
|
|
|
|
using System;
|
2011-05-21 00:23:49 +00:00
|
|
|
|
using System.Collections.Generic;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using Moq;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using NUnit.Framework;
|
2011-05-21 00:23:49 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-10-24 05:54:09 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.JobTests
|
2011-05-21 00:23:49 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 07:27:16 +00:00
|
|
|
|
public class DiskScanJobTest : CoreTest
|
2011-05-21 00:23:49 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void series_specific_scan_should_scan_series()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.SeriesId = 12)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetSeries(series.SeriesId))
|
|
|
|
|
.Returns(series);
|
|
|
|
|
|
2011-06-20 03:04:08 +00:00
|
|
|
|
mocker.GetMock<DiskScanProvider>()
|
2011-05-21 00:23:49 +00:00
|
|
|
|
.Setup(p => p.Scan(series))
|
|
|
|
|
.Returns(new List<EpisodeFile>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), series.SeriesId, 0);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void job_with_no_target_should_scan_all_series()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2011-10-23 05:39:14 +00:00
|
|
|
|
.TheFirst(1).With(s => s.SeriesId = 12)
|
|
|
|
|
.TheNext(1).With(s => s.SeriesId = 15)
|
2011-05-21 00:23:49 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetAllSeries())
|
2011-05-27 06:03:57 +00:00
|
|
|
|
.Returns(series);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-06-20 03:04:08 +00:00
|
|
|
|
mocker.GetMock<DiskScanProvider>()
|
2011-05-21 00:23:49 +00:00
|
|
|
|
.Setup(s => s.Scan(series[0]))
|
|
|
|
|
.Returns(new List<EpisodeFile>());
|
|
|
|
|
|
2011-06-20 03:04:08 +00:00
|
|
|
|
mocker.GetMock<DiskScanProvider>()
|
2011-05-21 00:23:49 +00:00
|
|
|
|
.Setup(s => s.Scan(series[1]))
|
|
|
|
|
.Returns(new List<EpisodeFile>());
|
|
|
|
|
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-24 00:44:44 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void failed_scan_should_not_terminated_job()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2011-10-23 05:39:14 +00:00
|
|
|
|
.TheFirst(1).With(s => s.SeriesId = 12)
|
|
|
|
|
.TheNext(1).With(s => s.SeriesId = 15)
|
2011-05-24 00:44:44 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetAllSeries())
|
2011-05-27 06:03:57 +00:00
|
|
|
|
.Returns(series);
|
2011-05-24 00:44:44 +00:00
|
|
|
|
|
2011-06-20 03:04:08 +00:00
|
|
|
|
mocker.GetMock<DiskScanProvider>()
|
2011-05-24 00:44:44 +00:00
|
|
|
|
.Setup(s => s.Scan(series[0]))
|
|
|
|
|
.Throws(new InvalidOperationException("Bad Job"));
|
|
|
|
|
|
2011-06-20 03:04:08 +00:00
|
|
|
|
mocker.GetMock<DiskScanProvider>()
|
2011-05-24 00:44:44 +00:00
|
|
|
|
.Setup(s => s.Scan(series[1]))
|
|
|
|
|
.Throws(new InvalidOperationException("Bad Job"));
|
|
|
|
|
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0);
|
2011-05-24 00:44:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
ExceptionVerification.ExcpectedErrors(2);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void job_with_no_target_should_scan_series_with_episodes()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2011-10-23 05:39:14 +00:00
|
|
|
|
.TheFirst(1).With(s => s.SeriesId = 12)
|
|
|
|
|
.TheNext(1).With(s => s.SeriesId = 15)
|
2011-05-21 00:23:49 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetAllSeries())
|
2011-05-27 06:03:57 +00:00
|
|
|
|
.Returns(series);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-06-20 03:04:08 +00:00
|
|
|
|
mocker.GetMock<DiskScanProvider>()
|
2011-05-21 00:23:49 +00:00
|
|
|
|
.Setup(s => s.Scan(series[0]))
|
|
|
|
|
.Returns(new List<EpisodeFile>());
|
|
|
|
|
|
2011-06-20 03:04:08 +00:00
|
|
|
|
mocker.GetMock<DiskScanProvider>()
|
2011-06-18 04:08:17 +00:00
|
|
|
|
.Setup(s => s.Scan(series[1]))
|
|
|
|
|
.Returns(new List<EpisodeFile>());
|
|
|
|
|
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), 0, 0);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
|
2011-06-18 04:08:17 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
mocker.VerifyAllMocks();
|
2011-06-20 03:04:08 +00:00
|
|
|
|
mocker.GetMock<DiskScanProvider>().Verify(s => s.Scan(It.IsAny<Series>()), Times.Exactly(2));
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|