more tests and bug fixes

This commit is contained in:
kay.one 2011-04-22 13:14:02 -07:00
parent 282870cd80
commit e074164a47
7 changed files with 86 additions and 13 deletions

View File

@ -116,6 +116,35 @@ namespace NzbDrone.Core.Test
Assert.AreEqual(excpected, result);
}
[Test]
public void get_episode_by_parse_result()
{
var mocker = new AutoMoqer();
var repo = MockLib.GetEmptyRepository();
var fakeEpisodes = MockLib.GetFakeEpisodes(2);
repo.AddMany(fakeEpisodes);
mocker.SetConstant(repo);
var targetEpisode = fakeEpisodes[4];
var parseResult1 = new EpisodeParseResult
{
SeriesId = targetEpisode.SeriesId,
SeasonNumber = targetEpisode.SeasonNumber,
Episodes = new List<int> { targetEpisode.EpisodeNumber },
Quality = QualityTypes.DVD
};
var result = mocker.Resolve<EpisodeProvider>().GetEpisodeByParseResult(parseResult1);
Assert.Count(1, result);
Assert.AreEqual(targetEpisode.EpisodeId, result.First().EpisodeId);
Assert.AreEqual(targetEpisode.EpisodeNumber, result.First().EpisodeNumber);
Assert.AreEqual(targetEpisode.SeasonNumber, result.First().SeasonNumber);
Assert.AreEqual(targetEpisode.SeriesId, result.First().SeriesId);
}
[Test]
public void Missing_episode_should_be_added()
{

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMoq;
using MbUnit.Framework;
using Moq;
using NzbDrone.Core.Providers;
@ -63,6 +64,30 @@ namespace NzbDrone.Core.Test
Assert.AreEqual(result.Count(), 1);
}
[Test]
public void add_item()
{
var mocker = new AutoMoqer();
var repo = MockLib.GetEmptyRepository();
mocker.SetConstant(repo);
var episodes = MockLib.GetFakeEpisodes(1);
repo.AddMany(episodes);
var episode = episodes[5];
var history = new History
{
Date = DateTime.Now,
EpisodeId = episode.EpisodeId,
NzbTitle = "my title"
};
mocker.Resolve<HistoryProvider>().Add(history);
}
[Test]
[Ignore]
public void Exists_True()

View File

@ -82,5 +82,14 @@ namespace NzbDrone.Core.Test
.With(c => c.CleanTitle = Parser.NormalizeTitle(title))
.Build();
}
public static IList<Episode> GetFakeEpisodes(int seriesId)
{
var epNumber = new SequentialGenerator<int>();
return Builder<Episode>.CreateListOfSize(10)
.WhereAll().Have(c => c.SeriesId = seriesId)
.WhereAll().Have(c => c.EpisodeNumber = epNumber.Generate())
.Build();
}
}
}

View File

@ -113,7 +113,7 @@ namespace NzbDrone.Core.Test
[Test]
[Row("The Test", "Test")]
[Row("The Test Title", "test title")]
[Row("Through the Wormhole", "Through.the.Wormhole")]
public void find_series_match(string title, string searchTitle)
{
var mocker = new AutoMoqer();

View File

@ -57,10 +57,12 @@ namespace NzbDrone.Core.Providers
public virtual IList<Episode> GetEpisodeByParseResult(EpisodeParseResult parseResult)
{
return _sonicRepo.Find<Episode>(e =>
var seasonEpisodes = _sonicRepo.All<Episode>().Where(e =>
e.SeriesId == parseResult.SeriesId &&
e.SeasonNumber == parseResult.SeasonNumber &&
parseResult.Episodes.Contains(e.EpisodeNumber));
e.SeasonNumber == parseResult.SeasonNumber).ToList();
//Has to be done separately since subsonic doesn't support contain method
return seasonEpisodes.Where(c => parseResult.Episodes.Contains(c.EpisodeNumber)).ToList();
}

View File

@ -40,10 +40,10 @@ namespace NzbDrone.Core.Providers
Logger.Info("History has been trimmed, items older than 30 days have been removed");
}
public virtual void Insert(History item)
public virtual void Add(History item)
{
_sonicRepo.Add(item);
Logger.Debug("Item added to history: {0} - {1}x{2:00}", item.Episode.Series.Title, item.Episode.SeasonNumber, item.Episode.EpisodeNumber);
Logger.Debug("Item added to history: {0}", item.NzbTitle);
}
public virtual bool Exists(int episodeId, QualityTypes quality, bool proper)

View File

@ -67,13 +67,21 @@ namespace NzbDrone.Core.Providers.Indexer
var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items;
foreach (var item in feed)
{
try
{
ProcessItem(item);
}
}
catch (Exception e)
catch (Exception itemEx)
{
_logger.ErrorException("An error occurred while processing feed", e);
_logger.ErrorException("An error occurred while processing feed item", itemEx);
}
}
}
catch (Exception feedEx)
{
_logger.ErrorException("An error occurred while processing feed", feedEx);
}
}
@ -82,7 +90,7 @@ namespace NzbDrone.Core.Providers.Indexer
internal void ProcessItem(SyndicationItem feedItem)
{
_logger.Info("Processing RSS feed item " + feedItem.Title.Text);
_logger.Debug("Processing RSS feed item " + feedItem.Title.Text);
var parseResult = ParseFeed(feedItem);
@ -124,7 +132,7 @@ namespace NzbDrone.Core.Providers.Indexer
//TODO: Add episode to sab
_historyProvider.Insert(new History
_historyProvider.Add(new History
{
Date = DateTime.Now,
EpisodeId = episode.EpisodeId,