2011-05-22 19:53:21 +03:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-05-21 03:23:49 +03:00
|
|
|
using System.Linq;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading;
|
|
|
|
using AutoMoq;
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
using MbUnit.Framework;
|
|
|
|
using Moq;
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-05-22 19:53:21 +03:00
|
|
|
using System;
|
2011-05-21 03:23:49 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
public class ImportNewSeriesJobTest : TestBase
|
|
|
|
{
|
|
|
|
[Test]
|
2011-05-27 05:12:28 +03:00
|
|
|
public void import_new_series_succesfull()
|
2011-05-21 03:23:49 +03:00
|
|
|
{
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
|
|
|
.WhereAll().Have(s => s.Episodes = Builder<Episode>.CreateListOfSize(10).Build())
|
|
|
|
.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 05:12:28 +03:00
|
|
|
.Returns(series.AsQueryable());
|
|
|
|
|
2011-05-21 03:23:49 +03:00
|
|
|
|
|
|
|
mocker.GetMock<DiskScanJob>()
|
2011-05-27 05:12:28 +03:00
|
|
|
.Setup(j => j.Start(notification, series[0].SeriesId))
|
|
|
|
.Callback(() => series[0].LastDiskSync = DateTime.Now)
|
|
|
|
.AtMostOnce();
|
2011-05-21 03:23:49 +03:00
|
|
|
|
|
|
|
mocker.GetMock<DiskScanJob>()
|
2011-05-27 05:12:28 +03:00
|
|
|
.Setup(j => j.Start(notification, series[1].SeriesId))
|
|
|
|
.Callback(() => series[1].LastDiskSync = DateTime.Now)
|
|
|
|
.AtMostOnce();
|
2011-05-21 03:23:49 +03:00
|
|
|
|
|
|
|
mocker.GetMock<UpdateInfoJob>()
|
2011-05-27 05:12:28 +03:00
|
|
|
.Setup(j => j.Start(notification, series[0].SeriesId))
|
|
|
|
.Callback(() => series[0].LastInfoSync = DateTime.Now)
|
|
|
|
.AtMostOnce();
|
2011-05-21 03:23:49 +03:00
|
|
|
|
|
|
|
mocker.GetMock<UpdateInfoJob>()
|
2011-05-27 05:12:28 +03:00
|
|
|
.Setup(j => j.Start(notification, series[1].SeriesId))
|
|
|
|
.Callback(() => series[1].LastInfoSync = DateTime.Now)
|
|
|
|
.AtMostOnce();
|
2011-05-21 03:23:49 +03:00
|
|
|
|
2011-05-27 05:12:28 +03: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 03:23:49 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-05-27 05:12:28 +03:00
|
|
|
[Timeout(3)]
|
|
|
|
public void failed_import_should_not_be_stuck_in_loop()
|
2011-05-21 03:23:49 +03:00
|
|
|
{
|
|
|
|
var series = Builder<Series>.CreateListOfSize(2)
|
2011-05-27 05:12:28 +03:00
|
|
|
.WhereAll().Have(s => s.Episodes = Builder<Episode>.CreateListOfSize(10).Build())
|
|
|
|
.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 03:23:49 +03:00
|
|
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
.Setup(p => p.GetAllSeries())
|
|
|
|
.Returns(series.AsQueryable());
|
|
|
|
|
2011-05-27 05:12:28 +03:00
|
|
|
mocker.GetMock<UpdateInfoJob>()
|
|
|
|
.Setup(j => j.Start(notification, series[0].SeriesId))
|
|
|
|
.Callback(() => series[0].LastInfoSync = DateTime.Now)
|
|
|
|
.AtMostOnce();
|
2011-05-21 03:23:49 +03:00
|
|
|
|
2011-05-27 05:12:28 +03:00
|
|
|
mocker.GetMock<UpdateInfoJob>()
|
|
|
|
.Setup(j => j.Start(notification, series[1].SeriesId))
|
|
|
|
.Throws(new InvalidOperationException())
|
|
|
|
.AtMostOnce();
|
2011-05-21 03:23:49 +03:00
|
|
|
|
2011-05-27 05:12:28 +03:00
|
|
|
mocker.GetMock<DiskScanJob>()
|
|
|
|
.Setup(j => j.Start(notification, series[0].SeriesId))
|
|
|
|
.Callback(() => series[0].LastDiskSync = DateTime.Now)
|
|
|
|
.AtMostOnce();
|
2011-05-21 03:23:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
2011-05-27 05:12:28 +03:00
|
|
|
.Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);
|
2011-05-21 03:23:49 +03:00
|
|
|
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
2011-05-27 05:12:28 +03:00
|
|
|
.Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());
|
2011-05-21 03:23:49 +03:00
|
|
|
|
2011-05-27 05:12:28 +03:00
|
|
|
//Act
|
|
|
|
mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0);
|
2011-05-21 03:23:49 +03:00
|
|
|
|
2011-05-27 05:12:28 +03:00
|
|
|
//Assert
|
2011-05-21 03:23:49 +03:00
|
|
|
mocker.VerifyAllMocks();
|
2011-05-27 05:12:28 +03:00
|
|
|
ExceptionVerification.ExcpectedErrors(1);
|
2011-05-21 03:23:49 +03:00
|
|
|
}
|
2011-05-27 05:12:28 +03:00
|
|
|
|
2011-05-21 03:23:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|