more test/fixes

This commit is contained in:
kay.one 2011-05-19 22:52:05 -07:00
parent 43e1c16cca
commit 8fca3c3419
10 changed files with 178 additions and 30 deletions

View File

@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test
.Build();
base.Setup();
}
@ -183,6 +183,45 @@ namespace NzbDrone.Core.Test
mocker.VerifyAllMocks();
}
[Test]
public void file_in_history_should_be_skipped()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber))
.Returns(episode);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.QualityWanted(series.SeriesId, parseResult.Quality))
.Returns(true);
mocker.GetMock<SeasonProvider>()
.Setup(p => p.IsIgnored(series.SeriesId, parseResult.SeasonNumber))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsNeeded(parseResult, episode))
.Returns(true);
mocker.GetMock<HistoryProvider>()
.Setup(p => p.Exists(episode.EpisodeId, parseResult.Quality, parseResult.Proper))
.Returns(true);
//Act
var result = mocker.Resolve<InventoryProvider>().IsNeeded(parseResult);
//Assert
Assert.IsFalse(result);
mocker.VerifyAllMocks();
}
[Test]
public void dailyshow_should_do_daily_lookup()
{
@ -254,7 +293,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsNeeded(parseResult, It.IsAny<Episode>()))
.Returns(false);
//Act
var result = mocker.Resolve<InventoryProvider>().IsNeeded(parseResult);
@ -262,6 +301,47 @@ namespace NzbDrone.Core.Test
Assert.IsFalse(result);
mocker.VerifyAllMocks();
}
[Test]
public void file_needed_should_return_true()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.FindSeries(It.IsAny<String>()))
.Returns(series);
mocker.GetMock<EpisodeProvider>()
.Setup(p => p.GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber))
.Returns(episode);
mocker.GetMock<SeriesProvider>()
.Setup(p => p.QualityWanted(series.SeriesId, parseResult.Quality))
.Returns(true);
mocker.GetMock<SeasonProvider>()
.Setup(p => p.IsIgnored(series.SeriesId, parseResult.SeasonNumber))
.Returns(false);
mocker.GetMock<EpisodeProvider>()
.Setup(p => p.IsNeeded(parseResult, episode))
.Returns(true);
mocker.GetMock<HistoryProvider>()
.Setup(p => p.Exists(episode.EpisodeId, parseResult.Quality, parseResult.Proper))
.Returns(false);
//Act
var result = mocker.Resolve<InventoryProvider>().IsNeeded(parseResult);
//Assert
Assert.IsTrue(result);
Assert.IsNotNull(parseResult.Series);
Assert.AreEqual(series, parseResult.Series);
mocker.VerifyAllMocks();
}
}

View File

@ -2,11 +2,13 @@
using System.IO;
using System.Linq;
using AutoMoq;
using FizzWare.NBuilder;
using MbUnit.Framework;
using Moq;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
@ -219,6 +221,10 @@ namespace NzbDrone.Core.Test
{
var mocker = new AutoMoqer();
var series = Builder<Series>.CreateNew()
.With(c => c.Path = @"d:\tv shows\My Series Name")
.Build();
var parsResult = new EpisodeParseResult()
{
AirDate = DateTime.Now,
@ -227,10 +233,11 @@ namespace NzbDrone.Core.Test
Quality = quality,
SeasonNumber = seasons,
EpisodeTitle = title,
Series = series
};
//Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult, "My Series Name");
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert
Assert.AreEqual(excpected, actual);

View File

@ -311,17 +311,5 @@ namespace NzbDrone.Core.Helpers
return map.SeriesId;
}
public static List<String> FindById(int seriesId)
{
List<String> results = new List<string>();
var maps = SceneNameMappings.Where(s => s.SeriesId == seriesId);
foreach (var map in maps)
results.Add(map.Name);
return results;
}
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Model
@ -24,6 +25,8 @@ namespace NzbDrone.Core.Model
public string NzbUrl { get; set; }
public Series Series { get; set; }
public override string ToString()
{
if (Episodes == null)

View File

@ -170,6 +170,7 @@
<Compile Include="Model\ExternalNotificationType.cs" />
<Compile Include="Model\LanguageType.cs" />
<Compile Include="Model\SabnzbdInfoModel.cs" />
<Compile Include="Providers\DownloadProvider.cs" />
<Compile Include="Providers\ExternalNotification\ExternalNotificationProviderBase.cs" />
<Compile Include="Providers\ExternalNotification\XbmcNotificationProvider.cs" />
<Compile Include="Providers\Indexer\InventoryProvider.cs" />

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using SubSonic.Repository;
namespace NzbDrone.Core.Providers
{
public class DownloadProvider
{
private readonly SabProvider _sabProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public DownloadProvider(SabProvider sabProvider)
{
_sabProvider = sabProvider;
}
public DownloadProvider()
{
}
public virtual bool DownloadReport(EpisodeParseResult parseResult)
{
var sabTitle = _sabProvider.GetSabTitle(parseResult);
if (_sabProvider.IsInQueue(sabTitle))
{
Logger.Warn("Episode {0} is already in sab's queue. skipping.", parseResult);
return false;
}
return _sabProvider.AddByUrl(parseResult.NzbUrl, sabTitle);
}
}
}

View File

@ -35,6 +35,8 @@ namespace NzbDrone.Core.Providers.Indexer
return false;
}
parseResult.Series = series;
foreach (var episodeNumber in parseResult.Episodes)
{
//Todo: How to handle full season files? Currently the episode list is completely empty for these releases
@ -96,16 +98,8 @@ namespace NzbDrone.Core.Providers.Indexer
return false;
}
parseResult.EpisodeTitle = episodeInfo.Title;
var sabTitle = _sabProvider.GetSabTitle(parseResult, new DirectoryInfo(series.Path).Name);
if (_sabProvider.IsInQueue(sabTitle))
{
Logger.Debug("Episode {0} is already in sab's queue. skipping.", parseResult);
return false;
}
//Congragulations younge feed item! you have made it this far. you are truly special!!!
Logger.Debug("Episode {0} is needed", parseResult);
return true;
}

View File

@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Indexer;
@ -9,13 +11,17 @@ namespace NzbDrone.Core.Providers.Jobs
public class RssSyncJob : IJob
{
private readonly IEnumerable<IndexerBase> _indexers;
private readonly InventoryProvider _inventoryProvider;
private readonly DownloadProvider _downloadProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public RssSyncJob(IEnumerable<IndexerBase> indexers)
public RssSyncJob(IEnumerable<IndexerBase> indexers, InventoryProvider inventoryProvider, DownloadProvider downloadProvider)
{
_indexers = indexers;
_inventoryProvider = inventoryProvider;
_downloadProvider = downloadProvider;
}
public string Name
@ -30,10 +36,39 @@ namespace NzbDrone.Core.Providers.Jobs
public void Start(ProgressNotification notification, int targetId)
{
var reports = new List<EpisodeParseResult>();
foreach (var indexer in _indexers.Where(i => i.Settings.Enable))
{
indexer.Fetch();
try
{
notification.CurrentMessage = "Fetching RSS from " + indexer.Name;
reports.AddRange(indexer.Fetch());
}
catch (Exception e)
{
Logger.ErrorException("An error has occured while fetching items from " + indexer.Name, e);
}
}
Logger.Debug("Finished fetching reports from all indexers. Total {0}", reports.Count);
notification.CurrentMessage = "Proccessing downloaded RSS";
foreach (var episodeParseResult in reports)
{
try
{
if (_inventoryProvider.IsNeeded(episodeParseResult))
{
_downloadProvider.DownloadReport(episodeParseResult);
}
}
catch (Exception e)
{
Logger.ErrorException("An error has occured while processing parse result items from " + episodeParseResult, e);
}
}
}
}
}

View File

@ -92,7 +92,7 @@ namespace NzbDrone.Core.Providers
_configProvider.SabPassword);
}
public String GetSabTitle(EpisodeParseResult parseResult, String folderName)
public String GetSabTitle(EpisodeParseResult parseResult)
{
//Show Name - 1x01-1x02 - Episode Name
//Show Name - 1x01 - Episode Name
@ -105,7 +105,7 @@ namespace NzbDrone.Core.Providers
var epNumberString = String.Join("-", episodeString);
var result = String.Format("{0} - {1} - {2} [{3}]", folderName, epNumberString, parseResult.EpisodeTitle, parseResult.Quality);
var result = String.Format("{0} - {1} - {2} [{3}]", new DirectoryInfo(parseResult.Series.Path).Name, epNumberString, parseResult.EpisodeTitle, parseResult.Quality);
if (parseResult.Proper)
{