JobProvider.Initialize will now update existing jobs.

pull/6/head
Mark McDowall 13 years ago
parent ac5296e0ab
commit f56bf62991

@ -326,6 +326,33 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
registeredJobs.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
}
[Test]
public void init_should_update_existing_job()
{
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
Mocker.SetConstant(fakeJobs);
WithRealDb();
var initialFakeJob = Builder<JobDefinition>.CreateNew()
.With(c => c.Name = fakeJob.Name)
.With(c => c.TypeName = fakeJob.GetType().ToString())
.With(c => c.Interval = 60)
.Build();
var id = Convert.ToInt32(Db.Insert(initialFakeJob));
var jobProvider = Mocker.Resolve<JobProvider>();
//Act
jobProvider.Initialize();
//Assert
var registeredJobs = Db.Fetch<JobDefinition>();
registeredJobs.Should().HaveCount(1);
registeredJobs.First().Interval.Should().Be(fakeJob.DefaultInterval);
registeredJobs.First().Id.Should().Be(id);
}
[Test]
public void jobs_with_zero_interval_are_registered_as_disabled()
{

@ -86,8 +86,7 @@ namespace NzbDrone.Core.Jobs
foreach (var job in _jobs)
{
var jobLocal = job;
if (!currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
{
var settings = new JobDefinition
{
Enable = jobLocal.DefaultInterval > 0,
@ -97,12 +96,13 @@ namespace NzbDrone.Core.Jobs
LastExecution = DateTime.Now
};
SaveDefinition(settings);
}
if (currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
{
settings.Id = currentJobs.Single(c => c.TypeName == jobLocal.GetType().ToString()).Id;
}
SaveDefinition(settings);
}
}
/// <summary>

Loading…
Cancel
Save