2011-05-22 16:53:21 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-06-18 02:00:44 +00:00
|
|
|
|
using System;
|
2011-05-21 00:23:49 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using AutoMoq;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class ImportNewSeriesJobTest : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
2011-05-27 02:12:28 +00:00
|
|
|
|
public void import_new_series_succesfull()
|
2011-05-21 00:23:49 +00:00
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
|
|
|
|
.WhereAll().Have(s => s.LastInfoSync = null)
|
|
|
|
|
.WhereTheFirst(1).Has(s => s.SeriesId = 12)
|
|
|
|
|
.AndTheNext(1).Has(s => s.SeriesId = 15)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Test");
|
|
|
|
|
|
|
|
|
|
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-27 02:12:28 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
mocker.GetMock<DiskScanJob>()
|
2011-08-22 00:48:37 +00:00
|
|
|
|
.Setup(j => j.Start(notification, series[0].SeriesId, 0))
|
2011-06-19 20:43:33 +00:00
|
|
|
|
.Callback(() => series[0].LastDiskSync = DateTime.Now);
|
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
mocker.GetMock<DiskScanJob>()
|
2011-08-22 00:48:37 +00:00
|
|
|
|
.Setup(j => j.Start(notification, series[1].SeriesId, 0))
|
2011-06-19 20:43:33 +00:00
|
|
|
|
.Callback(() => series[1].LastDiskSync = DateTime.Now);
|
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
mocker.GetMock<UpdateInfoJob>()
|
2011-08-22 00:48:37 +00:00
|
|
|
|
.Setup(j => j.Start(notification, series[0].SeriesId, 0))
|
2011-06-19 20:43:33 +00:00
|
|
|
|
.Callback(() => series[0].LastInfoSync = DateTime.Now);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
mocker.GetMock<UpdateInfoJob>()
|
2011-08-22 00:48:37 +00:00
|
|
|
|
.Setup(j => j.Start(notification, series[1].SeriesId, 0))
|
2011-06-19 20:43:33 +00:00
|
|
|
|
.Callback(() => series[1].LastInfoSync = DateTime.Now);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-05-27 02:12:28 +00:00
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(s => s.GetSeries(series[1].SeriesId)).Returns(series[1]);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
mocker.VerifyAllMocks();
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
|
|
|
|
|
mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once());
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
|
|
|
|
|
mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once());
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-06-02 21:06:46 +00:00
|
|
|
|
[Timeout(3000)]
|
2011-05-27 02:12:28 +00:00
|
|
|
|
public void failed_import_should_not_be_stuck_in_loop()
|
2011-05-21 00:23:49 +00:00
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2011-05-27 02:12:28 +00:00
|
|
|
|
.WhereAll().Have(s => s.LastInfoSync = null)
|
|
|
|
|
.WhereTheFirst(1).Has(s => s.SeriesId = 12)
|
|
|
|
|
.AndTheNext(1).Has(s => s.SeriesId = 15)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var notification = new ProgressNotification("Test");
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
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-05-27 02:12:28 +00:00
|
|
|
|
mocker.GetMock<UpdateInfoJob>()
|
2011-08-22 00:48:37 +00:00
|
|
|
|
.Setup(j => j.Start(notification, series[0].SeriesId, 0))
|
2011-06-19 20:43:33 +00:00
|
|
|
|
.Callback(() => series[0].LastInfoSync = DateTime.Now);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-05-27 02:12:28 +00:00
|
|
|
|
mocker.GetMock<UpdateInfoJob>()
|
2011-08-22 00:48:37 +00:00
|
|
|
|
.Setup(j => j.Start(notification, series[1].SeriesId, 0))
|
2011-06-19 20:43:33 +00:00
|
|
|
|
.Throws(new InvalidOperationException());
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-05-27 02:12:28 +00:00
|
|
|
|
mocker.GetMock<DiskScanJob>()
|
2011-08-22 00:48:37 +00:00
|
|
|
|
.Setup(j => j.Start(notification, series[0].SeriesId, 0))
|
2011-06-19 20:43:33 +00:00
|
|
|
|
.Callback(() => series[0].LastDiskSync = DateTime.Now);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
2011-05-27 02:12:28 +00:00
|
|
|
|
.Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
2011-05-27 02:12:28 +00:00
|
|
|
|
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-05-27 02:12:28 +00:00
|
|
|
|
//Act
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);
|
2011-05-21 00:23:49 +00:00
|
|
|
|
|
2011-05-27 02:12:28 +00:00
|
|
|
|
//Assert
|
2011-05-21 00:23:49 +00:00
|
|
|
|
mocker.VerifyAllMocks();
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
|
|
|
|
|
mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once());
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
2011-08-22 00:48:37 +00:00
|
|
|
|
mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
2011-05-27 02:12:28 +00:00
|
|
|
|
ExceptionVerification.ExcpectedErrors(1);
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|
2011-05-27 02:12:28 +00:00
|
|
|
|
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AutoIgnoreSeason_new_series_should_not_ignore_any()
|
|
|
|
|
{
|
|
|
|
|
int seriesId = 12;
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(p => p.GetSeriesFiles(seriesId))
|
|
|
|
|
.Returns(new List<EpisodeFile>());
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
|
.Setup(p => p.GetSeasons(seriesId))
|
|
|
|
|
.Returns(new List<int> { 0, 1, 2, 3, 4 });
|
|
|
|
|
|
|
|
|
|
mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, It.IsAny<int>(), It.IsAny<Boolean>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AutoIgnoreSeason_existing_should_not_ignore_currentseason()
|
|
|
|
|
{
|
|
|
|
|
int seriesId = 12;
|
|
|
|
|
|
|
|
|
|
var episodesFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
|
|
|
|
.WhereAll().Have(e => e.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
episodesFiles[0].SeasonNumber = 0;
|
|
|
|
|
episodesFiles[1].SeasonNumber = 1;
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(p => p.GetSeriesFiles(seriesId))
|
|
|
|
|
.Returns(episodesFiles);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
|
.Setup(p => p.GetSeasons(seriesId))
|
|
|
|
|
.Returns(new List<int> { 0, 1, 2 });
|
|
|
|
|
|
|
|
|
|
mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AutoIgnoreSeason_existing_should_ignore_seasons_with_no_file()
|
|
|
|
|
{
|
|
|
|
|
int seriesId = 12;
|
|
|
|
|
|
|
|
|
|
var episodesFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
|
|
|
|
.WhereAll().Have(e => e.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
episodesFiles[0].SeasonNumber = 1;
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
|
.Setup(p => p.GetSeriesFiles(seriesId))
|
|
|
|
|
.Returns(episodesFiles);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
|
.Setup(p => p.GetSeasons(seriesId))
|
|
|
|
|
.Returns(new List<int> { 0, 1, 2 });
|
|
|
|
|
|
|
|
|
|
mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 0, true), Times.Once());
|
|
|
|
|
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 1, true), Times.Never());
|
|
|
|
|
mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
|
|
|
|
|
}
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-19 20:43:33 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|