more better exception handling.

This commit is contained in:
Keivan Beigi 2011-10-17 12:23:34 -07:00
parent 2e174c03c9
commit 6af98f9e96
4 changed files with 37 additions and 21 deletions

View File

@ -62,7 +62,7 @@ namespace NzbDrone.Core.Test
db.Insert(fakeSeries); db.Insert(fakeSeries);
db.Insert(fakeEpisodes); db.Insert(fakeEpisodes);
//Act //Act
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(fakeSeries.SeriesId, 2, 1); var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(fakeSeries.SeriesId, 2, 1);
@ -452,8 +452,8 @@ namespace NzbDrone.Core.Test
.Build(); .Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build(); var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
var fakeEpisodeList = new List<Episode> { new Episode { TvDbEpisodeId = 99, SeasonNumber = 10, EpisodeNumber = 10, Series = fakeSeries} }; var fakeEpisodeList = new List<Episode> { new Episode { TvDbEpisodeId = 99, SeasonNumber = 10, EpisodeNumber = 10, Series = fakeSeries } };
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
mocker.GetMock<IDatabase>() mocker.GetMock<IDatabase>()
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>())) .Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
@ -511,7 +511,7 @@ namespace NzbDrone.Core.Test
//Assert //Assert
mocker.VerifyAllMocks(); mocker.VerifyAllMocks();
mocker.GetMock<IDatabase>().Verify(c => c.UpdateMany(new List<Episode>{localEpisode}), Times.Once()); mocker.GetMock<IDatabase>().Verify(c => c.UpdateMany(new List<Episode> { localEpisode }), Times.Once());
} }
[Test] [Test]
@ -527,7 +527,7 @@ namespace NzbDrone.Core.Test
var currentEpisodes = new List<Episode>(); var currentEpisodes = new List<Episode>();
foreach (var tvDbEpisode in tvdbSeries.Episodes) foreach (var tvDbEpisode in tvdbSeries.Episodes)
{ {
currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, EpisodeId = 99, EpisodeFileId = 69, Ignored = true, Series = fakeSeries}); currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, EpisodeId = 99, EpisodeFileId = 69, Ignored = true, Series = fakeSeries });
} }
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
@ -544,7 +544,7 @@ namespace NzbDrone.Core.Test
mocker.GetMock<IDatabase>() mocker.GetMock<IDatabase>()
.Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>())) .Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
.Callback<IEnumerable<Episode>>(ep => updatedEpisodes =ep.ToList()); .Callback<IEnumerable<Episode>>(ep => updatedEpisodes = ep.ToList());
//Act //Act
mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries); mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
@ -1496,11 +1496,19 @@ namespace NzbDrone.Core.Test
mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("officeus")).Returns(fakeSeries); mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries("officeus")).Returns(fakeSeries);
//Act //Act
mocker.Resolve<EpisodeProvider>().SetPostDownloadStatus(fakeEpisodes.Select(e => e.EpisodeId), postDownloadStatus); mocker.Resolve<EpisodeProvider>().SetPostDownloadStatus(fakeEpisodes.Select(e => e.EpisodeId).ToList(), postDownloadStatus);
//Assert //Assert
var result = db.Fetch<Episode>(); var result = db.Fetch<Episode>();
result.Where(e => e.PostDownloadStatus == postDownloadStatus).Count().Should().Be(episodeCount); result.Where(e => e.PostDownloadStatus == postDownloadStatus).Count().Should().Be(episodeCount);
} }
[Test]
[ExpectedException(typeof(ArgumentException))]
public void SetPostDownloadStatus_should_throw_if_episode_list_is_empty()
{
var mocker = new AutoMoqer();
mocker.Resolve<EpisodeProvider>().SetPostDownloadStatus(new List<int>(), PostDownloadStatusType.Failed);
}
} }
} }

View File

@ -13,9 +13,11 @@ namespace NzbDrone.Core.Instrumentation
{ {
if (logEvent == null || logEvent.Exception == null) return; if (logEvent == null || logEvent.Exception == null) return;
if (Debugger.IsAttached || Process.GetCurrentProcess().ProcessName.Contains("JetBrains")) return; if (Debugger.IsAttached || Process.GetCurrentProcess().ProcessName.Contains("JetBrains")) return;
Logger.Trace("Sending Exception to Exceptioneer. {0}", Process.GetCurrentProcess().ProcessName); Logger.Trace("Sending Exception to Exceptioneer. {0}", Process.GetCurrentProcess().ProcessName);
logEvent.Exception.Data.Add("Message", logEvent.Message);
new Client new Client
{ {
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265", ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",

View File

@ -397,8 +397,10 @@ namespace NzbDrone.Core.Providers
Logger.Trace("Finished deleting invalid episodes for {0}", series.SeriesId); Logger.Trace("Finished deleting invalid episodes for {0}", series.SeriesId);
} }
public virtual void SetPostDownloadStatus(IEnumerable<int> episodeIds, PostDownloadStatusType postDownloadStatus) public virtual void SetPostDownloadStatus(List<int> episodeIds, PostDownloadStatusType postDownloadStatus)
{ {
if (episodeIds.Count == 0) throw new ArgumentException("episodeIds should contain one or more episode ids.");
var episodeIdString = String.Join(", ", episodeIds); var episodeIdString = String.Join(", ", episodeIds);
var episodeIdQuery = String.Format(@"UPDATE Episodes SET PostDownloadStatus = {0} var episodeIdQuery = String.Format(@"UPDATE Episodes SET PostDownloadStatus = {0}

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using NLog; using NLog;
using Ninject; using Ninject;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
@ -23,7 +22,7 @@ namespace NzbDrone.Core.Providers
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private static readonly List<PostDownloadInfoModel> InfoList = new List<PostDownloadInfoModel>(); private static readonly List<PostDownloadInfoModel> InfoList = new List<PostDownloadInfoModel>();
[Inject] [Inject]
public PostDownloadProvider(ConfigProvider configProvider, DiskProvider diskProvider, public PostDownloadProvider(ConfigProvider configProvider, DiskProvider diskProvider,
DiskScanProvider diskScanProvider, SeriesProvider seriesProvider, DiskScanProvider diskScanProvider, SeriesProvider seriesProvider,
@ -38,7 +37,7 @@ namespace NzbDrone.Core.Providers
PostDownloadProvider() PostDownloadProvider()
{ {
} }
public virtual void ScanDropFolder(ProgressNotification notification) public virtual void ScanDropFolder(ProgressNotification notification)
@ -85,7 +84,7 @@ namespace NzbDrone.Core.Providers
if (subfolderInfo.Name.StartsWith("_NzbDrone_")) if (subfolderInfo.Name.StartsWith("_NzbDrone_"))
{ {
if (subfolderInfo.Name.StartsWith("_NzbDrone_InvalidSeries_")) if (subfolderInfo.Name.StartsWith("_NzbDrone_InvalidSeries_"))
ReProcessDownload(new PostDownloadInfoModel{ Name = subfolderInfo.FullName, Status = PostDownloadStatusType.InvalidSeries }); ReProcessDownload(new PostDownloadInfoModel { Name = subfolderInfo.FullName, Status = PostDownloadStatusType.InvalidSeries });
else if (subfolderInfo.Name.StartsWith("_NzbDrone_ParseError_")) else if (subfolderInfo.Name.StartsWith("_NzbDrone_ParseError_"))
ReProcessDownload(new PostDownloadInfoModel { Name = subfolderInfo.FullName, Status = PostDownloadStatusType.ParseError }); ReProcessDownload(new PostDownloadInfoModel { Name = subfolderInfo.FullName, Status = PostDownloadStatusType.ParseError });
@ -169,26 +168,31 @@ namespace NzbDrone.Core.Providers
InfoList.Remove(model); InfoList.Remove(model);
return; return;
} }
//Add to InfoList for possible later processing //Add to InfoList for possible later processing
InfoList.Add(new PostDownloadInfoModel{ Name = directoryInfo.FullName, InfoList.Add(new PostDownloadInfoModel
Added = DateTime.Now, {
Status = postDownloadStatus Name = directoryInfo.FullName,
}); Added = DateTime.Now,
Status = postDownloadStatus
});
//Remove the first 8 characters of the folder name (removes _UNPACK_ or _FAILED_) before processing //Remove the first 8 characters of the folder name (removes _UNPACK_ or _FAILED_) before processing
var parseResult = Parser.ParseTitle(directoryInfo.Name.Substring(8)); var parseResult = Parser.ParseTitle(directoryInfo.Name.Substring(8));
parseResult.Series = _seriesProvider.FindSeries(parseResult.CleanTitle); parseResult.Series = _seriesProvider.FindSeries(parseResult.CleanTitle);
var episodeIds = new List<int>(); List<int> episodeIds;
if (parseResult.EpisodeNumbers.Count == 0 && parseResult.FullSeason) if (parseResult.EpisodeNumbers.Count == 0 && parseResult.FullSeason)
{
episodeIds = episodeIds =
_episodeProvider.GetEpisodesBySeason(parseResult.Series.SeriesId, parseResult.SeasonNumber) _episodeProvider.GetEpisodesBySeason(parseResult.Series.SeriesId, parseResult.SeasonNumber)
.Select(e => e.EpisodeId).ToList(); .Select(e => e.EpisodeId).ToList();
}
else else
{
episodeIds = _episodeProvider.GetEpisodesByParseResult(parseResult).Select(e => e.EpisodeId).ToList(); episodeIds = _episodeProvider.GetEpisodesByParseResult(parseResult).Select(e => e.EpisodeId).ToList();
}
_episodeProvider.SetPostDownloadStatus(episodeIds, postDownloadStatus); _episodeProvider.SetPostDownloadStatus(episodeIds, postDownloadStatus);
} }