diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs index 6b4c7338c..c54778b1c 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs @@ -24,6 +24,10 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests { new object[] { QualityTypes.SDTV, false }, new object[] { QualityTypes.DVD, true }, + }; + + public static object[] SkipImportTestCases = + { new object[] { QualityTypes.HDTV720p, false } }; @@ -78,7 +82,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests } [Test, TestCaseSource("ImportTestCases")] - public void import_new_file_with_better_same_quality_should_succeed(QualityTypes currentFileQuality, bool currentFileProper) + public void import_new_file_with_better_quality_should_succeed(QualityTypes currentFileQuality, bool currentFileProper) { const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv"; @@ -103,6 +107,33 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests VerifyFileImport(result, Mocker, fakeEpisode, SIZE); } + [Test, TestCaseSource("SkipImportTestCases")] + public void import_new_file_with_same_quality_should_not_import(QualityTypes currentFileQuality, bool currentFileProper) + { + const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv"; + + //Fakes + var fakeSeries = Builder.CreateNew().Build(); + var fakeEpisode = Builder.CreateNew() + .With(e => e.EpisodeFile = Builder.CreateNew() + .With(g => g.Quality = (QualityTypes)currentFileQuality) + .And(g => g.Proper = currentFileProper).Build() + ).Build(); + + + With80MBFile(); + + Mocker.GetMock() + .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode }); + + //Act + var result = Mocker.Resolve().ImportFile(fakeSeries, newFile); + + //Assert + VerifySkipImport(result, Mocker); + } + + [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.SDTV.XviD.AC3.-HELLYWOOD.avi")] public void import_new_file_episode_has_same_or_better_quality_should_skip(string fileName) @@ -235,10 +266,9 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock().Verify(p => p.DeleteFile(It.IsAny()), Times.Once()); } - [TestCase("WEEDS.S03E01.DUAL.hdtv.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv")] - public void import_new_multi_part_file_episode_has_equal_or_better_quality_than_existing(string fileName) + public void import_new_multi_part_file_episode_has_better_quality_than_existing(string fileName) { //Fakes var fakeSeries = Builder.CreateNew().Build(); @@ -267,6 +297,35 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock().Verify(p => p.DeleteFile(It.IsAny()), Times.Once()); } + [TestCase("WEEDS.S03E01.DUAL.hdtv.XviD.AC3.-HELLYWOOD.avi")] + public void skip_import_new_multi_part_file_episode_has_same_quality_as_existing(string fileName) + { + //Fakes + var fakeSeries = Builder.CreateNew().Build(); + + var fakeEpisodes = Builder.CreateListOfSize(2) + .All() + .With(e => e.EpisodeFile = Builder.CreateNew() + .With(f => f.Quality = QualityTypes.SDTV) + .Build()) + .Build(); + + With80MBFile(); + + Mocker.GetMock() + .Setup(p => p.Exists(It.IsAny())) + .Returns(false); + + Mocker.GetMock() + .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(fakeEpisodes); + + //Act + var result = Mocker.Resolve().ImportFile(fakeSeries, fileName); + + //Assert + VerifySkipImport(result, Mocker); + } + [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.HDTV.XviD.AC3.-HELLYWOOD.avi")] public void skip_import_new_multi_part_file_episode_existing_has_better_quality(string fileName) diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 51f3572a2..bf23acc79 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -143,7 +143,7 @@ namespace NzbDrone.Core.Providers } //Make sure this file is an upgrade for ALL episodes already on disk - if (episodes.All(e => e.EpisodeFile == null || e.EpisodeFile.QualityWrapper <= parseResult.Quality)) + if (episodes.All(e => e.EpisodeFile == null || e.EpisodeFile.QualityWrapper < parseResult.Quality)) { Logger.Debug("Deleting the existing file(s) on disk to upgrade to: {0}", filePath); //Do the delete for files where there is already an episode on disk