You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/src/NzbDrone.Core.Test/MediaFiles/UpgradeMediaFileServiceFixt...

110 lines
3.3 KiB

using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Marr.Data;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Movies;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles
{
public class UpgradeMediaFileServiceFixture : CoreTest<UpgradeMediaFileService>
{
private MovieFile _movieFile;
private LocalMovie _localMovie;
[SetUp]
public void Setup()
{
_localMovie = new LocalMovie();
_localMovie.Movie = new Movie
{
Path = @"C:\Test\TV\Series".AsOsAgnostic()
};
_movieFile = Builder<MovieFile>
.CreateNew()
.Build();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true);
}
private void GivenSingleEpisodeWithSingleEpisodeFile()
{
_localMovie.Movie.MovieFileId = 1;
_localMovie.Movie.MovieFile =
new MovieFile
{
Id = 1,
RelativePath = @"Season 01\30.rock.s01e01.avi",
};
}
[Test]
public void should_delete_single_episode_file_once()
{
GivenSingleEpisodeWithSingleEpisodeFile();
Subject.UpgradeMovieFile(_movieFile, _localMovie);
Mocker.GetMock<IRecycleBinProvider>().Verify(v => v.DeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
}
[Test]
public void should_delete_episode_file_from_database()
{
GivenSingleEpisodeWithSingleEpisodeFile();
Subject.UpgradeMovieFile(_movieFile, _localMovie);
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(It.IsAny<MovieFile>(), DeleteMediaFileReason.Upgrade), 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.UpgradeMovieFile(_movieFile, _localMovie);
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(_localMovie.Movie.MovieFile, DeleteMediaFileReason.Upgrade), Times.Once());
}
[Test]
public void should_not_try_to_recyclebin_existing_file_if_file_doesnt_exist()
{
GivenSingleEpisodeWithSingleEpisodeFile();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(false);
Subject.UpgradeMovieFile(_movieFile, _localMovie);
Mocker.GetMock<IRecycleBinProvider>().Verify(v => v.DeleteFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
}
[Test]
public void should_return_old_episode_file_in_oldFiles()
{
GivenSingleEpisodeWithSingleEpisodeFile();
Subject.UpgradeMovieFile(_movieFile, _localMovie).OldFiles.Count.Should().Be(1);
}
}
}