mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-26 17:57:43 +00:00
Fixed job provider existing job update bug.
This commit is contained in:
parent
98e8f4361e
commit
a7a7c4ab49
2 changed files with 22 additions and 17 deletions
|
@ -313,7 +313,7 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
||||||
WithRealDb();
|
WithRealDb();
|
||||||
var deletedJob = Builder<JobDefinition>.CreateNew()
|
var deletedJob = Builder<JobDefinition>.CreateNew()
|
||||||
.With(c => c.Name = fakeJob.Name).Build();
|
.With(c => c.Name = fakeJob.Name).Build();
|
||||||
|
|
||||||
Db.Insert(deletedJob);
|
Db.Insert(deletedJob);
|
||||||
var jobProvider = Mocker.Resolve<JobProvider>();
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
||||||
|
|
||||||
|
@ -334,9 +334,12 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
||||||
|
|
||||||
WithRealDb();
|
WithRealDb();
|
||||||
var initialFakeJob = Builder<JobDefinition>.CreateNew()
|
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.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();
|
.Build();
|
||||||
|
|
||||||
var id = Convert.ToInt32(Db.Insert(initialFakeJob));
|
var id = Convert.ToInt32(Db.Insert(initialFakeJob));
|
||||||
|
@ -349,8 +352,13 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
||||||
//Assert
|
//Assert
|
||||||
var registeredJobs = Db.Fetch<JobDefinition>();
|
var registeredJobs = Db.Fetch<JobDefinition>();
|
||||||
registeredJobs.Should().HaveCount(1);
|
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().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]
|
[Test]
|
||||||
|
|
|
@ -85,23 +85,20 @@ namespace NzbDrone.Core.Jobs
|
||||||
|
|
||||||
foreach (var job in _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,
|
jobDefinition = new JobDefinition();
|
||||||
TypeName = job.GetType().ToString(),
|
jobDefinition.TypeName = job.GetType().ToString();
|
||||||
Name = jobLocal.Name,
|
jobDefinition.LastExecution = DateTime.Now;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveDefinition(settings);
|
jobDefinition.Enable = job.DefaultInterval > 0;
|
||||||
|
jobDefinition.Name = job.Name;
|
||||||
|
jobDefinition.Interval = job.DefaultInterval;
|
||||||
|
|
||||||
|
SaveDefinition(jobDefinition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue