1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-18 21:35:51 -04:00

removed all the jobs.

This commit is contained in:
Keivan Beigi
2013-05-06 17:39:33 -07:00
parent 40f384968a
commit ec58b8b595
42 changed files with 122 additions and 1599 deletions
@@ -1,111 +0,0 @@
using System;
using System.Collections.Generic;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Jobs.Implementations;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
using System.Linq;
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
public class DiskScanJobTest : CoreTest
{
[Test]
public void series_specific_scan_should_scan_series()
{
var series = Builder<Series>.CreateNew()
.With(s => s.Id = 12)
.Build();
Mocker.GetMock<ISeriesRepository>()
.Setup(p => p.Get(series.Id))
.Returns(series);
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), new { SeriesId = series.Id });
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)
.Build().ToList();
Mocker.GetMock<ISeriesRepository>()
.Setup(p => p.All())
.Returns(series);
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
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)
.Build().ToList();
Mocker.GetMock<ISeriesRepository>()
.Setup(p => p.All())
.Returns(series);
Mocker.GetMock<IDiskScanService>()
.Setup(s => s.Scan(series[0]))
.Throws(new InvalidOperationException("Bad Job"));
Mocker.GetMock<IDiskScanService>()
.Setup(s => s.Scan(series[1]))
.Throws(new InvalidOperationException("Bad Job"));
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
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)
.Build().ToList();
Mocker.GetMock<ISeriesRepository>()
.Setup(p => p.All())
.Returns(series);
Mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("Test"), null);
Mocker.VerifyAllMocks();
Mocker.GetMock<IDiskScanService>().Verify(s => s.Scan(It.IsAny<Series>()), Times.Exactly(2));
}
}
}
@@ -1,232 +0,0 @@
/*
using System.Linq;
using System;
using System.Collections.Generic;
using System.Threading;
using FluentAssertions;
using Moq;
using NCrunch.Framework;
using NUnit.Framework;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Jobs.Implementations;
using NzbDrone.Core.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.JobTests
{
/* [TestFixture]
[ExclusivelyUses("JOB_PROVIDER")]
public class JobControllerFixture : CoreTest<JobController>
{
FakeJob _fakeJob;
SlowJob _slowJob;
SlowJob2 _slowJob2;
BrokenJob _brokenJob;
DisabledJob _disabledJob;
private JobDefinition _updatedJob = null;
[SetUp]
public void Setup()
{
_fakeJob = new FakeJob();
_slowJob = new SlowJob();
_slowJob2 = new SlowJob2();
_brokenJob = new BrokenJob();
_disabledJob = new DisabledJob();
_updatedJob = null;
IEnumerable<IJob> jobs = new List<IJob> { _fakeJob, _slowJob, _slowJob2, _brokenJob, _disabledJob };
Mocker.SetConstant(jobs);
Mocker.GetMock<IJobRepository>()
.Setup(c => c.Update(It.IsAny<JobDefinition>()))
.Callback<JobDefinition>(c => _updatedJob = c);
Mocker.GetMock<IJobRepository>()
.Setup(c => c.GetDefinition(It.IsAny<Type>()))
.Returns(new JobDefinition());
}
private void GivenPendingJob(IList<JobDefinition> jobDefinition)
{
Mocker.GetMock<IJobRepository>().Setup(c => c.GetPendingJobs()).Returns(jobDefinition);
}
[TearDown]
public void TearDown()
{
Subject.Queue.Should().BeEmpty();
}
private void WaitForQueue()
{
Console.WriteLine("Waiting for queue to clear.");
var queue = Mocker.Resolve<JobController>().Queue;
while (Subject.IsProcessing)
{
Thread.Sleep(100);
}
}
[Test]
public void running_scheduled_jobs_should_updates_last_execution_time()
{
GivenPendingJob(new List<JobDefinition> { new JobDefinition { Type = _fakeJob.GetType().FullName } });
Subject.EnqueueScheduled();
WaitForQueue();
_updatedJob.LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10));
_updatedJob.LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10));
_fakeJob.ExecutionCount.Should().Be(1);
}
[Test]
public void failing_scheduled_job_should_mark_job_as_failed()
{
GivenPendingJob(new List<JobDefinition> { new JobDefinition { Type = _brokenJob.GetType().FullName } });
Subject.EnqueueScheduled();
WaitForQueue();
_updatedJob.LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10));
_updatedJob.Success.Should().BeFalse();
_brokenJob.ExecutionCount.Should().Be(1);
ExceptionVerification.ExpectedErrors(1);
}
[Test]
public void can_run_job_again()
{
Subject.Enqueue(typeof(FakeJob));
WaitForQueue();
Subject.Enqueue(typeof(FakeJob));
WaitForQueue();
Subject.Queue.Should().BeEmpty();
_fakeJob.ExecutionCount.Should().Be(2);
}
[Test]
public void should_ignore_job_with_same_arg()
{
Subject.Enqueue(typeof(SlowJob2), 1);
Subject.Enqueue(typeof(FakeJob), 1);
Subject.Enqueue(typeof(FakeJob), 1);
WaitForQueue();
Subject.Queue.Should().BeEmpty();
_fakeJob.ExecutionCount.Should().Be(1);
ExceptionVerification.AssertNoUnexcpectedLogs();
}
[Test]
public void can_run_broken_job_again()
{
Subject.Enqueue(typeof(BrokenJob));
WaitForQueue();
Subject.Enqueue(typeof(BrokenJob));
WaitForQueue();
_brokenJob.ExecutionCount.Should().Be(2);
ExceptionVerification.ExpectedErrors(2);
}
[Test]
public void schedule_hit_should_be_ignored_if_queue_is_running()
{
Subject.Enqueue(typeof(SlowJob));
Subject.EnqueueScheduled();
WaitForQueue();
_slowJob.ExecutionCount.Should().Be(1);
_fakeJob.ExecutionCount.Should().Be(0);
}
[Test]
public void can_queue_jobs_at_the_same_time()
{
Subject.Enqueue(typeof(SlowJob));
var thread1 = new Thread(() => Subject.Enqueue(typeof(FakeJob)));
var thread2 = new Thread(() => Subject.Enqueue(typeof(FakeJob)));
thread1.Start();
thread2.Start();
thread1.Join();
thread2.Join();
WaitForQueue();
_fakeJob.ExecutionCount.Should().Be(1);
_slowJob.ExecutionCount.Should().Be(1);
Subject.Queue.Should().BeEmpty();
}
[Test]
public void job_with_specific_target_should_not_update_status()
{
Subject.Enqueue(typeof(FakeJob), 10);
WaitForQueue();
Mocker.GetMock<IJobRepository>().Verify(c => c.Update(It.IsAny<JobDefinition>()), Times.Never());
_updatedJob.Should().BeNull();
}
[Test]
public void Item_added_to_queue_while_scheduler_runs_should_be_executed()
{
GivenPendingJob(new List<JobDefinition> { new JobDefinition { Type = _slowJob.GetType().FullName } });
var jobThread = new Thread(Subject.EnqueueScheduled);
jobThread.Start();
Thread.Sleep(200);
Subject.Enqueue(typeof(DisabledJob), 12);
WaitForQueue();
_slowJob.ExecutionCount.Should().Be(1);
_disabledJob.ExecutionCount.Should().Be(1);
}
[Test]
public void trygin_to_queue_unregistered_job_should_fail()
{
Subject.Enqueue(typeof(UpdateInfoJob));
WaitForQueue();
ExceptionVerification.ExpectedErrors(1);
}
[Test]
public void scheduled_job_should_have_scheduler_as_source()
{
GivenPendingJob(new List<JobDefinition> { new JobDefinition { Type = _slowJob.GetType().FullName }, new JobDefinition { Type = _slowJob2.GetType().FullName } });
Subject.EnqueueScheduled();
Subject.Queue.Should().OnlyContain(c => c.Source == JobQueueItem.JobSourceType.Scheduler);
WaitForQueue();
}#1#
}
}
*/
@@ -1,4 +1,4 @@
using System.Linq;
/*
using System;
using System.Collections.Generic;
using FizzWare.NBuilder;
@@ -42,11 +42,10 @@ namespace NzbDrone.Core.Test.JobTests
Storage.All().Should().HaveCount(1);
StoredModel.Interval.Should().Be((Int32)_fakeJob.DefaultInterval.TotalMinutes);
StoredModel.Name.Should().Be(_fakeJob.Name);
StoredModel.Type.Should().Be(_fakeJob.GetType().ToString());
StoredModel.Name.Should().Be(_fakeJob.GetType().ToString());
StoredModel.LastExecution.Should().HaveYear(DateTime.Now.Year);
StoredModel.LastExecution.Should().HaveMonth(DateTime.Now.Month);
StoredModel.LastExecution.Should().HaveDay(DateTime.Today.Day);
StoredModel.Enable.Should().BeTrue();
}
[Test]
@@ -63,13 +62,13 @@ namespace NzbDrone.Core.Test.JobTests
//Make sure deleted job is stored
AllStoredModels.Should().HaveCount(1);
AllStoredModels.Should().Contain(c => c.Type == deletedJob.Type);
AllStoredModels.Should().Contain(c => c.Name == deletedJob.Name);
Initialize();
//Make sure init has cleaned up the deleted job
AllStoredModels.Should().HaveCount(1);
AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type);
AllStoredModels.Should().NotContain(c => c.Name == deletedJob.Name);
}
[Test]
@@ -87,13 +86,13 @@ namespace NzbDrone.Core.Test.JobTests
//Make sure deleted job is stored
AllStoredModels.Should().HaveCount(1);
AllStoredModels.Should().Contain(c => c.Type == deletedJob.Type);
AllStoredModels.Should().Contain(c => c.Name == deletedJob.Name);
Initialize();
//Make sure init has cleaned up the deleted job
AllStoredModels.Should().HaveCount(1);
AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type);
AllStoredModels.Should().NotContain(c => c.Name == deletedJob.Name);
}
[Test]
@@ -103,9 +102,8 @@ namespace NzbDrone.Core.Test.JobTests
var oldJob = Builder<JobDefinition>.CreateNew()
.With(c => c.Id = 0)
.With(c => c.Name = "OldName")
.With(c => c.Type = typeof(FakeJob).ToString())
.With(c => c.Name = typeof(FakeJob).ToString())
.With(c => c.Interval = 0)
.With(c => c.Enable = true)
.With(c => c.Success = true)
.With(c => c.LastExecution = DateTime.Now.AddDays(-7).Date)
.Build();
@@ -121,27 +119,13 @@ namespace NzbDrone.Core.Test.JobTests
AllStoredModels.Should().HaveCount(1);
StoredModel.Type.Should().Be(newJob.GetType().FullName);
StoredModel.Name.Should().Be(newJob.GetType().FullName);
StoredModel.Name.Should().Be(newJob.Name);
StoredModel.Interval.Should().Be((int)newJob.DefaultInterval.TotalMinutes);
StoredModel.Enable.Should().Be(true);
StoredModel.Success.Should().Be(oldJob.Success);
StoredModel.LastExecution.Should().Be(oldJob.LastExecution);
}
[Test]
public void jobs_with_zero_interval_are_registered_as_disabled()
{
IEnumerable<IJob> fakeJobs = new List<IJob> { _disabledJob };
Mocker.SetConstant(fakeJobs);
Initialize();
Storage.All().Should().HaveCount(1);
Storage.All().First().Enable.Should().BeFalse();
}
[Test]
public void pending_job_should_get_jobs_that_have_matured()
@@ -149,7 +133,6 @@ namespace NzbDrone.Core.Test.JobTests
var oldJob = Builder<JobDefinition>.CreateNew()
.With(c => c.Id = 0)
.With(c => c.Interval = 1)
.With(c => c.Enable = true)
.With(c => c.Success = true)
.With(c => c.LastExecution = DateTime.Now.AddMinutes(-5))
.Build();
@@ -168,7 +151,6 @@ namespace NzbDrone.Core.Test.JobTests
var recent = Builder<JobDefinition>.CreateNew()
.With(c => c.Id = 0)
.With(c => c.Interval = 60)
.With(c => c.Enable = true)
.With(c => c.Success = true)
.With(c => c.LastExecution = DateTime.Now.AddMinutes(-5))
.Build();
@@ -193,7 +175,8 @@ namespace NzbDrone.Core.Test.JobTests
disabledJob.ExecutionCount.Should().Be(0);
}*/
}#1#
}
}
*/
@@ -1,65 +0,0 @@
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Jobs.Implementations;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
public class PostDownloadScanJobFixture : CoreTest<PostDownloadScanJob>
{
[SetUp]
public void Setup()
{
Mocker.GetMock<DiskProvider>().Setup(s => s.FolderExists(It.IsAny<string>())).Returns(true);
}
[Test]
public void should_use_options_Path_when_provided()
{
var path = @"C:\Test\Unsorted TV";
Mocker.GetMock<IDropFolderImportService>().Setup(s => s.ProcessDropFolder(path));
Subject.Start(MockNotification, new { Path = path });
Mocker.GetMock<IDropFolderImportService>().Verify(s => s.ProcessDropFolder(path), Times.Once());
}
[Test]
public void should_not_get_sabDropDir_when_path_is_supplied()
{
var path = @"C:\Test\Unsorted TV";
Mocker.GetMock<IDropFolderImportService>().Setup(s => s.ProcessDropFolder(path));
Subject.Start(MockNotification, new { Path = path });
Mocker.GetMock<IConfigService>().Verify(s => s.DownloadClientTvDirectory, Times.Never());
}
[Test]
public void should_get_sabDropDir_when_path_is_not_supplied()
{
var path = @"C:\Test\Unsorted TV";
Mocker.GetMock<IConfigService>().SetupGet(s => s.DownloadClientTvDirectory).Returns(path);
Subject.Start(MockNotification, null);
Mocker.GetMock<IConfigService>().Verify(s => s.DownloadClientTvDirectory, Times.Once());
}
[Test]
public void should_use_sabDropDir_when_options_Path_is_not_provided()
{
var path = @"C:\Test\Unsorted TV";
Mocker.GetMock<IConfigService>().SetupGet(s => s.DownloadClientTvDirectory).Returns(path);
Subject.Start(MockNotification, null);
Mocker.GetMock<IDropFolderImportService>().Verify(s => s.ProcessDropFolder(path), Times.Once());
}
}
}
@@ -1,70 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using NUnit.Framework;
using NzbDrone.Core.Jobs.Implementations;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.JobTests
{
[TestFixture]
public class RenameSeasonJobFixture : TestBase
{
private ProgressNotification _testNotification;
private Series _series;
private IList<EpisodeFile> _episodeFiles;
[SetUp]
public void Setup()
{
_testNotification = new ProgressNotification("TEST");
_series = Builder<Series>
.CreateNew()
.Build();
_episodeFiles = Builder<EpisodeFile>
.CreateListOfSize(5)
.All()
.With(e => e.SeasonNumber = 5)
.Build();
Mocker.GetMock<ISeriesRepository>()
.Setup(s => s.Get(_series.Id))
.Returns(_series);
Mocker.GetMock<IMediaFileService>()
.Setup(s => s.GetFilesBySeason(_series.Id, 5))
.Returns(_episodeFiles.ToList());
}
[Test]
public void should_throw_if_seriesId_is_zero()
{
Assert.Throws<ArgumentException>(() =>
Mocker.Resolve<RenameSeasonJob>().Start(_testNotification, new { SeriesId = 0, SeasonNumber = 10 }));
}
[Test]
public void should_throw_if_seasonId_is_less_than_zero()
{
Assert.Throws<ArgumentException>(() =>
Mocker.Resolve<RenameSeasonJob>().Start(_testNotification, new { SeriesId = _series.Id, SeasonNumber = -10 }));
}
[Test]
public void should_log_warning_if_no_episode_files_are_found()
{
Mocker.Resolve<RenameSeasonJob>().Start(_testNotification, new { SeriesId = _series.Id, SeasonNumber = 10 });
ExceptionVerification.ExpectedWarns(1);
}
}
}
+3 -1
View File
@@ -1,4 +1,5 @@
using System;
/*
using System;
using System.Linq;
using System.Threading;
using NzbDrone.Core.Jobs;
@@ -66,3 +67,4 @@ namespace NzbDrone.Core.Test.JobTests
}
}
}
*/