2010-10-05 09:21:18 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2010-10-17 20:22:48 +03:00
|
|
|
using System.Diagnostics;
|
2011-02-17 19:45:02 +02:00
|
|
|
using System.Linq;
|
2010-10-05 09:21:18 +03:00
|
|
|
using System.Text;
|
2011-04-07 06:34:48 +03:00
|
|
|
using AutoMoq;
|
2010-10-17 20:22:48 +03:00
|
|
|
using FizzWare.NBuilder;
|
2010-10-05 09:21:18 +03:00
|
|
|
using Gallio.Framework;
|
|
|
|
using MbUnit.Framework;
|
|
|
|
using MbUnit.Framework.ContractVerifiers;
|
2010-10-17 20:22:48 +03:00
|
|
|
using Moq;
|
|
|
|
using Ninject;
|
|
|
|
using Ninject.Moq;
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-02-17 19:45:02 +02:00
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-10-17 20:22:48 +03:00
|
|
|
using SubSonic.Repository;
|
|
|
|
using TvdbLib.Data;
|
|
|
|
using SubSonic.Extensions;
|
2010-10-05 09:21:18 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2010-10-08 01:17:24 +03:00
|
|
|
// ReSharper disable InconsistentNaming
|
2010-10-05 09:21:18 +03:00
|
|
|
public class EpisodeProviderTest
|
|
|
|
{
|
2010-10-17 20:22:48 +03:00
|
|
|
[Test]
|
2010-10-21 04:49:23 +03:00
|
|
|
public void RefreshEpisodeInfo()
|
2010-10-17 20:22:48 +03:00
|
|
|
{
|
|
|
|
//Arrange
|
2011-04-07 06:34:48 +03:00
|
|
|
const int seriesId = 71663;
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
2010-10-17 20:22:48 +03: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 09:21:18 +03:00
|
|
|
|
2011-04-07 06:34:48 +03:00
|
|
|
var mocker = new AutoMoqer();
|
2010-10-17 20:22:48 +03:00
|
|
|
|
2011-04-07 06:34:48 +03:00
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
2010-10-17 20:22:48 +03:00
|
|
|
|
2011-04-07 06:34:48 +03:00
|
|
|
mocker.GetMock<TvDbProvider>()
|
|
|
|
.Setup(c => c.GetSeries(seriesId, true))
|
|
|
|
.Returns(fakeEpisodes).Verifiable();
|
|
|
|
|
|
|
|
//mocker.GetMock<IRepository>().SetReturnsDefault();
|
2010-10-17 20:22:48 +03:00
|
|
|
|
|
|
|
|
2011-04-07 06:34:48 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var sw = Stopwatch.StartNew();
|
|
|
|
mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(seriesId);
|
|
|
|
var actualCount = mocker.Resolve<EpisodeProvider>().GetEpisodeBySeries(seriesId);
|
2010-10-17 20:22:48 +03:00
|
|
|
//Assert
|
2011-04-07 06:34:48 +03:00
|
|
|
mocker.GetMock<TvDbProvider>().VerifyAll();
|
|
|
|
Assert.Count(episodeCount, actualCount);
|
|
|
|
Console.WriteLine("Duration: " + sw.Elapsed);
|
2010-10-17 20:22:48 +03:00
|
|
|
}
|
2011-02-17 19:45:02 +02:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void IsNeededTrue()
|
|
|
|
{
|
|
|
|
//Setup
|
2011-04-10 04:34:36 +03:00
|
|
|
var season = new Mock<SeasonProvider>();
|
2011-04-09 02:55:23 +03:00
|
|
|
var series = new Mock<SeriesProvider>();
|
2011-04-08 07:03:46 +03:00
|
|
|
//var history = new Mock<IHistoryProvider>();
|
|
|
|
//var quality = new Mock<IQualityProvider>();
|
2011-02-17 19:45:02 +02: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 09:21:18 +03:00
|
|
|
}
|
|
|
|
}
|