From c1bbd0bd5dda1e026be800f2b203ff52bccb92a7 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Thu, 30 May 2013 18:43:13 -0700 Subject: [PATCH] cleaned up handling of Unknown quality type. --- NzbDrone.Api/Mapping/ValueInjectorExtensions.cs | 4 ++-- NzbDrone.Api/Qualities/QualityProfileResource.cs | 2 -- NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs | 8 ++++---- NzbDrone.Core/Qualities/Quality.cs | 3 ++- NzbDrone.Core/Qualities/QualitySizeService.cs | 7 +------ 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/NzbDrone.Api/Mapping/ValueInjectorExtensions.cs b/NzbDrone.Api/Mapping/ValueInjectorExtensions.cs index 481360662..ce21efaef 100644 --- a/NzbDrone.Api/Mapping/ValueInjectorExtensions.cs +++ b/NzbDrone.Api/Mapping/ValueInjectorExtensions.cs @@ -28,14 +28,14 @@ public static class ValueInjectorExtensions foreach (var sourceItem in (IEnumerable)source) { - var e = Activator.CreateInstance(listSubType).InjectFrom(sourceItem); + var e = Activator.CreateInstance(listSubType).InjectFrom(sourceItem); addMethod.Invoke(result, new[] { e }); } return result; } - return (TTarget)new TTarget().InjectFrom(source); + return (TTarget)new TTarget().InjectFrom(source); } } } \ No newline at end of file diff --git a/NzbDrone.Api/Qualities/QualityProfileResource.cs b/NzbDrone.Api/Qualities/QualityProfileResource.cs index 363c5c90c..8bb65bfaf 100644 --- a/NzbDrone.Api/Qualities/QualityProfileResource.cs +++ b/NzbDrone.Api/Qualities/QualityProfileResource.cs @@ -6,7 +6,6 @@ namespace NzbDrone.Api.Qualities { public class QualityProfileResource : RestResource { - public Int32 Id { get; set; } public String Name { get; set; } public QualityResource Cutoff { get; set; } public List Qualities { get; set; } @@ -15,7 +14,6 @@ public class QualityProfileResource : RestResource public class QualityResource : RestResource { - public Int32 Id { get; set; } public Int32 Weight { get; set; } public String Name { get; set; } } diff --git a/NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs b/NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs index f3dded938..9c0b0b626 100644 --- a/NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs +++ b/NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs @@ -8,16 +8,16 @@ namespace NzbDrone.Core.Test.Qualities { [TestFixture] - + public class QualitySizeServiceFixture : CoreTest { [Test] public void Init_should_add_all_sizes() { Subject.Handle(new ApplicationStartedEvent()); - + Mocker.GetMock() - .Verify(v => v.Insert(It.IsAny()), Times.Exactly(Quality.All().Count - 1)); + .Verify(v => v.Insert(It.IsAny()), Times.Exactly(Quality.All().Count)); } [Test] @@ -33,7 +33,7 @@ public void Init_should_insert_any_missing_sizes() Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() - .Verify(v => v.Insert(It.IsAny()), Times.Exactly(Quality.All().Count - 2)); + .Verify(v => v.Insert(It.IsAny()), Times.Exactly(Quality.All().Count - 1)); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Qualities/Quality.cs b/NzbDrone.Core/Qualities/Quality.cs index bdd6f11b1..5d62d3b04 100644 --- a/NzbDrone.Core/Qualities/Quality.cs +++ b/NzbDrone.Core/Qualities/Quality.cs @@ -152,7 +152,6 @@ public static List All() { return new List { - Unknown, SDTV, WEBDL480p, DVD, @@ -168,6 +167,8 @@ public static List All() public static Quality FindById(int id) { + if (id == 0) return Unknown; + var quality = All().SingleOrDefault(q => q.Id == id); if (quality == null) diff --git a/NzbDrone.Core/Qualities/QualitySizeService.cs b/NzbDrone.Core/Qualities/QualitySizeService.cs index 7d7a00830..d3dce3199 100644 --- a/NzbDrone.Core/Qualities/QualitySizeService.cs +++ b/NzbDrone.Core/Qualities/QualitySizeService.cs @@ -45,18 +45,13 @@ public virtual QualitySize Get(int qualityId) return _qualitySizeRepository.GetByQualityId(qualityId); } - public void Init() - { - - } - public void Handle(ApplicationStartedEvent message) { var existing = All(); _logger.Debug("Setting up default quality sizes"); - foreach (var quality in Quality.All().Where(q => q.Id > 0)) + foreach (var quality in Quality.All()) { if (!existing.Any(s => s.QualityId == quality.Id)) {