1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-13 22:43:35 +01:00
Radarr/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs

111 lines
3.1 KiB
C#
Raw Normal View History

2013-03-28 23:07:09 +01:00

using System;
using System.Collections.Generic;
using FizzWare.NBuilder;
using Moq;
2011-06-02 23:06:46 +02:00
using NUnit.Framework;
2013-03-05 06:37:33 +01:00
using NzbDrone.Core.Jobs.Implementations;
2013-03-01 08:03:41 +01:00
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Tv;
2011-12-02 02:33:17 +01:00
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
2013-03-07 02:51:47 +01:00
using NzbDrone.Core.Test.Framework;
2011-10-24 07:54:09 +02:00
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
2013-02-19 07:56:02 +01:00
using System.Linq;
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
2013-03-28 23:07:09 +01:00
public class DiskScanJobTest : CoreTest
{
[Test]
public void series_specific_scan_should_scan_series()
{
var series = Builder<Series>.CreateNew()
.With(s => s.Id = 12)
.Build();
2013-02-19 07:56:02 +01:00
Mocker.GetMock<ISeriesRepository>()
2013-02-27 04:55:52 +01:00
.Setup(p => p.Get(series.Id))
.Returns(series);
2013-03-28 23:07:09 +01:00
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), new { SeriesId = series.Id });
2013-03-28 23:07:09 +01:00
2011-12-15 05:15:53 +01:00
Mocker.VerifyAllMocks();
}
[Test]
public void job_with_no_target_should_scan_all_series()
{
var series = Builder<Series>.CreateListOfSize(2)
.TheFirst(1).With(s => s.Id = 12)
.TheNext(1).With(s => s.Id = 15)
2013-02-19 07:56:02 +01:00
.Build().ToList();
2013-02-19 07:56:02 +01:00
Mocker.GetMock<ISeriesRepository>()
.Setup(p => p.All())
2011-05-27 08:03:57 +02:00
.Returns(series);
2012-09-10 21:04:17 +02:00
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
2011-12-15 05:15:53 +01:00
Mocker.VerifyAllMocks();
}
[Test]
public void failed_scan_should_not_terminated_job()
{
var series = Builder<Series>.CreateListOfSize(2)
.TheFirst(1).With(s => s.Id = 12)
.TheNext(1).With(s => s.Id = 15)
2013-02-19 07:56:02 +01:00
.Build().ToList();
2013-02-19 07:56:02 +01:00
Mocker.GetMock<ISeriesRepository>()
.Setup(p => p.All())
2011-05-27 08:03:57 +02:00
.Returns(series);
2013-04-15 07:27:32 +02:00
Mocker.GetMock<IDiskScanService>()
.Setup(s => s.Scan(series[0]))
.Throws(new InvalidOperationException("Bad Job"));
2013-04-15 07:27:32 +02:00
Mocker.GetMock<IDiskScanService>()
.Setup(s => s.Scan(series[1]))
.Throws(new InvalidOperationException("Bad Job"));
2012-09-10 21:04:17 +02:00
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
2011-12-15 05:15:53 +01:00
Mocker.VerifyAllMocks();
ExceptionVerification.ExpectedErrors(2);
}
[Test]
public void job_with_no_target_should_scan_series_with_episodes()
{
var series = Builder<Series>.CreateListOfSize(2)
.TheFirst(1).With(s => s.Id = 12)
.TheNext(1).With(s => s.Id = 15)
2013-02-19 07:56:02 +01:00
.Build().ToList();
2013-02-19 07:56:02 +01:00
Mocker.GetMock<ISeriesRepository>()
.Setup(p => p.All())
2011-05-27 08:03:57 +02:00
.Returns(series);
2012-09-10 21:04:17 +02:00
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
2011-12-15 05:15:53 +01:00
Mocker.VerifyAllMocks();
2013-04-15 07:27:32 +02:00
Mocker.GetMock<IDiskScanService>().Verify(s => s.Scan(It.IsAny<Series>()), Times.Exactly(2));
}
}
}