1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 23:42:33 +01:00

Fixed broken tests.

This commit is contained in:
kay.one 2011-11-30 20:16:46 -08:00
parent 6805a1041b
commit 5c091ccb80

View File

@ -40,6 +40,19 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
Mocker.Resolve<JobProvider>().Queue.Should().BeEmpty();
}
private void ResetLastExecution()
{
var jobProvider = Mocker.Resolve<JobProvider>();
jobProvider.Initialize();
var jobs = jobProvider.All();
foreach (var jobDefinition in jobs)
{
jobDefinition.LastExecution = new DateTime(2000, 1, 1);
jobProvider.SaveDefinition(jobDefinition);
}
}
private void WaitForQueue()
{
Console.WriteLine("Waiting for queue to clear.");
@ -58,13 +71,12 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
Mocker.SetConstant(BaseFakeJobs);
//Act
var jobProvider = Mocker.Resolve<JobProvider>();
jobProvider.Initialize();
jobProvider.QueueScheduled();
ResetLastExecution();
Mocker.Resolve<JobProvider>().QueueScheduled();
WaitForQueue();
//Assert
WaitForQueue();
var settings = jobProvider.All();
var settings = Mocker.Resolve<JobProvider>().All();
settings.First().LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10));
fakeJob.ExecutionCount.Should().Be(1);
}
@ -76,13 +88,12 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
Mocker.SetConstant(BaseFakeJobs);
//Act
var jobProvider = Mocker.Resolve<JobProvider>();
jobProvider.Initialize();
jobProvider.QueueScheduled();
ResetLastExecution();
Mocker.Resolve<JobProvider>().QueueScheduled();
WaitForQueue();
//Assert
WaitForQueue();
var settings = jobProvider.All();
var settings = Mocker.Resolve<JobProvider>().All();
settings.First().LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10));
settings.First().Success.Should().BeFalse();
brokenJob.ExecutionCount.Should().Be(1);
@ -96,11 +107,12 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
Mocker.SetConstant(BaseFakeJobs);
//Act
var jobProvider = Mocker.Resolve<JobProvider>();
jobProvider.Initialize();
jobProvider.QueueScheduled();
ResetLastExecution();
Mocker.Resolve<JobProvider>().QueueScheduled();
WaitForQueue();
jobProvider.QueueScheduled();
Mocker.Resolve<JobProvider>().QueueScheduled();
WaitForQueue();
//Assert
@ -327,6 +339,7 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
//Act
var jobProvider = Mocker.Resolve<JobProvider>();
jobProvider.Initialize();
ResetLastExecution();
jobProvider.QueueJob(typeof(FakeJob), 10);
WaitForQueue();
@ -386,15 +399,13 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
IList<IJob> BaseFakeJobs = new List<IJob> { slowJob, disabledJob };
Mocker.SetConstant(BaseFakeJobs);
var jobProvider = Mocker.Resolve<JobProvider>();
jobProvider.Initialize();
var _jobThread = new Thread(jobProvider.QueueScheduled);
ResetLastExecution();
var _jobThread = new Thread(Mocker.Resolve<JobProvider>().QueueScheduled);
_jobThread.Start();
Thread.Sleep(200);
jobProvider.QueueJob(typeof(DisabledJob), 12);
Mocker.Resolve<JobProvider>().QueueJob(typeof(DisabledJob), 12);
WaitForQueue();