diff --git a/src/NzbDrone.Core.Test/RootFolderTests/GetBestRootFolderPathFixture.cs b/src/NzbDrone.Core.Test/RootFolderTests/GetBestRootFolderPathFixture.cs index 49a013703..baa8a9556 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 @@ namespace NzbDrone.Core.Test.RootFolderTests } [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 seriesPath = @"T:\Test\Music\Series Title".AsOsAgnostic(); + var artistPath = @"T:\Test\Music\Artist Title".AsOsAgnostic(); GivenRootFolders(@"C:\Test\Music".AsOsAgnostic(), @"D:\Test\Music".AsOsAgnostic()); - Subject.GetBestRootFolderPath(seriesPath); + Subject.GetBestRootFolderPath(artistPath).Should().Be(@"T:\Test\Music".AsOsAgnostic()); + } + + [Test] + public void should_get_parent_path_from_os_path_if_matching_root_folder_is_not_found_for_posix_path() + { + WindowsOnly(); - Mocker.GetMock() - .Verify(v => v.GetParentFolder(seriesPath), Times.Once); + var artistPath = "/mnt/music/Artist Title"; + + GivenRootFolders(@"C:\Test\Music".AsOsAgnostic(), @"D:\Test\Music".AsOsAgnostic()); + Subject.GetBestRootFolderPath(artistPath).Should().Be(@"/mnt/music"); + } + + [Test] + public void should_get_parent_path_from_os_path_if_matching_root_folder_is_not_found_for_windows_path() + { + PosixOnly(); + + var artistPath = @"T:\Test\Music\Artist Title"; + + GivenRootFolders(@"C:\Test\Music".AsOsAgnostic(), @"D:\Test\Music".AsOsAgnostic()); + Subject.GetBestRootFolderPath(artistPath).Should().Be(@"T:\Test\Music"); } } } diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index 81be2b286..709b75750 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -154,7 +154,7 @@ namespace NzbDrone.Core.RootFolders { var osPath = new OsPath(path); - return osPath.Directory.ToString(); + return osPath.Directory.ToString().TrimEnd(osPath.IsUnixPath ? '/' : '\\'); } return possibleRootFolder?.Path;