Fixed getting parent path from a path without another slash

Fixed: Manual Import failing for some paths
This commit is contained in:
Mark McDowall 2019-01-01 15:01:24 -08:00
parent c14b339d80
commit edd6c0bd4c
3 changed files with 21 additions and 1 deletions

View File

@ -140,6 +140,8 @@ namespace NzbDrone.Common.Test
[TestCase(@"C:\Test\mydir", @"C:\Test")]
[TestCase(@"C:\Test\", @"C:")]
[TestCase(@"C:\", null)]
[TestCase(@"/", null)]
[TestCase(@"/test", null)]
public void path_should_return_parent(string path, string parentPath)
{
path.GetParentPath().Should().Be(parentPath);

View File

@ -71,10 +71,11 @@ namespace NzbDrone.Common.Extensions
var index = parentPath.LastIndexOfAny(new[] { '\\', '/' });
if (index != -1)
if (index > 0)
{
return parentPath.Substring(0, index);
}
return null;
}

View File

@ -341,6 +341,23 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.OriginalFilePath == $"{name}\\subfolder\\{name}.mkv".AsOsAgnostic())));
}
[Test]
public void should_get_relative_path_when_there_is_no_grandparent()
{
var name = "Series.Title.S01E01.720p.HDTV.x264-Sonarr";
var outputPath = Path.Combine(@"C:\".AsOsAgnostic());
var localEpisode = _approvedDecisions.First().LocalEpisode;
localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo { ReleaseTitle = name };
localEpisode.Path = Path.Combine(outputPath, name + ".mkv");
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, null);
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<EpisodeFile>(c => c.OriginalFilePath == $"{name}.mkv".AsOsAgnostic())));
}
[Test]
public void should_delete_existing_metadata_files_with_the_same_path()
{
Mocker.GetMock<IMediaFileService>()