2010-10-05 08:21:18 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2010-10-17 19:22:48 +02:00
|
|
|
|
using System.Diagnostics;
|
2011-02-17 18:45:02 +01:00
|
|
|
|
using System.Linq;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
using System.Text;
|
2010-10-17 19:22:48 +02:00
|
|
|
|
using FizzWare.NBuilder;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
using Gallio.Framework;
|
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using MbUnit.Framework.ContractVerifiers;
|
2010-10-17 19:22:48 +02:00
|
|
|
|
using Moq;
|
|
|
|
|
using Ninject;
|
|
|
|
|
using Ninject.Moq;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-02-17 18:45:02 +01:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-10-17 19:22:48 +02:00
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
using TvdbLib.Data;
|
|
|
|
|
using SubSonic.Extensions;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2010-10-08 00:17:24 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2010-10-05 08:21:18 +02:00
|
|
|
|
public class EpisodeProviderTest
|
|
|
|
|
{
|
2010-10-17 19:22:48 +02:00
|
|
|
|
[Test]
|
2010-10-21 03:49:23 +02:00
|
|
|
|
public void RefreshEpisodeInfo()
|
2010-10-17 19:22:48 +02:00
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
int seriesId = 71663;
|
2010-10-21 03:49:23 +02:00
|
|
|
|
int episodeCount = 10;
|
2010-10-17 19:22:48 +02: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 08:21:18 +02:00
|
|
|
|
|
2010-10-17 19:22:48 +02:00
|
|
|
|
var tvdbMock = new Mock<ITvDbProvider>();
|
|
|
|
|
tvdbMock.Setup(c => c.GetSeries(seriesId, true)).Returns(fakeEpisodes).Verifiable();
|
|
|
|
|
|
|
|
|
|
var kernel = new MockingKernel();
|
|
|
|
|
kernel.Bind<IRepository>().ToConstant(MockLib.GetEmptyRepository(false)).InSingletonScope();
|
|
|
|
|
kernel.Bind<ITvDbProvider>().ToConstant(tvdbMock.Object);
|
|
|
|
|
kernel.Bind<IEpisodeProvider>().To<EpisodeProvider>().InSingletonScope();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var sw = Stopwatch.StartNew();
|
|
|
|
|
kernel.Get<IEpisodeProvider>().RefreshEpisodeInfo(seriesId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
tvdbMock.VerifyAll();
|
|
|
|
|
Assert.Count(episodeCount, kernel.Get<IEpisodeProvider>().GetEpisodeBySeries(seriesId));
|
|
|
|
|
Console.WriteLine("Duration: " + sw.Elapsed.ToString());
|
|
|
|
|
}
|
2011-02-17 18:45:02 +01:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsNeededTrue()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
var season = new Mock<ISeasonProvider>();
|
|
|
|
|
var series = new Mock<ISeriesProvider>();
|
|
|
|
|
var history = new Mock<IHistoryProvider>();
|
|
|
|
|
var quality = new Mock<IQualityProvider>();
|
|
|
|
|
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 08:21:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|