From 197979ea3c8bd52fcfd0f09cf4cfd176e1ee8cdc Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 23 Jan 2012 08:24:07 -0800 Subject: [PATCH] QualityParseTest will accept bool IsProper as a parameter. IsUpgrade will take into account that a proper of the same quality should be accepted even if the cutoff was met. --- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + NzbDrone.Core.Test/ParserTest.cs | 72 +++++----- .../IsUpgradeFixture.cs | 127 ++++++++++++++++++ NzbDrone.Core/Providers/InventoryProvider.cs | 10 +- 4 files changed, 172 insertions(+), 38 deletions(-) create mode 100644 NzbDrone.Core.Test/ProviderTests/InventoryProviderTests/IsUpgradeFixture.cs diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index ab489fa14..62f65849c 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -102,6 +102,7 @@ + diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 112c5b520..54fbef9fc 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -104,44 +104,46 @@ namespace NzbDrone.Core.Test ExceptionVerification.IgnoreWarns(); } - [TestCase("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.DVD)] - [TestCase("WEEDS.S03E01-06.DUAL.BDRip.X-viD.AC3.-HELLYWOOD", QualityTypes.DVD)] - [TestCase("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.DVD)] - [TestCase("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV)] - [TestCase("this has no extention or periods HDTV", QualityTypes.SDTV)] - [TestCase("Chuck.S04E05.HDTV.XviD-LOL", QualityTypes.SDTV)] - [TestCase("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", QualityTypes.DVD)] - [TestCase("The.Girls.Next.Door.S03E06.DVD.Rip.XviD-WiDE", QualityTypes.DVD)] - [TestCase("The.Girls.Next.Door.S03E06.HDTV-WiDE", QualityTypes.SDTV)] - [TestCase("Degrassi.S10E27.WS.DSR.XviD-2HD", QualityTypes.SDTV)] - [TestCase("Sonny.With.a.Chance.S02E15.720p.WEB-DL.DD5.1.H.264-SURFER", QualityTypes.WEBDL)] - [TestCase("Sonny.With.a.Chance.S02E15.720p", QualityTypes.HDTV)] - [TestCase("Sonny.With.a.Chance.S02E15.mkv", QualityTypes.HDTV)] - [TestCase("Sonny.With.a.Chance.S02E15.avi", QualityTypes.SDTV)] - [TestCase("Sonny.With.a.Chance.S02E15.xvid", QualityTypes.SDTV)] - [TestCase("Sonny.With.a.Chance.S02E15.divx", QualityTypes.SDTV)] - [TestCase("Sonny.With.a.Chance.S02E15", QualityTypes.Unknown)] - [TestCase("Chuck - S01E04 - So Old - Playdate - 720p TV.mkv", QualityTypes.HDTV)] - [TestCase("Chuck - S22E03 - MoneyBART - HD TV.mkv", QualityTypes.HDTV)] - [TestCase("Chuck - S01E03 - Come Fly With Me - 720p BluRay.mkv", QualityTypes.Bluray720p)] - [TestCase("Chuck - S01E03 - Come Fly With Me - 1080p BluRay.mkv", QualityTypes.Bluray1080p)] - [TestCase("Chuck - S11E06 - D-Yikes! - 720p WEB-DL.mkv", QualityTypes.WEBDL)] - [TestCase("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.DVD)] - [TestCase("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.DVD)] - [TestCase("Law & Order: Special Victims Unit - 11x11 - Quickie", QualityTypes.Unknown)] - [TestCase("(NZB)", QualityTypes.Unknown)] - [TestCase("S07E23 - [HDTV].mkv ", QualityTypes.HDTV)] - [TestCase("S07E23 - [WEBDL].mkv ", QualityTypes.WEBDL)] - [TestCase("S07E23.mkv ", QualityTypes.HDTV)] - [TestCase("S07E23 .avi ", QualityTypes.SDTV)] - [TestCase("WEEDS.S03E01-06.DUAL.XviD.Bluray.AC3.-HELLYWOOD.avi", QualityTypes.DVD)] - [TestCase("WEEDS.S03E01-06.DUAL.Bluray.AC3.-HELLYWOOD.avi", QualityTypes.Bluray720p)] - [TestCase("The Voice S01E11 The Finals 1080i HDTV DD5.1 MPEG2-TrollHD", QualityTypes.Unknown)] - [TestCase("Nikita S02E01 HDTV XviD 2HD", QualityTypes.SDTV)] - public void quality_parse(string postTitle, object quality) + [TestCase("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.DVD, false)] + [TestCase("WEEDS.S03E01-06.DUAL.BDRip.X-viD.AC3.-HELLYWOOD", QualityTypes.DVD, false)] + [TestCase("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.DVD, false)] + [TestCase("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV, false)] + [TestCase("this has no extention or periods HDTV", QualityTypes.SDTV, false)] + [TestCase("Chuck.S04E05.HDTV.XviD-LOL", QualityTypes.SDTV, false)] + [TestCase("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", QualityTypes.DVD, false)] + [TestCase("The.Girls.Next.Door.S03E06.DVD.Rip.XviD-WiDE", QualityTypes.DVD, false)] + [TestCase("The.Girls.Next.Door.S03E06.HDTV-WiDE", QualityTypes.SDTV, false)] + [TestCase("Degrassi.S10E27.WS.DSR.XviD-2HD", QualityTypes.SDTV, false)] + [TestCase("Sonny.With.a.Chance.S02E15.720p.WEB-DL.DD5.1.H.264-SURFER", QualityTypes.WEBDL, false)] + [TestCase("Sonny.With.a.Chance.S02E15.720p", QualityTypes.HDTV, false)] + [TestCase("Sonny.With.a.Chance.S02E15.mkv", QualityTypes.HDTV, false)] + [TestCase("Sonny.With.a.Chance.S02E15.avi", QualityTypes.SDTV, false)] + [TestCase("Sonny.With.a.Chance.S02E15.xvid", QualityTypes.SDTV, false)] + [TestCase("Sonny.With.a.Chance.S02E15.divx", QualityTypes.SDTV, false)] + [TestCase("Sonny.With.a.Chance.S02E15", QualityTypes.Unknown, false)] + [TestCase("Chuck - S01E04 - So Old - Playdate - 720p TV.mkv", QualityTypes.HDTV, false)] + [TestCase("Chuck - S22E03 - MoneyBART - HD TV.mkv", QualityTypes.HDTV, false)] + [TestCase("Chuck - S01E03 - Come Fly With Me - 720p BluRay.mkv", QualityTypes.Bluray720p, false)] + [TestCase("Chuck - S01E03 - Come Fly With Me - 1080p BluRay.mkv", QualityTypes.Bluray1080p, false)] + [TestCase("Chuck - S11E06 - D-Yikes! - 720p WEB-DL.mkv", QualityTypes.WEBDL, false)] + [TestCase("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.DVD, false)] + [TestCase("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.DVD, false)] + [TestCase("Law & Order: Special Victims Unit - 11x11 - Quickie", QualityTypes.Unknown, false)] + [TestCase("(NZB)", QualityTypes.Unknown, false)] + [TestCase("S07E23 - [HDTV].mkv ", QualityTypes.HDTV, false)] + [TestCase("S07E23 - [WEBDL].mkv ", QualityTypes.WEBDL, false)] + [TestCase("S07E23.mkv ", QualityTypes.HDTV, false)] + [TestCase("S07E23 .avi ", QualityTypes.SDTV, false)] + [TestCase("WEEDS.S03E01-06.DUAL.XviD.Bluray.AC3.-HELLYWOOD.avi", QualityTypes.DVD, false)] + [TestCase("WEEDS.S03E01-06.DUAL.Bluray.AC3.-HELLYWOOD.avi", QualityTypes.Bluray720p, false)] + [TestCase("The Voice S01E11 The Finals 1080i HDTV DD5.1 MPEG2-TrollHD", QualityTypes.Unknown, false)] + [TestCase("Nikita S02E01 HDTV XviD 2HD", QualityTypes.SDTV, false)] + [TestCase("Gossip Girl S05E11 PROPER HDTV XviD 2HD", QualityTypes.SDTV, true)] + public void quality_parse(string postTitle, object quality, bool proper) { var result = Parser.ParseQuality(postTitle); result.QualityType.Should().Be(quality); + result.Proper.Should().Be(proper); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/InventoryProviderTests/IsUpgradeFixture.cs b/NzbDrone.Core.Test/ProviderTests/InventoryProviderTests/IsUpgradeFixture.cs new file mode 100644 index 000000000..08e6bf614 --- /dev/null +++ b/NzbDrone.Core.Test/ProviderTests/InventoryProviderTests/IsUpgradeFixture.cs @@ -0,0 +1,127 @@ +// ReSharper disable RedundantUsingDirective + +using System; +using System.Collections.Generic; + +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common.AutoMoq; + +namespace NzbDrone.Core.Test.ProviderTests.InventoryProviderTests +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class IsUpgradeFixture : CoreTest + { + [Test] + public void IsUpgrade_should_return_true_if_new_is_proper_and_current_isnt_even_if_cutoff_is_met() + { + var currentQuality = new Quality(QualityTypes.SDTV, false); + var newQuality = new Quality(QualityTypes.SDTV, true); + var cutoff = QualityTypes.SDTV; + + var result = InventoryProvider.IsUpgrade(currentQuality, newQuality, cutoff); + + //Assert + result.Should().BeTrue(); + } + + [Test] + public void IsUpgrade_should_return_true_if_new_quality_is_better_than_current_and_cutoff_is_not_met() + { + var currentQuality = new Quality(QualityTypes.SDTV, false); + var newQuality = new Quality(QualityTypes.DVD, true); + var cutoff = QualityTypes.DVD; + + var result = InventoryProvider.IsUpgrade(currentQuality, newQuality, cutoff); + + //Assert + result.Should().BeTrue(); + } + + [Test] + public void IsUpgrade_should_return_false_if_new_quality_is_same_as_current_and_cutoff_is_met() + { + var currentQuality = new Quality(QualityTypes.SDTV, false); + var newQuality = new Quality(QualityTypes.SDTV, false); + var cutoff = QualityTypes.SDTV; + + var result = InventoryProvider.IsUpgrade(currentQuality, newQuality, cutoff); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsUpgrade_should_return_false_if_new_quality_is_better_than_current_and_cutoff_is_met() + { + var currentQuality = new Quality(QualityTypes.SDTV, false); + var newQuality = new Quality(QualityTypes.DVD, true); + var cutoff = QualityTypes.SDTV; + + var result = InventoryProvider.IsUpgrade(currentQuality, newQuality, cutoff); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsUpgrade_should_return_false_if_new_quality_is_worse_than_current_and_cutoff_is_not_met() + { + var currentQuality = new Quality(QualityTypes.WEBDL, false); + var newQuality = new Quality(QualityTypes.HDTV, true); + var cutoff = QualityTypes.Bluray720p; + + var result = InventoryProvider.IsUpgrade(currentQuality, newQuality, cutoff); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsUpgrade_should_return_false_if_new_quality_is_worse_than_current_and_cutoff_is_met() + { + var currentQuality = new Quality(QualityTypes.WEBDL, false); + var newQuality = new Quality(QualityTypes.HDTV, true); + var cutoff = QualityTypes.WEBDL; + + var result = InventoryProvider.IsUpgrade(currentQuality, newQuality, cutoff); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsUpgrade_should_return_false_if_new_quality_is_the_same_as_current_and_cutoff_is_met() + { + var currentQuality = new Quality(QualityTypes.WEBDL, false); + var newQuality = new Quality(QualityTypes.WEBDL, false); + var cutoff = QualityTypes.WEBDL; + + var result = InventoryProvider.IsUpgrade(currentQuality, newQuality, cutoff); + + //Assert + result.Should().BeFalse(); + } + + [Test] + public void IsUpgrade_should_return_true_if_new_quality_is_a_proper_with_the_same_quality_as_current_and_cutoff_is_not_met() + { + var currentQuality = new Quality(QualityTypes.WEBDL, false); + var newQuality = new Quality(QualityTypes.WEBDL, true); + var cutoff = QualityTypes.Bluray720p; + + var result = InventoryProvider.IsUpgrade(currentQuality, newQuality, cutoff); + + //Assert + result.Should().BeTrue(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/InventoryProvider.cs b/NzbDrone.Core/Providers/InventoryProvider.cs index 9ca358eb2..42a212811 100644 --- a/NzbDrone.Core/Providers/InventoryProvider.cs +++ b/NzbDrone.Core/Providers/InventoryProvider.cs @@ -125,8 +125,12 @@ namespace NzbDrone.Core.Providers { if (currentQuality.QualityType >= cutOff) { - Logger.Trace("Existing item meets cut-off. skipping."); - return false; + if (newQuality.QualityType > currentQuality.QualityType || + (newQuality.QualityType == currentQuality.QualityType && newQuality.Proper == currentQuality.Proper)) + { + Logger.Trace("Existing item meets cut-off. skipping."); + return false; + } } if (newQuality > currentQuality) @@ -140,7 +144,7 @@ namespace NzbDrone.Core.Providers if (currentQuality == newQuality && !newQuality.Proper) { - Logger.Trace("same quality. not proper skipping"); + Logger.Trace("Same quality, not proper skipping"); return false; }