More tests

This commit is contained in:
kay.one 2011-04-22 12:16:52 -07:00
parent ccbbad54ce
commit 23f6cc3901
9 changed files with 203 additions and 50 deletions

View File

@ -53,11 +53,24 @@ namespace NzbDrone.Core.Test
//Assert //Assert
Assert.Count(1, indexers); Assert.Count(1, indexers);
} }
[Test]
public void unmapped_series_shouldnt_call_any_providers()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<SeriesProvider>()
.Setup(c => c.FindSeries(It.IsAny<String>()))
.Returns<Series>(null);
var indexer = mocker.Resolve<MockIndexerProvider>();
indexer.ProcessItem(new SyndicationItem { Title = new TextSyndicationContent("Adventure.Inc.S01E18.DVDRip.XviD-OSiTV") });
}
} }
public class MockIndexerProvider : IndexerProviderBase public class MockIndexerProvider : IndexerProviderBase
{ {
public MockIndexerProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider) public MockIndexerProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider)
: base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider)
{ {
} }

View File

@ -2,9 +2,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using FizzWare.NBuilder;
using Moq; using Moq;
using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using SubSonic.DataProviders; using SubSonic.DataProviders;
using SubSonic.Repository; using SubSonic.Repository;
@ -17,7 +19,7 @@ namespace NzbDrone.Core.Test
{ {
public static string[] StandardSeries public static string[] StandardSeries
{ {
get { return new[] {"c:\\tv\\the simpsons", "c:\\tv\\family guy", "c:\\tv\\southpark", "c:\\tv\\24"}; } get { return new[] { "c:\\tv\\the simpsons", "c:\\tv\\family guy", "c:\\tv\\southpark", "c:\\tv\\24" }; }
} }
public static ConfigProvider StandardConfig public static ConfigProvider StandardConfig
@ -71,5 +73,14 @@ namespace NzbDrone.Core.Test
return mock.Object; return mock.Object;
} }
public static Series GetFakeSeries(int id, string title)
{
return Builder<Series>.CreateNew()
.With(c => c.SeriesId = id)
.With(c => c.Title = title)
.With(c => c.CleanTitle = Parser.NormalizeTitle(title))
.Build();
}
} }
} }

View File

@ -16,31 +16,41 @@ namespace NzbDrone.Core.Test
*/ */
[Test] [Test]
[Timeout(1)] [Row("Sonny.With.a.Chance.S02E15", "Sonny.With.a.Chance", 2, 15)]
[Row("Sonny.With.a.Chance.S02E15", 2, 15)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", "WEEDS", 3, 1)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, 1)] [Row("Two.and.a.Half.Me.103.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Me", 1, 3)]
[Row("Two.and.a.Half.Me.103.720p.HDTV.X264-DIMENSION", 1, 3)] [Row("Two.and.a.Half.Me.113.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Me", 1, 13)]
[Row("Two.and.a.Half.Me.113.720p.HDTV.X264-DIMENSION", 1, 13)] [Row("Two.and.a.Half.Me.1013.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Me", 10, 13)]
[Row("Two.and.a.Half.Me.1013.720p.HDTV.X264-DIMENSION", 10, 13)] [Row("Chuck.4x05.HDTV.XviD-LOL", "Chuck", 4, 5)]
[Row("Chuck.4x05.HDTV.XviD-LOL", 4, 5)] [Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", "The.Girls.Next.Door", 3, 6)]
[Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", 3, 6)] [Row("Degrassi.S10E27.WS.DSR.XviD-2HD", "Degrassi", 10, 27)]
[Row("Degrassi.S10E27.WS.DSR.XviD-2HD", 10, 27)] [Row("Parenthood.2010.S02E14.HDTV.XviD-LOL", "Parenthood", 2, 14)]
[Row("Hawaii Five 0 S01E19 720p WEB DL DD5 1 H 264 NT", "Hawaii Five", 1, 19)]
[Row("The Event S01E14 A Message Back 720p WEB DL DD5 1 H264 SURFER", "The Event", 1, 14)]
[Row("Adam Hills In Gordon St Tonight S01E07 WS PDTV XviD FUtV", "Adam Hills In Gordon St Tonight", 1, 7)]
[Row("Adam Hills In Gordon St Tonight S01E07 WS PDTV XviD FUtV", "Adam Hills In Gordon St Tonight", 1, 7)]
[Row("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", "Adventure.Inc", 3, 19)]
//[Row("The.Kennedys.Part.2.DSR.XviD-SYS", 1, 2)]
public void episode_parse(string postTitle, string title, int season, int episode)
{
var result = Parser.ParseEpisodeInfo(postTitle);
Assert.AreEqual(season, result.SeasonNumber);
Assert.AreEqual(episode, result.Episodes[0]);
Assert.AreEqual(Parser.NormalizeTitle(title), result.CleanTitle);
}
[Test]
[Row(@"z:\tv shows\battlestar galactica (2003)\Season 3\S03E05 - Collaborators.mkv", 3, 5)] [Row(@"z:\tv shows\battlestar galactica (2003)\Season 3\S03E05 - Collaborators.mkv", 3, 5)]
[Row(@"z:\tv shows\modern marvels\Season 16\S16E03 - The Potato.mkv", 16, 3)] [Row(@"z:\tv shows\modern marvels\Season 16\S16E03 - The Potato.mkv", 16, 3)]
[Row(@"z:\tv shows\robot chicken\Specials\S00E16 - Dear Consumer - SD TV.avi", 0, 16)] [Row(@"z:\tv shows\robot chicken\Specials\S00E16 - Dear Consumer - SD TV.avi", 0, 16)]
[Row(@"Parenthood.2010.S02E14.HDTV.XviD-LOL", 2, 14)] public void file_path_parse(string path, int season, int episode)
[Row(@"Hawaii Five 0 S01E19 720p WEB DL DD5 1 H 264 NT", 1, 19)]
[Row(@"The Event S01E14 A Message Back 720p WEB DL DD5 1 H264 SURFER", 1, 14)]
[Row(@"Adam Hills In Gordon St Tonight S01E07 WS PDTV XviD FUtV", 1, 7)]
[Row(@"Adam Hills In Gordon St Tonight S01E07 WS PDTV XviD FUtV", 1, 7)]
//[Row("The.Kennedys.Part.2.DSR.XviD-SYS", 1, 2)]
public void episode_parse(string path, int season, int episode)
{ {
var result = Parser.ParseEpisodeInfo(path); var result = Parser.ParseEpisodeInfo(path);
Assert.AreEqual(season, result.SeasonNumber); Assert.AreEqual(season, result.SeasonNumber);
Assert.AreEqual(episode, result.Episodes[0]); Assert.AreEqual(episode, result.Episodes[0]);
} }
[Test] [Test]
[Timeout(1)] [Timeout(1)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.BDRip)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.BDRip)]
@ -62,37 +72,40 @@ namespace NzbDrone.Core.Test
[Row("Chuck - S01E03 - Come Fly With Me - 1080p BluRay.mkv", QualityTypes.Bluray1080)] [Row("Chuck - S01E03 - Come Fly With Me - 1080p BluRay.mkv", QualityTypes.Bluray1080)]
[Row("Chuck - S11E06 - D-Yikes! - 720p WEB-DL.mkv", QualityTypes.WEBDL)] [Row("Chuck - S11E06 - D-Yikes! - 720p WEB-DL.mkv", QualityTypes.WEBDL)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.BDRip)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.BDRip)]
public void quality_parse(string path, object quality) public void quality_parse(string postTitle, object quality)
{ {
var result = Parser.ParseEpisodeInfo(path).Quality; var result = Parser.ParseEpisodeInfo(postTitle).Quality;
Assert.AreEqual(quality, result); Assert.AreEqual(quality, result);
} }
[Test] [Test]
[Timeout(1)] [Timeout(1)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, new[] { 1, 2, 3, 4, 5, 6 })] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", "WEEDS", 3, new[] { 1, 2, 3, 4, 5, 6 })]
[Row("Two.and.a.Half.Men.103.104.720p.HDTV.X264-DIMENSION", 1, new[] { 3, 4 })] [Row("Two.and.a.Half.Men.103.104.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Men", 1, new[] { 3, 4 })]
[Row("Weeds.S03E01.S03E02.720p.HDTV.X264-DIMENSION", 3, new[] { 1, 2 })] [Row("Weeds.S03E01.S03E02.720p.HDTV.X264-DIMENSION", "Weeds", 3, new[] { 1, 2 })]
[Row("The Borgias S01e01 e02 ShoHD On Demand 1080i DD5 1 ALANiS", 1, new[] { 1, 2 })] [Row("The Borgias S01e01 e02 ShoHD On Demand 1080i DD5 1 ALANiS", "The Borgias", 1, new[] { 1, 2 })]
[Row("Big Time Rush 1x01 to 10 480i DD2 0 Sianto", 1, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })] [Row("Big Time Rush 1x01 to 10 480i DD2 0 Sianto", "Big Time Rush", 1, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })]
[Row("White.Collar.2x04.2x05.720p.BluRay-FUTV", 2, new[] { 4, 5 })] [Row("White.Collar.2x04.2x05.720p.BluRay-FUTV", "White.Collar", 2, new[] { 4, 5 })]
//[Row("The.Kennedys.Part.1.and.Part.2.DSR.XviD-SYS", 1, new[] { 1, 2 })] //[Row("The.Kennedys.Part.1.and.Part.2.DSR.XviD-SYS", 1, new[] { 1, 2 })]
public void episode_multipart_parse(string path, int season, int[] episodes) public void episode_multipart_parse(string postTitle, string title, int season, int[] episodes)
{ {
var result = Parser.ParseEpisodeInfo(path); var result = Parser.ParseEpisodeInfo(postTitle);
Assert.AreEqual(season, result.SeasonNumber); Assert.AreEqual(season, result.SeasonNumber);
Assert.Count(episodes.Length, result.Episodes); Assert.Count(episodes.Length, result.Episodes);
Assert.AreElementsEqualIgnoringOrder(episodes, result.Episodes); Assert.AreElementsEqualIgnoringOrder(episodes, result.Episodes);
Assert.AreEqual(Parser.NormalizeTitle(title), result.CleanTitle);
} }
[Test] [Test]
[Row("Conan 2011 04 18 Emma Roberts HDTV XviD BFF", 2011, 04, 18)] [Row("Conan 2011 04 18 Emma Roberts HDTV XviD BFF", "Conan", 2011, 04, 18)]
[Row("The Tonight Show With Jay Leno 2011 04 15 1080i HDTV DD5 1 MPEG2 TrollHD", 2011, 04, 15)] [Row("The Tonight Show With Jay Leno 2011 04 15 1080i HDTV DD5 1 MPEG2 TrollHD", "The Tonight Show With Jay Leno", 2011, 04, 15)]
public void episode_daily_parse(string path, int year, int month, int day) [Row("The.Daily.Show.2010.10.11.Johnny.Knoxville.iTouch-MW", "The.Daily.Show", 2010, 10, 11)]
[Row("The Daily Show - 2011-04-12 - Gov. Deval Patrick", "The.Daily.Show", 2011, 04, 12)]
public void episode_daily_parse(string postTitle, string title, int year, int month, int day)
{ {
var result = Parser.ParseEpisodeInfo(path); var result = Parser.ParseEpisodeInfo(postTitle);
var airDate = new DateTime(year, month, day); var airDate = new DateTime(year, month, day);
Assert.AreEqual(Parser.NormalizeTitle(title), result.CleanTitle);
Assert.AreEqual(airDate, result.AirDate); Assert.AreEqual(airDate, result.AirDate);
} }
@ -107,5 +120,66 @@ namespace NzbDrone.Core.Test
var result = Parser.NormalizePath(dirty); var result = Parser.NormalizePath(dirty);
Assert.AreEqual(clean, result); Assert.AreEqual(clean, result);
} }
[Test]
[Row("CaPitAl", "capital")]
[Row("peri.od", "period")]
[Row("this.^&%^**$%@#$!That", "thisthat")]
public void Normalize_Title(string dirty, string clean)
{
var result = Parser.NormalizeTitle(dirty);
Assert.AreEqual(clean, result);
}
[Test]
[Row("the")]
[Row("And")]
[Row("Or")]
public void Normalize_removed_common_words(string word)
{
var dirtyFormat = new[]
{
"word.{0}.word",
"word {0} word",
"word-{0}-word",
"{0}.word.word",
"{0}-word-word",
"{0} word word",
"word.word.{0}",
"word-word-{0}",
"word-word {0}",
};
foreach (var s in dirtyFormat)
{
var dirty = String.Format(s, word);
Assert.AreEqual("wordword", Parser.NormalizeTitle(dirty));
}
}
[Test]
[Row("the")]
[Row("And")]
[Row("Or")]
public void Normalize_not_removed_common_words_in_the_middle(string word)
{
var dirtyFormat = new[]
{
"word.{0}word",
"word {0}word",
"word-{0}word",
"word{0}.word",
"word{0}-word",
"word{0}-word",
};
foreach (var s in dirtyFormat)
{
var dirty = String.Format(s, word);
Assert.AreEqual("word" + word.ToLower() + "word", Parser.NormalizeTitle(dirty));
}
}
} }
} }

View File

@ -80,12 +80,62 @@ namespace NzbDrone.Core.Test
Assert.AreEqual(qualityProfileId, series.First().QualityProfileId); Assert.AreEqual(qualityProfileId, series.First().QualityProfileId);
} }
[Test]
public void find_series_empty_repo()
{
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
//Act
var seriesProvider = mocker.Resolve<SeriesProvider>();
var series = seriesProvider.FindSeries("My Title");
//Assert
Assert.IsNull(series);
}
[Test] [Test]
[Row(new object[] {"That's Life - 2x03 -The Devil and Miss DeLucca", "That's Life"})] public void find_series_empty_match()
[Row(new object[] {"Van.Duin.Op.Zn.Best.S02E05.DUTCH.WS.PDTV.XViD-DiFFERENT", "Van Duin Op Zn Best"})] {
[Row(new object[] {"Dollhouse.S02E06.The.Left.Hand.720p.BluRay.x264-SiNNERS", "Dollhouse"})] var mocker = new AutoMoqer();
[Row(new object[] {"Heroes.S02.COMPLETE.German.PROPER.DVDRip.XviD-Prim3time", "Heroes"})] var emptyRepository = MockLib.GetEmptyRepository();
mocker.SetConstant(emptyRepository);
emptyRepository.Add<Series>(MockLib.GetFakeSeries(1, "MyTitle"));
//Act
var seriesProvider = mocker.Resolve<SeriesProvider>();
var series = seriesProvider.FindSeries("WrongTitle");
//Assert
Assert.IsNull(series);
}
[Test]
[Row("The Test", "Test")]
[Row("The Test Title", "test title")]
public void find_series_match(string title, string searchTitle)
{
var mocker = new AutoMoqer();
var emptyRepository = MockLib.GetEmptyRepository();
mocker.SetConstant(emptyRepository);
emptyRepository.Add<Series>(MockLib.GetFakeSeries(1, title));
//Act
var seriesProvider = mocker.Resolve<SeriesProvider>();
var series = seriesProvider.FindSeries(searchTitle);
//Assert
Assert.IsNotNull(series);
Assert.AreEqual(title, series.Title);
}
[Test]
[Row(new object[] { "That's Life - 2x03 -The Devil and Miss DeLucca", "That's Life" })]
[Row(new object[] { "Van.Duin.Op.Zn.Best.S02E05.DUTCH.WS.PDTV.XViD-DiFFERENT", "Van Duin Op Zn Best" })]
[Row(new object[] { "Dollhouse.S02E06.The.Left.Hand.720p.BluRay.x264-SiNNERS", "Dollhouse" })]
[Row(new object[] { "Heroes.S02.COMPLETE.German.PROPER.DVDRip.XviD-Prim3time", "Heroes" })]
[Ignore("should be updated to validate agains a remote episode instance rather than just the title string")] [Ignore("should be updated to validate agains a remote episode instance rather than just the title string")]
public void Test_Parse_Success(string postTitle, string title) public void Test_Parse_Success(string postTitle, string title)
{ {
@ -129,7 +179,7 @@ namespace NzbDrone.Core.Test
public void QualityWanted(int seriesId, QualityTypes qualityTypes, Boolean result) public void QualityWanted(int seriesId, QualityTypes qualityTypes, Boolean result)
{ {
var quality = Builder<QualityProfile>.CreateNew() var quality = Builder<QualityProfile>.CreateNew()
.With(q => q.Allowed = new List<QualityTypes> {QualityTypes.BDRip, QualityTypes.DVD, QualityTypes.TV}) .With(q => q.Allowed = new List<QualityTypes> { QualityTypes.BDRip, QualityTypes.DVD, QualityTypes.TV })
.With(q => q.Cutoff = QualityTypes.DVD) .With(q => q.Cutoff = QualityTypes.DVD)
.Build(); .Build();

View File

@ -6,7 +6,7 @@ namespace NzbDrone.Core.Model
{ {
public class EpisodeParseResult public class EpisodeParseResult
{ {
internal string SeriesTitle { get; set; } internal string CleanTitle { get; set; }
public int SeriesId { get; set; } public int SeriesId { get; set; }
internal int SeasonNumber { get; set; } internal int SeasonNumber { get; set; }
@ -24,9 +24,9 @@ namespace NzbDrone.Core.Model
public override string ToString() public override string ToString()
{ {
if (Episodes == null) if (Episodes == null)
return string.Format("Series:{0} Air Date:{1}", SeriesTitle, AirDate.Date); return string.Format("Series:{0} Air Date:{1}", CleanTitle, AirDate.Date);
return string.Format("Series:{0} Season:{1} Episode:{2}", SeriesTitle, SeasonNumber, return string.Format("Series:{0} Season:{1} Episode:{2}", CleanTitle, SeasonNumber,
String.Join(",", Episodes)); String.Join(",", Episodes));
} }

View File

@ -76,7 +76,7 @@ namespace NzbDrone.Core
parsedEpisode = new EpisodeParseResult parsedEpisode = new EpisodeParseResult
{ {
Proper = title.ToLower().Contains("proper"), Proper = title.ToLower().Contains("proper"),
SeriesTitle = seriesName, CleanTitle = seriesName,
SeasonNumber = season, SeasonNumber = season,
Year = year, Year = year,
Episodes = new List<int>() Episodes = new List<int>()
@ -106,7 +106,7 @@ namespace NzbDrone.Core
parsedEpisode = new EpisodeParseResult parsedEpisode = new EpisodeParseResult
{ {
Proper = title.ToLower().Contains("proper"), Proper = title.ToLower().Contains("proper"),
SeriesTitle = seriesName, CleanTitle = seriesName,
Year = year, Year = year,
AirDate = new DateTime(airyear, airmonth, airday) AirDate = new DateTime(airyear, airmonth, airday)
}; };

View File

@ -80,17 +80,17 @@ namespace NzbDrone.Core.Providers.Indexer
_logger.Info("Finished processing feeds from " + Settings.Name); _logger.Info("Finished processing feeds from " + Settings.Name);
} }
private void ProcessItem(SyndicationItem feedItem) internal void ProcessItem(SyndicationItem feedItem)
{ {
_logger.Info("Processing RSS feed item " + feedItem.Title.Text); _logger.Info("Processing RSS feed item " + feedItem.Title.Text);
var parseResult = ParseFeed(feedItem); var parseResult = ParseFeed(feedItem);
if (parseResult != null) if (parseResult != null && parseResult.SeriesId != 0)
{ {
if (!_seriesProvider.IsMonitored(parseResult.SeriesId)) if (!_seriesProvider.IsMonitored(parseResult.SeriesId))
{ {
_logger.Debug("{0} is present in the DB but not tracked. skipping.", parseResult.SeriesTitle); _logger.Debug("{0} is present in the DB but not tracked. skipping.", parseResult.CleanTitle);
return; return;
} }
@ -147,16 +147,16 @@ namespace NzbDrone.Core.Providers.Indexer
var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.Text); var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.Text);
if (episodeParseResult == null) return CustomParser(item, null); if (episodeParseResult == null) return CustomParser(item, null);
var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.SeriesTitle); var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);
if (seriesInfo != null) if (seriesInfo != null)
{ {
episodeParseResult.SeriesId = seriesInfo.SeriesId; episodeParseResult.SeriesId = seriesInfo.SeriesId;
episodeParseResult.SeriesTitle = seriesInfo.Title; episodeParseResult.CleanTitle = seriesInfo.Title;
return CustomParser(item, episodeParseResult); return CustomParser(item, episodeParseResult);
} }
_logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.SeriesTitle); _logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.CleanTitle);
return CustomParser(item, episodeParseResult); return CustomParser(item, episodeParseResult);
} }

View File

@ -112,7 +112,8 @@ namespace NzbDrone.Core.Providers
public virtual Series FindSeries(string title) public virtual Series FindSeries(string title)
{ {
return _sonioRepo.Single<Series>(s => s.CleanTitle == Parser.NormalizeTitle(title)); var normalizeTitle = Parser.NormalizeTitle(title);
return _sonioRepo.Single<Series>(s => s.CleanTitle == normalizeTitle);
} }
public virtual void UpdateSeries(Series series) public virtual void UpdateSeries(Series series)

View File

@ -46,6 +46,10 @@ namespace NzbDrone
AppDomainException(e); AppDomainException(e);
} }
while (true)
{
Console.ReadLine();
}
} }
private static void Attach() private static void Attach()