Fixed broken tests.

pull/2/head
kay.one 13 years ago
parent 6805a1041b
commit 5c091ccb80

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

Loading…
Cancel
Save