2013-02-23 21:29:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.History;
|
2013-02-27 03:19:22 +00:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
2013-02-23 21:29:22 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.HistoryTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-03-27 00:51:37 +00:00
|
|
|
|
public class HistoryRepositoryFixture : DbTest<HistoryRepository, History.History>
|
2013-02-23 21:29:22 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void Trim_Items()
|
|
|
|
|
{
|
|
|
|
|
var historyItem = Builder<History.History>.CreateListOfSize(30)
|
|
|
|
|
.All()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(c=>c.Id = 0)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.TheFirst(10).With(c => c.Date = DateTime.Now)
|
|
|
|
|
.TheNext(20).With(c => c.Date = DateTime.Now.AddDays(-31))
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(historyItem);
|
|
|
|
|
|
|
|
|
|
AllStoredModels.Should().HaveCount(30);
|
|
|
|
|
Subject.Trim();
|
|
|
|
|
|
|
|
|
|
AllStoredModels.Should().HaveCount(10);
|
|
|
|
|
AllStoredModels.Should().OnlyContain(s => s.Date > DateTime.Now.AddDays(-30));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetBestQualityInHistory_no_result()
|
|
|
|
|
{
|
2013-03-25 01:38:11 +00:00
|
|
|
|
Subject.GetBestQualityInHistory(12).Should().Be(null);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetBestQualityInHistory_single_result()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var episode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(c => c.Series = series)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(c => c.SeriesId = series.Id)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var history = Builder<History.History>.CreateNew()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(c => c.Id = 0)
|
2013-02-27 03:19:22 +00:00
|
|
|
|
.With(h => h.Quality = new QualityModel(Quality.Bluray720p, true))
|
2013-03-25 01:38:11 +00:00
|
|
|
|
.With(h => h.EpisodeId = episode.Id)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.Insert(history);
|
|
|
|
|
|
2013-03-25 01:38:11 +00:00
|
|
|
|
var result = Subject.GetBestQualityInHistory(episode.Id);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
|
|
|
|
|
result.Should().NotBeNull();
|
2013-02-27 03:19:22 +00:00
|
|
|
|
result.Quality.Should().Be(Quality.Bluray720p);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
result.Proper.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetBestQualityInHistory_should_return_highest_result()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var series = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var episode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(c => c.Series = series)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(c => c.SeriesId = series.Id)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var history = Builder<History.History>
|
|
|
|
|
.CreateListOfSize(5)
|
|
|
|
|
.All()
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(c => c.Id = 0)
|
2013-03-25 01:38:11 +00:00
|
|
|
|
.With(h => h.EpisodeId = episode.Id)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.TheFirst(1)
|
2013-02-27 03:19:22 +00:00
|
|
|
|
.With(h => h.Quality = new QualityModel(Quality.DVD, true))
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.TheNext(1)
|
2013-02-27 03:19:22 +00:00
|
|
|
|
.With(h => h.Quality = new QualityModel(Quality.Bluray720p, true))
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.TheNext(1)
|
2013-02-27 03:19:22 +00:00
|
|
|
|
.With(h => h.Quality = new QualityModel(Quality.Bluray720p, true))
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.TheNext(1)
|
2013-02-27 03:19:22 +00:00
|
|
|
|
.With(h => h.Quality = new QualityModel(Quality.Bluray720p, false))
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.TheNext(1)
|
2013-02-27 03:19:22 +00:00
|
|
|
|
.With(h => h.Quality = new QualityModel(Quality.SDTV, true))
|
2013-02-23 21:29:22 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(history);
|
|
|
|
|
|
2013-03-25 01:38:11 +00:00
|
|
|
|
var result = Subject.GetBestQualityInHistory(episode.Id);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
|
|
|
|
|
result.Should().NotBeNull();
|
2013-02-27 03:19:22 +00:00
|
|
|
|
result.Quality.Should().Be(Quality.Bluray720p);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
result.Proper.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|