mirror of https://github.com/Radarr/Radarr
89 lines
3.1 KiB
C#
89 lines
3.1 KiB
C#
using System.IO;
|
|
using System.Linq;
|
|
using FizzWare.NBuilder;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using NzbDrone.Core.MediaFiles;
|
|
using NzbDrone.Core.MediaFiles.Events;
|
|
using NzbDrone.Core.Parser.Model;
|
|
using NzbDrone.Core.Profiles;
|
|
using NzbDrone.Core.Test.Framework;
|
|
using NzbDrone.Core.History;
|
|
using NzbDrone.Core.Qualities;
|
|
using System.Collections.Generic;
|
|
using NzbDrone.Core.Test.Qualities;
|
|
using FluentAssertions;
|
|
using NzbDrone.Core.Movies;
|
|
|
|
namespace NzbDrone.Core.Test.HistoryTests
|
|
{
|
|
public class HistoryServiceFixture : CoreTest<HistoryService>
|
|
{
|
|
private Profile _profile;
|
|
private Profile _profileCustom;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_profile = new Profile { Cutoff = Quality.WEBDL720p, Items = QualityFixture.GetDefaultQualities() };
|
|
_profileCustom = new Profile { Cutoff = Quality.WEBDL720p, Items = QualityFixture.GetDefaultQualities(Quality.DVD) };
|
|
}
|
|
|
|
[Test]
|
|
public void should_return_null_if_no_history()
|
|
{
|
|
Mocker.GetMock<IHistoryRepository>()
|
|
.Setup(v => v.GetBestQualityInHistory(2))
|
|
.Returns(new List<QualityModel>());
|
|
|
|
var quality = Subject.GetBestQualityInHistory(_profile, 2);
|
|
|
|
quality.Should().BeNull();
|
|
}
|
|
|
|
[Test]
|
|
public void should_return_best_quality()
|
|
{
|
|
Mocker.GetMock<IHistoryRepository>()
|
|
.Setup(v => v.GetBestQualityInHistory(2))
|
|
.Returns(new List<QualityModel> { new QualityModel(Quality.DVD), new QualityModel(Quality.Bluray1080p) });
|
|
|
|
var quality = Subject.GetBestQualityInHistory(_profile, 2);
|
|
|
|
quality.Should().Be(new QualityModel(Quality.Bluray1080p));
|
|
}
|
|
|
|
[Test]
|
|
public void should_return_best_quality_with_custom_order()
|
|
{
|
|
Mocker.GetMock<IHistoryRepository>()
|
|
.Setup(v => v.GetBestQualityInHistory(2))
|
|
.Returns(new List<QualityModel> { new QualityModel(Quality.DVD), new QualityModel(Quality.Bluray1080p) });
|
|
|
|
var quality = Subject.GetBestQualityInHistory(_profileCustom, 2);
|
|
|
|
quality.Should().Be(new QualityModel(Quality.DVD));
|
|
}
|
|
|
|
[Test]
|
|
public void should_use_file_name_for_source_title_if_scene_name_is_null()
|
|
{
|
|
var movie = Builder<Movie>.CreateNew().Build();
|
|
var movieFile = Builder<MovieFile>.CreateNew()
|
|
.With(f => f.SceneName = null)
|
|
.Build();
|
|
|
|
var localMovie = new LocalMovie()
|
|
{
|
|
Movie = movie,
|
|
Path = @"C:\Test\Unsorted\Movie.2011.mkv"
|
|
};
|
|
|
|
Subject.Handle(new MovieImportedEvent(localMovie, movieFile, true, "sab", "abcd"));
|
|
|
|
Mocker.GetMock<IHistoryRepository>()
|
|
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localMovie.Path))));
|
|
}
|
|
}
|
|
}
|