Solved error in quality comparison for HistoryService

pull/3113/head
Taloth Saldono 11 years ago
parent 31e0524389
commit 45304b1bbc

@ -62,9 +62,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
_upgradableQuality = new QualityModel(Quality.SDTV, false); _upgradableQuality = new QualityModel(Quality.SDTV, false);
_notupgradableQuality = new QualityModel(Quality.HDTV1080p, true); _notupgradableQuality = new QualityModel(Quality.HDTV1080p, true);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_notupgradableQuality); Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(It.IsAny<QualityProfile>(), 1)).Returns(_notupgradableQuality);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_notupgradableQuality); Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(It.IsAny<QualityProfile>(), 2)).Returns(_notupgradableQuality);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(3)).Returns<QualityModel>(null); Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(It.IsAny<QualityProfile>(), 3)).Returns<QualityModel>(null);
Mocker.GetMock<IProvideDownloadClient>() Mocker.GetMock<IProvideDownloadClient>()
.Setup(c => c.GetDownloadClient()).Returns(Mocker.GetMock<IDownloadClient>().Object); .Setup(c => c.GetDownloadClient()).Returns(Mocker.GetMock<IDownloadClient>().Object);
@ -72,12 +72,12 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
private void WithFirstReportUpgradable() private void WithFirstReportUpgradable()
{ {
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality); Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(It.IsAny<QualityProfile>(), 1)).Returns(_upgradableQuality);
} }
private void WithSecondReportUpgradable() private void WithSecondReportUpgradable()
{ {
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(2)).Returns(_upgradableQuality); Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(It.IsAny<QualityProfile>(), 2)).Returns(_upgradableQuality);
} }
private void GivenSabnzbdDownloadClient() private void GivenSabnzbdDownloadClient()
@ -134,7 +134,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
_parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.WEBDL1080p, false); _parseResultSingle.ParsedEpisodeInfo.Quality = new QualityModel(Quality.WEBDL1080p, false);
_upgradableQuality = new QualityModel(Quality.WEBDL1080p, false); _upgradableQuality = new QualityModel(Quality.WEBDL1080p, false);
Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(1)).Returns(_upgradableQuality); Mocker.GetMock<IHistoryService>().Setup(c => c.GetBestQualityInHistory(It.IsAny<QualityProfile>(), 1)).Returns(_upgradableQuality);
_upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Should().BeFalse(); _upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Should().BeFalse();
} }

@ -0,0 +1,59 @@
using NUnit.Framework;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.History;
using NzbDrone.Core.Qualities;
using System.Collections.Generic;
using NzbDrone.Core.Test.Qualities;
using FluentAssertions;
namespace NzbDrone.Core.Test.HistoryTests
{
public class HistoryServiceFixture : CoreTest<HistoryService>
{
private QualityProfile _profile;
private QualityProfile _profileCustom;
[SetUp]
public void Setup()
{
_profile = new QualityProfile { Cutoff = Quality.WEBDL720p, Items = QualityFixture.GetDefaultQualities() };
_profileCustom = new QualityProfile { 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));
}
}
}

@ -130,6 +130,7 @@
<Compile Include="Framework\CoreTest.cs" /> <Compile Include="Framework\CoreTest.cs" />
<Compile Include="Framework\DbTest.cs" /> <Compile Include="Framework\DbTest.cs" />
<Compile Include="Framework\NBuilderExtensions.cs" /> <Compile Include="Framework\NBuilderExtensions.cs" />
<Compile Include="HistoryTests\HistoryServiceFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedHistoryItemsFixture.cs" /> <Compile Include="Housekeeping\Housekeepers\CleanupOrphanedHistoryItemsFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodeFilesFixture.cs" /> <Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodeFilesFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecsFixture.cs" /> <Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecsFixture.cs" />

@ -59,7 +59,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
foreach (var episode in subject.Episodes) foreach (var episode in subject.Episodes)
{ {
var bestQualityInHistory = _historyService.GetBestQualityInHistory(episode.Id); var bestQualityInHistory = _historyService.GetBestQualityInHistory(subject.Series.QualityProfile, episode.Id);
if (bestQualityInHistory != null) if (bestQualityInHistory != null)
{ {
_logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory); _logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);

@ -16,7 +16,7 @@ namespace NzbDrone.Core.History
List<History> All(); List<History> All();
void Purge(); void Purge();
void Trim(); void Trim();
QualityModel GetBestQualityInHistory(int episodeId); QualityModel GetBestQualityInHistory(QualityProfile qualityProfile, int episodeId);
PagingSpec<History> Paged(PagingSpec<History> pagingSpec); PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
List<History> BetweenDates(DateTime startDate, DateTime endDate, HistoryEventType eventType); List<History> BetweenDates(DateTime startDate, DateTime endDate, HistoryEventType eventType);
List<History> Failed(); List<History> Failed();
@ -81,9 +81,12 @@ namespace NzbDrone.Core.History
_historyRepository.Trim(); _historyRepository.Trim();
} }
public QualityModel GetBestQualityInHistory(int episodeId) public QualityModel GetBestQualityInHistory(QualityProfile qualityProfile, int episodeId)
{ {
return _historyRepository.GetBestQualityInHistory(episodeId).OrderByDescending(q => q).FirstOrDefault(); var comparer = new QualityModelComparer(qualityProfile);
return _historyRepository.GetBestQualityInHistory(episodeId)
.OrderByDescending(q => q, comparer)
.FirstOrDefault();
} }
public void Handle(EpisodeGrabbedEvent message) public void Handle(EpisodeGrabbedEvent message)

Loading…
Cancel
Save