From 5c091ccb800e922321d97504b5f2edd91a168350 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 30 Nov 2011 20:16:46 -0800 Subject: [PATCH] Fixed broken tests. --- .../JobProviderTests/JobProviderFixture.cs | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs index 6e8927510..8e0550f28 100644 --- a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs @@ -40,6 +40,19 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests Mocker.Resolve().Queue.Should().BeEmpty(); } + private void ResetLastExecution() + { + var jobProvider = Mocker.Resolve(); + 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.Initialize(); - jobProvider.QueueScheduled(); + ResetLastExecution(); + Mocker.Resolve().QueueScheduled(); + WaitForQueue(); //Assert - WaitForQueue(); - var settings = jobProvider.All(); + var settings = Mocker.Resolve().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.Initialize(); - jobProvider.QueueScheduled(); + ResetLastExecution(); + Mocker.Resolve().QueueScheduled(); + WaitForQueue(); //Assert - WaitForQueue(); - var settings = jobProvider.All(); + var settings = Mocker.Resolve().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.Initialize(); - jobProvider.QueueScheduled(); + ResetLastExecution(); + + Mocker.Resolve().QueueScheduled(); WaitForQueue(); - jobProvider.QueueScheduled(); + + Mocker.Resolve().QueueScheduled(); WaitForQueue(); //Assert @@ -327,6 +339,7 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests //Act var jobProvider = Mocker.Resolve(); jobProvider.Initialize(); + ResetLastExecution(); jobProvider.QueueJob(typeof(FakeJob), 10); WaitForQueue(); @@ -386,15 +399,13 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests IList BaseFakeJobs = new List { slowJob, disabledJob }; Mocker.SetConstant(BaseFakeJobs); - var jobProvider = Mocker.Resolve(); - jobProvider.Initialize(); - - var _jobThread = new Thread(jobProvider.QueueScheduled); + ResetLastExecution(); + var _jobThread = new Thread(Mocker.Resolve().QueueScheduled); _jobThread.Start(); Thread.Sleep(200); - jobProvider.QueueJob(typeof(DisabledJob), 12); + Mocker.Resolve().QueueJob(typeof(DisabledJob), 12); WaitForQueue();