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