From cb0f1fe513ef7129f46244c0ccb47eaa513b49f8 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 22 Sep 2012 23:01:31 -0700 Subject: [PATCH] PostDownloadScanJob can now be passed a path --- .../JobTests/PostDownloadScanJobFixture.cs | 72 +++++++++++++++++++ NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + NzbDrone.Core/Jobs/PostDownloadScanJob.cs | 8 ++- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs diff --git a/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs b/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs new file mode 100644 index 000000000..e754d4d0d --- /dev/null +++ b/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs @@ -0,0 +1,72 @@ +using System.Linq; +using System; +using System.Diagnostics; +using System.IO; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Core.Jobs; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.JobTests +{ + [TestFixture] + internal class PostDownloadScanJobFixture : CoreTest + { + [SetUp] + public void Setup() + { + Mocker.GetMock().Setup(s => s.FolderExists(It.IsAny())).Returns(true); + } + + [Test] + public void should_use_options_Path_when_provided() + { + var path = @"C:\Test\Unsorted TV"; + + Mocker.GetMock().Setup(s => s.ProcessDropFolder(path)); + Mocker.Resolve().Start(MockNotification, new { Path = path }); + + Mocker.GetMock().Verify(s => s.ProcessDropFolder(path), Times.Once()); + } + + [Test] + public void should_not_get_sabDropDir_when_path_is_supplied() + { + var path = @"C:\Test\Unsorted TV"; + + Mocker.GetMock().Setup(s => s.ProcessDropFolder(path)); + Mocker.Resolve().Start(MockNotification, new { Path = path }); + + Mocker.GetMock().Verify(s => s.SabDropDirectory, Times.Never()); + } + + [Test] + public void should_get_sabDropDir_when_path_is_not_supplied() + { + var path = @"C:\Test\Unsorted TV"; + + Mocker.GetMock().SetupGet(s => s.SabDropDirectory).Returns(path); + Mocker.Resolve().Start(MockNotification, null); + + Mocker.GetMock().Verify(s => s.SabDropDirectory, Times.Once()); + } + + [Test] + public void should_use_sabDropDir_when_options_Path_is_not_provided() + { + var path = @"C:\Test\Unsorted TV"; + + Mocker.GetMock().SetupGet(s => s.SabDropDirectory).Returns(path); + Mocker.Resolve().Start(MockNotification, null); + + Mocker.GetMock().Verify(s => s.ProcessDropFolder(path), Times.Once()); + } + } +} diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 7cabc5537..76de94954 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -143,6 +143,7 @@ + diff --git a/NzbDrone.Core/Jobs/PostDownloadScanJob.cs b/NzbDrone.Core/Jobs/PostDownloadScanJob.cs index 6a156b3c0..4ab9b8732 100644 --- a/NzbDrone.Core/Jobs/PostDownloadScanJob.cs +++ b/NzbDrone.Core/Jobs/PostDownloadScanJob.cs @@ -41,7 +41,13 @@ namespace NzbDrone.Core.Jobs public virtual void Start(ProgressNotification notification, dynamic options) { - var dropFolder = _configProvider.SabDropDirectory; + string dropFolder; + + if (options != null && !String.IsNullOrWhiteSpace(options.Path)) + dropFolder = options.Path; + + else + dropFolder = _configProvider.SabDropDirectory; if (String.IsNullOrWhiteSpace(dropFolder)) {