more tests and bug fixes

pull/4/head
kay.one 14 years ago
parent 282870cd80
commit e074164a47

@ -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()
{

@ -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()

@ -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();
}
}
}

@ -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();

@ -57,10 +57,12 @@ namespace NzbDrone.Core.Providers
public virtual IList<Episode> GetEpisodeByParseResult(EpisodeParseResult parseResult)
{
return _sonicRepo.Find<Episode>(e =>
e.SeriesId == parseResult.SeriesId &&
e.SeasonNumber == parseResult.SeasonNumber &&
parseResult.Episodes.Contains(e.EpisodeNumber));
var seasonEpisodes = _sonicRepo.All<Episode>().Where(e =>
e.SeriesId == parseResult.SeriesId &&
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();
}

@ -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)
@ -52,7 +52,7 @@ namespace NzbDrone.Core.Providers
if (_sonicRepo.Exists<History>(h => h.EpisodeId == episodeId && h.Quality == quality && h.IsProper == proper))
return true;
Logger.Debug("Episode not in History. ID:{0} Q:{1} Proper:{2}", episodeId , quality, proper);
Logger.Debug("Episode not in History. ID:{0} Q:{1} Proper:{2}", episodeId, quality, proper);
return false;
}
}

@ -68,12 +68,20 @@ namespace NzbDrone.Core.Providers.Indexer
foreach (var item in feed)
{
ProcessItem(item);
try
{
ProcessItem(item);
}
catch (Exception itemEx)
{
_logger.ErrorException("An error occurred while processing feed item", itemEx);
}
}
}
catch (Exception e)
catch (Exception feedEx)
{
_logger.ErrorException("An error occurred while processing feed", e);
_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,

Loading…
Cancel
Save