mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Solved error in quality comparison for HistoryService
This commit is contained in:
parent
31e0524389
commit
45304b1bbc
@ -62,9 +62,9 @@ public void Setup()
|
|||||||
_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 @@ public void Setup()
|
|||||||
|
|
||||||
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 @@ public void should_not_be_upgradable_if_episode_is_of_same_quality_as_existing()
|
|||||||
_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();
|
||||||
}
|
}
|
||||||
|
59
src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs
Normal file
59
src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs
Normal file
@ -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 @@ public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase sear
|
|||||||
|
|
||||||
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 @@ public interface IHistoryService
|
|||||||
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 @@ public virtual void Trim()
|
|||||||
_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…
Reference in New Issue
Block a user