mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
moved history over to objectdb
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
@@ -65,9 +66,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
firstQuality = new QualityModel(QualityTypes.Bluray1080p, true);
|
||||
secondQuality = new QualityModel(QualityTypes.Bluray1080p, true);
|
||||
|
||||
Mocker.GetMock<HistoryProvider>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 3)).Returns(firstQuality);
|
||||
Mocker.GetMock<HistoryProvider>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 4)).Returns(secondQuality);
|
||||
Mocker.GetMock<HistoryProvider>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 5)).Returns<QualityModel>(null);
|
||||
Mocker.GetMock<HistoryService>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 3)).Returns(firstQuality);
|
||||
Mocker.GetMock<HistoryService>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 4)).Returns(secondQuality);
|
||||
Mocker.GetMock<HistoryService>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 5)).Returns<QualityModel>(null);
|
||||
}
|
||||
|
||||
private void WithFirstReportUpgradable()
|
||||
@@ -123,7 +124,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
parseResultSingle.Quality = new QualityModel(QualityTypes.WEBDL1080p, false);
|
||||
firstQuality = new QualityModel(QualityTypes.WEBDL1080p, false);
|
||||
|
||||
Mocker.GetMock<HistoryProvider>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 3)).Returns(firstQuality);
|
||||
Mocker.GetMock<HistoryService>().Setup(c => c.GetBestQualityInHistory(fakeSeries.SeriesId, 12, 3)).Returns(firstQuality);
|
||||
|
||||
_upgradeHistory.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace NzbDrone.Core.Test.Framework
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class CoreTest<TSubject> : CoreTest where TSubject: class
|
||||
public abstract class CoreTest<TSubject> : CoreTest where TSubject : class
|
||||
{
|
||||
private TSubject _subject;
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.HistoryTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class HistoryServiceTest : ObjectDbTest<HistoryRepository, History.History>
|
||||
{
|
||||
[Test]
|
||||
public void Trim_Items()
|
||||
{
|
||||
var historyItem = Builder<History.History>.CreateListOfSize(30)
|
||||
.All()
|
||||
.With(c=>c.OID = 0)
|
||||
.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()
|
||||
{
|
||||
Subject.GetBestQualityInHistory(12, 12, 12).Should().Be(null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBestQualityInHistory_single_result()
|
||||
{
|
||||
var series = Builder<Series>.CreateNew().Build();
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.With(c => c.Series = series)
|
||||
.With(c => c.SeriesId = series.OID)
|
||||
.Build();
|
||||
|
||||
|
||||
|
||||
var history = Builder<History.History>.CreateNew()
|
||||
.With(c => c.OID = 0)
|
||||
.With(h => h.Quality = new QualityModel(QualityTypes.Bluray720p, true))
|
||||
.With(h => h.Episode = episode)
|
||||
.Build();
|
||||
|
||||
Db.Insert(history);
|
||||
|
||||
var result = Subject.GetBestQualityInHistory(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
result.Quality.Should().Be(QualityTypes.Bluray720p);
|
||||
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)
|
||||
.With(c => c.SeriesId = series.OID)
|
||||
.Build();
|
||||
|
||||
|
||||
var history = Builder<History.History>
|
||||
.CreateListOfSize(5)
|
||||
.All()
|
||||
.With(c => c.OID = 0)
|
||||
.With(h => h.Episode = episode)
|
||||
.TheFirst(1)
|
||||
.With(h => h.Quality = new QualityModel(QualityTypes.DVD, true))
|
||||
.TheNext(1)
|
||||
.With(h => h.Quality = new QualityModel(QualityTypes.Bluray720p, true))
|
||||
.TheNext(1)
|
||||
.With(h => h.Quality = new QualityModel(QualityTypes.Bluray720p, true))
|
||||
.TheNext(1)
|
||||
.With(h => h.Quality = new QualityModel(QualityTypes.Bluray720p, false))
|
||||
.TheNext(1)
|
||||
.With(h => h.Quality = new QualityModel(QualityTypes.SDTV, true))
|
||||
.Build();
|
||||
|
||||
Db.InsertMany(history);
|
||||
|
||||
var result = Subject.GetBestQualityInHistory(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
result.Quality.Should().Be(QualityTypes.Bluray720p);
|
||||
result.Proper.Should().BeTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@
|
||||
<Compile Include="QualityTest.cs" />
|
||||
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
|
||||
<Compile Include="Indexers\IndexerServiceTest.cs" />
|
||||
<Compile Include="ProviderTests\HistoryProviderTest.cs" />
|
||||
<Compile Include="HistoryTests\HistoryServiceTest.cs" />
|
||||
<Compile Include="ProviderTests\MediaFileProviderTest.cs" />
|
||||
<Compile Include="ProviderTests\ConfigProviderTests\ConfigProviderFixture.cs" />
|
||||
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest.cs" />
|
||||
|
||||
@@ -5,12 +5,12 @@ using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Providers.DownloadClients;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
@@ -98,11 +98,11 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
|
||||
Mocker.GetMock<BlackholeProvider>()
|
||||
.Verify(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), true), Times.Never());
|
||||
|
||||
Mocker.GetMock<HistoryProvider>()
|
||||
.Verify(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5)), Times.Once());
|
||||
Mocker.GetMock<HistoryService>()
|
||||
.Verify(s => s.Add(It.Is<History.History>(h => h.Episode == parseResult.Episodes[0])), Times.Once());
|
||||
|
||||
Mocker.GetMock<HistoryProvider>()
|
||||
.Verify(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)), Times.Once());
|
||||
Mocker.GetMock<HistoryService>()
|
||||
.Verify(s => s.Add(It.Is<History.History>(h => h.Episode == parseResult.Episodes[1])), Times.Once());
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(c => c.MarkEpisodeAsFetched(12));
|
||||
@@ -133,11 +133,11 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
|
||||
Mocker.GetMock<BlackholeProvider>()
|
||||
.Verify(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), true), Times.Once());
|
||||
|
||||
Mocker.GetMock<HistoryProvider>()
|
||||
.Verify(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5)), Times.Once());
|
||||
Mocker.GetMock<HistoryService>()
|
||||
.Verify(s => s.Add(It.Is<History.History>(h => h.Episode == parseResult.Episodes[0])), Times.Once());
|
||||
|
||||
Mocker.GetMock<HistoryProvider>()
|
||||
.Verify(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)), Times.Once());
|
||||
Mocker.GetMock<HistoryService>()
|
||||
.Verify(s => s.Add(It.Is<History.History>(h => h.Episode == parseResult.Episodes[1])), Times.Once());
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(c => c.MarkEpisodeAsFetched(12));
|
||||
@@ -161,8 +161,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
|
||||
//Act
|
||||
Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
||||
|
||||
Mocker.GetMock<HistoryProvider>()
|
||||
.Verify(s => s.Add(It.IsAny<History>()), Times.Never());
|
||||
Mocker.GetMock<HistoryService>()
|
||||
.Verify(s => s.Add(It.IsAny<History.History>()), Times.Never());
|
||||
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
|
||||
@@ -1,278 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class HistoryProviderTest : SqlCeTest
|
||||
{
|
||||
[Test]
|
||||
public void AllItems()
|
||||
{
|
||||
WithRealDb();
|
||||
//Setup
|
||||
var historyItem = Builder<History>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Quality = QualityTypes.SDTV)
|
||||
.Build();
|
||||
|
||||
Db.InsertMany(historyItem);
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<HistoryProvider>().AllItems();
|
||||
|
||||
//Assert
|
||||
result.Should().HaveSameCount(historyItem);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllItemsWithRelationships()
|
||||
{
|
||||
WithRealDb();
|
||||
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();
|
||||
|
||||
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();
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PurgeItem()
|
||||
{
|
||||
WithRealDb();
|
||||
|
||||
var historyItem = Builder<History>
|
||||
.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Quality = QualityTypes.SDTV)
|
||||
.Build();
|
||||
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()
|
||||
{
|
||||
WithRealDb();
|
||||
|
||||
var historyItem = Builder<History>.CreateListOfSize(30)
|
||||
.All()
|
||||
.With(c => c.Quality = QualityTypes.SDTV)
|
||||
.TheFirst(10).With(c => c.Date = DateTime.Now)
|
||||
.TheNext(20).With(c => c.Date = DateTime.Now.AddDays(-31))
|
||||
.Build();
|
||||
|
||||
Db.InsertMany(historyItem);
|
||||
|
||||
//Act
|
||||
Db.Fetch<History>().Should().HaveCount(30);
|
||||
Mocker.Resolve<HistoryProvider>().Trim();
|
||||
|
||||
//Assert
|
||||
var result = Db.Fetch<History>();
|
||||
result.Should().HaveCount(10);
|
||||
result.Should().OnlyContain(s => s.Date > DateTime.Now.AddDays(-30));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetBestQualityInHistory_no_result()
|
||||
{
|
||||
WithRealDb();
|
||||
Mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(12, 12, 12).Should().Be(null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBestQualityInHistory_single_result()
|
||||
{
|
||||
WithRealDb();
|
||||
|
||||
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.OID)
|
||||
.Build();
|
||||
|
||||
Db.Insert(history);
|
||||
Db.InsertMany(episodes);
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<HistoryProvider>()
|
||||
.GetBestQualityInHistory(historyEpisode.SeriesId, historyEpisode.SeasonNumber, historyEpisode.EpisodeNumber);
|
||||
|
||||
//Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Quality.Should().Be(QualityTypes.Bluray720p);
|
||||
result.Proper.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBestQualityInHistory_should_return_highest_result()
|
||||
{
|
||||
WithRealDb();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
|
||||
var historyEpisode = episodes[6];
|
||||
|
||||
var history = Builder<History>
|
||||
.CreateListOfSize(5)
|
||||
.All()
|
||||
.With(h => h.EpisodeId = historyEpisode.OID)
|
||||
.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);
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<HistoryProvider>()
|
||||
.GetBestQualityInHistory(historyEpisode.SeriesId, historyEpisode.SeasonNumber, historyEpisode.EpisodeNumber);
|
||||
|
||||
//Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Quality.Should().Be(QualityTypes.Bluray720p);
|
||||
result.Proper.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBestQualityInHistory_should_return_highest_weighted_result()
|
||||
{
|
||||
WithRealDb();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
|
||||
var historyEpisode = episodes[6];
|
||||
|
||||
var history = Builder<History>
|
||||
.CreateListOfSize(5)
|
||||
.All()
|
||||
.With(h => h.EpisodeId = historyEpisode.OID)
|
||||
.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);
|
||||
|
||||
//Act
|
||||
var result = Mocker.Resolve<HistoryProvider>()
|
||||
.GetBestQualityInHistory(historyEpisode.SeriesId, historyEpisode.SeasonNumber, historyEpisode.EpisodeNumber);
|
||||
|
||||
//Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Quality.Should().Be(QualityTypes.WEBDL1080p);
|
||||
result.Proper.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void add_item()
|
||||
{
|
||||
WithRealDb();
|
||||
|
||||
var episode = Builder<Episode>.CreateNew().Build();
|
||||
|
||||
QualityTypes quality = QualityTypes.HDTV720p;
|
||||
const bool proper = true;
|
||||
|
||||
var history = new History
|
||||
{
|
||||
Date = DateTime.Now,
|
||||
EpisodeId = episode.OID,
|
||||
SeriesId = episode.SeriesId,
|
||||
NzbTitle = "my title",
|
||||
Indexer = "Fake Indexer",
|
||||
Quality = quality,
|
||||
IsProper = proper
|
||||
};
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<HistoryProvider>().Add(history);
|
||||
|
||||
//Assert
|
||||
var storedHistory = Db.Fetch<History>();
|
||||
|
||||
storedHistory.Should().HaveCount(1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user