From 08b2e293d3f1d1d43023b1e4740ad01f96ed1868 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 24 Jul 2014 18:02:47 -0700 Subject: [PATCH] Verify disk scan won't scan if root folder doesn't exist --- .../DiskScanServiceTests/ScanFixture.cs | 44 +++++++++++++++++++ .../NzbDrone.Core.Test.csproj | 1 + .../Configuration/ConfigFileProvider.cs | 4 +- .../MediaFiles/DiskScanService.cs | 4 +- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/NzbDrone.Core.Test/MediaFiles/DiskScanServiceTests/ScanFixture.cs diff --git a/src/NzbDrone.Core.Test/MediaFiles/DiskScanServiceTests/ScanFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/DiskScanServiceTests/ScanFixture.cs new file mode 100644 index 000000000..ea1a07f8d --- /dev/null +++ b/src/NzbDrone.Core.Test/MediaFiles/DiskScanServiceTests/ScanFixture.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using FizzWare.NBuilder; +using Moq; +using NUnit.Framework; +using NzbDrone.Common.Disk; +using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.MediaFiles.Commands; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests +{ + [TestFixture] + public class ScanFixture : CoreTest + { + private Series _series; + + [SetUp] + public void Setup() + { + _series = Builder.CreateNew() + .With(s => s.Path = @"C:\Test\TV\Series") + .Build(); + + Mocker.GetMock() + .Setup(s => s.GetParentFolder(It.IsAny())) + .Returns((String path) => Directory.GetParent(path).FullName); + } + + [Test] + public void should_not_scan_if_series_root_folder_does_not_exist() + { + Subject.Scan(_series); + + ExceptionVerification.ExpectedWarns(1); + + Mocker.GetMock() + .Verify(v => v.PublishCommand(It.IsAny()), Times.Never()); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 59e3a0599..a36695aa6 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -155,6 +155,7 @@ + diff --git a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs index d0954c221..ecb23d0a2 100644 --- a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -168,9 +168,9 @@ public string UrlBase { get { - var urlBase = GetValue("UrlBase", ""); + var urlBase = GetValue("UrlBase", "").Trim('/'); - if (String.IsNullOrEmpty(urlBase)) + if (urlBase.IsNullOrWhiteSpace()) { return urlBase; } diff --git a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs index c8d94c2ed..4bdfe04b7 100644 --- a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +using System.Diagnostics; using System.IO; using System.Linq; using NLog;