diff --git a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs new file mode 100644 index 000000000..e7ae66846 --- /dev/null +++ b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FizzWare.NBuilder; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Jobs; +using NzbDrone.Core.Model.Notification; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Repository; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.JobTests +{ + [TestFixture] + public class RenameSeasonJobFixture : TestBase + { + private ProgressNotification _testNotification; + private Series _series; + private IList _episodeFiles; + + [SetUp] + public void Setup() + { + _testNotification = new ProgressNotification("TEST"); + + _series = Builder + .CreateNew() + .Build(); + + _episodeFiles = Builder + .CreateListOfSize(5) + .All() + .With(e => e.SeasonNumber = 5) + .Build(); + + Mocker.GetMock() + .Setup(s => s.GetSeries(_series.SeriesId)) + .Returns(_series); + + Mocker.GetMock() + .Setup(s => s.GetSeasonFiles(_series.SeriesId, 5)) + .Returns(_episodeFiles); + } + + private void WithMovedFiles() + { + Mocker.GetMock() + .Setup(s => s.MoveEpisodeFile(It.IsAny(), false)) + .Returns(_episodeFiles.First()); + } + + [Test] + public void should_throw_if_seriesId_is_zero() + { + Assert.Throws(() => + Mocker.Resolve().Start(_testNotification, new { SeriesId = 0, SeasonNumber = 10 })); + } + + [Test] + public void should_throw_if_seasonId_is_less_than_zero() + { + Assert.Throws(() => + Mocker.Resolve().Start(_testNotification, new { SeriesId = _series.SeriesId, SeasonNumber = -10 })); + } + + [Test] + public void should_log_warning_if_no_episode_files_are_found() + { + Mocker.Resolve().Start(_testNotification, new { SeriesId = _series.SeriesId, SeasonNumber = 10 }); + + ExceptionVerification.ExpectedWarns(1); + } + + [Test] + public void should_return_if_no_episodes_are_moved() + { + Mocker.Resolve().Start(_testNotification, new { SeriesId = _series.SeriesId, SeasonNumber = 5 }); + + Mocker.GetMock().Verify(v => v.RemoveForEpisodeFiles(It.IsAny>()), Times.Never()); + } + + [Test] + public void should_return_process_metadata_if_files_are_moved() + { + WithMovedFiles(); + Mocker.Resolve().Start(_testNotification, new { SeriesId = _series.SeriesId, SeasonNumber = 5 }); + + Mocker.GetMock().Verify(v => v.RemoveForEpisodeFiles(It.IsAny>()), Times.Once()); + } + } +} diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 7c4d44a22..f3aa10b36 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -139,6 +139,7 @@ + diff --git a/NzbDrone.Core/Jobs/RenameSeasonJob.cs b/NzbDrone.Core/Jobs/RenameSeasonJob.cs index f442fa372..de771c24f 100644 --- a/NzbDrone.Core/Jobs/RenameSeasonJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeasonJob.cs @@ -85,12 +85,20 @@ namespace NzbDrone.Core.Jobs } } + if(!oldEpisodeFiles.Any()) + { + logger.Trace("No episodes were renamed for: {0} Season {1}, no changes were made", series.Title, + options.SeasonNumber); + notification.CurrentMessage = String.Format("Rename completed for: {0} Season {1}, no changes were made", series.Title, options.SeasonNumber); + return; + } + //Remove & Create Metadata for episode files + //Todo: Add a metadata manager to avoid this hack _metadataProvider.RemoveForEpisodeFiles(oldEpisodeFiles); _metadataProvider.CreateForEpisodeFiles(newEpisodeFiles); //Start AfterRename - var message = String.Format("Renamed: Series {0}, Season: {1}", series.Title, options.SeasonNumber); _externalNotificationProvider.AfterRename(message, series);