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.
122 lines
3.8 KiB
122 lines
3.8 KiB
7 years ago
|
using System.Collections.Generic;
|
||
11 years ago
|
using System.Linq;
|
||
|
using FizzWare.NBuilder;
|
||
|
using Moq;
|
||
|
using NUnit.Framework;
|
||
|
using NzbDrone.Core.MediaFiles;
|
||
|
using NzbDrone.Core.MediaFiles.Commands;
|
||
|
using NzbDrone.Core.MediaFiles.Events;
|
||
11 years ago
|
using NzbDrone.Core.Messaging.Events;
|
||
11 years ago
|
using NzbDrone.Core.Test.Framework;
|
||
7 years ago
|
using NzbDrone.Core.Movies;
|
||
11 years ago
|
|
||
11 years ago
|
namespace NzbDrone.Core.Test.MediaFiles
|
||
11 years ago
|
{
|
||
7 years ago
|
public class RenameMovieFileServiceFixture : CoreTest<RenameMovieFileService>
|
||
11 years ago
|
{
|
||
7 years ago
|
private Movie _movie;
|
||
|
private List<MovieFile> _movieFiles;
|
||
11 years ago
|
|
||
|
[SetUp]
|
||
|
public void Setup()
|
||
|
{
|
||
7 years ago
|
_movie = Builder<Movie>.CreateNew()
|
||
11 years ago
|
.Build();
|
||
|
|
||
7 years ago
|
_movieFiles = Builder<MovieFile>.CreateListOfSize(2)
|
||
11 years ago
|
.All()
|
||
7 years ago
|
.With(e => e.MovieId = _movie.Id)
|
||
11 years ago
|
.Build()
|
||
|
.ToList();
|
||
|
|
||
7 years ago
|
Mocker.GetMock<IMovieService>()
|
||
|
.Setup(s => s.GetMovie(_movie.Id))
|
||
|
.Returns(_movie);
|
||
11 years ago
|
}
|
||
|
|
||
|
private void GivenNoEpisodeFiles()
|
||
|
{
|
||
|
Mocker.GetMock<IMediaFileService>()
|
||
7 years ago
|
.Setup(s => s.GetMovies(It.IsAny<IEnumerable<int>>()))
|
||
|
.Returns(new List<MovieFile>());
|
||
11 years ago
|
}
|
||
|
|
||
|
private void GivenEpisodeFiles()
|
||
|
{
|
||
|
Mocker.GetMock<IMediaFileService>()
|
||
7 years ago
|
.Setup(s => s.GetMovies(It.IsAny<IEnumerable<int>>()))
|
||
|
.Returns(_movieFiles);
|
||
11 years ago
|
}
|
||
|
|
||
|
private void GivenMovedFiles()
|
||
|
{
|
||
7 years ago
|
Mocker.GetMock<IMoveMovieFiles>()
|
||
|
.Setup(s => s.MoveMovieFile(It.IsAny<MovieFile>(), _movie));
|
||
11 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void should_not_publish_event_if_no_files_to_rename()
|
||
|
{
|
||
|
GivenNoEpisodeFiles();
|
||
|
|
||
7 years ago
|
Subject.Execute(new RenameMovieFilesCommand(_movie.Id, new List<int>{1}));
|
||
11 years ago
|
|
||
11 years ago
|
Mocker.GetMock<IEventAggregator>()
|
||
7 years ago
|
.Verify(v => v.PublishEvent(It.IsAny<MovieRenamedEvent>()), Times.Never());
|
||
11 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void should_not_publish_event_if_no_files_are_renamed()
|
||
|
{
|
||
|
GivenEpisodeFiles();
|
||
|
|
||
7 years ago
|
Mocker.GetMock<IMoveMovieFiles>()
|
||
|
.Setup(s => s.MoveMovieFile(It.IsAny<MovieFile>(), It.IsAny<Movie>()))
|
||
11 years ago
|
.Throws(new SameFilenameException("Same file name", "Filename"));
|
||
|
|
||
7 years ago
|
Subject.Execute(new RenameMovieFilesCommand(_movie.Id, new List<int> { 1 }));
|
||
11 years ago
|
|
||
11 years ago
|
Mocker.GetMock<IEventAggregator>()
|
||
7 years ago
|
.Verify(v => v.PublishEvent(It.IsAny<MovieRenamedEvent>()), Times.Never());
|
||
11 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void should_publish_event_if_files_are_renamed()
|
||
|
{
|
||
|
GivenEpisodeFiles();
|
||
|
GivenMovedFiles();
|
||
|
|
||
7 years ago
|
Subject.Execute(new RenameMovieFilesCommand(_movie.Id, new List<int> { 1 }));
|
||
11 years ago
|
|
||
11 years ago
|
Mocker.GetMock<IEventAggregator>()
|
||
7 years ago
|
.Verify(v => v.PublishEvent(It.IsAny<MovieRenamedEvent>()), Times.Once());
|
||
11 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void should_update_moved_files()
|
||
|
{
|
||
|
GivenEpisodeFiles();
|
||
|
GivenMovedFiles();
|
||
|
|
||
7 years ago
|
Subject.Execute(new RenameMovieFilesCommand(_movie.Id, new List<int> { 1 }));
|
||
11 years ago
|
|
||
|
Mocker.GetMock<IMediaFileService>()
|
||
7 years ago
|
.Verify(v => v.Update(It.IsAny<MovieFile>()), Times.Exactly(2));
|
||
11 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
11 years ago
|
public void should_get_episodefiles_by_ids_only()
|
||
11 years ago
|
{
|
||
|
GivenEpisodeFiles();
|
||
|
GivenMovedFiles();
|
||
|
|
||
11 years ago
|
var files = new List<int> { 1 };
|
||
11 years ago
|
|
||
7 years ago
|
Subject.Execute(new RenameMovieFilesCommand(_movie.Id, files));
|
||
11 years ago
|
|
||
|
Mocker.GetMock<IMediaFileService>()
|
||
7 years ago
|
.Verify(v => v.GetMovies(files), Times.Once());
|
||
11 years ago
|
}
|
||
|
}
|
||
|
}
|