From edf9d1d2ccf7e94f8a46394d22257576e4f856cd Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 7 Jul 2011 20:57:31 -0700 Subject: [PATCH] Initial quality is only setup if no other quality profiles exists. --- NzbDrone.Core.Test/QualityProfileTest.cs | 47 +++++++++++++++++++++- NzbDrone.Core/Providers/QualityProvider.cs | 23 +++-------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/NzbDrone.Core.Test/QualityProfileTest.cs b/NzbDrone.Core.Test/QualityProfileTest.cs index af617b935..186356dad 100644 --- a/NzbDrone.Core.Test/QualityProfileTest.cs +++ b/NzbDrone.Core.Test/QualityProfileTest.cs @@ -1,6 +1,7 @@ // ReSharper disable RedundantUsingDirective using System; using System.Collections.Generic; +using System.Linq; using AutoMoq; using FizzWare.NBuilder; using FluentAssertions; @@ -73,7 +74,7 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); var db = MockLib.GetEmptyDatabase(); mocker.SetConstant(db); - + var testProfile = new QualityProfile { Name = Guid.NewGuid().ToString(), @@ -95,7 +96,7 @@ namespace NzbDrone.Core.Test updated.Name.Should().Be(currentProfile.Name); updated.Cutoff.Should().Be(QualityTypes.Bluray720p); updated.AllowedString.Should().Be(currentProfile.AllowedString); - + } [Test] @@ -127,5 +128,47 @@ namespace NzbDrone.Core.Test Assert.AreEqual(profileId, result[0].QualityProfileId); Assert.AreEqual(testProfile.Name, profile.Name); } + + + [Test] + public void SetupInitial_should_add_two_profiles() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + //Act + mocker.Resolve().SetupDefaultProfiles(); + + //Assert + var profiles = mocker.Resolve().GetAllProfiles(); + + + profiles.Should().HaveCount(2); + profiles.Should().Contain(e => e.Name == "HD"); + profiles.Should().Contain(e => e.Name == "SD"); + + } + + [Test] + //This confirms that new profiles are added only if no other profiles exists. + //We don't want to keep adding them back if a user deleted them on purpose. + public void SetupInitial_should_skip_if_any_profile_exists() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + var fakeProfile = Builder.CreateNew().Build(); + + //Act + mocker.Resolve().Add(fakeProfile); + mocker.Resolve().SetupDefaultProfiles(); + + //Assert + var profiles = mocker.Resolve().GetAllProfiles(); + + + profiles.Should().HaveCount(1); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/QualityProvider.cs b/NzbDrone.Core/Providers/QualityProvider.cs index fc9fd5353..b7ba8ebe4 100644 --- a/NzbDrone.Core/Providers/QualityProvider.cs +++ b/NzbDrone.Core/Providers/QualityProvider.cs @@ -58,9 +58,10 @@ namespace NzbDrone.Core.Providers public virtual void SetupDefaultProfiles() { - Logger.Info("Setting up default quality profiles"); + if (GetAllProfiles().Count != 0) + return; - var profiles = GetAllProfiles(); + Logger.Info("Setting up default quality profiles"); var sd = new QualityProfile { Name = "SD", Allowed = new List { QualityTypes.SDTV, QualityTypes.DVD }, Cutoff = QualityTypes.SDTV }; @@ -71,23 +72,9 @@ namespace NzbDrone.Core.Providers Cutoff = QualityTypes.HDTV }; - //Add or Update SD - Logger.Debug(String.Format("Checking for default QualityProfile: {0}", sd.Name)); - var sdDb = profiles.Where(p => p.Name == sd.Name).FirstOrDefault(); - if (sdDb == null) - { - Logger.Debug(String.Format("Adding new default QualityProfile: {0}", sd.Name)); - Add(sd); - } + Add(sd); + Add(hd); - //Add or Update HD - Logger.Debug(String.Format("Checking for default QualityProfile: {0}", hd.Name)); - var hdDb = profiles.Where(p => p.Name == hd.Name).FirstOrDefault(); - if (hdDb == null) - { - Logger.Debug(String.Format("Adding new default QualityProfile: {0}", hd.Name)); - Add(hd); - } } } } \ No newline at end of file