From 05370518c5f0ecd90b2c48ceb8ad97312755860a Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 25 Jul 2013 22:00:57 -0700 Subject: [PATCH] fixing linux tests --- NzbDrone.Common.Test/DiskProviderFixture.cs | 22 ++++++++----------- .../EnsureTest/PathExtensionFixture.cs | 10 +++++++++ .../BlackholeProviderFixture.cs | 8 +++++-- .../RootFolderServiceFixture.cs | 9 ++++---- .../NzbDrone.Test.Common.csproj | 1 + NzbDrone.Test.Common/StringExtensions.cs | 22 +++++++++++++++++++ 6 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 NzbDrone.Test.Common/StringExtensions.cs diff --git a/NzbDrone.Common.Test/DiskProviderFixture.cs b/NzbDrone.Common.Test/DiskProviderFixture.cs index 0b95d93b7..c5d1fefea 100644 --- a/NzbDrone.Common.Test/DiskProviderFixture.cs +++ b/NzbDrone.Common.Test/DiskProviderFixture.cs @@ -42,13 +42,15 @@ namespace NzbDrone.Common.Test [Test] public void directory_exist_should_be_able_to_find_existing_unc_share() { + WindowsOnly(); + Subject.FolderExists(@"\\localhost\c$").Should().BeTrue(); } [Test] public void directory_exist_should_not_be_able_to_find_none_existing_folder() { - Subject.FolderExists(@"C:\ThisBetterNotExist\").Should().BeFalse(); + Subject.FolderExists(@"C:\ThisBetterNotExist\".AsOsAgnostic()).Should().BeFalse(); } [Test] @@ -140,20 +142,14 @@ namespace NzbDrone.Common.Test [TestCase(@"\\smallcheese\DRIVE_G\TV-C\Simspsons", @"\\smallcheese\DRIVE_G\TV-C\Simspsons")] public void paths_should_be_equal(string first, string second) { - if (first.StartsWith("\\")) - { - //verify the linux equivalent. - DiskProvider.PathEquals(first, second).Should().BeTrue(); - } - - DiskProvider.PathEquals(first, second).Should().BeTrue(); + DiskProvider.PathEquals(first.AsOsAgnostic(), second.AsOsAgnostic()).Should().BeTrue(); } - [TestCase(@"D:\Test", @"C:\Test\")] - [TestCase(@"D:\Test\Test", @"C:\TestTest\")] + [TestCase(@"C:\Test", @"C:\Test2\")] + [TestCase(@"C:\Test\Test", @"C:\TestTest\")] public void paths_should_not_be_equal(string first, string second) { - DiskProvider.PathEquals(first, second).Should().BeFalse(); + DiskProvider.PathEquals(first.AsOsAgnostic(), second.AsOsAgnostic()).Should().BeFalse(); } [Test] @@ -180,8 +176,8 @@ namespace NzbDrone.Common.Test [Explicit] public void check_last_write() { - Console.WriteLine(Subject.GetLastFolderWrite(@"C:\DRIVERS")); - Console.WriteLine(new DirectoryInfo(@"C:\DRIVERS").LastWriteTimeUtc); + Console.WriteLine(Subject.GetLastFolderWrite(_binFolder.FullName)); + Console.WriteLine(_binFolder.LastWriteTimeUtc); } private void VerifyCopy() diff --git a/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs b/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs index 82b134be4..1d5cd62ff 100644 --- a/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs +++ b/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs @@ -8,8 +8,18 @@ namespace NzbDrone.Common.Test.EnsureTest public class PathExtensionFixture : TestBase { [TestCase(@"p:\TV Shows\file with, comma.mkv")] + [TestCase(@"\\serer\share\file with, comma.mkv")] public void EnsureWindowsPath(string path) { + WindowsOnly(); + Ensure.That(() => path).IsValidPath(); + } + + + [TestCase(@"var/user/file with, comma.mkv")] + public void EnsureLinuxPath(string path) + { + LinuxOnly(); Ensure.That(() => path).IsValidPath(); } } diff --git a/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs b/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs index 67d0e455e..91bdbf0cc 100644 --- a/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs @@ -17,13 +17,17 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests { private const string _nzbUrl = "http://www.nzbs.com/url"; private const string _title = "some_nzb_title"; - private const string _blackHoleFolder = @"d:\nzb\blackhole\"; - private const string _nzbPath = @"d:\nzb\blackhole\some_nzb_title.nzb"; + private string _blackHoleFolder; + private string _nzbPath; private RemoteEpisode _remoteEpisode; [SetUp] public void Setup() { + _blackHoleFolder = @"c:\nzb\blackhole\".AsOsAgnostic(); + _nzbPath = @"c:\nzb\blackhole\some_nzb_title.nzb".AsOsAgnostic(); + + Mocker.GetMock().SetupGet(c => c.BlackholeFolder).Returns(_blackHoleFolder); _remoteEpisode = new RemoteEpisode(); diff --git a/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs b/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs index ebfb71ed6..8f5bf7b99 100644 --- a/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs +++ b/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs @@ -10,11 +10,12 @@ using NzbDrone.Common; using NzbDrone.Core.Datastore; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.RootFolderTests { [TestFixture] - + public class RootFolderServiceFixture : CoreTest { [SetUp] @@ -40,8 +41,8 @@ namespace NzbDrone.Core.Test.RootFolderTests [TestCase("//server//folder")] public void should_be_able_to_add_root_dir(string path) { - var root = new RootFolder { Path = path }; - + var root = new RootFolder { Path = path.AsOsAgnostic() }; + Subject.Add(root); Mocker.GetMock>().Verify(c => c.Insert(root), Times.Once()); @@ -52,7 +53,7 @@ namespace NzbDrone.Core.Test.RootFolderTests { WithNoneExistingFolder(); - Assert.Throws(() => Subject.Add(new RootFolder { Path = "C:\\TEST" })); + Assert.Throws(() => Subject.Add(new RootFolder { Path = "C:\\TEST".AsOsAgnostic() })); } [Test] diff --git a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj index f7bf56f61..23db88822 100644 --- a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj +++ b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj @@ -97,6 +97,7 @@ + diff --git a/NzbDrone.Test.Common/StringExtensions.cs b/NzbDrone.Test.Common/StringExtensions.cs new file mode 100644 index 000000000..19da86cc1 --- /dev/null +++ b/NzbDrone.Test.Common/StringExtensions.cs @@ -0,0 +1,22 @@ +using System.IO; +using NzbDrone.Common.EnvironmentInfo; + +namespace NzbDrone.Test.Common +{ + public static class StringExtensions + { + public static string AsOsAgnostic(this string path) + { + if (OsInfo.IsLinux) + { + if (path.Length > 2 && path[1] == ':') + { + path = path.Replace(':', Path.DirectorySeparatorChar); + } + path = path.Replace("\\", Path.DirectorySeparatorChar.ToString()); + } + + return path; + } + } +} \ No newline at end of file