|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
using System.IO;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
|
using NzbDrone.Core.MediaFiles.MovieImport;
|
|
|
|
|
using NzbDrone.Core.Movies;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
@ -22,33 +24,41 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
_localMovie = new LocalMovie();
|
|
|
|
|
_localMovie.Movie = new Movie
|
|
|
|
|
{
|
|
|
|
|
Path = @"C:\Test\TV\Series".AsOsAgnostic()
|
|
|
|
|
Path = @"C:\Test\Movies\Movie".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_movieFile = Builder<MovieFile>
|
|
|
|
|
.CreateNew()
|
|
|
|
|
.Build();
|
|
|
|
|
.CreateNew()
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.FileExists(It.IsAny<string>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
.Setup(c => c.FolderExists(Directory.GetParent(_localMovie.Movie.Path).FullName))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.FileExists(It.IsAny<string>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.GetParentFolder(It.IsAny<string>()))
|
|
|
|
|
.Returns<string>(c => Path.GetDirectoryName(c));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenSingleEpisodeWithSingleEpisodeFile()
|
|
|
|
|
private void GivenSingleMovieWithSingleMovieFile()
|
|
|
|
|
{
|
|
|
|
|
_localMovie.Movie.MovieFileId = 1;
|
|
|
|
|
_localMovie.Movie.MovieFile =
|
|
|
|
|
new MovieFile
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
RelativePath = @"Season 01\30.rock.s01e01.avi",
|
|
|
|
|
RelativePath = @"A.Movie.2019.avi",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_delete_single_episode_file_once()
|
|
|
|
|
public void should_delete_single_movie_file_once()
|
|
|
|
|
{
|
|
|
|
|
GivenSingleEpisodeWithSingleEpisodeFile();
|
|
|
|
|
GivenSingleMovieWithSingleMovieFile();
|
|
|
|
|
|
|
|
|
|
Subject.UpgradeMovieFile(_movieFile, _localMovie);
|
|
|
|
|
|
|
|
|
@ -56,9 +66,9 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_delete_episode_file_from_database()
|
|
|
|
|
public void should_delete_movie_file_from_database()
|
|
|
|
|
{
|
|
|
|
|
GivenSingleEpisodeWithSingleEpisodeFile();
|
|
|
|
|
GivenSingleMovieWithSingleMovieFile();
|
|
|
|
|
|
|
|
|
|
Subject.UpgradeMovieFile(_movieFile, _localMovie);
|
|
|
|
|
|
|
|
|
@ -68,7 +78,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_delete_existing_file_fromdb_if_file_doesnt_exist()
|
|
|
|
|
{
|
|
|
|
|
GivenSingleEpisodeWithSingleEpisodeFile();
|
|
|
|
|
GivenSingleMovieWithSingleMovieFile();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.FileExists(It.IsAny<string>()))
|
|
|
|
@ -82,7 +92,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_try_to_recyclebin_existing_file_if_file_doesnt_exist()
|
|
|
|
|
{
|
|
|
|
|
GivenSingleEpisodeWithSingleEpisodeFile();
|
|
|
|
|
GivenSingleMovieWithSingleMovieFile();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.FileExists(It.IsAny<string>()))
|
|
|
|
@ -94,11 +104,25 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_old_episode_file_in_oldFiles()
|
|
|
|
|
public void should_return_old_movie_file_in_oldFiles()
|
|
|
|
|
{
|
|
|
|
|
GivenSingleEpisodeWithSingleEpisodeFile();
|
|
|
|
|
GivenSingleMovieWithSingleMovieFile();
|
|
|
|
|
|
|
|
|
|
Subject.UpgradeMovieFile(_movieFile, _localMovie).OldFiles.Count.Should().Be(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_throw_if_there_are_existing_movie_files_and_the_root_folder_is_missing()
|
|
|
|
|
{
|
|
|
|
|
GivenSingleMovieWithSingleMovieFile();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(c => c.FolderExists(Directory.GetParent(_localMovie.Movie.Path).FullName))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
Assert.Throws<RootFolderNotFoundException>(() => Subject.UpgradeMovieFile(_movieFile, _localMovie));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(_localMovie.Movie.MovieFile, DeleteMediaFileReason.Upgrade), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|