2010-10-05 06:21:18 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2010-10-17 17:22:48 +00:00
|
|
|
|
using System.Diagnostics;
|
2011-02-17 17:45:02 +00:00
|
|
|
|
using System.Linq;
|
2010-10-05 06:21:18 +00:00
|
|
|
|
using System.Text;
|
2011-04-07 03:34:48 +00:00
|
|
|
|
using AutoMoq;
|
2010-10-17 17:22:48 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
2010-10-05 06:21:18 +00:00
|
|
|
|
using Gallio.Framework;
|
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using MbUnit.Framework.ContractVerifiers;
|
2010-10-17 17:22:48 +00:00
|
|
|
|
using Moq;
|
|
|
|
|
using Ninject;
|
|
|
|
|
using Ninject.Moq;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-02-17 17:45:02 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-10-17 17:22:48 +00:00
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
using TvdbLib.Data;
|
|
|
|
|
using SubSonic.Extensions;
|
2010-10-05 06:21:18 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2010-10-07 22:17:24 +00:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2010-10-05 06:21:18 +00:00
|
|
|
|
public class EpisodeProviderTest
|
|
|
|
|
{
|
2010-10-17 17:22:48 +00:00
|
|
|
|
[Test]
|
2010-10-21 01:49:23 +00:00
|
|
|
|
public void RefreshEpisodeInfo()
|
2010-10-17 17:22:48 +00:00
|
|
|
|
{
|
|
|
|
|
//Arrange
|
2011-04-07 03:34:48 +00:00
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
2010-10-17 17:22:48 +00:00
|
|
|
|
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
|
c => c.Episodes =
|
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
|
WhereAll()
|
|
|
|
|
.Have(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
|
|
|
|
.Build())
|
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
2010-10-05 06:21:18 +00:00
|
|
|
|
|
2011-04-07 03:34:48 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
2010-10-17 17:22:48 +00:00
|
|
|
|
|
2011-04-07 03:34:48 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
2010-10-17 17:22:48 +00:00
|
|
|
|
|
2011-04-07 03:34:48 +00:00
|
|
|
|
mocker.GetMock<TvDbProvider>()
|
|
|
|
|
.Setup(c => c.GetSeries(seriesId, true))
|
|
|
|
|
.Returns(fakeEpisodes).Verifiable();
|
|
|
|
|
|
|
|
|
|
//mocker.GetMock<IRepository>().SetReturnsDefault();
|
2010-10-17 17:22:48 +00:00
|
|
|
|
|
|
|
|
|
|
2011-04-07 03:34:48 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var sw = Stopwatch.StartNew();
|
|
|
|
|
mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(seriesId);
|
|
|
|
|
var actualCount = mocker.Resolve<EpisodeProvider>().GetEpisodeBySeries(seriesId);
|
2010-10-17 17:22:48 +00:00
|
|
|
|
//Assert
|
2011-04-07 03:34:48 +00:00
|
|
|
|
mocker.GetMock<TvDbProvider>().VerifyAll();
|
|
|
|
|
Assert.Count(episodeCount, actualCount);
|
|
|
|
|
Console.WriteLine("Duration: " + sw.Elapsed);
|
2010-10-17 17:22:48 +00:00
|
|
|
|
}
|
2011-02-17 17:45:02 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsNeededTrue()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var season = new Mock<ISeasonProvider>();
|
|
|
|
|
var series = new Mock<ISeriesProvider>();
|
2011-04-08 04:03:46 +00:00
|
|
|
|
//var history = new Mock<IHistoryProvider>();
|
|
|
|
|
//var quality = new Mock<IQualityProvider>();
|
2011-02-17 17:45:02 +00:00
|
|
|
|
var repo = new Mock<IRepository>();
|
|
|
|
|
|
|
|
|
|
var epInDb = new Episode
|
|
|
|
|
{
|
|
|
|
|
AirDate = DateTime.Today,
|
|
|
|
|
EpisodeId = 55555,
|
|
|
|
|
EpisodeNumber = 5,
|
|
|
|
|
Language = "en",
|
|
|
|
|
SeasonId = 4444,
|
|
|
|
|
SeasonNumber = 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
season.Setup(s => s.IsIgnored(12345, 1)).Returns(false);
|
|
|
|
|
series.Setup(s => s.QualityWanted(12345, QualityTypes.TV)).Returns(true);
|
|
|
|
|
repo.Setup(s => s.Single<Episode>(c => c.SeriesId == 12345 && c.SeasonNumber == 1 && c.EpisodeNumber == 5)).
|
|
|
|
|
Returns(epInDb);
|
|
|
|
|
|
|
|
|
|
//repo.Setup(s => s.All<EpisodeFile>()).Returns();
|
|
|
|
|
//repo.All<EpisodeFile>().Where(c => c.EpisodeId == episode.EpisodeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
}
|
2010-10-05 06:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|