From 4ac4ba5067f3e857ddcbe6ac0cb07fc4cd118f1f Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 17 May 2011 20:52:49 -0700 Subject: [PATCH] Mediascan job doesn't scan series that aren't fully added to the db yet --- NzbDrone.Core.Test/MediaFileProviderTests.cs | 22 +++++++++++++++++++ .../Providers/Jobs/MediaFileScanJob.cs | 2 +- NzbDrone.Core/Providers/MediaFileProvider.cs | 12 +++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index 1b8fc1933..9e0e2b453 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -1,12 +1,17 @@ using System; +using System.Collections.Generic; +using System.IO; using System.Linq.Expressions; +using System.Linq; using AutoMoq; using FizzWare.NBuilder; using MbUnit.Framework; using Moq; using Moq.Linq; +using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Jobs; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using SubSonic.Repository; @@ -285,5 +290,22 @@ namespace NzbDrone.Core.Test mocker.VerifyAllMocks(); } + + + [Test] + public void scan_media_job_should_not_scan_new_series() + { + var mocker = new AutoMoqer(); + mocker.GetMock() + .Setup(c => c.GetAllSeries()) + .Returns(Builder.CreateListOfSize(2) + .WhereTheFirst(1).Has(c => c.LastInfoSync = DateTime.Now).Build().AsQueryable()); + mocker.GetMock( MockBehavior.Strict) + .Setup(c=>c.Scan(It.Is(s=>s.LastInfoSync != null))).Returns(new List()).Verifiable(); + + mocker.Resolve().Start(new ProgressNotification("test"), 0); + + mocker.VerifyAllMocks(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Jobs/MediaFileScanJob.cs b/NzbDrone.Core/Providers/Jobs/MediaFileScanJob.cs index a53a10672..5638638ad 100644 --- a/NzbDrone.Core/Providers/Jobs/MediaFileScanJob.cs +++ b/NzbDrone.Core/Providers/Jobs/MediaFileScanJob.cs @@ -40,7 +40,7 @@ namespace NzbDrone.Core.Providers.Jobs seriesToScan = new List() { _seriesProvider.GetSeries(targetId) }; } - foreach (var series in seriesToScan) + foreach (var series in seriesToScan.Where(c => c.LastInfoSync != null)) { notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title); _mediaFileProvider.Scan(series); diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index 5d353bea2..75d9fbc28 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -33,7 +33,7 @@ namespace NzbDrone.Core.Providers /// Scans the specified series folder for media files /// /// The series to be scanned - public List Scan(Series series) + public virtual List Scan(Series series) { var mediaFileList = GetMediaFileList(series.Path); var fileList = new List(); @@ -51,7 +51,7 @@ namespace NzbDrone.Core.Providers return fileList; } - public EpisodeFile ImportFile(Series series, string filePath) + public virtual EpisodeFile ImportFile(Series series, string filePath) { Logger.Trace("Importing file to database [{0}]", filePath); @@ -150,7 +150,7 @@ namespace NzbDrone.Core.Providers /// Removes files that no longer exist from the database /// /// list of files to verify - public void CleanUp(List files) + public virtual void CleanUp(List files) { //TODO: remove orphaned files. in files table but not linked to from episode table. foreach (var episodeFile in files) @@ -165,17 +165,17 @@ namespace NzbDrone.Core.Providers - public void Update(EpisodeFile episodeFile) + public virtual void Update(EpisodeFile episodeFile) { _repository.Update(episodeFile); } - public EpisodeFile GetEpisodeFile(int episodeFileId) + public virtual EpisodeFile GetEpisodeFile(int episodeFileId) { return _repository.Single(episodeFileId); } - public List GetEpisodeFiles() + public virtual List GetEpisodeFiles() { return _repository.All().ToList(); }