2011-05-22 16:53:21 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
using System;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2011-04-22 20:14:02 +00:00
|
|
|
|
using AutoMoq;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using Moq;
|
|
|
|
|
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
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[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-05-19 03:55:35 +00:00
|
|
|
|
Season season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
|
2011-01-29 06:10:22 +00:00
|
|
|
|
var episode = new Episode
|
|
|
|
|
{
|
|
|
|
|
AirDate = DateTime.Today.AddDays(-1),
|
|
|
|
|
EpisodeId = 1234,
|
|
|
|
|
EpisodeNumber = 5,
|
|
|
|
|
Overview = "This is an Overview",
|
|
|
|
|
SeasonNumber = 1,
|
|
|
|
|
SeasonId = 4321,
|
|
|
|
|
Season = season,
|
|
|
|
|
SeriesId = 5656
|
|
|
|
|
};
|
|
|
|
|
|
2011-05-19 03:55:35 +00:00
|
|
|
|
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,
|
2011-05-19 03:55:35 +00:00
|
|
|
|
EpisodeId = episode.EpisodeId
|
|
|
|
|
}
|
|
|
|
|
};
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void add_item()
|
|
|
|
|
{
|
2011-05-19 03:55:35 +00:00
|
|
|
|
//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,
|
2011-05-19 03:55:35 +00:00
|
|
|
|
NzbTitle = "my title",
|
|
|
|
|
Indexer = "Fake Indexer"
|
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
|
|
|
|
|
var storedHistory = repo.All<History>();
|
|
|
|
|
var newHistiory = repo.All<History>().First();
|
|
|
|
|
|
|
|
|
|
Assert.Count(1, storedHistory);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2011-01-29 06:10:22 +00:00
|
|
|
|
[Test]
|
2011-03-30 06:18:35 +00:00
|
|
|
|
[Ignore]
|
2011-01-29 06:10:22 +00:00
|
|
|
|
public void Exists_True()
|
|
|
|
|
{
|
|
|
|
|
//Todo: This test fails... Moq Setup doesn't return the expected value
|
|
|
|
|
//Setup
|
2011-04-19 00:12:06 +00:00
|
|
|
|
var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
|
2011-01-29 06:10:22 +00:00
|
|
|
|
var episode = new Episode
|
2011-04-10 02:44:01 +00:00
|
|
|
|
{
|
|
|
|
|
AirDate = DateTime.Today.AddDays(-1),
|
|
|
|
|
EpisodeId = 1234,
|
|
|
|
|
EpisodeNumber = 5,
|
|
|
|
|
Overview = "This is an Overview",
|
|
|
|
|
SeasonNumber = 1,
|
|
|
|
|
SeasonId = 4321,
|
|
|
|
|
Season = season,
|
|
|
|
|
SeriesId = 5656
|
|
|
|
|
};
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
var proper = false;
|
|
|
|
|
|
|
|
|
|
var repo = new Mock<IRepository>();
|
2011-04-10 02:44:01 +00:00
|
|
|
|
repo.Setup(r => r.Exists<History>(h => h.EpisodeId == episode.EpisodeId && h.IsProper == proper)).Returns(
|
|
|
|
|
true);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
var target = new HistoryProvider(repo.Object);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-05-23 17:20:43 +00:00
|
|
|
|
var result = target.Exists(episode.EpisodeId, QualityTypes.SDTV, false);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.AreEqual(result, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-03-30 06:18:35 +00:00
|
|
|
|
[Ignore]
|
2011-01-29 06:10:22 +00:00
|
|
|
|
public void Exists_False()
|
|
|
|
|
{
|
|
|
|
|
//Todo: This test fails... Moq Setup doesn't return the expected value
|
|
|
|
|
|
|
|
|
|
//Setup
|
2011-05-22 16:53:21 +00:00
|
|
|
|
var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
|
2011-01-29 06:10:22 +00:00
|
|
|
|
var episode = new Episode
|
2011-04-10 02:44:01 +00:00
|
|
|
|
{
|
|
|
|
|
AirDate = DateTime.Today.AddDays(-1),
|
|
|
|
|
EpisodeId = 1234,
|
|
|
|
|
EpisodeNumber = 5,
|
|
|
|
|
Overview = "This is an Overview",
|
|
|
|
|
SeasonNumber = 1,
|
|
|
|
|
SeasonId = 4321,
|
|
|
|
|
Season = season,
|
|
|
|
|
SeriesId = 5656
|
|
|
|
|
};
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-05-19 03:55:35 +00:00
|
|
|
|
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,
|
2011-05-19 03:55:35 +00:00
|
|
|
|
EpisodeId = episode.EpisodeId
|
|
|
|
|
}
|
|
|
|
|
};
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
var repo = new Mock<IRepository>();
|
2011-04-10 02:44:01 +00:00
|
|
|
|
repo.Setup(r => r.Exists<History>(h => h.Episode == episode && h.IsProper == list[0].IsProper)).Returns(
|
|
|
|
|
false);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
var target = new HistoryProvider(repo.Object);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-05-23 17:20:43 +00:00
|
|
|
|
var result = target.Exists(episode.EpisodeId, QualityTypes.SDTV, true);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.AreEqual(result, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-17 17:45:02 +00:00
|
|
|
|
}
|