2011-05-22 18:53:21 +02:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-21 01:42:17 +02:00
|
|
|
|
|
2011-06-18 04:00:44 +02:00
|
|
|
|
using System;
|
2011-05-21 02:23:49 +02:00
|
|
|
|
using System.Collections.Generic;
|
2011-11-14 01:22:18 +01:00
|
|
|
|
|
2011-05-21 02:23:49 +02:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using Moq;
|
2011-06-02 23:06:46 +02:00
|
|
|
|
using NUnit.Framework;
|
2011-12-02 02:33:17 +01:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-05-21 02:23:49 +02:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-10-24 07:54:09 +02:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-11-14 01:22:18 +01:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-10-21 01:42:17 +02:00
|
|
|
|
namespace NzbDrone.Core.Test.JobTests
|
|
|
|
|
{
|
2011-05-21 02:23:49 +02:00
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 08:27:16 +01:00
|
|
|
|
public class ImportNewSeriesJobTest : CoreTest
|
2011-05-21 02:23:49 +02:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
2012-09-11 08:35:25 +02:00
|
|
|
|
public void import_new_series_succesful()
|
2011-05-21 02:23:49 +02:00
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All().With(s => s.LastInfoSync = null)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.TheFirst(1).With(s => s.SeriesId = 12)
|
|
|
|
|
.TheNext(1).With(s => s.SeriesId = 15)
|
2011-05-21 02:23:49 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Test");
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-05-21 02:23:49 +02:00
|
|
|
|
.Setup(p => p.GetAllSeries())
|
2011-05-27 08:03:57 +02:00
|
|
|
|
.Returns(series);
|
2011-05-27 04:12:28 +02:00
|
|
|
|
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskScanJob>()
|
2012-09-11 08:35:25 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)))
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Callback(() => series[0].LastDiskSync = DateTime.Now);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskScanJob>()
|
2012-09-11 08:35:25 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)))
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Callback(() => series[1].LastDiskSync = DateTime.Now);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<BannerDownloadJob>()
|
2012-10-21 01:07:04 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") > 0)));
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2012-10-18 06:28:54 +02:00
|
|
|
|
Mocker.GetMock<XemUpdateJob>()
|
2012-10-21 01:07:04 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") > 0)));
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<UpdateInfoJob>()
|
2012-09-11 08:35:25 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)))
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Callback(() => series[0].LastInfoSync = DateTime.Now);
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<UpdateInfoJob>()
|
2012-09-11 08:35:25 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)))
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Callback(() => series[1].LastInfoSync = DateTime.Now);
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-05-27 04:12:28 +02:00
|
|
|
|
.Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-05-27 04:12:28 +02:00
|
|
|
|
.Setup(s => s.GetSeries(series[1].SeriesId)).Returns(series[1]);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-05-27 04:12:28 +02:00
|
|
|
|
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-09-10 21:04:17 +02:00
|
|
|
|
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, null);
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-09-11 08:35:25 +02:00
|
|
|
|
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)), Times.Once());
|
|
|
|
|
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)), Times.Once());
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2012-09-11 08:35:25 +02:00
|
|
|
|
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)), Times.Once());
|
|
|
|
|
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)), Times.Once());
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2011-05-21 02:23:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-06-02 23:06:46 +02:00
|
|
|
|
[Timeout(3000)]
|
2011-05-27 04:12:28 +02:00
|
|
|
|
public void failed_import_should_not_be_stuck_in_loop()
|
2011-05-21 02:23:49 +02:00
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All().With(s => s.LastInfoSync = null)
|
2011-10-23 07:39:14 +02:00
|
|
|
|
.TheFirst(1).With(s => s.SeriesId = 12)
|
|
|
|
|
.TheNext(1).With(s => s.SeriesId = 15)
|
2011-05-27 04:12:28 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Test");
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-05-21 02:23:49 +02:00
|
|
|
|
.Setup(p => p.GetAllSeries())
|
2011-05-27 08:03:57 +02:00
|
|
|
|
.Returns(series);
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<UpdateInfoJob>()
|
2012-09-11 08:35:25 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)))
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Callback(() => series[0].LastInfoSync = DateTime.Now);
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<UpdateInfoJob>()
|
2012-09-11 08:35:25 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)))
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Throws(new InvalidOperationException());
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<DiskScanJob>()
|
2012-09-11 08:35:25 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)))
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Callback(() => series[0].LastDiskSync = DateTime.Now);
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<BannerDownloadJob>()
|
2012-09-11 08:35:25 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)));
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<SeriesProvider>()
|
2011-05-27 04:12:28 +02:00
|
|
|
|
.Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-05-27 04:12:28 +02:00
|
|
|
|
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2012-10-18 06:28:54 +02:00
|
|
|
|
Mocker.GetMock<XemUpdateJob>()
|
2012-10-21 01:07:04 +02:00
|
|
|
|
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)));
|
2012-10-18 06:28:54 +02:00
|
|
|
|
|
2011-05-27 04:12:28 +02:00
|
|
|
|
//Act
|
2012-09-10 21:04:17 +02:00
|
|
|
|
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, null);
|
2011-05-21 02:23:49 +02:00
|
|
|
|
|
2011-05-27 04:12:28 +02:00
|
|
|
|
//Assert
|
2012-09-11 08:35:25 +02:00
|
|
|
|
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)), Times.Once());
|
|
|
|
|
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)), Times.Once());
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2012-09-11 08:35:25 +02:00
|
|
|
|
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)), Times.Once());
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2011-12-20 01:58:26 +01:00
|
|
|
|
ExceptionVerification.ExpectedErrors(1);
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2011-05-21 02:23:49 +02:00
|
|
|
|
}
|
2011-05-27 04:12:28 +02:00
|
|
|
|
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AutoIgnoreSeason_new_series_should_not_ignore_any()
|
|
|
|
|
{
|
|
|
|
|
int seriesId = 12;
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Setup(p => p.GetSeriesFiles(seriesId))
|
|
|
|
|
.Returns(new List<EpisodeFile>());
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Setup(p => p.GetSeasons(seriesId))
|
|
|
|
|
.Returns(new List<int> { 0, 1, 2, 3, 4 });
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
|
|
|
|
|
2012-02-28 06:50:56 +01:00
|
|
|
|
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, It.IsAny<int>(), It.IsAny<Boolean>()), Times.Never());
|
2011-06-19 22:43:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AutoIgnoreSeason_existing_should_not_ignore_currentseason()
|
|
|
|
|
{
|
|
|
|
|
int seriesId = 12;
|
|
|
|
|
|
|
|
|
|
var episodesFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All().With(e => e.SeriesId = seriesId)
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
episodesFiles[0].SeasonNumber = 0;
|
|
|
|
|
episodesFiles[1].SeasonNumber = 1;
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
WithStrictMocker();
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Setup(p => p.GetSeriesFiles(seriesId))
|
|
|
|
|
.Returns(episodesFiles);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Setup(p => p.GetSeasons(seriesId))
|
|
|
|
|
.Returns(new List<int> { 0, 1, 2 });
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2012-02-28 06:50:56 +01:00
|
|
|
|
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
|
2011-06-19 22:43:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AutoIgnoreSeason_existing_should_ignore_seasons_with_no_file()
|
|
|
|
|
{
|
|
|
|
|
int seriesId = 12;
|
|
|
|
|
|
|
|
|
|
var episodesFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.All().With(e => e.SeriesId = seriesId)
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
episodesFiles[0].SeasonNumber = 1;
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Setup(p => p.GetSeriesFiles(seriesId))
|
|
|
|
|
.Returns(episodesFiles);
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.GetMock<EpisodeProvider>()
|
2011-06-19 22:43:33 +02:00
|
|
|
|
.Setup(p => p.GetSeasons(seriesId))
|
|
|
|
|
.Returns(new List<int> { 0, 1, 2 });
|
|
|
|
|
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2012-02-28 06:50:56 +01:00
|
|
|
|
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, 0, true), Times.Once());
|
|
|
|
|
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, 1, true), Times.Never());
|
|
|
|
|
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
|
2011-06-19 22:43:33 +02:00
|
|
|
|
}
|
2011-05-21 02:23:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-19 22:43:33 +02:00
|
|
|
|
|
2011-05-21 02:23:49 +02:00
|
|
|
|
}
|