sonarr-repo-only/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs

218 lines
8.5 KiB
C#
Raw Normal View History

2011-05-22 16:53:21 +00:00
// ReSharper disable RedundantUsingDirective
2011-06-18 02:00:44 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
2011-06-02 21:06:46 +00:00
using NUnit.Framework;
using NzbDrone.Core.Jobs.Implementations;
2013-03-01 07:03:41 +00:00
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Tv;
2011-12-02 01:33:17 +00:00
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
2013-03-07 01:51:47 +00:00
using NzbDrone.Core.Test.Framework;
2011-10-24 05:54:09 +00:00
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class ImportNewSeriesJobTest : CoreTest
{
[Test]
2012-09-11 06:35:25 +00:00
public void import_new_series_succesful()
{
var series = Builder<Series>.CreateListOfSize(2)
2011-10-18 21:46:06 +00:00
.All().With(s => s.LastInfoSync = null)
.TheFirst(1).With(s => s.Id = 12)
.TheNext(1).With(s => s.Id = 15)
.Build();
var notification = new ProgressNotification("Test");
2011-12-15 04:15:53 +00:00
WithStrictMocker();
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-12-15 04:15:53 +00:00
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)))
2011-06-19 20:43:33 +00:00
.Callback(() => series[0].LastDiskSync = DateTime.Now);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].Id)))
2011-06-19 20:43:33 +00:00
.Callback(() => series[1].LastDiskSync = DateTime.Now);
2012-10-18 04:28:54 +00:00
Mocker.GetMock<XemUpdateJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") > 0)));
2011-12-15 04:15:53 +00:00
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)))
2011-06-19 20:43:33 +00:00
.Callback(() => series[0].LastInfoSync = DateTime.Now);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].Id)))
2011-06-19 20:43:33 +00:00
.Callback(() => series[1].LastInfoSync = DateTime.Now);
2013-02-19 06:56:02 +00:00
Mocker.GetMock<ISeriesRepository>()
.Setup(s => s.Get(series[0].Id)).Returns(series[0]);
2013-02-19 06:56:02 +00:00
Mocker.GetMock<ISeriesRepository>()
.Setup(s => s.Get(series[1].Id)).Returns(series[1]);
2013-03-01 07:03:41 +00:00
Mocker.GetMock<IMediaFileService>()
.Setup(s => s.GetFilesBySeries(It.IsAny<int>())).Returns(new List<EpisodeFile>());
//Act
2012-09-10 19:04:17 +00:00
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, null);
//Assert
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)), Times.Once());
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].Id)), Times.Once());
2011-06-19 20:43:33 +00:00
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].Id)), Times.Once());
2011-06-19 20:43:33 +00:00
}
[Test]
2011-06-02 21:06:46 +00:00
[Timeout(3000)]
public void failed_import_should_not_be_stuck_in_loop()
{
var series = Builder<Series>.CreateListOfSize(2)
2011-10-18 21:46:06 +00:00
.All().With(s => s.LastInfoSync = null)
.TheFirst(1).With(s => s.Id = 12)
.TheNext(1).With(s => s.Id = 15)
.Build();
var notification = new ProgressNotification("Test");
2011-12-15 04:15:53 +00:00
WithStrictMocker();
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-12-15 04:15:53 +00:00
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)))
2011-06-19 20:43:33 +00:00
.Callback(() => series[0].LastInfoSync = DateTime.Now);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].Id)))
2011-06-19 20:43:33 +00:00
.Throws(new InvalidOperationException());
2011-12-15 04:15:53 +00:00
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)))
2011-06-19 20:43:33 +00:00
.Callback(() => series[0].LastDiskSync = DateTime.Now);
2013-02-19 06:56:02 +00:00
Mocker.GetMock<ISeriesRepository>()
.Setup(s => s.Get(series[0].Id)).Returns(series[0]);
2013-03-01 07:03:41 +00:00
Mocker.GetMock<IMediaFileService>()
.Setup(s => s.GetFilesBySeries(It.IsAny<int>())).Returns(new List<EpisodeFile>());
2012-10-18 04:28:54 +00:00
Mocker.GetMock<XemUpdateJob>()
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)));
2012-10-18 04:28:54 +00:00
//Act
2012-09-10 19:04:17 +00:00
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, null);
//Assert
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].Id)), Times.Once());
2011-06-19 20:43:33 +00:00
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].Id)), Times.Once());
2011-06-19 20:43:33 +00:00
ExceptionVerification.ExpectedErrors(1);
2011-06-19 20:43:33 +00:00
}
2011-06-19 20:43:33 +00:00
[Test]
public void AutoIgnoreSeason_new_series_should_not_ignore_any()
{
int seriesId = 12;
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2013-03-01 07:03:41 +00:00
Mocker.GetMock<IMediaFileService>()
.Setup(p => p.GetFilesBySeries(seriesId))
2011-06-19 20:43:33 +00:00
.Returns(new List<EpisodeFile>());
Mocker.GetMock<ISeasonRepository>()
.Setup(p => p.GetSeasonNumbers(seriesId))
2011-06-19 20:43:33 +00:00
.Returns(new List<int> { 0, 1, 2, 3, 4 });
2011-12-15 04:15:53 +00:00
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
2011-06-19 20:43:33 +00:00
Mocker.GetMock<ISeasonService>().Verify(p => p.SetIgnore(seriesId, It.IsAny<int>(), It.IsAny<Boolean>()), Times.Never());
2011-06-19 20:43:33 +00:00
}
[Test]
public void AutoIgnoreSeason_existing_should_not_ignore_currentseason()
{
int seriesId = 12;
var episodesFiles = Builder<EpisodeFile>.CreateListOfSize(2)
2011-10-18 21:46:06 +00:00
.All().With(e => e.SeriesId = seriesId)
2011-06-19 20:43:33 +00:00
.Build();
episodesFiles[0].SeasonNumber = 0;
episodesFiles[1].SeasonNumber = 1;
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-06-19 20:43:33 +00:00
2013-03-01 07:03:41 +00:00
Mocker.GetMock<IMediaFileService>()
.Setup(p => p.GetFilesBySeries(seriesId))
.Returns(episodesFiles.ToList());
2011-06-19 20:43:33 +00:00
Mocker.GetMock<ISeasonRepository>()
.Setup(p => p.GetSeasonNumbers(seriesId))
2011-06-19 20:43:33 +00:00
.Returns(new List<int> { 0, 1, 2 });
2011-12-15 04:15:53 +00:00
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
2011-06-19 20:43:33 +00:00
Mocker.GetMock<ISeasonService>().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
2011-06-19 20:43:33 +00:00
}
[Test]
public void AutoIgnoreSeason_existing_should_ignore_seasons_with_no_file()
{
int seriesId = 12;
var episodesFiles = Builder<EpisodeFile>.CreateListOfSize(2)
2011-10-18 21:46:06 +00:00
.All().With(e => e.SeriesId = seriesId)
2011-06-19 20:43:33 +00:00
.Build();
episodesFiles[0].SeasonNumber = 1;
2011-12-15 04:15:53 +00:00
2011-06-19 20:43:33 +00:00
2013-03-01 07:03:41 +00:00
Mocker.GetMock<IMediaFileService>()
.Setup(p => p.GetFilesBySeries(seriesId))
.Returns(episodesFiles.ToList());
2011-06-19 20:43:33 +00:00
Mocker.GetMock<ISeasonRepository>()
.Setup(p => p.GetSeasonNumbers(seriesId))
2011-06-19 20:43:33 +00:00
.Returns(new List<int> { 0, 1, 2 });
2011-12-15 04:15:53 +00:00
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
2011-06-19 20:43:33 +00:00
Mocker.GetMock<ISeasonService>().Verify(p => p.SetIgnore(seriesId, 0, true), Times.Once());
Mocker.GetMock<ISeasonService>().Verify(p => p.SetIgnore(seriesId, 1, true), Times.Never());
Mocker.GetMock<ISeasonService>().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
2011-06-19 20:43:33 +00:00
}
}
2011-06-19 20:43:33 +00:00
}