1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-08-16 23:39:44 +02:00

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 @@ public void Is_Needed_Tv_Dvd_BluRay_BluRay720_Is_Cutoff(QualityTypes reportQuali
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 @@ public void AllItems()
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 @@ public static Series GetFakeSeries(int id, string title)
.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 @@ public void find_series_empty_match()
[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 @@ public virtual IList<Episode> GetEpisodeBySeason(long seasonId)
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();
}

View File

@ -40,10 +40,10 @@ public virtual void Trim()
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 @@ public virtual bool Exists(int episodeId, QualityTypes quality, bool proper)
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;
}
}

View File

@ -68,12 +68,20 @@ public void Fetch()
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 @@ public void Fetch()
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 @@ internal void ProcessItem(SyndicationItem feedItem)
//TODO: Add episode to sab
_historyProvider.Insert(new History
_historyProvider.Add(new History
{
Date = DateTime.Now,
EpisodeId = episode.EpisodeId,