2010-10-05 09:21:18 +03:00
|
|
|
using System;
|
2011-04-21 04:26:13 +03:00
|
|
|
using System.Linq;
|
2010-10-05 09:21:18 +03:00
|
|
|
using System.Collections.Generic;
|
2010-10-17 20:22:48 +03:00
|
|
|
using System.Diagnostics;
|
2011-04-21 04:26:13 +03:00
|
|
|
using System.Linq.Expressions;
|
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 MbUnit.Framework;
|
2010-10-17 20:22:48 +03:00
|
|
|
using Moq;
|
2011-04-21 04:26:13 +03:00
|
|
|
using NzbDrone.Core.Model;
|
2010-10-17 20:22:48 +03:00
|
|
|
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;
|
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 =
|
2011-04-10 05:44:01 +03:00
|
|
|
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>()
|
2011-04-10 05:44:01 +03:00
|
|
|
.Setup(c => c.GetSeries(seriesId, true))
|
|
|
|
.Returns(fakeEpisodes).Verifiable();
|
2011-04-07 06:34:48 +03:00
|
|
|
|
|
|
|
//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]
|
2011-04-21 04:26:13 +03:00
|
|
|
|
|
|
|
//Should Download
|
|
|
|
[Row(QualityTypes.TV, true, QualityTypes.TV, false, true)]
|
|
|
|
[Row(QualityTypes.DVD, true, QualityTypes.TV, true, true)]
|
|
|
|
[Row(QualityTypes.DVD, true, QualityTypes.TV, true, true)]
|
|
|
|
//Should Skip
|
|
|
|
[Row(QualityTypes.Bluray720, true, QualityTypes.Bluray1080, false, false)]
|
|
|
|
[Row(QualityTypes.TV, true, QualityTypes.HDTV, true, false)]
|
|
|
|
public void Is_Needed_Tv_Dvd_BluRay_BluRay720_Is_Cutoff(QualityTypes reportQuality, Boolean isReportProper, QualityTypes fileQuality, Boolean isFileProper, bool excpected)
|
2011-02-17 19:45:02 +02:00
|
|
|
{
|
|
|
|
//Setup
|
2011-04-21 04:26:13 +03:00
|
|
|
var parseResult = new EpisodeParseResult
|
|
|
|
{
|
|
|
|
SeriesId = 12,
|
|
|
|
SeasonNumber = 2,
|
|
|
|
Episodes = new List<int> { 3 },
|
|
|
|
Quality = reportQuality,
|
|
|
|
Proper = isReportProper
|
|
|
|
};
|
|
|
|
|
|
|
|
var epFile = new EpisodeFile()
|
|
|
|
{
|
|
|
|
Proper = isFileProper,
|
|
|
|
Quality = fileQuality
|
|
|
|
};
|
|
|
|
|
|
|
|
var episodeInfo = new Episode
|
|
|
|
{
|
|
|
|
SeriesId = 12,
|
|
|
|
SeasonNumber = 2,
|
|
|
|
EpisodeNumber = 3,
|
|
|
|
Series = new Series() { QualityProfileId = 1 },
|
|
|
|
EpisodeFile = epFile
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var seriesQualityProfile = new QualityProfile()
|
|
|
|
{
|
|
|
|
Allowed = new List<QualityTypes> { QualityTypes.TV, QualityTypes.DVD, QualityTypes.Bluray720, QualityTypes.Bluray1080 },
|
|
|
|
Cutoff = QualityTypes.Bluray720,
|
|
|
|
Name = "TV/DVD",
|
|
|
|
};
|
2011-02-17 19:45:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-21 04:26:13 +03:00
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
.Setup(r => r.Single(It.IsAny<Expression<Func<Episode, Boolean>>>()))
|
|
|
|
.Returns(episodeInfo);
|
|
|
|
|
|
|
|
mocker.GetMock<QualityProvider>()
|
|
|
|
.Setup(q => q.Find(1))
|
|
|
|
.Returns(seriesQualityProfile);
|
|
|
|
|
|
|
|
var result = mocker.Resolve<EpisodeProvider>().IsNeeded(parseResult);
|
|
|
|
|
|
|
|
Assert.AreEqual(excpected, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Missing_episode_should_be_added()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var parseResult1 = new EpisodeParseResult
|
|
|
|
{
|
|
|
|
SeriesId = 12,
|
|
|
|
SeasonNumber = 2,
|
|
|
|
Episodes = new List<int> { 3 },
|
|
|
|
Quality = QualityTypes.DVD
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var parseResult2 = new EpisodeParseResult
|
|
|
|
{
|
|
|
|
SeriesId = 12,
|
|
|
|
SeasonNumber = 3,
|
|
|
|
Episodes = new List<int> { 3 },
|
|
|
|
Quality = QualityTypes.DVD
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
|
|
|
|
|
|
|
var episodeProvider = mocker.Resolve<EpisodeProvider>();
|
|
|
|
var result1 = episodeProvider.IsNeeded(parseResult1);
|
|
|
|
var result2 = episodeProvider.IsNeeded(parseResult2);
|
|
|
|
var episodes = episodeProvider.GetEpisodeBySeries(12);
|
|
|
|
Assert.IsTrue(result1);
|
|
|
|
Assert.IsTrue(result2);
|
|
|
|
Assert.IsNotEmpty(episodes);
|
|
|
|
Assert.Count(2, episodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Row(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, false, "My Series Name - 1x2 - My Episode Title DVD")]
|
|
|
|
[Row(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, true, "My Series Name - 1x2 - My Episode Title DVD [Proper]")]
|
|
|
|
[Row(1, new[] { 2 }, "", QualityTypes.DVD, true, "My Series Name - 1x2 - DVD [Proper]")]
|
|
|
|
[Row(1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV, false, "My Series Name - 1x2-1x4 - My Episode Title HDTV")]
|
|
|
|
[Row(1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - My Episode Title HDTV [Proper]")]
|
|
|
|
[Row(1, new[] { 2, 4 }, "", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - HDTV [Proper]")]
|
|
|
|
public void sab_title(int seasons, int[] episodes, string title, QualityTypes quality, bool proper, string excpected)
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
var fakeSeries = new Series()
|
|
|
|
{
|
|
|
|
SeriesId = 12,
|
|
|
|
Path = "C:\\TV Shows\\My Series Name"
|
|
|
|
};
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.GetMock<SeriesProvider>(MockBehavior.Strict)
|
|
|
|
.Setup(c => c.GetSeries(12))
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
var parsResult = new EpisodeParseResult()
|
|
|
|
{
|
|
|
|
SeriesId = 12,
|
|
|
|
AirDate = DateTime.Now,
|
|
|
|
Episodes = episodes.ToList(),
|
|
|
|
Proper = proper,
|
|
|
|
Quality = quality,
|
|
|
|
SeasonNumber = seasons,
|
|
|
|
EpisodeTitle = title
|
|
|
|
};
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var actual = mocker.Resolve<EpisodeProvider>().GetSabTitle(parsResult);
|
2011-02-17 19:45:02 +02:00
|
|
|
|
|
|
|
//Assert
|
2011-04-21 04:26:13 +03:00
|
|
|
Assert.AreEqual(excpected, actual);
|
2011-02-17 19:45:02 +02:00
|
|
|
}
|
2011-04-20 10:44:13 +03:00
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-04-21 04:26:13 +03:00
|
|
|
[Explicit]
|
2011-04-20 10:44:13 +03:00
|
|
|
public void Add_daily_show_episodes()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
|
|
|
mocker.Resolve<TvDbProvider>();
|
|
|
|
const int tvDbSeriesId = 71256;
|
|
|
|
//act
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
|
|
|
seriesProvider.AddSeries("c:\\test\\", tvDbSeriesId, 0);
|
|
|
|
var episodeProvider = mocker.Resolve<EpisodeProvider>();
|
|
|
|
episodeProvider.RefreshEpisodeInfo(tvDbSeriesId);
|
|
|
|
|
|
|
|
//assert
|
|
|
|
var episodes = episodeProvider.GetEpisodeBySeries(tvDbSeriesId);
|
|
|
|
Assert.IsNotEmpty(episodes);
|
|
|
|
}
|
2010-10-05 09:21:18 +03:00
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|