2011-10-23 02:31:28 +00:00
|
|
|
|
using System;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
using System.Linq;
|
2011-04-22 20:14:02 +00:00
|
|
|
|
using AutoMoq;
|
2011-05-28 19:23:35 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using FluentAssertions;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
using Moq;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using NUnit.Framework;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-01-29 20:03:47 +00:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-19 03:55:35 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-05-19 03:55:35 +00:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class HistoryProviderTest : TestBase
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void AllItems()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2011-06-17 06:59:13 +00:00
|
|
|
|
var historyItem = Builder<History>.CreateListOfSize(10).Build();
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-06-17 06:59:13 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-06-17 06:59:13 +00:00
|
|
|
|
db.InsertMany(historyItem);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-06-17 06:59:13 +00:00
|
|
|
|
var result = mocker.Resolve<HistoryProvider>().AllItems();
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-17 06:59:13 +00:00
|
|
|
|
result.Should().HaveSameCount(historyItem);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 00:02:10 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void AllItemsWithRelationships()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
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();
|
|
|
|
|
|
2011-10-23 05:39:14 +00:00
|
|
|
|
var historyItems = Builder<History>.CreateListOfSize(10).TheFirst(5).With(h => h.SeriesId = seriesOne.SeriesId).TheLast(5).With(h => h.SeriesId = seriesTwo.SeriesId).Build();
|
2011-06-20 00:02:10 +00:00
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
db.InsertMany(historyItems);
|
|
|
|
|
db.InsertMany(episodes);
|
|
|
|
|
db.Insert(seriesOne);
|
|
|
|
|
db.Insert(seriesTwo);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<HistoryProvider>().AllItemsWithRelationships();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().HaveSameCount(historyItems);
|
|
|
|
|
|
|
|
|
|
foreach (var history in result)
|
|
|
|
|
{
|
|
|
|
|
Assert.NotNull(history.Episode);
|
|
|
|
|
Assert.That(!String.IsNullOrEmpty(history.SeriesTitle));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-17 06:59:13 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void PurgeItem()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var historyItem = Builder<History>.CreateListOfSize(10).Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
db.InsertMany(historyItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
db.Fetch<History>().Should().HaveCount(10);
|
|
|
|
|
mocker.Resolve<HistoryProvider>().Purge();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
db.Fetch<History>().Should().HaveCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Trim_Items()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var historyItem = Builder<History>.CreateListOfSize(20)
|
2011-10-18 21:46:06 +00:00
|
|
|
|
.TheFirst(10).With(c => c.Date = DateTime.Now)
|
2011-10-23 05:39:14 +00:00
|
|
|
|
.TheNext(10).With(c => c.Date = DateTime.Now.AddDays(-31))
|
2011-06-17 06:59:13 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
db.InsertMany(historyItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
db.Fetch<History>().Should().HaveCount(20);
|
|
|
|
|
mocker.Resolve<HistoryProvider>().Trim();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
db.Fetch<History>().Should().HaveCount(10);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 20:14:02 +00:00
|
|
|
|
|
2011-05-28 19:23:35 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void GetBestQualityInHistory_no_result()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
2011-06-17 06:59:13 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-28 19:23:35 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(12);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetBestQualityInHistory_single_result()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
|
2011-06-17 06:59:13 +00:00
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
2011-06-05 19:15:46 +00:00
|
|
|
|
var history = Builder<History>.CreateNew()
|
|
|
|
|
.With(h => h.Quality = QualityTypes.Bluray720p).Build();
|
2011-06-17 06:59:13 +00:00
|
|
|
|
|
|
|
|
|
db.Insert(history);
|
|
|
|
|
mocker.SetConstant(db);
|
2011-05-28 19:23:35 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(history.EpisodeId);
|
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-23 06:56:17 +00:00
|
|
|
|
result.Should().NotBeNull();
|
2011-06-05 19:15:46 +00:00
|
|
|
|
result.QualityType.Should().Be(QualityTypes.Bluray720p);
|
2011-05-28 19:23:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 20:14:02 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void add_item()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-17 06:59:13 +00:00
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
2011-04-22 20:14:02 +00:00
|
|
|
|
|
2011-06-17 06:59:13 +00:00
|
|
|
|
mocker.SetConstant(db);
|
2011-04-22 20:14:02 +00:00
|
|
|
|
|
2011-06-17 06:59:13 +00:00
|
|
|
|
var episode = Builder<Episode>.CreateNew().Build();
|
2011-04-22 20:14:02 +00:00
|
|
|
|
|
2011-06-17 06:59:13 +00:00
|
|
|
|
const QualityTypes quality = QualityTypes.HDTV;
|
|
|
|
|
const bool proper = true;
|
2011-04-22 20:14:02 +00:00
|
|
|
|
|
|
|
|
|
var history = new History
|
|
|
|
|
{
|
|
|
|
|
Date = DateTime.Now,
|
|
|
|
|
EpisodeId = episode.EpisodeId,
|
2011-06-17 06:59:13 +00:00
|
|
|
|
SeriesId = episode.SeriesId,
|
2011-05-19 03:55:35 +00:00
|
|
|
|
NzbTitle = "my title",
|
2011-06-17 06:59:13 +00:00
|
|
|
|
Indexer = "Fake Indexer",
|
|
|
|
|
Quality = quality,
|
|
|
|
|
IsProper = proper
|
2011-04-22 20:14:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-05-19 03:55:35 +00:00
|
|
|
|
//Act
|
2011-04-22 20:14:02 +00:00
|
|
|
|
mocker.Resolve<HistoryProvider>().Add(history);
|
2011-05-19 03:55:35 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-17 06:59:13 +00:00
|
|
|
|
var storedHistory = db.Fetch<History>();
|
2011-05-19 03:55:35 +00:00
|
|
|
|
|
2011-06-02 21:06:46 +00:00
|
|
|
|
storedHistory.Should().HaveCount(1);
|
2011-06-23 06:56:17 +00:00
|
|
|
|
history.Date.Should().BeWithin(TimeSpan.FromMinutes(1)).Before(storedHistory.First().Date);
|
|
|
|
|
|
|
|
|
|
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 20:14:02 +00:00
|
|
|
|
}
|
2011-01-29 06:10:22 +00:00
|
|
|
|
}
|
2011-02-17 17:45:02 +00:00
|
|
|
|
}
|