Radarr/src/NzbDrone.Core.Test/MediaFiles/UpgradeMediaFileServiceFixture.cs
Leonardo Galli 77f146b262
Added: Ability to add custom formats, working similar to qualities. (#2669)
Originally called project metis, this feature allows you to do a lot of cool stuff, such as upgrading to a x265 encode, downloading releases with multiple languages, etc. Check out the wiki page at: https://github.com/Radarr/Radarr/wiki/Custom-Formats to learn more! Note: This feature is currently in "beta" and will get more tags and features in the future. Please let me know, if you have any issues and I hope this will allow for a lot of customization!
2018-08-05 16:28:05 +02:00

109 lines
3.3 KiB
C#

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>()), 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>()), Times.Never());
}
[Test]
public void should_return_old_episode_file_in_oldFiles()
{
GivenSingleEpisodeWithSingleEpisodeFile();
Subject.UpgradeMovieFile(_movieFile, _localMovie).OldFiles.Count.Should().Be(1);
}
}
}