From 69406a95d44b74cd361fc56315a0d606f471a2ef Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 19 May 2011 19:12:36 -0700 Subject: [PATCH] Fixed bug when a file that wasn't parsable would try to be imported --- NzbDrone.Core.Test/MediaFileProviderTests.cs | 34 ++++++++++++++++++++ NzbDrone.Core/Providers/MediaFileProvider.cs | 4 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index 6fe658c41..1ed614356 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -166,6 +166,40 @@ public void import_existing_season_file() Assert.IsNull(result); } + + [Test] + [Description("Verifies that a un-parsable file isn't imported")] + public void import_unparsable_file() + { + //Arrange + ///////////////////////////////////////// + + //Constants + const string fileName = @"WEEDS.avi"; + const int size = 12345; + + //Fakes + var fakeSeries = Builder.CreateNew().Build(); + + //Mocks + var mocker = new AutoMoqer(); + + mocker.GetMock(MockBehavior.Strict) + .Setup(r => r.Exists(It.IsAny>>())).Returns(false).Verifiable(); + + mocker.GetMock() + .Setup(e => e.GetSize(fileName)).Returns(size).Verifiable(); + + + //Act + var result = mocker.Resolve().ImportFile(fakeSeries, fileName); + + //Assert + mocker.VerifyAllMocks(); + Assert.IsNull(result); + ExceptionVerification.ExcpectedWarns(1); + } + [Test] [Description("Verifies that a new file imported properly")] public void import_sample_file() diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index 29832ca21..56b3a433c 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -72,11 +72,13 @@ public virtual EpisodeFile ImportFile(Series series, string filePath) if (!_repository.Exists(e => e.Path == Parser.NormalizePath(filePath))) { var parseResult = Parser.ParseEpisodeInfo(filePath); - parseResult.CleanTitle = series.Title;//replaces the nasty path as title to help with logging + if (parseResult == null) return null; + parseResult.CleanTitle = series.Title;//replaces the nasty path as title to help with logging + //Stores the list of episodes to add to the EpisodeFile var episodes = new List();