2013-03-28 22:07:09 +00:00
|
|
|
|
|
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;
|
2013-03-05 05:37:33 +00:00
|
|
|
|
using NzbDrone.Core.Jobs.Implementations;
|
2013-03-01 07:03:41 +00:00
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-05-21 00:23:49 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2013-03-07 01:51:47 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
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;
|
2013-02-19 06:56:02 +00:00
|
|
|
|
using System.Linq;
|
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]
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2013-02-17 05:44:06 +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()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 12)
|
2011-05-21 00:23:49 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
2013-02-27 03:55:52 +00:00
|
|
|
|
.Setup(p => p.Get(series.Id))
|
|
|
|
|
.Returns(series);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2013-02-26 03:58:57 +00:00
|
|
|
|
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), new { SeriesId = series.Id });
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void job_with_no_target_should_scan_all_series()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.TheFirst(1).With(s => s.Id = 12)
|
|
|
|
|
.TheNext(1).With(s => s.Id = 15)
|
2013-02-19 06:56:02 +00:00
|
|
|
|
.Build().ToList();
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
|
|
|
|
.Setup(p => p.All())
|
2011-05-27 06:03:57 +00:00
|
|
|
|
.Returns(series);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-24 00:44:44 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void failed_scan_should_not_terminated_job()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.TheFirst(1).With(s => s.Id = 12)
|
|
|
|
|
.TheNext(1).With(s => s.Id = 15)
|
2013-02-19 06:56:02 +00:00
|
|
|
|
.Build().ToList();
|
2011-05-24 00:44:44 +00:00
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
|
|
|
|
.Setup(p => p.All())
|
2011-05-27 06:03:57 +00:00
|
|
|
|
.Returns(series);
|
2011-05-24 00:44:44 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +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-12-15 04:15:53 +00:00
|
|
|
|
Mocker.GetMock<DiskScanProvider>()
|
2011-05-24 00:44:44 +00:00
|
|
|
|
.Setup(s => s.Scan(series[1]))
|
|
|
|
|
.Throws(new InvalidOperationException("Bad Job"));
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
|
2011-05-24 00:44:44 +00:00
|
|
|
|
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
2011-12-20 00:58:26 +00:00
|
|
|
|
ExceptionVerification.ExpectedErrors(2);
|
2011-05-24 00:44:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
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)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.TheFirst(1).With(s => s.Id = 12)
|
|
|
|
|
.TheNext(1).With(s => s.Id = 15)
|
2013-02-19 06:56:02 +00:00
|
|
|
|
.Build().ToList();
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2013-02-19 06:56:02 +00:00
|
|
|
|
Mocker.GetMock<ISeriesRepository>()
|
|
|
|
|
.Setup(p => p.All())
|
2011-05-27 06:03:57 +00:00
|
|
|
|
.Returns(series);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
Mocker.GetMock<DiskScanProvider>().Verify(s => s.Scan(It.IsAny<Series>()), Times.Exactly(2));
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|