2011-10-23 04:31:28 +02:00
|
|
|
|
using System;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
using System.Linq;
|
2011-05-28 21:23:35 +02:00
|
|
|
|
using FizzWare.NBuilder;
|
2011-06-02 23:06:46 +02:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-01-29 21:03:47 +01:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-19 05:55:35 +02:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-10-21 01:42:17 +02:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-05-19 05:55:35 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-02 21:54:03 +01:00
|
|
|
|
public class HistoryProviderTest : SqlCeTest
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void AllItems()
|
|
|
|
|
{
|
2012-02-07 06:08:07 +01:00
|
|
|
|
WithRealDb();
|
2011-01-29 07:10:22 +01:00
|
|
|
|
//Setup
|
2012-10-14 02:36:16 +02:00
|
|
|
|
var historyItem = Builder<History>.CreateListOfSize(10)
|
|
|
|
|
.All()
|
|
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
|
|
|
|
.Build();
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
Db.InsertMany(historyItem);
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<HistoryProvider>().AllItems();
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-17 08:59:13 +02:00
|
|
|
|
result.Should().HaveSameCount(historyItem);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 02:02:10 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void AllItemsWithRelationships()
|
|
|
|
|
{
|
2012-02-07 06:08:07 +01:00
|
|
|
|
WithRealDb();
|
2011-06-20 02:02:10 +02:00
|
|
|
|
var seriesOne = Builder<Series>.CreateNew().With(s => s.SeriesId = 12345).Build();
|
|
|
|
|
var seriesTwo = Builder<Series>.CreateNew().With(s => s.SeriesId = 54321).Build();
|
|
|
|
|
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
|
|
|
|
|
|
2012-10-14 02:36:16 +02:00
|
|
|
|
var historyItems = Builder<History>
|
|
|
|
|
.CreateListOfSize(10)
|
|
|
|
|
.All()
|
|
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
|
|
|
|
.TheFirst(5)
|
|
|
|
|
.With(h => h.SeriesId = seriesOne.SeriesId)
|
|
|
|
|
.TheLast(5)
|
|
|
|
|
.With(h => h.SeriesId = seriesTwo.SeriesId)
|
|
|
|
|
.Build();
|
2011-06-20 02:02:10 +02:00
|
|
|
|
|
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
Db.InsertMany(historyItems);
|
|
|
|
|
Db.InsertMany(episodes);
|
|
|
|
|
Db.Insert(seriesOne);
|
|
|
|
|
Db.Insert(seriesTwo);
|
2011-06-20 02:02:10 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
var result = Mocker.Resolve<HistoryProvider>().AllItemsWithRelationships();
|
2011-06-20 02:02:10 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().HaveSameCount(historyItems);
|
|
|
|
|
|
|
|
|
|
foreach (var history in result)
|
|
|
|
|
{
|
|
|
|
|
Assert.NotNull(history.Episode);
|
|
|
|
|
Assert.That(!String.IsNullOrEmpty(history.SeriesTitle));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-17 08:59:13 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void PurgeItem()
|
|
|
|
|
{
|
2012-02-07 06:08:07 +01:00
|
|
|
|
WithRealDb();
|
2011-06-17 08:59:13 +02:00
|
|
|
|
|
2012-10-14 02:36:16 +02:00
|
|
|
|
var historyItem = Builder<History>
|
|
|
|
|
.CreateListOfSize(10)
|
|
|
|
|
.All()
|
|
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
|
|
|
|
.Build();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
Db.InsertMany(historyItem);
|
2011-06-17 08:59:13 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-02-07 06:08:07 +01:00
|
|
|
|
Db.Fetch<History>().Should().HaveCount(10);
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.Resolve<HistoryProvider>().Purge();
|
2011-06-17 08:59:13 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-02-07 06:08:07 +01:00
|
|
|
|
Db.Fetch<History>().Should().HaveCount(0);
|
2011-06-17 08:59:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Trim_Items()
|
|
|
|
|
{
|
2012-02-07 06:08:07 +01:00
|
|
|
|
WithRealDb();
|
|
|
|
|
|
2011-11-23 02:09:06 +01:00
|
|
|
|
var historyItem = Builder<History>.CreateListOfSize(30)
|
2012-10-14 02:36:16 +02:00
|
|
|
|
.All()
|
|
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
2011-10-18 23:46:06 +02:00
|
|
|
|
.TheFirst(10).With(c => c.Date = DateTime.Now)
|
2011-11-23 02:09:06 +01:00
|
|
|
|
.TheNext(20).With(c => c.Date = DateTime.Now.AddDays(-31))
|
2011-06-17 08:59:13 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
Db.InsertMany(historyItem);
|
2011-06-17 08:59:13 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-02-07 06:08:07 +01:00
|
|
|
|
Db.Fetch<History>().Should().HaveCount(30);
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.Resolve<HistoryProvider>().Trim();
|
2011-06-17 08:59:13 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var result = Db.Fetch<History>();
|
2011-11-23 02:09:06 +01:00
|
|
|
|
result.Should().HaveCount(10);
|
|
|
|
|
result.Should().OnlyContain(s => s.Date > DateTime.Now.AddDays(-30));
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 22:14:02 +02:00
|
|
|
|
|
2011-05-28 21:23:35 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void GetBestQualityInHistory_no_result()
|
|
|
|
|
{
|
2012-02-07 06:08:07 +01:00
|
|
|
|
WithRealDb();
|
|
|
|
|
Mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(12, 12, 12).Should().Be(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetBestQualityInHistory_single_result()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
2011-05-28 21:23:35 +02:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
|
|
|
|
|
var historyEpisode = episodes[6];
|
|
|
|
|
|
|
|
|
|
var history = Builder<History>.CreateNew()
|
|
|
|
|
.With(h => h.Quality = QualityTypes.Bluray720p)
|
|
|
|
|
.With(h => h.IsProper = true)
|
|
|
|
|
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.Insert(history);
|
|
|
|
|
Db.InsertMany(episodes);
|
2011-05-28 21:23:35 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var result = Mocker.Resolve<HistoryProvider>()
|
|
|
|
|
.GetBestQualityInHistory(historyEpisode.SeriesId, historyEpisode.SeasonNumber, historyEpisode.EpisodeNumber);
|
2011-05-28 21:23:35 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-02-07 06:08:07 +01:00
|
|
|
|
result.Should().NotBeNull();
|
2012-10-14 02:36:16 +02:00
|
|
|
|
result.Quality.Should().Be(QualityTypes.Bluray720p);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
result.Proper.Should().BeTrue();
|
2011-05-28 21:23:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-02-07 06:08:07 +01:00
|
|
|
|
public void GetBestQualityInHistory_should_return_highest_result()
|
2011-05-28 21:23:35 +02:00
|
|
|
|
{
|
2012-02-07 06:08:07 +01:00
|
|
|
|
WithRealDb();
|
2011-05-28 21:23:35 +02:00
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
|
|
|
|
|
var historyEpisode = episodes[6];
|
2011-06-17 08:59:13 +02:00
|
|
|
|
|
2013-01-11 02:15:36 +01:00
|
|
|
|
var history = Builder<History>
|
|
|
|
|
.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
|
|
|
|
|
.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);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-01-11 02:15:36 +01:00
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<HistoryProvider>()
|
|
|
|
|
.GetBestQualityInHistory(historyEpisode.SeriesId, historyEpisode.SeasonNumber, historyEpisode.EpisodeNumber);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-01-11 02:15:36 +01:00
|
|
|
|
//Assert
|
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
|
result.Quality.Should().Be(QualityTypes.Bluray720p);
|
|
|
|
|
result.Proper.Should().BeTrue();
|
|
|
|
|
}
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-01-11 02:15:36 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void GetBestQualityInHistory_should_return_highest_weighted_result()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-01-11 02:15:36 +01:00
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
|
|
|
|
|
var historyEpisode = episodes[6];
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-01-11 02:15:36 +01:00
|
|
|
|
var history = Builder<History>
|
|
|
|
|
.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(h => h.EpisodeId = historyEpisode.EpisodeId)
|
|
|
|
|
.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);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
Db.InsertMany(episodes);
|
2011-05-28 21:23:35 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var result = Mocker.Resolve<HistoryProvider>()
|
|
|
|
|
.GetBestQualityInHistory(historyEpisode.SeriesId, historyEpisode.SeasonNumber, historyEpisode.EpisodeNumber);
|
2011-05-28 21:23:35 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-23 08:56:17 +02:00
|
|
|
|
result.Should().NotBeNull();
|
2013-01-11 02:15:36 +01:00
|
|
|
|
result.Quality.Should().Be(QualityTypes.WEBDL1080p);
|
|
|
|
|
result.Proper.Should().BeFalse();
|
2011-05-28 21:23:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 22:14:02 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void add_item()
|
|
|
|
|
{
|
2012-02-07 06:08:07 +01:00
|
|
|
|
WithRealDb();
|
2011-04-22 22:14:02 +02:00
|
|
|
|
|
2011-06-17 08:59:13 +02:00
|
|
|
|
var episode = Builder<Episode>.CreateNew().Build();
|
2011-04-22 22:14:02 +02:00
|
|
|
|
|
2013-01-01 04:45:57 +01:00
|
|
|
|
QualityTypes quality = QualityTypes.HDTV720p;
|
2011-06-17 08:59:13 +02:00
|
|
|
|
const bool proper = true;
|
2011-04-22 22:14:02 +02:00
|
|
|
|
|
|
|
|
|
var history = new History
|
|
|
|
|
{
|
|
|
|
|
Date = DateTime.Now,
|
|
|
|
|
EpisodeId = episode.EpisodeId,
|
2011-06-17 08:59:13 +02:00
|
|
|
|
SeriesId = episode.SeriesId,
|
2011-05-19 05:55:35 +02:00
|
|
|
|
NzbTitle = "my title",
|
2011-06-17 08:59:13 +02:00
|
|
|
|
Indexer = "Fake Indexer",
|
|
|
|
|
Quality = quality,
|
|
|
|
|
IsProper = proper
|
2011-04-22 22:14:02 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-05-19 05:55:35 +02:00
|
|
|
|
//Act
|
2011-12-15 05:15:53 +01:00
|
|
|
|
Mocker.Resolve<HistoryProvider>().Add(history);
|
2011-05-19 05:55:35 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-02-07 06:08:07 +01:00
|
|
|
|
var storedHistory = Db.Fetch<History>();
|
2011-05-19 05:55:35 +02:00
|
|
|
|
|
2011-06-02 23:06:46 +02:00
|
|
|
|
storedHistory.Should().HaveCount(1);
|
2011-06-23 08:56:17 +02:00
|
|
|
|
history.Date.Should().BeWithin(TimeSpan.FromMinutes(1)).Before(storedHistory.First().Date);
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2011-06-23 08:56:17 +02:00
|
|
|
|
history.EpisodeId.Should().Be(storedHistory.First().EpisodeId);
|
|
|
|
|
history.SeriesId.Should().Be(storedHistory.First().SeriesId);
|
|
|
|
|
history.NzbTitle.Should().Be(storedHistory.First().NzbTitle);
|
|
|
|
|
history.Indexer.Should().Be(storedHistory.First().Indexer);
|
|
|
|
|
history.Quality.Should().Be(storedHistory.First().Quality);
|
|
|
|
|
history.IsProper.Should().Be(storedHistory.First().IsProper);
|
2011-04-22 22:14:02 +02:00
|
|
|
|
}
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
2011-02-17 18:45:02 +01:00
|
|
|
|
}
|