Fixed job provider existing job update bug.

This commit is contained in:
kay.one 2011-12-14 00:40:39 -08:00
parent 98e8f4361e
commit a7a7c4ab49
2 changed files with 22 additions and 17 deletions

View File

@ -313,7 +313,7 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
WithRealDb();
var deletedJob = Builder<JobDefinition>.CreateNew()
.With(c => c.Name = fakeJob.Name).Build();
Db.Insert(deletedJob);
var jobProvider = Mocker.Resolve<JobProvider>();
@ -334,9 +334,12 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
WithRealDb();
var initialFakeJob = Builder<JobDefinition>.CreateNew()
.With(c => c.Name = fakeJob.Name)
.With(c => c.Name = "NewName")
.With(c => c.TypeName = fakeJob.GetType().ToString())
.With(c => c.Interval = 60)
.With(c => c.Interval = 0)
.With(c => c.Enable = false)
.With(c => c.Success = true)
.With(c => c.LastExecution = DateTime.Now.AddDays(-7).Date)
.Build();
var id = Convert.ToInt32(Db.Insert(initialFakeJob));
@ -349,8 +352,13 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
//Assert
var registeredJobs = Db.Fetch<JobDefinition>();
registeredJobs.Should().HaveCount(1);
registeredJobs.First().TypeName.Should().Be(fakeJob.GetType().ToString());
registeredJobs.First().Name.Should().Be(fakeJob.Name);
registeredJobs.First().Interval.Should().Be(fakeJob.DefaultInterval);
registeredJobs.First().Id.Should().Be(id);
registeredJobs.First().Enable.Should().Be(true);
registeredJobs.First().Success.Should().Be(initialFakeJob.Success);
registeredJobs.First().LastExecution.Should().Be(initialFakeJob.LastExecution);
}
[Test]

View File

@ -85,23 +85,20 @@ namespace NzbDrone.Core.Jobs
foreach (var job in _jobs)
{
var jobLocal = job;
var jobDefinition = currentJobs.SingleOrDefault(c => c.TypeName == job.GetType().ToString());
var settings = new JobDefinition
if (jobDefinition == null)
{
Enable = jobLocal.DefaultInterval > 0,
TypeName = job.GetType().ToString(),
Name = jobLocal.Name,
Interval = jobLocal.DefaultInterval,
LastExecution = DateTime.Now
};
if (currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
{
settings.Id = currentJobs.Single(c => c.TypeName == jobLocal.GetType().ToString()).Id;
jobDefinition = new JobDefinition();
jobDefinition.TypeName = job.GetType().ToString();
jobDefinition.LastExecution = DateTime.Now;
}
SaveDefinition(settings);
jobDefinition.Enable = job.DefaultInterval > 0;
jobDefinition.Name = job.Name;
jobDefinition.Interval = job.DefaultInterval;
SaveDefinition(jobDefinition);
}
}