sonarr-repo-only/NzbDrone.Core.Test/ProviderTests/InventoryProvider_QualityNe...

311 lines
12 KiB
C#
Raw Normal View History

2011-05-28 19:23:35 +00:00
// ReSharper disable RedundantUsingDirective
2011-05-28 19:23:35 +00:00
using System;
using System.Collections.Generic;
2011-05-28 19:23:35 +00:00
using FizzWare.NBuilder;
2011-06-23 06:56:17 +00:00
using FluentAssertions;
2011-05-28 19:23:35 +00:00
using Moq;
2011-06-02 21:06:46 +00:00
using NUnit.Framework;
2011-05-28 19:23:35 +00:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
2011-05-28 19:23:35 +00:00
namespace NzbDrone.Core.Test.ProviderTests
2011-05-28 19:23:35 +00:00
{
[TestFixture]
// ReSharper disable InconsistentNaming
2011-11-13 07:27:16 +00:00
public class InventoryProvider_QualityNeededTest : CoreTest
2011-05-28 19:23:35 +00:00
{
private Episode episode;
private Episode episode2;
private EpisodeFile episodeFile;
private QualityProfile hdProfile;
private EpisodeParseResult parseResultMulti;
private EpisodeParseResult parseResultSingle;
private QualityProfile sdProfile;
private Series series;
[SetUp]
2011-12-15 04:15:53 +00:00
public void Setup()
2011-05-28 19:23:35 +00:00
{
parseResultMulti = new EpisodeParseResult
{
CleanTitle = "Title",
Language = LanguageType.English,
Quality = new Quality(QualityTypes.Bluray720p, true),
EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12,
AirDate = DateTime.Now.AddDays(-12).Date,
};
parseResultSingle = new EpisodeParseResult
{
CleanTitle = "Title",
Language = LanguageType.English,
Quality = new Quality(QualityTypes.Bluray720p, true),
EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12,
AirDate = DateTime.Now.AddDays(-12).Date,
};
episodeFile = Builder<EpisodeFile>.CreateNew().With(c => c.Quality = QualityTypes.DVD).Build();
episode = Builder<Episode>.CreateNew()
.With(c => c.EpisodeNumber = parseResultMulti.EpisodeNumbers[0])
.With(c => c.SeasonNumber = parseResultMulti.SeasonNumber)
.With(c => c.AirDate = parseResultMulti.AirDate)
.With(c => c.Title = "EpisodeTitle1")
.With(c => c.EpisodeFile = episodeFile)
.Build();
episode2 = Builder<Episode>.CreateNew()
.With(c => c.EpisodeNumber = parseResultMulti.EpisodeNumbers[1])
.With(c => c.SeasonNumber = parseResultMulti.SeasonNumber)
.With(c => c.AirDate = parseResultMulti.AirDate)
.With(c => c.Title = "EpisodeTitle2")
.With(c => c.EpisodeFile = episodeFile)
.Build();
sdProfile = new QualityProfile
{
Name = "SD",
Allowed = new List<QualityTypes> { QualityTypes.SDTV, QualityTypes.DVD },
Cutoff = QualityTypes.DVD
};
hdProfile = new QualityProfile
{
Name = "HD",
Allowed =
new List<QualityTypes>
{
QualityTypes.HDTV,
QualityTypes.WEBDL,
QualityTypes.Bluray720p,
QualityTypes.Bluray1080p
},
Cutoff = QualityTypes.Bluray720p
};
series = Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
.With(d => d.CleanTitle = parseResultMulti.CleanTitle)
.With(c => c.QualityProfile = sdProfile)
.Build();
parseResultMulti.Series = series;
parseResultSingle.Series = series;
2011-06-22 01:12:20 +00:00
/* parseResultSingle.Episodes.Add(episode);
parseResultMulti.Episodes.Add(episode);
parseResultMulti.Episodes.Add(episode2);*/
2011-05-28 19:23:35 +00:00
}
[Test]
public void IsQualityNeeded_report_not_in_quality_profile_should_be_skipped()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
parseResultMulti.Series.QualityProfile = sdProfile;
parseResultMulti.Quality = new Quality(QualityTypes.HDTV, true);
//Act
2011-12-15 04:15:53 +00:00
bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultMulti);
2011-05-28 19:23:35 +00:00
//Assert
Assert.IsFalse(result);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
[Test]
public void IsQualityNeeded_file_already_at_cut_off_should_be_skipped()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
parseResultMulti.Series.QualityProfile = hdProfile;
2011-06-22 01:12:20 +00:00
2011-05-28 19:23:35 +00:00
parseResultMulti.Quality = new Quality(QualityTypes.HDTV, true);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(parseResultMulti, true))
.Returns(new List<Episode> { episode, episode2 });
2011-12-15 04:15:53 +00:00
Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
2011-06-22 01:12:20 +00:00
episode.EpisodeFile.Quality = QualityTypes.Bluray720p;
2011-05-28 19:23:35 +00:00
//Act
2011-12-15 04:15:53 +00:00
bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultMulti);
2011-05-28 19:23:35 +00:00
//Assert
Assert.IsFalse(result);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
[Test]
public void IsQualityNeeded_file_in_history_should_be_skipped()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD;
2011-12-15 04:15:53 +00:00
Mocker.GetMock<HistoryProvider>()
2011-05-28 19:23:35 +00:00
.Setup(p => p.GetBestQualityInHistory(episode.EpisodeId))
.Returns(new Quality(QualityTypes.DVD, true));
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true))
.Returns(new List<Episode> { episode });
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
2011-06-22 01:12:20 +00:00
episode.EpisodeFile.Quality = QualityTypes.SDTV;
2011-05-28 19:23:35 +00:00
//Act
2011-12-15 04:15:53 +00:00
bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle);
2011-05-28 19:23:35 +00:00
//Assert
Assert.IsFalse(result);
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
[Test]
public void IsQualityNeeded_lesser_file_in_history_should_be_downloaded()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD;
2011-12-15 04:15:53 +00:00
Mocker.GetMock<HistoryProvider>()
2011-05-28 19:23:35 +00:00
.Setup(p => p.GetBestQualityInHistory(episode.EpisodeId))
.Returns(new Quality(QualityTypes.SDTV, true));
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true))
.Returns(new List<Episode> { episode });
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
2011-06-22 01:12:20 +00:00
episode.EpisodeFile.Quality = QualityTypes.SDTV;
2011-05-28 19:23:35 +00:00
//Act
2011-12-15 04:15:53 +00:00
bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle);
2011-05-28 19:23:35 +00:00
//Assert
2011-06-23 06:56:17 +00:00
result.Should().BeTrue();
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
[Test]
public void IsQualityNeeded_file_not_in_history_should_be_downloaded()
{
2011-12-15 04:15:53 +00:00
WithStrictMocker();
2011-05-28 19:23:35 +00:00
parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD;
2011-12-15 04:15:53 +00:00
Mocker.GetMock<HistoryProvider>()
2011-05-28 19:23:35 +00:00
.Setup(p => p.GetBestQualityInHistory(episode.EpisodeId))
.Returns<Quality>(null);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
2011-06-22 01:12:20 +00:00
.Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true))
.Returns(new List<Episode> { episode });
2011-12-15 04:15:53 +00:00
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
2011-12-15 04:15:53 +00:00
Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
2011-06-22 01:12:20 +00:00
episode.EpisodeFile.Quality = QualityTypes.SDTV;
2011-05-28 19:23:35 +00:00
//Act
2011-12-15 04:15:53 +00:00
bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle);
2011-05-28 19:23:35 +00:00
//Assert
2011-06-23 06:56:17 +00:00
result.Should().BeTrue();
2011-12-15 04:15:53 +00:00
Mocker.VerifyAllMocks();
2011-05-28 19:23:35 +00:00
}
//Should Download
2011-06-13 04:20:29 +00:00
[TestCase(QualityTypes.SDTV, true, QualityTypes.HDTV, false, true)]
[TestCase(QualityTypes.DVD, true, QualityTypes.Bluray720p, true, true)]
[TestCase(QualityTypes.HDTV, false, QualityTypes.HDTV, true, true)]
[TestCase(QualityTypes.HDTV, false, QualityTypes.HDTV, false, false)]
[TestCase(QualityTypes.Bluray720p, true, QualityTypes.Bluray1080p, false, false)]
[TestCase(QualityTypes.HDTV, true, QualityTypes.Bluray720p, true, true)]
[TestCase(QualityTypes.Bluray1080p, true, QualityTypes.Bluray720p, true, false)]
[TestCase(QualityTypes.Bluray1080p, true, QualityTypes.Bluray720p, false, false)]
[TestCase(QualityTypes.Bluray1080p, false, QualityTypes.Bluray720p, true, false)]
[TestCase(QualityTypes.HDTV, false, QualityTypes.Bluray720p, true, true)]
[TestCase(QualityTypes.HDTV, true, QualityTypes.HDTV, false, false)]
2011-05-28 19:23:35 +00:00
public void Is_upgrade(QualityTypes fileQuality, bool isFileProper, QualityTypes reportQuality,
bool isReportProper, bool excpected)
{
//Setup
var currentQuality = new Quality(fileQuality, isFileProper);
var newQuality = new Quality(reportQuality, isReportProper);
bool result = InventoryProvider.IsUpgrade(currentQuality, newQuality, QualityTypes.Bluray720p);
Assert.AreEqual(excpected, result);
}
[Test]
public void IsQualityNeeded_file_should_skip_history_check_for_manual_search()
{
WithStrictMocker();
parseResultSingle.Series.QualityProfile = sdProfile;
parseResultSingle.Quality.QualityType = QualityTypes.DVD;
Mocker.GetMock<HistoryProvider>()
.Setup(p => p.GetBestQualityInHistory(episode.EpisodeId))
.Returns<Quality>(null);
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisodesByParseResult(parseResultSingle, true))
.Returns(new List<Episode> { episode });
Mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsFirstOrLastEpisodeOfSeason(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
Mocker.GetMock<QualityTypeProvider>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(new QualityType { MaxSize = 100, MinSize = 0 });
episode.EpisodeFile.Quality = QualityTypes.SDTV;
//Act
bool result = Mocker.Resolve<InventoryProvider>().IsQualityNeeded(parseResultSingle, true);
//Assert
result.Should().BeTrue();
Mocker.Verify<HistoryProvider>(c => c.GetBestQualityInHistory(It.IsAny<int>()), Times.Never());
}
2011-05-28 19:23:35 +00:00
}
}