upgrade service only tries to delete existing file if it actually exists.

This commit is contained in:
kay.one 2013-07-30 22:11:54 -07:00
commit c57fb29db4
3 changed files with 51 additions and 6 deletions

View file

@ -3,6 +3,7 @@ using FizzWare.NBuilder;
using Marr.Data;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
@ -23,6 +24,11 @@ namespace NzbDrone.Core.Test.MediaFileTests
_episodeFile = Builder<EpisodeFile>
.CreateNew()
.Build();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true);
}
private void GivenSingleEpisodeWithSingleEpisodeFile()
@ -115,5 +121,34 @@ namespace NzbDrone.Core.Test.MediaFileTests
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(It.IsAny<EpisodeFile>(), true), Times.Once());
}
[Test]
public void should_delete_existing_file_fromdb_if_file_doesnt_exist()
{
GivenSingleEpisodeWithSingleEpisodeFile();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(false);
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(_localEpisode.Episodes.Single().EpisodeFile.Value, true), Times.Once());
}
[Test]
public void should_not_try_to_recyclebin_existing_file_fromdb_if_file_doesnt_exist()
{
GivenSingleEpisodeWithSingleEpisodeFile();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(false);
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
Mocker.GetMock<IRecycleBinProvider>().Verify(v => v.DeleteFile(It.IsAny<string>()), Times.Never());
}
}
}