Radarr/NzbDrone.Core.Test/HistoryProviderTest.cs

131 lines
4.0 KiB
C#
Raw Normal View History

2011-05-22 16:53:21 +00:00
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
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;
using Moq;
2011-06-02 21:06:46 +00:00
using NUnit.Framework;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
2011-01-29 20:03:47 +00:00
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class HistoryProviderTest : TestBase
{
[Test]
public void AllItems()
{
//Setup
var episode = new Episode
{
AirDate = DateTime.Today.AddDays(-1),
EpisodeId = 1234,
EpisodeNumber = 5,
Overview = "This is an Overview",
SeasonNumber = 1,
SeriesId = 5656
};
var list = new List<History>
{
new History
{
HistoryId = new int(),
Date = DateTime.Now,
IsProper = false,
2011-05-23 17:20:43 +00:00
Quality = QualityTypes.SDTV,
EpisodeId = episode.EpisodeId
}
};
var repo = new Mock<IRepository>();
repo.Setup(r => r.All<History>()).Returns(list.AsQueryable());
var target = new HistoryProvider(repo.Object);
//Act
var result = target.AllItems();
//Assert
Assert.AreEqual(result.Count(), 1);
}
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);
mocker.SetConstant(MockLib.GetEmptyRepository());
//Act
var result = mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(12);
//Assert
Assert.IsNull(result);
}
[Test]
public void GetBestQualityInHistory_single_result()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var repo = MockLib.GetEmptyRepository();
var history = Builder<History>.CreateNew().Build();
repo.Add(history);
mocker.SetConstant(repo);
//Act
var result = mocker.Resolve<HistoryProvider>().GetBestQualityInHistory(history.EpisodeId);
//Assert
Assert.IsNotNull(result);
}
2011-04-22 20:14:02 +00:00
[Test]
public void add_item()
{
//Arange
2011-04-22 20:14:02 +00:00
var mocker = new AutoMoqer();
var repo = MockLib.GetEmptyRepository();
mocker.SetConstant(repo);
var episodes = MockLib.GetFakeEpisodes(1);
repo.AddMany(episodes);
var episode = episodes[5];
var history = new History
{
Date = DateTime.Now,
EpisodeId = episode.EpisodeId,
NzbTitle = "my title",
Indexer = "Fake Indexer"
2011-04-22 20:14:02 +00:00
};
//Act
2011-04-22 20:14:02 +00:00
mocker.Resolve<HistoryProvider>().Add(history);
//Assert
var storedHistory = repo.All<History>();
var newHistiory = repo.All<History>().First();
2011-06-02 21:06:46 +00:00
storedHistory.Should().HaveCount(1);
Assert.AreEqual(history.Date, newHistiory.Date);
Assert.AreEqual(history.EpisodeId, newHistiory.EpisodeId);
Assert.AreEqual(history.NzbTitle, newHistiory.NzbTitle);
Assert.AreEqual(history.Indexer, newHistiory.Indexer);
2011-04-22 20:14:02 +00:00
}
}
}