CalculateFilePath will use configured season folder, with tests.

MoveFile creates folder before move.
pull/2/head
Mark McDowall 14 years ago
parent a31858bb4c
commit 584a96a4f2

@ -25,9 +25,6 @@ namespace NzbDrone.Core.Test
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
public class MediaFileProviderTests : TestBase public class MediaFileProviderTests : TestBase
{ {
[Test] [Test]
public void get_series_files() public void get_series_files()
{ {
@ -136,5 +133,30 @@ namespace NzbDrone.Core.Test
result.Should().OnlyContain(e => e.EpisodeFileId > 0); result.Should().OnlyContain(e => e.EpisodeFileId > 0);
ExceptionVerification.ExcpectedWarns(1); ExceptionVerification.ExcpectedWarns(1);
} }
[Test]
[TestCase("30 Rock - S01E05 - Episode Title", 1, true, "Season %0s", @"C:\Test\30 Rock\Season 01\30 Rock - S01E05 - Episode Title.mkv")]
[TestCase("30 Rock - S01E05 - Episode Title", 1, true, "Season %s", @"C:\Test\30 Rock\Season 1\30 Rock - S01E05 - Episode Title.mkv")]
[TestCase("30 Rock - S01E05 - Episode Title", 1, false, "Season %0s", @"C:\Test\30 Rock\30 Rock - S01E05 - Episode Title.mkv")]
[TestCase("30 Rock - S01E05 - Episode Title", 1, false, "Season %s", @"C:\Test\30 Rock\30 Rock - S01E05 - Episode Title.mkv")]
[TestCase("30 Rock - S01E05 - Episode Title", 1, true, "ReallyUglySeasonFolder %s", @"C:\Test\30 Rock\ReallyUglySeasonFolder 1\30 Rock - S01E05 - Episode Title.mkv")]
public void CalculateFilePath_SeasonFolder_SingleNumber(string filename, int seasonNumber, bool useSeasonFolder, string seasonFolderFormat, string expectedPath)
{
//Setup
var fakeSeries = Builder<Series>.CreateNew()
.With(s => s.Title = "30 Rock")
.With(s => s.Path = @"C:\Test\30 Rock")
.With(s => s.SeasonFolder = useSeasonFolder)
.Build();
var mocker = new AutoMoqer();
mocker.GetMock<ConfigProvider>().Setup(e => e.SeasonFolderFormat).Returns(seasonFolderFormat);
//Act
var result = mocker.Resolve<MediaFileProvider>().CalculateFilePath(fakeSeries, 1, filename, ".mkv");
//Assert
Assert.AreEqual(expectedPath, result.FullName);
}
} }
} }

@ -142,7 +142,6 @@ namespace NzbDrone.Core.Providers
return episodeFile; return episodeFile;
} }
public virtual bool MoveEpisodeFile(EpisodeFile episodeFile) public virtual bool MoveEpisodeFile(EpisodeFile episodeFile)
{ {
if (episodeFile == null) if (episodeFile == null)
@ -153,6 +152,9 @@ namespace NzbDrone.Core.Providers
string newFileName = _mediaFileProvider.GetNewFilename(episodes, series.Title, episodeFile.Quality); string newFileName = _mediaFileProvider.GetNewFilename(episodes, series.Title, episodeFile.Quality);
var newFile = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); var newFile = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
//Ensure the folder Exists before trying to move it (No error is thrown if the folder already exists)
_diskProvider.CreateDirectory(newFile.DirectoryName);
//Do the rename //Do the rename
Logger.Trace("Attempting to rename {0} to {1}", episodeFile.Path, newFile.FullName); Logger.Trace("Attempting to rename {0} to {1}", episodeFile.Path, newFile.FullName);
_diskProvider.MoveFile(episodeFile.Path, newFile.FullName); _diskProvider.MoveFile(episodeFile.Path, newFile.FullName);
@ -164,7 +166,6 @@ namespace NzbDrone.Core.Providers
return true; return true;
} }
/// <summary> /// <summary>
/// Removes files that no longer exist on disk from the database /// Removes files that no longer exist on disk from the database
/// </summary> /// </summary>

@ -83,7 +83,11 @@ namespace NzbDrone.Core.Providers
string path = series.Path; string path = series.Path;
if (series.SeasonFolder) if (series.SeasonFolder)
{ {
path = Path.Combine(path, "Season " + seasonNumber); var seasonFolder = _configProvider.SeasonFolderFormat
.Replace("%0s", seasonNumber.ToString("00"))
.Replace("%s", seasonNumber.ToString());
path = Path.Combine(path, seasonFolder);
} }
path = Path.Combine(path, fileName + extention); path = Path.Combine(path, fileName + extention);

Loading…
Cancel
Save