From a4dde81cebb3546c36c218a85e09e91e9948269b Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 10 Sep 2012 12:04:17 -0700 Subject: [PATCH 1/5] Converted jobs to dynamic --- .../JobTests/AppUpdateJobFixture.cs | 2 +- .../JobTests/BacklogSearchJobTest.cs | 48 +++++++++---------- .../JobTests/BannerDownloadJobTest.cs | 6 +-- .../JobTests/DiskScanJobTest.cs | 8 ++-- .../JobTests/ImportNewSeriesJobTest.cs | 38 +++++++-------- .../JobTests/RecentBacklogSearchJobTest.cs | 10 ++-- NzbDrone.Core.Test/JobTests/SearchJobTest.cs | 4 +- .../JobTests/SeasonSearchJobTest.cs | 12 ++--- .../JobTests/SeriesSearchJobTest.cs | 14 +++--- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + .../JobProviderTests/JobProviderFixture.cs | 5 +- .../JobProviderTests/TestJobs.cs | 2 +- NzbDrone.Core/Jobs/AppUpdateJob.cs | 2 +- NzbDrone.Core/Jobs/BacklogSearchJob.cs | 6 +-- NzbDrone.Core/Jobs/BannerDownloadJob.cs | 6 +-- NzbDrone.Core/Jobs/CleanupRecycleBinJob.cs | 2 +- NzbDrone.Core/Jobs/ConvertEpisodeJob.cs | 9 ++-- NzbDrone.Core/Jobs/DeleteSeriesJob.cs | 4 +- NzbDrone.Core/Jobs/DiskScanJob.cs | 6 +-- NzbDrone.Core/Jobs/EmptyRecycleBinJob.cs | 2 +- NzbDrone.Core/Jobs/EpisodeSearchJob.cs | 8 ++-- NzbDrone.Core/Jobs/IJob.cs | 2 +- NzbDrone.Core/Jobs/ImportNewSeriesJob.cs | 8 ++-- NzbDrone.Core/Jobs/JobProvider.cs | 11 ++--- .../Jobs/PastWeekBacklogSearchJob.cs | 4 +- NzbDrone.Core/Jobs/PostDownloadScanJob.cs | 2 +- NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs | 4 +- NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs | 6 +-- NzbDrone.Core/Jobs/RenameSeasonJob.cs | 24 +++++----- NzbDrone.Core/Jobs/RenameSeriesJob.cs | 6 +-- NzbDrone.Core/Jobs/RssSyncJob.cs | 2 +- NzbDrone.Core/Jobs/SearchHistoryCleanupJob.cs | 2 +- NzbDrone.Core/Jobs/SeasonSearchJob.cs | 22 +++++---- NzbDrone.Core/Jobs/SeriesSearchJob.cs | 18 +++---- NzbDrone.Core/Jobs/TrimLogsJob.cs | 2 +- NzbDrone.Core/Jobs/UpdateInfoJob.cs | 6 +-- NzbDrone.Core/Jobs/UpdateSceneMappingsJob.cs | 2 +- NzbDrone.Core/Model/JobQueueItem.cs | 8 ++-- NzbDrone.Web/Controllers/EpisodeController.cs | 4 +- NzbDrone.Web/Controllers/SeriesController.cs | 2 +- NzbDrone.Web/Controllers/SystemController.cs | 3 +- NzbDrone.Web/Models/JobQueueItemModel.cs | 3 +- 42 files changed, 166 insertions(+), 170 deletions(-) diff --git a/NzbDrone.Core.Test/JobTests/AppUpdateJobFixture.cs b/NzbDrone.Core.Test/JobTests/AppUpdateJobFixture.cs index 2e39a2bf1..a7f384dd7 100644 --- a/NzbDrone.Core.Test/JobTests/AppUpdateJobFixture.cs +++ b/NzbDrone.Core.Test/JobTests/AppUpdateJobFixture.cs @@ -161,7 +161,7 @@ namespace NzbDrone.Core.Test.JobTests private void StartUpdate() { - Mocker.Resolve().Start(MockNotification, 0, 0); + Mocker.Resolve().Start(MockNotification, null); } } } diff --git a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs index ee8f0bf98..17fd588b0 100644 --- a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs @@ -39,13 +39,13 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act - Mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), It.IsAny()), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), Times.Never()); - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = 0 }), Times.Never()); } @@ -72,16 +72,16 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock() - .Setup(s => s.Start(notification, It.IsAny(), 0)).Verifiable(); + .Setup(s => s.Start(notification, new { EpisodeId = 1 })); //Act - Mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), It.IsAny()), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), Times.Never()); - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), + Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), Times.Once()); } @@ -108,16 +108,16 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock() - .Setup(s => s.Start(notification, It.IsAny(), 0)).Verifiable(); + .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny()})).Verifiable(); //Act - Mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), It.IsAny()), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), Times.Never()); - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = 0 }), Times.Exactly(episodes.Count)); } @@ -145,19 +145,19 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock() - .Setup(s => s.Start(notification, It.IsAny(), 0)).Verifiable(); + .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny() })).Verifiable(); Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); //Act - Mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), It.IsAny()), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), Times.Never()); - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), + Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), Times.Exactly(episodes.Count)); } @@ -186,19 +186,19 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock() - .Setup(s => s.Start(notification, It.IsAny(), It.IsAny())).Verifiable(); + .Setup(s => s.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() })).Verifiable(); Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList()); //Act - Mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), It.IsAny()), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), Times.Once()); - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), + Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), Times.Never()); } @@ -234,22 +234,22 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock() - .Setup(s => s.Start(notification, It.IsAny(), It.IsAny())).Verifiable(); + .Setup(s => s.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() })).Verifiable(); Mocker.GetMock() - .Setup(s => s.Start(notification, It.IsAny(), 0)).Verifiable(); + .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny() })).Verifiable(); Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5 }); //Act - Mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), It.IsAny()), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), Times.Once()); - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), + Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), Times.Exactly(5)); } diff --git a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs index 9b1b4e481..88b746c8a 100644 --- a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs @@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock().Setup(s => s.GetAllSeries()) .Returns(series); - Mocker.Resolve().Start(_notification, 0, 0); + Mocker.Resolve().Start(_notification, null); VerifyDownloadMock(series.Count); } @@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock().Setup(s => s.GetAllSeries()) .Returns(series); - Mocker.Resolve().Start(_notification, 0, 0); + Mocker.Resolve().Start(_notification, null); VerifyDownloadMock(3); } @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock().Setup(s => s.GetSeries(series.SeriesId)) .Returns(series); - Mocker.Resolve().Start(_notification, 1, 0); + Mocker.Resolve().Start(_notification, new { SeriesId = 0 }); VerifyDownloadMock(1); } } diff --git a/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs b/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs index b9500df52..f5590c3fe 100644 --- a/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs @@ -38,7 +38,7 @@ namespace NzbDrone.Core.Test.JobTests .Returns(new List()); //Act - Mocker.Resolve().Start(new ProgressNotification("Test"), series.SeriesId, 0); + Mocker.Resolve().Start(new ProgressNotification("Test"), new { SeriesId = series.SeriesId }); //Assert Mocker.VerifyAllMocks(); @@ -68,7 +68,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.Scan(series[1])) .Returns(new List()); - Mocker.Resolve().Start(new ProgressNotification("Test"), 0, 0); + Mocker.Resolve().Start(new ProgressNotification("Test"), null); Mocker.VerifyAllMocks(); @@ -96,7 +96,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.Scan(series[1])) .Throws(new InvalidOperationException("Bad Job")); - Mocker.Resolve().Start(new ProgressNotification("Test"), 0, 0); + Mocker.Resolve().Start(new ProgressNotification("Test"), null); Mocker.VerifyAllMocks(); @@ -126,7 +126,7 @@ namespace NzbDrone.Core.Test.JobTests .Returns(new List()); - Mocker.Resolve().Start(new ProgressNotification("Test"), 0, 0); + Mocker.Resolve().Start(new ProgressNotification("Test"), null); diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index 8300b7185..8b5aa8e4a 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -39,23 +39,23 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock() - .Setup(j => j.Start(notification, series[0].SeriesId, 0)) + .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0})) .Callback(() => series[0].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, series[1].SeriesId, 0)) + .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) .Callback(() => series[1].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, It.IsAny(), 0)); + .Setup(j => j.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = 0 })); Mocker.GetMock() - .Setup(j => j.Start(notification, series[0].SeriesId, 0)) + .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) .Callback(() => series[0].LastInfoSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, series[1].SeriesId, 0)) + .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) .Callback(() => series[1].LastInfoSync = DateTime.Now); Mocker.GetMock() @@ -68,16 +68,14 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.GetSeriesFiles(It.IsAny())).Returns(new List()); //Act - Mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, null); //Assert - Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once()); - - Mocker.GetMock().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); } @@ -103,19 +101,19 @@ namespace NzbDrone.Core.Test.JobTests .Returns(series); Mocker.GetMock() - .Setup(j => j.Start(notification, series[0].SeriesId, 0)) + .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) .Callback(() => series[0].LastInfoSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, series[1].SeriesId, 0)) + .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) .Throws(new InvalidOperationException()); Mocker.GetMock() - .Setup(j => j.Start(notification, series[0].SeriesId, 0)) + .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) .Callback(() => series[0].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, series[0].SeriesId, 0)); + .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })); Mocker.GetMock() .Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]); @@ -124,15 +122,15 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.GetSeriesFiles(It.IsAny())).Returns(new List()); //Act - Mocker.Resolve().Start(notification, 0, 0); + Mocker.Resolve().Start(notification, null); //Assert Mocker.VerifyAllMocks(); - Mocker.GetMock().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0}), Times.Once()); ExceptionVerification.ExpectedErrors(1); diff --git a/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs index 31e9c6d19..329d2840c 100644 --- a/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs @@ -41,10 +41,10 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act - Mocker.Resolve().Start(MockNotification, 0, 0); + Mocker.Resolve().Start(MockNotification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(MockNotification, It.IsAny(), 0), + Mocker.GetMock().Verify(c => c.Start(MockNotification, new { EpisodeId = It.IsAny() }), Times.Never()); } @@ -87,13 +87,13 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock().Setup(c => c.Start(It.IsAny(), It.IsAny(), 0)); + Mocker.GetMock().Setup(c => c.Start(It.IsAny(), new { EpisodeId = It.IsAny() })); //Act - Mocker.Resolve().Start(MockNotification, 0, 0); + Mocker.Resolve().Start(MockNotification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(It.IsAny(), It.IsAny(), 0), + Mocker.GetMock().Verify(c => c.Start(It.IsAny(), new { EpisodeId = It.IsAny() }), Times.Exactly(40)); } diff --git a/NzbDrone.Core.Test/JobTests/SearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SearchJobTest.cs index 288e173d8..5ca459f08 100644 --- a/NzbDrone.Core.Test/JobTests/SearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SearchJobTest.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.JobTests public void start_target_id_less_than_0_throws_exception(int target) { WithStrictMocker(); - Mocker.Resolve().Start(new ProgressNotification("Test"), target, 0); + //Mocker.Resolve().Start(new ProgressNotification("Test"), target, 0); } [TestCase(0)] @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.JobTests public void start_secondary_target_id_less_than_0_throws_exception(int target) { WithStrictMocker(); - Mocker.Resolve().Start(new ProgressNotification("Test"), 0, target); + //Mocker.Resolve().Start(new ProgressNotification("Test"), 0, target); } } } diff --git a/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs index cf526885b..ebdbeeda5 100644 --- a/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs @@ -51,12 +51,12 @@ namespace NzbDrone.Core.Test.JobTests .Returns(episodes.Select(e => e.EpisodeNumber).ToList()); //Act - Mocker.Resolve().Start(notification, 1, 1); + Mocker.Resolve().Start(notification, new { SeriesId = 1, SeasonNumber = 1 }); //Assert Mocker.VerifyAllMocks(); Mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once()); - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Never()); + Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), Times.Never()); } [Test] @@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.JobTests .Returns(new List()); //Act - Mocker.Resolve().Start(notification, 1, 1); + Mocker.Resolve().Start(notification, new { SeriesId = 1, SeasonNumber = 1 }); //Assert Mocker.VerifyAllMocks(); @@ -104,7 +104,7 @@ namespace NzbDrone.Core.Test.JobTests //Act - Mocker.Resolve().Start(notification, 1, 1); + Mocker.Resolve().Start(notification, new { SeriesId = 1, SeasonNumber = 1 }); //Assert Mocker.VerifyAllMocks(); @@ -118,11 +118,11 @@ namespace NzbDrone.Core.Test.JobTests .Setup(c => c.PartialSeasonSearch(notification, 1, 0)).Returns(new List()); //Act - Mocker.Resolve().Start(notification, 1, 0); + Mocker.Resolve().Start(notification, new { SeriesId = 1, SeasonNumber = 0 }); //Assert Mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Never()); - Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Never()); + Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), Times.Never()); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs index 47961d3ba..6236f497e 100644 --- a/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs @@ -30,14 +30,14 @@ namespace NzbDrone.Core.Test.JobTests .Setup(c => c.IsIgnored(It.IsAny(), It.IsAny())).Returns(false); Mocker.GetMock() - .Setup(c => c.Start(notification, 1, It.IsAny())).Verifiable(); + .Setup(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny() })).Verifiable(); //Act - Mocker.Resolve().Start(notification, 1, 0); + Mocker.Resolve().Start(notification, new { SeriesId = 1 }); //Assert Mocker.VerifyAllMocks(); - Mocker.GetMock().Verify(c => c.Start(notification, 1, It.IsAny()), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny() }), Times.Exactly(seasons.Count)); } @@ -54,11 +54,11 @@ namespace NzbDrone.Core.Test.JobTests .Setup(c => c.GetSeasons(1)).Returns(seasons); //Act - Mocker.Resolve().Start(notification, 1, 0); + Mocker.Resolve().Start(notification, new { SeriesId = 1 }); //Assert Mocker.VerifyAllMocks(); - Mocker.GetMock().Verify(c => c.Start(notification, 1, It.IsAny()), + Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny() }), Times.Never()); } @@ -69,11 +69,11 @@ namespace NzbDrone.Core.Test.JobTests .Setup(c => c.GetSeasons(It.IsAny())) .Returns(new List { 0, 1, 2 }); - Mocker.Resolve().Start(MockNotification, 12, 0); + Mocker.Resolve().Start(MockNotification, new { SeriesId = 12 }); Mocker.GetMock() - .Verify(c => c.Start(It.IsAny(), It.IsAny(), 0), Times.Never()); + .Verify(c => c.Start(It.IsAny(), new { SeriesId = It.IsAny(), SeasonNumber = 0 }), Times.Never()); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index a6efa6cf9..56876f014 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -53,6 +53,7 @@ False ..\packages\FluentAssertions.1.7.0\Lib\net40\FluentAssertions.dll + True ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll diff --git a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs index d3cd84548..2ec52b4f7 100644 --- a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs @@ -436,8 +436,7 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests var stuckQueueItem = new JobQueueItem { JobType = fakeJob.GetType(), - TargetId = 12, - SecondaryTargetId = 0 + Options = new { TargetId = 12 } }; //Act @@ -446,7 +445,7 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests jobProvider.Queue.Add(stuckQueueItem); WaitForQueue(); - jobProvider.QueueJob(stuckQueueItem.JobType, stuckQueueItem.TargetId, stuckQueueItem.SecondaryTargetId); + jobProvider.QueueJob(stuckQueueItem.JobType, stuckQueueItem.Options); WaitForQueue(); //Assert diff --git a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/TestJobs.cs b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/TestJobs.cs index b53d8329b..386ef6b73 100644 --- a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/TestJobs.cs +++ b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/TestJobs.cs @@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests public int ExecutionCount { get; private set; } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { ExecutionCount++; Console.WriteLine("Begin " + Name); diff --git a/NzbDrone.Core/Jobs/AppUpdateJob.cs b/NzbDrone.Core/Jobs/AppUpdateJob.cs index 9be7bd970..1389b68b1 100644 --- a/NzbDrone.Core/Jobs/AppUpdateJob.cs +++ b/NzbDrone.Core/Jobs/AppUpdateJob.cs @@ -46,7 +46,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromDays(2); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { notification.CurrentMessage = "Checking for updates"; diff --git a/NzbDrone.Core/Jobs/BacklogSearchJob.cs b/NzbDrone.Core/Jobs/BacklogSearchJob.cs index a12c40307..df682f99d 100644 --- a/NzbDrone.Core/Jobs/BacklogSearchJob.cs +++ b/NzbDrone.Core/Jobs/BacklogSearchJob.cs @@ -38,7 +38,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromDays(30); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { var missingEpisodes = GetMissingForEnabledSeries().GroupBy(e => new { e.SeriesId, e.SeasonNumber }); @@ -73,7 +73,7 @@ namespace NzbDrone.Core.Jobs { //Process as a full season Logger.Debug("Processing Full Season: {0} Season {1}", seriesId, seasonNumber); - _seasonSearchJob.Start(notification, seriesId, seasonNumber); + _seasonSearchJob.Start(notification, new { SeriesId = seriesId, SeasonNumber = seasonNumber }); } } } @@ -82,7 +82,7 @@ namespace NzbDrone.Core.Jobs //Process the list of remaining episodes, 1 by 1 foreach (var episode in individualEpisodes) { - _episodeSearchJob.Start(notification, episode.EpisodeId, 0); + _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId}); } } diff --git a/NzbDrone.Core/Jobs/BannerDownloadJob.cs b/NzbDrone.Core/Jobs/BannerDownloadJob.cs index a23bb7135..614a4aa36 100644 --- a/NzbDrone.Core/Jobs/BannerDownloadJob.cs +++ b/NzbDrone.Core/Jobs/BannerDownloadJob.cs @@ -40,13 +40,13 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromDays(30); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { Logger.Debug("Starting banner download job"); - if (targetId > 0) + if (options != null) { - var series = _seriesProvider.GetSeries(targetId); + var series = _seriesProvider.GetSeries(options.SeriesId); if (series != null && !String.IsNullOrEmpty(series.BannerUrl)) { diff --git a/NzbDrone.Core/Jobs/CleanupRecycleBinJob.cs b/NzbDrone.Core/Jobs/CleanupRecycleBinJob.cs index f8c62cdb3..2f28ade7d 100644 --- a/NzbDrone.Core/Jobs/CleanupRecycleBinJob.cs +++ b/NzbDrone.Core/Jobs/CleanupRecycleBinJob.cs @@ -28,7 +28,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromDays(24); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { _recycleBinProvider.Cleanup(); } diff --git a/NzbDrone.Core/Jobs/ConvertEpisodeJob.cs b/NzbDrone.Core/Jobs/ConvertEpisodeJob.cs index 08fe467e0..4d142eef0 100644 --- a/NzbDrone.Core/Jobs/ConvertEpisodeJob.cs +++ b/NzbDrone.Core/Jobs/ConvertEpisodeJob.cs @@ -35,12 +35,13 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { - if (targetId <= 0) - throw new ArgumentOutOfRangeException("targetId"); - var episode = _episodeProvider.GetEpisode(targetId); + if (options == null || options.EpisodeId <= 0) + throw new ArgumentNullException(options); + + var episode = _episodeProvider.GetEpisode(options.EpisodeId); notification.CurrentMessage = String.Format("Starting Conversion for {0}", episode); var outputFile = _handbrakeProvider.ConvertFile(episode, notification); diff --git a/NzbDrone.Core/Jobs/DeleteSeriesJob.cs b/NzbDrone.Core/Jobs/DeleteSeriesJob.cs index ac910e146..5ef69d3ae 100644 --- a/NzbDrone.Core/Jobs/DeleteSeriesJob.cs +++ b/NzbDrone.Core/Jobs/DeleteSeriesJob.cs @@ -32,9 +32,9 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { - DeleteSeries(notification, targetId, Convert.ToBoolean(secondaryTargetId)); + DeleteSeries(notification, options.SeriesId, options.DeleteFiless); } private void DeleteSeries(ProgressNotification notification, int seriesId, bool deleteFiles) diff --git a/NzbDrone.Core/Jobs/DiskScanJob.cs b/NzbDrone.Core/Jobs/DiskScanJob.cs index c5f651df9..aeb97a8d4 100644 --- a/NzbDrone.Core/Jobs/DiskScanJob.cs +++ b/NzbDrone.Core/Jobs/DiskScanJob.cs @@ -38,16 +38,16 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromHours(6); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { IList seriesToScan; - if (targetId == 0) + if (options == null || options.SeriesId == 0) { seriesToScan = _seriesProvider.GetAllSeries().OrderBy(o => SortHelper.SkipArticles(o.Title)).ToList(); } else { - seriesToScan = new List() { _seriesProvider.GetSeries(targetId) }; + seriesToScan = new List() { _seriesProvider.GetSeries(options.SeriesId) }; } foreach (var series in seriesToScan) diff --git a/NzbDrone.Core/Jobs/EmptyRecycleBinJob.cs b/NzbDrone.Core/Jobs/EmptyRecycleBinJob.cs index 46d390492..7133b4080 100644 --- a/NzbDrone.Core/Jobs/EmptyRecycleBinJob.cs +++ b/NzbDrone.Core/Jobs/EmptyRecycleBinJob.cs @@ -28,7 +28,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { _recycleBinProvider.Empty(); } diff --git a/NzbDrone.Core/Jobs/EpisodeSearchJob.cs b/NzbDrone.Core/Jobs/EpisodeSearchJob.cs index cc18a1fd9..0eeb50dcf 100644 --- a/NzbDrone.Core/Jobs/EpisodeSearchJob.cs +++ b/NzbDrone.Core/Jobs/EpisodeSearchJob.cs @@ -31,12 +31,12 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { - if (targetId <= 0) - throw new ArgumentOutOfRangeException("targetId"); + if (options == null || options.EpisodeId <= 0) + throw new ArgumentException("options"); - _searchProvider.EpisodeSearch(notification, targetId); + _searchProvider.EpisodeSearch(notification, options.EpisodeId); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/IJob.cs b/NzbDrone.Core/Jobs/IJob.cs index 30cce3775..6b8dcb8f7 100644 --- a/NzbDrone.Core/Jobs/IJob.cs +++ b/NzbDrone.Core/Jobs/IJob.cs @@ -28,6 +28,6 @@ namespace NzbDrone.Core.Jobs /// this object should be used to update the progress on the UI /// The that should be used to limit the target of this job /// /// The that should be used to limit the target of this job - void Start(ProgressNotification notification, int targetId, int secondaryTargetId); + void Start(ProgressNotification notification, dynamic options); } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs index c6d0f66cb..fdba25b51 100644 --- a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs +++ b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs @@ -51,7 +51,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromMinutes(1); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { _attemptedSeries = new List(); ScanSeries(notification); @@ -72,14 +72,14 @@ namespace NzbDrone.Core.Jobs _attemptedSeries.Add(currentSeries.SeriesId); notification.CurrentMessage = String.Format("Searching for '{0}'", new DirectoryInfo(currentSeries.Path).Name); - _updateInfoJob.Start(notification, currentSeries.SeriesId, 0); - _diskScanJob.Start(notification, currentSeries.SeriesId, 0); + _updateInfoJob.Start(notification, new { SeriesId = currentSeries.SeriesId }); + _diskScanJob.Start(notification, new { SeriesId = currentSeries.SeriesId }); var updatedSeries = _seriesProvider.GetSeries(currentSeries.SeriesId); AutoIgnoreSeasons(updatedSeries.SeriesId); //Download the banner for the new series - _bannerDownloadJob.Start(notification, updatedSeries.SeriesId, 0); + _bannerDownloadJob.Start(notification, new { SeriesId = updatedSeries.SeriesId }); notification.CurrentMessage = String.Format("{0} was successfully imported", updatedSeries.Title); } diff --git a/NzbDrone.Core/Jobs/JobProvider.cs b/NzbDrone.Core/Jobs/JobProvider.cs index 03e2b50d2..fa3cedc92 100644 --- a/NzbDrone.Core/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Jobs/JobProvider.cs @@ -143,13 +143,12 @@ namespace NzbDrone.Core.Jobs logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobTypes.Count); } - public virtual void QueueJob(Type jobType, int targetId = 0, int secondaryTargetId = 0, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User) + public virtual void QueueJob(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User) { var queueItem = new JobQueueItem { JobType = jobType, - TargetId = targetId, - SecondaryTargetId = secondaryTargetId, + Options = options, Source = source }; @@ -270,7 +269,7 @@ namespace NzbDrone.Core.Jobs var sw = Stopwatch.StartNew(); _notificationProvider.Register(_notification); - jobImplementation.Start(_notification, queueItem.TargetId, queueItem.SecondaryTargetId); + jobImplementation.Start(_notification, queueItem.Options); _notification.Status = ProgressNotificationStatus.Completed; settings.LastExecution = DateTime.Now; @@ -296,7 +295,7 @@ namespace NzbDrone.Core.Jobs } //Only update last execution status if was triggered by the scheduler - if (queueItem.TargetId == 0) + if (queueItem.Options == null) { SaveDefinition(settings); } @@ -321,7 +320,5 @@ namespace NzbDrone.Core.Jobs logger.Trace("resetting queue processor thread"); _jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" }; } - - } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs b/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs index 885dd8656..87d6b92e5 100644 --- a/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs +++ b/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs @@ -36,14 +36,14 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { var missingEpisodes = GetMissingForEnabledSeries(); Logger.Debug("Processing missing episodes from the past week, count: {0}", missingEpisodes.Count); foreach (var episode in missingEpisodes) { - _episodeSearchJob.Start(notification, episode.EpisodeId, 0); + _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId }); } } diff --git a/NzbDrone.Core/Jobs/PostDownloadScanJob.cs b/NzbDrone.Core/Jobs/PostDownloadScanJob.cs index c021fc9eb..6a156b3c0 100644 --- a/NzbDrone.Core/Jobs/PostDownloadScanJob.cs +++ b/NzbDrone.Core/Jobs/PostDownloadScanJob.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromMinutes(1); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { var dropFolder = _configProvider.SabDropDirectory; diff --git a/NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs b/NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs index 58f606508..4e0333531 100644 --- a/NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs +++ b/NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs @@ -36,14 +36,14 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromDays(1); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { var missingEpisodes = GetMissingForEnabledSeries(); Logger.Debug("Processing missing episodes from the last 30 days, count: {0}", missingEpisodes.Count); foreach (var episode in missingEpisodes) { - _episodeSearchJob.Start(notification, episode.EpisodeId, 0); + _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId }); } } diff --git a/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs b/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs index ac09affe3..7cd38bae1 100644 --- a/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs +++ b/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs @@ -36,15 +36,15 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { List seriesToRefresh; - if (targetId <= 0) + if (options == null || options.SeriesId <= 0) seriesToRefresh = _seriesProvider.GetAllSeries().ToList(); else - seriesToRefresh = new List { _seriesProvider.GetSeries(targetId) }; + seriesToRefresh = new List { _seriesProvider.GetSeries(options.SeriesId) }; foreach(var series in seriesToRefresh) { diff --git a/NzbDrone.Core/Jobs/RenameSeasonJob.cs b/NzbDrone.Core/Jobs/RenameSeasonJob.cs index 72da83101..f236c5822 100644 --- a/NzbDrone.Core/Jobs/RenameSeasonJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeasonJob.cs @@ -41,24 +41,24 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { - if (targetId <= 0) - throw new ArgumentOutOfRangeException("targetId"); + if (options == null || options.SeriesId <= 0) + throw new ArgumentException("options"); - if (secondaryTargetId <= 0) - throw new ArgumentOutOfRangeException("secondaryTargetId"); + if (options.SeasonNumber < 0) + throw new ArgumentException("options.SeasonNumber"); - var series = _seriesProvider.GetSeries(targetId); + var series = _seriesProvider.GetSeries(options.SeriesId); - notification.CurrentMessage = String.Format("Renaming episodes for {0} Season {1}", series.Title, secondaryTargetId); + notification.CurrentMessage = String.Format("Renaming episodes for {0} Season {1}", series.Title, options.SeasonNumber); - logger.Debug("Getting episodes from database for series: {0} and season: {1}", targetId, secondaryTargetId); - var episodeFiles = _mediaFileProvider.GetSeasonFiles(targetId, secondaryTargetId); + logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber); + var episodeFiles = _mediaFileProvider.GetSeasonFiles(options.SeriesId, options.SeasonNumber); if (episodeFiles == null || !episodeFiles.Any()) { - logger.Warn("No episodes in database found for series: {0} and season: {1}.", targetId, secondaryTargetId); + logger.Warn("No episodes in database found for series: {0} and season: {1}.", options.SeriesId, options.SeasonNumber); return; } @@ -91,10 +91,10 @@ namespace NzbDrone.Core.Jobs //Start AfterRename - var message = String.Format("Renamed: Series {0}, Season: {1}", series.Title, secondaryTargetId); + var message = String.Format("Renamed: Series {0}, Season: {1}", series.Title, options.SeasonNumber); _externalNotificationProvider.AfterRename(message, series); - notification.CurrentMessage = String.Format("Rename completed for {0} Season {1}", series.Title, secondaryTargetId); + notification.CurrentMessage = String.Format("Rename completed for {0} Season {1}", series.Title, options.SeasonNumber); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/RenameSeriesJob.cs b/NzbDrone.Core/Jobs/RenameSeriesJob.cs index 622acf5cc..171ccf363 100644 --- a/NzbDrone.Core/Jobs/RenameSeriesJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeriesJob.cs @@ -41,18 +41,18 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { List seriesToRename; - if (targetId <= 0) + if (options == null || options.SeriesId <= 0) { seriesToRename = _seriesProvider.GetAllSeries().ToList(); } else { - seriesToRename = new List{ _seriesProvider.GetSeries(targetId) }; + seriesToRename = new List{ _seriesProvider.GetSeries(options.SeriesId) }; } foreach(var series in seriesToRename) diff --git a/NzbDrone.Core/Jobs/RssSyncJob.cs b/NzbDrone.Core/Jobs/RssSyncJob.cs index 66703cdac..f8d4c4460 100644 --- a/NzbDrone.Core/Jobs/RssSyncJob.cs +++ b/NzbDrone.Core/Jobs/RssSyncJob.cs @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromMinutes(25); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { var reports = new List(); diff --git a/NzbDrone.Core/Jobs/SearchHistoryCleanupJob.cs b/NzbDrone.Core/Jobs/SearchHistoryCleanupJob.cs index 1da3d2796..797afb7aa 100644 --- a/NzbDrone.Core/Jobs/SearchHistoryCleanupJob.cs +++ b/NzbDrone.Core/Jobs/SearchHistoryCleanupJob.cs @@ -36,7 +36,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromHours(24); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { Logger.Info("Running search history cleanup."); _searchHistoryProvider.Cleanup(); diff --git a/NzbDrone.Core/Jobs/SeasonSearchJob.cs b/NzbDrone.Core/Jobs/SeasonSearchJob.cs index ddde3e265..9354a08ed 100644 --- a/NzbDrone.Core/Jobs/SeasonSearchJob.cs +++ b/NzbDrone.Core/Jobs/SeasonSearchJob.cs @@ -1,8 +1,10 @@ using System; +using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; +using NzbDrone.Core.Repository; namespace NzbDrone.Core.Jobs { @@ -37,27 +39,27 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { - if (targetId <= 0) - throw new ArgumentOutOfRangeException("targetId"); + if (options == null || options.SeriesId <= 0) + throw new ArgumentException("options"); - if (secondaryTargetId < 0) - throw new ArgumentOutOfRangeException("secondaryTargetId"); + if (options.SeasonNumber < 0) + throw new ArgumentException("options.SeasonNumber"); //Perform a Partial Season Search - Because a full season search is a waste //3 searches should guarentee results, (24 eps) versus, a potential 4 to get the same eps. - var successes = _searchProvider.PartialSeasonSearch(notification, targetId, secondaryTargetId); + List successes = _searchProvider.PartialSeasonSearch(notification, options.SeriesId, options.SeasonNumber); if (successes.Count == 0) return; - Logger.Debug("Getting episodes from database for series: {0} and season: {1}", targetId, secondaryTargetId); - var episodes = _episodeProvider.GetEpisodesBySeason(targetId, secondaryTargetId); + Logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber); + List episodes = _episodeProvider.GetEpisodesBySeason(options.SeriesId, options.SeasonNumber); if (episodes == null || episodes.Count == 0) { - Logger.Warn("No episodes in database found for series: {0} and season: {1}.", targetId, secondaryTargetId); + Logger.Warn("No episodes in database found for series: {0} and season: {1}.", options.SeriesId, options.SeasonNumber); return; } @@ -68,7 +70,7 @@ namespace NzbDrone.Core.Jobs foreach (var episode in episodes.Where(e => !e.Ignored && missingEpisodes.Contains(e.EpisodeNumber)).OrderBy(o => o.EpisodeNumber)) { - _episodeSearchJob.Start(notification, episode.EpisodeId, 0); + _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId }); } } } diff --git a/NzbDrone.Core/Jobs/SeriesSearchJob.cs b/NzbDrone.Core/Jobs/SeriesSearchJob.cs index d14195fda..53bd5b52e 100644 --- a/NzbDrone.Core/Jobs/SeriesSearchJob.cs +++ b/NzbDrone.Core/Jobs/SeriesSearchJob.cs @@ -1,8 +1,10 @@ using System; +using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; +using NzbDrone.Core.Repository; namespace NzbDrone.Core.Jobs { @@ -30,19 +32,19 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromTicks(0); } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public void Start(ProgressNotification notification, dynamic options) { - if (targetId <= 0) - throw new ArgumentOutOfRangeException("targetId"); + if (options == null || options.SeriesId <= 0) + throw new ArgumentException("options.SeriesId"); - logger.Debug("Getting seasons from database for series: {0}", targetId); - var seasons = _seasonProvider.GetSeasons(targetId).Where(s => s > 0); + logger.Debug("Getting seasons from database for series: {0}", options.SeriesId); + IList seasons = _seasonProvider.GetSeasons(options.SeriesId); - foreach (var season in seasons) + foreach (var season in seasons.Where(s => s > 0)) { - if (!_seasonProvider.IsIgnored(targetId, season)) + if (!_seasonProvider.IsIgnored(options.SeriesId, season)) { - _seasonSearchJob.Start(notification, targetId, season); + _seasonSearchJob.Start(notification, new { SeriesId = options.SeriesId, SeasonNumber = season }); } } } diff --git a/NzbDrone.Core/Jobs/TrimLogsJob.cs b/NzbDrone.Core/Jobs/TrimLogsJob.cs index cee44292f..146e243dc 100644 --- a/NzbDrone.Core/Jobs/TrimLogsJob.cs +++ b/NzbDrone.Core/Jobs/TrimLogsJob.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromDays(1); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { _logProvider.Trim(); } diff --git a/NzbDrone.Core/Jobs/UpdateInfoJob.cs b/NzbDrone.Core/Jobs/UpdateInfoJob.cs index db6033b11..269879608 100644 --- a/NzbDrone.Core/Jobs/UpdateInfoJob.cs +++ b/NzbDrone.Core/Jobs/UpdateInfoJob.cs @@ -41,16 +41,16 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromHours(12); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { IList seriesToUpdate; - if (targetId == 0) + if (options == null || options.SeriesId == 0) { seriesToUpdate = _seriesProvider.GetAllSeries().OrderBy(o => SortHelper.SkipArticles(o.Title)).ToList(); } else { - seriesToUpdate = new List { _seriesProvider.GetSeries(targetId) }; + seriesToUpdate = new List { _seriesProvider.GetSeries(options.SeriesId) }; } //Update any Daily Series in the DB with the IsDaily flag diff --git a/NzbDrone.Core/Jobs/UpdateSceneMappingsJob.cs b/NzbDrone.Core/Jobs/UpdateSceneMappingsJob.cs index 67267ed01..85acc6329 100644 --- a/NzbDrone.Core/Jobs/UpdateSceneMappingsJob.cs +++ b/NzbDrone.Core/Jobs/UpdateSceneMappingsJob.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Jobs get { return TimeSpan.FromHours(12); } } - public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, dynamic options) { _sceneNameMappingProvider.UpdateMappings(); } diff --git a/NzbDrone.Core/Model/JobQueueItem.cs b/NzbDrone.Core/Model/JobQueueItem.cs index f8332d801..69f562e9d 100644 --- a/NzbDrone.Core/Model/JobQueueItem.cs +++ b/NzbDrone.Core/Model/JobQueueItem.cs @@ -5,20 +5,18 @@ namespace NzbDrone.Core.Model public class JobQueueItem : IEquatable { public Type JobType { get; set; } - public int TargetId { get; set; } - public int SecondaryTargetId { get; set; } + public dynamic Options { get; set; } public JobSourceType Source { get; set; } public bool Equals(JobQueueItem other) { - return (JobType == other.JobType && TargetId == other.TargetId - && SecondaryTargetId == other.SecondaryTargetId); + return (JobType == other.JobType && Options == other.Options); } public override string ToString() { - return string.Format("[{0}({1}, {2})]", JobType.Name, TargetId, SecondaryTargetId); + return string.Format("[{0}({1})]", JobType.Name, Options); } public enum JobSourceType diff --git a/NzbDrone.Web/Controllers/EpisodeController.cs b/NzbDrone.Web/Controllers/EpisodeController.cs index 86a7c3771..b0b6988e2 100644 --- a/NzbDrone.Web/Controllers/EpisodeController.cs +++ b/NzbDrone.Web/Controllers/EpisodeController.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Web.Controllers public JsonResult SearchSeason(int seriesId, int seasonNumber) { - _jobProvider.QueueJob(typeof(SeasonSearchJob), seriesId, seasonNumber); + _jobProvider.QueueJob(typeof(SeasonSearchJob), new { SeriesId = seriesId, SeasonNumber = seasonNumber }); return JsonNotificationResult.Queued("Season search"); } @@ -40,7 +40,7 @@ namespace NzbDrone.Web.Controllers public JsonResult RenameSeason(int seriesId, int seasonNumber) { - _jobProvider.QueueJob(typeof(RenameSeasonJob), seriesId, seasonNumber); + _jobProvider.QueueJob(typeof(RenameSeasonJob), new { SeriesId = seriesId, SeasonNumber = seasonNumber }); return JsonNotificationResult.Queued("Season rename"); } diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index e18e7ef4d..d062502a0 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -80,7 +80,7 @@ namespace NzbDrone.Web.Controllers [HttpPost] public EmptyResult DeleteSeries(int seriesId, bool deleteFiles) { - _jobProvider.QueueJob(typeof(DeleteSeriesJob), seriesId, Convert.ToInt32(deleteFiles)); + _jobProvider.QueueJob(typeof(DeleteSeriesJob), new { SeriesId = seriesId, DeleteFiles = deleteFiles }); return new EmptyResult(); } diff --git a/NzbDrone.Web/Controllers/SystemController.cs b/NzbDrone.Web/Controllers/SystemController.cs index f58fa99ae..796fcda2c 100644 --- a/NzbDrone.Web/Controllers/SystemController.cs +++ b/NzbDrone.Web/Controllers/SystemController.cs @@ -41,8 +41,7 @@ namespace NzbDrone.Web.Controllers var queue = _jobProvider.Queue.Select(c => new JobQueueItemModel { Name = c.JobType.Name, - TargetId = c.TargetId, - SecondaryTargetId = c.SecondaryTargetId + Options = c.Options }); var serializedQueue = new JavaScriptSerializer().Serialize(queue); diff --git a/NzbDrone.Web/Models/JobQueueItemModel.cs b/NzbDrone.Web/Models/JobQueueItemModel.cs index ad93a0fed..590dcaf6d 100644 --- a/NzbDrone.Web/Models/JobQueueItemModel.cs +++ b/NzbDrone.Web/Models/JobQueueItemModel.cs @@ -7,7 +7,6 @@ namespace NzbDrone.Web.Models public class JobQueueItemModel { public string Name { get; set; } - public int TargetId { get; set; } - public int SecondaryTargetId { get; set; } + public dynamic Options { get; set; } } } \ No newline at end of file From aa282fbd4d2e4c9e227bc0032a32ef333ed1fc32 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 10 Sep 2012 23:35:25 -0700 Subject: [PATCH 2/5] Fixed up tests --- .../NzbDrone.Common.Test.csproj | 1 + NzbDrone.Common.Test/ReflectionExtensions.cs | 15 ++++++ .../JobTests/BacklogSearchJobTest.cs | 53 +++++-------------- .../JobTests/BannerDownloadJobTest.cs | 2 +- .../JobTests/ImportNewSeriesJobTest.cs | 36 ++++++------- .../JobTests/RecentBacklogSearchJobTest.cs | 5 +- NzbDrone.Core.Test/JobTests/SearchJobTest.cs | 9 ++-- .../JobTests/SeriesSearchJobTest.cs | 5 +- NzbDrone.Core.Test/Properties/AssemblyInfo.cs | 5 +- NzbDrone.Core/Properties/AssemblyInfo.cs | 1 + .../NzbDrone.Test.Common.csproj | 1 + NzbDrone.Test.Common/ReflectionExtensions.cs | 15 ++++++ NzbDrone.Web/Properties/AssemblyInfo.cs | 5 +- 13 files changed, 81 insertions(+), 72 deletions(-) create mode 100644 NzbDrone.Common.Test/ReflectionExtensions.cs create mode 100644 NzbDrone.Test.Common/ReflectionExtensions.cs diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index a0c96e899..f24ba68be 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -61,6 +61,7 @@ + diff --git a/NzbDrone.Common.Test/ReflectionExtensions.cs b/NzbDrone.Common.Test/ReflectionExtensions.cs new file mode 100644 index 000000000..c5aee4d5e --- /dev/null +++ b/NzbDrone.Common.Test/ReflectionExtensions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Common.Test +{ + public static class ReflectionExtensions + { + public static T GetPropertyValue(this object obj, string propertyName) + { + return (T)obj.GetType().GetProperty(propertyName).GetValue(obj, null); + } + } +} diff --git a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs index 17fd588b0..7362c71d3 100644 --- a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs @@ -12,6 +12,7 @@ using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test.JobTests @@ -65,23 +66,19 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.Series = series) .Build(); - WithStrictMocker(); WithEnableBacklogSearching(); Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock() - .Setup(s => s.Start(notification, new { EpisodeId = 1 })); + .Setup(s => s.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") == 1))); //Act Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), - Times.Never()); - - Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), Times.Once()); } @@ -101,23 +98,16 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.Series = series) .Build(); - WithStrictMocker(); WithEnableBacklogSearching(); Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() - .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny()})).Verifiable(); - //Act Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), - Times.Never()); - - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = 0 }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), Times.Exactly(episodes.Count)); } @@ -138,15 +128,11 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.SeasonNumber = 1) .Build(); - WithStrictMocker(); WithEnableBacklogSearching(); Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() - .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny() })).Verifiable(); - Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); @@ -154,11 +140,8 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), - Times.Never()); - - Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), - Times.Exactly(episodes.Count)); + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), + Times.Exactly(episodes.Count)); } [Test] @@ -179,15 +162,11 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.SeasonNumber = 1) .Build(); - WithStrictMocker(); WithEnableBacklogSearching(); Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() - .Setup(s => s.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() })).Verifiable(); - Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList()); @@ -195,11 +174,9 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0 && + d.GetPropertyValue("SeasonNumber") >= 0)), Times.Once()); - - Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), - Times.Never()); } [Test] @@ -227,18 +204,11 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.Series = series2) .Build(); - WithStrictMocker(); WithEnableBacklogSearching(); Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() - .Setup(s => s.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() })).Verifiable(); - - Mocker.GetMock() - .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny() })).Verifiable(); - Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5 }); @@ -246,11 +216,12 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0 && + d.GetPropertyValue("SeasonNumber") >= 0)), Times.Once()); - Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), - Times.Exactly(5)); + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), + Times.Exactly(5)); } [Test] diff --git a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs index 88b746c8a..768d187be 100644 --- a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock().Setup(s => s.GetSeries(series.SeriesId)) .Returns(series); - Mocker.Resolve().Start(_notification, new { SeriesId = 0 }); + Mocker.Resolve().Start(_notification, new { SeriesId = series.SeriesId }); VerifyDownloadMock(1); } } diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index 8b5aa8e4a..46110a053 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.JobTests public class ImportNewSeriesJobTest : CoreTest { [Test] - public void import_new_series_succesfull() + public void import_new_series_succesful() { var series = Builder.CreateListOfSize(2) .All().With(s => s.LastInfoSync = null) @@ -39,23 +39,23 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0})) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))) .Callback(() => series[0].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId))) .Callback(() => series[1].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = 0 })); + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0))); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))) .Callback(() => series[0].LastInfoSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId))) .Callback(() => series[1].LastInfoSync = DateTime.Now); Mocker.GetMock() @@ -71,11 +71,11 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId)), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId)), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId)), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId)), Times.Once()); } @@ -101,19 +101,19 @@ namespace NzbDrone.Core.Test.JobTests .Returns(series); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))) .Callback(() => series[0].LastInfoSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId))) .Throws(new InvalidOperationException()); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))) .Callback(() => series[0].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })); + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))); Mocker.GetMock() .Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]); @@ -125,12 +125,10 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId)), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId)), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); - - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0}), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId)), Times.Once()); ExceptionVerification.ExpectedErrors(1); diff --git a/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs index 329d2840c..5a9a814bf 100644 --- a/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs @@ -13,6 +13,7 @@ using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test.JobTests @@ -87,13 +88,13 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock().Setup(c => c.Start(It.IsAny(), new { EpisodeId = It.IsAny() })); + Mocker.GetMock().Setup(c => c.Start(It.IsAny(), It.Is(d => d.GetPropertyValue("EpisodeId") >= 0))); //Act Mocker.Resolve().Start(MockNotification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(It.IsAny(), new { EpisodeId = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(It.IsAny(), It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), Times.Exactly(40)); } diff --git a/NzbDrone.Core.Test/JobTests/SearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SearchJobTest.cs index 5ca459f08..e3c6a5a52 100644 --- a/NzbDrone.Core.Test/JobTests/SearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SearchJobTest.cs @@ -15,21 +15,20 @@ namespace NzbDrone.Core.Test.JobTests [TestCase(0)] [TestCase(-1)] [TestCase(-100)] - [ExpectedException(typeof(ArgumentOutOfRangeException))] + [ExpectedException(typeof(ArgumentException))] public void start_target_id_less_than_0_throws_exception(int target) { WithStrictMocker(); - //Mocker.Resolve().Start(new ProgressNotification("Test"), target, 0); + Mocker.Resolve().Start(new ProgressNotification("Test"), new { EpisodeId = target }); } - [TestCase(0)] [TestCase(-1)] [TestCase(-100)] - [ExpectedException(typeof(ArgumentOutOfRangeException))] + [ExpectedException(typeof(ArgumentException))] public void start_secondary_target_id_less_than_0_throws_exception(int target) { WithStrictMocker(); - //Mocker.Resolve().Start(new ProgressNotification("Test"), 0, target); + Mocker.Resolve().Start(new ProgressNotification("Test"), new { SeriesId = 1, SeasonNumber = target }); } } } diff --git a/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs index 6236f497e..8dc9069b3 100644 --- a/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs @@ -6,6 +6,7 @@ using NzbDrone.Core.Jobs; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test.JobTests @@ -30,14 +31,14 @@ namespace NzbDrone.Core.Test.JobTests .Setup(c => c.IsIgnored(It.IsAny(), It.IsAny())).Returns(false); Mocker.GetMock() - .Setup(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny() })).Verifiable(); + .Setup(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == 1 && d.GetPropertyValue("SeasonNumber") >= 0))).Verifiable(); //Act Mocker.Resolve().Start(notification, new { SeriesId = 1 }); //Assert Mocker.VerifyAllMocks(); - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == 1 && d.GetPropertyValue("SeasonNumber") >= 0)), Times.Exactly(seasons.Count)); } diff --git a/NzbDrone.Core.Test/Properties/AssemblyInfo.cs b/NzbDrone.Core.Test/Properties/AssemblyInfo.cs index b3fff6ebe..15b5d7b1f 100644 --- a/NzbDrone.Core.Test/Properties/AssemblyInfo.cs +++ b/NzbDrone.Core.Test/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -36,4 +37,6 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.0")] + +[assembly: InternalsVisibleTo("NzbDrone.Core")] \ No newline at end of file diff --git a/NzbDrone.Core/Properties/AssemblyInfo.cs b/NzbDrone.Core/Properties/AssemblyInfo.cs index 9c41cc91f..0445cde9a 100644 --- a/NzbDrone.Core/Properties/AssemblyInfo.cs +++ b/NzbDrone.Core/Properties/AssemblyInfo.cs @@ -12,6 +12,7 @@ using System.Runtime.InteropServices; [assembly: Guid("3C29FEF7-4B07-49ED-822E-1C29DC49BFAB")] [assembly: InternalsVisibleTo("NzbDrone.Core.Test")] +[assembly: InternalsVisibleTo("NzbDrone.Web")] // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: diff --git a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj index 61264ae1d..d9f881b96 100644 --- a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj +++ b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj @@ -69,6 +69,7 @@ + diff --git a/NzbDrone.Test.Common/ReflectionExtensions.cs b/NzbDrone.Test.Common/ReflectionExtensions.cs new file mode 100644 index 000000000..4b32830e2 --- /dev/null +++ b/NzbDrone.Test.Common/ReflectionExtensions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Test.Common +{ + public static class ReflectionExtensions + { + public static T GetPropertyValue(this object obj, string propertyName) + { + return (T)obj.GetType().GetProperty(propertyName).GetValue(obj, null); + } + } +} diff --git a/NzbDrone.Web/Properties/AssemblyInfo.cs b/NzbDrone.Web/Properties/AssemblyInfo.cs index f638cd457..9f3959149 100644 --- a/NzbDrone.Web/Properties/AssemblyInfo.cs +++ b/NzbDrone.Web/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("NzbDrone.Web")] @@ -10,4 +11,6 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.0.*")] -[assembly: AssemblyFileVersion("1.0.0.*")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.*")] + +[assembly: InternalsVisibleTo("NzbDrone.Core")] \ No newline at end of file From 89d22f2eb9acb15c1c489bc9b8c17c1ef58c076e Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 10 Sep 2012 23:46:56 -0700 Subject: [PATCH 3/5] Updated jobs view --- NzbDrone.Web/Views/System/Jobs.cshtml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/NzbDrone.Web/Views/System/Jobs.cshtml b/NzbDrone.Web/Views/System/Jobs.cshtml index e21a6d74e..9fb9a20cb 100644 --- a/NzbDrone.Web/Views/System/Jobs.cshtml +++ b/NzbDrone.Web/Views/System/Jobs.cshtml @@ -31,8 +31,7 @@ Type - Target - Secondary + Options @@ -92,8 +91,7 @@ "sPaginationType": "four_button", "aoColumns": [ { sWidth: 'auto', "mDataProp": "Type"}, //Type - { sWidth: '100px', "mDataProp": "Target" }, //Target - { sWidth: '100px', "mDataProp": "SecondaryTarget" }, //SecondaryTarget + { sWidth: '100px', "mDataProp": "Options" } //Options ] }); }); From a1029b11dd1eb577f9a792e52013e04a315317ed Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 11 Sep 2012 22:52:25 -0700 Subject: [PATCH 4/5] Renamed DeleteSeries to Delete --- NzbDrone.Web/Controllers/SeriesController.cs | 2 +- NzbDrone.Web/Scripts/NzbDrone/series.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index d062502a0..55304a9b6 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -78,7 +78,7 @@ namespace NzbDrone.Web.Controllers } [HttpPost] - public EmptyResult DeleteSeries(int seriesId, bool deleteFiles) + public EmptyResult Delete(int seriesId, bool deleteFiles) { _jobProvider.QueueJob(typeof(DeleteSeriesJob), new { SeriesId = seriesId, DeleteFiles = deleteFiles }); diff --git a/NzbDrone.Web/Scripts/NzbDrone/series.js b/NzbDrone.Web/Scripts/NzbDrone/series.js index c630adf50..b8b40b300 100644 --- a/NzbDrone.Web/Scripts/NzbDrone/series.js +++ b/NzbDrone.Web/Scripts/NzbDrone/series.js @@ -1,6 +1,6 @@ var seriesEditorUrl = '../Series/SingleSeriesEditor'; var saveSeriesEditorUrl = '../Series/SaveSingleSeriesEditor'; -var seriesDeleteUrl = '../Series/DeleteSeries'; +var seriesDeleteUrl = '../Series/Delete'; $("#seriesEditor").dialog({ autoOpen: false, From cb0f1fe513ef7129f46244c0ccb47eaa513b49f8 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 22 Sep 2012 23:01:31 -0700 Subject: [PATCH 5/5] PostDownloadScanJob can now be passed a path --- .../JobTests/PostDownloadScanJobFixture.cs | 72 +++++++++++++++++++ NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + NzbDrone.Core/Jobs/PostDownloadScanJob.cs | 8 ++- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs diff --git a/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs b/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs new file mode 100644 index 000000000..e754d4d0d --- /dev/null +++ b/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs @@ -0,0 +1,72 @@ +using System.Linq; +using System; +using System.Diagnostics; +using System.IO; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Core.Jobs; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.JobTests +{ + [TestFixture] + internal class PostDownloadScanJobFixture : CoreTest + { + [SetUp] + public void Setup() + { + Mocker.GetMock().Setup(s => s.FolderExists(It.IsAny())).Returns(true); + } + + [Test] + public void should_use_options_Path_when_provided() + { + var path = @"C:\Test\Unsorted TV"; + + Mocker.GetMock().Setup(s => s.ProcessDropFolder(path)); + Mocker.Resolve().Start(MockNotification, new { Path = path }); + + Mocker.GetMock().Verify(s => s.ProcessDropFolder(path), Times.Once()); + } + + [Test] + public void should_not_get_sabDropDir_when_path_is_supplied() + { + var path = @"C:\Test\Unsorted TV"; + + Mocker.GetMock().Setup(s => s.ProcessDropFolder(path)); + Mocker.Resolve().Start(MockNotification, new { Path = path }); + + Mocker.GetMock().Verify(s => s.SabDropDirectory, Times.Never()); + } + + [Test] + public void should_get_sabDropDir_when_path_is_not_supplied() + { + var path = @"C:\Test\Unsorted TV"; + + Mocker.GetMock().SetupGet(s => s.SabDropDirectory).Returns(path); + Mocker.Resolve().Start(MockNotification, null); + + Mocker.GetMock().Verify(s => s.SabDropDirectory, Times.Once()); + } + + [Test] + public void should_use_sabDropDir_when_options_Path_is_not_provided() + { + var path = @"C:\Test\Unsorted TV"; + + Mocker.GetMock().SetupGet(s => s.SabDropDirectory).Returns(path); + Mocker.Resolve().Start(MockNotification, null); + + Mocker.GetMock().Verify(s => s.ProcessDropFolder(path), Times.Once()); + } + } +} diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 7cabc5537..76de94954 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -143,6 +143,7 @@ + diff --git a/NzbDrone.Core/Jobs/PostDownloadScanJob.cs b/NzbDrone.Core/Jobs/PostDownloadScanJob.cs index 6a156b3c0..4ab9b8732 100644 --- a/NzbDrone.Core/Jobs/PostDownloadScanJob.cs +++ b/NzbDrone.Core/Jobs/PostDownloadScanJob.cs @@ -41,7 +41,13 @@ namespace NzbDrone.Core.Jobs public virtual void Start(ProgressNotification notification, dynamic options) { - var dropFolder = _configProvider.SabDropDirectory; + string dropFolder; + + if (options != null && !String.IsNullOrWhiteSpace(options.Path)) + dropFolder = options.Path; + + else + dropFolder = _configProvider.SabDropDirectory; if (String.IsNullOrWhiteSpace(dropFolder)) {