BestQualityInHistory fixed

#ND-138 fixed
#ND-138 comment "No issue with Disk upgrade check, just history."
Fixed: An issue with some qualities being treated as lower than expected
when checking history
pull/2/head
Mark McDowall 12 years ago
parent 210a0c1936
commit 8d9e69af96

@ -120,7 +120,6 @@ namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
//Act //Act
Mocker.Resolve<EpisodeProvider>().GetEpisode(1); Mocker.Resolve<EpisodeProvider>().GetEpisode(1);
} }
[Test] [Test]
public void GetEpisodesBySeason_success() public void GetEpisodesBySeason_success()
@ -181,7 +180,6 @@ namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
actualCount.Should().Be(episodeCount); actualCount.Should().Be(episodeCount);
} }
[Test] [Test]
public void RefreshEpisodeInfo_should_set_older_than_1900_to_null() public void RefreshEpisodeInfo_should_set_older_than_1900_to_null()
{ {
@ -1518,5 +1516,26 @@ namespace NzbDrone.Core.Test.ProviderTests.EpisodeProviderTests
result.Where(e => e.Ignored).Should().HaveCount(episodeCount - 1); result.Where(e => e.Ignored).Should().HaveCount(episodeCount - 1);
result.Single(e => e.SeasonNumber == 1).Ignored.Should().BeFalse(); result.Single(e => e.SeasonNumber == 1).Ignored.Should().BeFalse();
} }
[Test]
public void GetEpisode_with_EpisodeFile_should_have_quality_set_properly()
{
WithRealDb();
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.WEBDL1080p).Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
.All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build();
Db.Insert(fakeSeries);
Db.InsertMany(fakeEpisodes);
Db.Insert(fakeFile);
//Act
var episode = Mocker.Resolve<EpisodeProvider>().GetEpisode(1);
//Assert
episode.EpisodeFile.Quality.Should().Be(QualityTypes.WEBDL1080p);
}
} }
} }

@ -158,41 +158,72 @@ namespace NzbDrone.Core.Test.ProviderTests
var episodes = Builder<Episode>.CreateListOfSize(10).Build(); var episodes = Builder<Episode>.CreateListOfSize(10).Build();
var historyEpisode = episodes[6]; var historyEpisode = episodes[6];
var history0 = Builder<History>.CreateNew() var history = Builder<History>
.With(h => h.Quality = QualityTypes.DVD) .CreateListOfSize(5)
.With(h => h.IsProper = true) .All()
.With(h => h.EpisodeId = historyEpisode.EpisodeId) .With(h => h.EpisodeId = historyEpisode.EpisodeId)
.Build(); .With(h => h.SeriesId = historyEpisode.SeriesId)
.TheFirst(1)
.With(h => h.Quality = QualityTypes.DVD)
.With(h => h.IsProper = true)
.TheNext(1)
.With(h => h.Quality = QualityTypes.Bluray720p)
.With(h => h.IsProper = false)
.TheNext(1)
.With(h => h.Quality = QualityTypes.Bluray720p)
.With(h => h.IsProper = true)
.TheNext(1)
.With(h => h.Quality = QualityTypes.Bluray720p)
.With(h => h.IsProper = false)
.TheNext(1)
.With(h => h.Quality = QualityTypes.SDTV)
.With(h => h.IsProper = true)
.Build();
Db.InsertMany(history);
Db.InsertMany(episodes);
var history1 = Builder<History>.CreateNew() //Act
.With(h => h.Quality = QualityTypes.Bluray720p) var result = Mocker.Resolve<HistoryProvider>()
.With(h => h.IsProper = false) .GetBestQualityInHistory(historyEpisode.SeriesId, historyEpisode.SeasonNumber, historyEpisode.EpisodeNumber);
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
.Build();
var history2 = Builder<History>.CreateNew() //Assert
.With(h => h.Quality = QualityTypes.Bluray720p) result.Should().NotBeNull();
.With(h => h.IsProper = true) result.Quality.Should().Be(QualityTypes.Bluray720p);
.With(h => h.EpisodeId = historyEpisode.EpisodeId) result.Proper.Should().BeTrue();
.Build(); }
var history3 = Builder<History>.CreateNew() [Test]
.With(h => h.Quality = QualityTypes.Bluray720p) public void GetBestQualityInHistory_should_return_highest_weighted_result()
.With(h => h.IsProper = false) {
.With(h => h.EpisodeId = historyEpisode.EpisodeId) WithRealDb();
.Build();
var history4 = Builder<History>.CreateNew() var episodes = Builder<Episode>.CreateListOfSize(10).Build();
.With(h => h.Quality = QualityTypes.SDTV) var historyEpisode = episodes[6];
.With(h => h.IsProper = true)
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
.Build();
Db.Insert(history0); var history = Builder<History>
Db.Insert(history1); .CreateListOfSize(5)
Db.Insert(history2); .All()
Db.Insert(history2); .With(h => h.EpisodeId = historyEpisode.EpisodeId)
Db.Insert(history4); .With(h => h.SeriesId = historyEpisode.SeriesId)
.TheFirst(1)
.With(h => h.Quality = QualityTypes.DVD)
.With(h => h.IsProper = true)
.TheNext(1)
.With(h => h.Quality = QualityTypes.WEBDL720p)
.With(h => h.IsProper = false)
.TheNext(1)
.With(h => h.Quality = QualityTypes.WEBDL720p)
.With(h => h.IsProper = true)
.TheNext(1)
.With(h => h.Quality = QualityTypes.WEBDL1080p)
.With(h => h.IsProper = false)
.TheNext(1)
.With(h => h.Quality = QualityTypes.SDTV)
.With(h => h.IsProper = true)
.Build();
Db.InsertMany(history);
Db.InsertMany(episodes); Db.InsertMany(episodes);
//Act //Act
@ -201,8 +232,8 @@ namespace NzbDrone.Core.Test.ProviderTests
//Assert //Assert
result.Should().NotBeNull(); result.Should().NotBeNull();
result.Quality.Should().Be(QualityTypes.Bluray720p); result.Quality.Should().Be(QualityTypes.WEBDL1080p);
result.Proper.Should().BeTrue(); result.Proper.Should().BeFalse();
} }
[Test] [Test]

@ -60,17 +60,16 @@ namespace NzbDrone.Core.Providers
public virtual QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber) public virtual QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber)
{ {
var quality = _database.SingleOrDefault<dynamic>(@"SELECT TOP 1 History.Quality , History.IsProper FROM History var quality = _database.Fetch<QualityModel>(@"SELECT History.Quality , History.IsProper as Proper FROM History
INNER JOIN Episodes ON History.EpisodeId = Episodes.EpisodeId INNER JOIN Episodes ON History.EpisodeId = Episodes.EpisodeId
WHERE Episodes.seriesId = @0 AND WHERE Episodes.seriesId = @0 AND
Episodes.SeasonNumber = @1 AND Episodes.SeasonNumber = @1 AND
Episodes.EpisodeNumber = @2 Episodes.EpisodeNumber = @2"
ORDER BY History.Quality DESC, History.IsProper DESC"
, seriesId, seasonNumber, episodeNumber); , seriesId, seasonNumber, episodeNumber);
if (quality == null) return null; var best = quality.OrderByDescending(q => q).FirstOrDefault();
return new QualityModel((QualityTypes)quality.Quality, quality.IsProper); return best;
} }
public virtual void Delete(int historyId) public virtual void Delete(int historyId)

Loading…
Cancel
Save