diff --git a/src/NzbDrone.Core.Test/RootFolderTests/GetBestRootFolderPathFixture.cs b/src/NzbDrone.Core.Test/RootFolderTests/GetBestRootFolderPathFixture.cs index cf8f7648d..f783e60f6 100644 --- a/src/NzbDrone.Core.Test/RootFolderTests/GetBestRootFolderPathFixture.cs +++ b/src/NzbDrone.Core.Test/RootFolderTests/GetBestRootFolderPathFixture.cs @@ -1,8 +1,6 @@ using System.Linq; using FluentAssertions; -using Moq; using NUnit.Framework; -using NzbDrone.Common.Disk; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; @@ -34,15 +32,34 @@ public void should_return_root_folder_that_is_grandparent_path() } [Test] - public void should_get_parent_path_from_diskProvider_if_matching_root_folder_is_not_found() + public void should_get_parent_path_from_os_path_if_matching_root_folder_is_not_found() { var moviePath = @"T:\Test\Movies\Movie Title".AsOsAgnostic(); GivenRootFolders(@"C:\Test\Movies".AsOsAgnostic(), @"D:\Test\Movies".AsOsAgnostic()); - Subject.GetBestRootFolderPath(moviePath); + Subject.GetBestRootFolderPath(moviePath).Should().Be(@"T:\Test\Movies".AsOsAgnostic()); + } - Mocker.GetMock() - .Verify(v => v.GetParentFolder(moviePath), Times.Once); + [Test] + public void should_get_parent_path_from_os_path_if_matching_root_folder_is_not_found_for_posix_path() + { + WindowsOnly(); + + var moviePath = "/mnt/movies/Movie Title"; + + GivenRootFolders(@"C:\Test\Movies".AsOsAgnostic(), @"D:\Test\Movies".AsOsAgnostic()); + Subject.GetBestRootFolderPath(moviePath).Should().Be(@"/mnt/movies"); + } + + [Test] + public void should_get_parent_path_from_os_path_if_matching_root_folder_is_not_found_for_windows_path() + { + PosixOnly(); + + var moviePath = @"T:\Test\Movies\Movie Title"; + + GivenRootFolders(@"C:\Test\Movies".AsOsAgnostic(), @"D:\Test\Movies".AsOsAgnostic()); + Subject.GetBestRootFolderPath(moviePath).Should().Be(@"T:\Test\Movies"); } } } diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index a77fbc165..5d0a0d45f 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -190,7 +190,7 @@ public string GetBestRootFolderPath(string path, List rootFolders = { var osPath = new OsPath(path); - return osPath.Directory.ToString(); + return osPath.Directory.ToString().TrimEnd(osPath.IsUnixPath ? '/' : '\\'); } return possibleRootFolder?.Path;