From b5644bf660894a82e78762f42fca89e3b233c2a7 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Tue, 19 Feb 2013 18:05:15 -0800 Subject: [PATCH] moved series/season/episodes to object db. --- NzbDrone.Api/AutomapperBootstraper.cs | 2 +- NzbDrone.Api/Resolvers/NextAiringResolver.cs | 9 +- NzbDrone.Api/Series/SeriesModule.cs | 8 +- .../EnsureThat/EnsureIntExtensions.cs | 9 + .../AcceptableSizeSpecificationFixture.cs | 30 +- .../MonitoredEpisodeSpecificationFixture.cs | 10 +- .../UpgradePossibleSpecificationFixture.cs | 4 +- NzbDrone.Core.Test/EpisodeStatusTest.cs | 16 +- .../JobTests/BacklogSearchJobTest.cs | 24 +- .../JobTests/ImportNewSeriesJobTest.cs | 22 +- .../JobTests/RecentBacklogSearchJobTest.cs | 10 +- .../JobTests/SeasonSearchJobTest.cs | 4 +- .../JobTests/SeriesSearchJobTest.cs | 14 +- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 - .../CleanUpDropFolderFixture.cs | 4 +- .../DiskScanProviderTests/CleanUpFixture.cs | 16 +- .../ImportFileFixture.cs | 50 +- .../MoveEpisodeFileFixture.cs | 6 +- .../DiskScanProviderTests/ScanFixture.cs | 4 +- .../SabProviderTests/QueueFixture.cs | 2 +- .../DownloadProviderFixture.cs | 18 +- .../ProviderTests/HistoryProviderTest.cs | 8 +- .../ProviderTests/MediaFileProviderTest.cs | 2 +- .../CleanUpDatabaseFixture.cs | 1 - .../GetNewFilenameFixture.cs | 6 +- .../Metadata/Xbmc_ForEpisodeFile_Fixture.cs | 4 +- .../ProviderTests/MisnamedProviderTest.cs | 20 +- .../ProcessDownloadFixture.cs | 24 +- .../ProcessDropDirectoryFixture.cs | 4 +- .../ProcessVideoFileFixture.cs | 12 +- .../ReferenceDataProviderTest.cs | 18 +- .../SearchHistoryProviderTest.cs | 2 +- .../SearchTests/ProcessResultsFixture.cs | 8 +- .../ProviderTests/SearchTests/TestSearch.cs | 4 +- .../FindMatchingTvRageSeriesFixture.cs | 2 +- .../EpisodeProviderTest.cs | 198 ++++---- ...isodeProviderTest_DeleteInvalidEpisodes.cs | 12 +- ...deProviderTest_GetEpisodesByParseResult.cs | 30 +- .../GetEpisodeBySceneNumberFixture.cs | 8 +- .../TvTests/SeasonProviderTest.cs | 62 +-- .../TvTests/SeriesProviderTest.cs | Bin 35625 -> 3392 bytes NzbDrone.Core.Test/dbBenchmark.cs | 244 --------- NzbDrone.Core/Datastore/BasicRepository.cs | 12 + .../PetaPoco/EpisodeSeasonRelator.cs | 2 +- .../AcceptableSizeSpecification.cs | 8 +- .../MonitoredEpisodeSpecification.cs | 12 +- .../UpgradeHistorySpecification.cs | 6 +- .../Instrumentation/LogInjectionModule.cs | 3 +- NzbDrone.Core/Jobs/BacklogSearchJob.cs | 14 +- NzbDrone.Core/Jobs/BannerDownloadJob.cs | 12 +- NzbDrone.Core/Jobs/ConvertEpisodeJob.cs | 8 +- NzbDrone.Core/Jobs/DeleteSeriesJob.cs | 12 +- NzbDrone.Core/Jobs/DiskScanJob.cs | 16 +- NzbDrone.Core/Jobs/EpisodeSearchJob.cs | 10 +- NzbDrone.Core/Jobs/ImportNewSeriesJob.cs | 28 +- NzbDrone.Core/Jobs/JobRepository.cs | 2 +- .../Jobs/PastWeekBacklogSearchJob.cs | 10 +- NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs | 14 +- NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs | 14 +- NzbDrone.Core/Jobs/RenameSeasonJob.cs | 6 +- NzbDrone.Core/Jobs/RenameSeriesJob.cs | 6 +- NzbDrone.Core/Jobs/SeasonSearchJob.cs | 14 +- NzbDrone.Core/Jobs/SeriesSearchJob.cs | 11 +- NzbDrone.Core/Jobs/UpdateInfoJob.cs | 14 +- NzbDrone.Core/NzbDrone.Core.csproj | 6 +- NzbDrone.Core/Providers/DiskScanProvider.cs | 50 +- .../DownloadClients/NzbgetProvider.cs | 3 +- .../Providers/DownloadClients/SabProvider.cs | 3 +- NzbDrone.Core/Providers/DownloadProvider.cs | 14 +- NzbDrone.Core/Providers/MediaFileProvider.cs | 10 +- .../Providers/Metadata/MetadataBase.cs | 6 +- NzbDrone.Core/Providers/Metadata/Xbmc.cs | 6 +- NzbDrone.Core/Providers/MisnamedProvider.cs | 8 +- .../Providers/PostDownloadProvider.cs | 10 +- .../Providers/Search/DailyEpisodeSearch.cs | 4 +- .../Providers/Search/EpisodeSearch.cs | 4 +- .../Providers/Search/PartialSeasonSearch.cs | 4 +- NzbDrone.Core/Providers/Search/SearchBase.cs | 20 +- .../Providers/SearchHistoryProvider.cs | 14 +- NzbDrone.Core/Providers/SearchProvider.cs | 18 +- .../Providers/TvRageMappingProvider.cs | 8 +- NzbDrone.Core/Providers/XemProvider.cs | 14 +- .../RootFolders/RootFolderService.cs | 6 +- NzbDrone.Core/Tv/Episode.cs | 25 +- NzbDrone.Core/Tv/EpisodeProvider.cs | 476 ------------------ ...SeasonProvider.cs => EpisodeRepository.cs} | Bin 7023 -> 6489 bytes NzbDrone.Core/Tv/EpisodeService.cs | 360 +++++++++++++ NzbDrone.Core/Tv/Season.cs | 5 +- NzbDrone.Core/Tv/SeasonRepository.cs | 49 ++ NzbDrone.Core/Tv/SeasonService.cs | Bin 0 -> 4916 bytes NzbDrone.Core/Tv/Series.cs | 12 +- NzbDrone.Core/Tv/SeriesProvider.cs | 58 ++- NzbDrone.Core/Tv/SeriesRepository.cs | 4 +- 93 files changed, 1025 insertions(+), 1338 deletions(-) delete mode 100644 NzbDrone.Core.Test/dbBenchmark.cs delete mode 100644 NzbDrone.Core/Tv/EpisodeProvider.cs rename NzbDrone.Core/Tv/{SeasonProvider.cs => EpisodeRepository.cs} (58%) create mode 100644 NzbDrone.Core/Tv/EpisodeService.cs create mode 100644 NzbDrone.Core/Tv/SeasonRepository.cs create mode 100644 NzbDrone.Core/Tv/SeasonService.cs diff --git a/NzbDrone.Api/AutomapperBootstraper.cs b/NzbDrone.Api/AutomapperBootstraper.cs index 52d5ce4f1..7fcec8128 100644 --- a/NzbDrone.Api/AutomapperBootstraper.cs +++ b/NzbDrone.Api/AutomapperBootstraper.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Api .ForMember(dest => dest.QualityTypeId, opt => opt.MapFrom(src => src.Id)); //Series - Mapper.CreateMap() + Mapper.CreateMap() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.SeriesId)) .ForMember(dest => dest.CustomStartDate, opt => opt.ResolveUsing().FromMember(src => src.CustomStartDate)) .ForMember(dest => dest.BacklogSetting, opt => opt.MapFrom(src => (Int32)src.BacklogSetting)) diff --git a/NzbDrone.Api/Resolvers/NextAiringResolver.cs b/NzbDrone.Api/Resolvers/NextAiringResolver.cs index 4459f5b91..a159b8239 100644 --- a/NzbDrone.Api/Resolvers/NextAiringResolver.cs +++ b/NzbDrone.Api/Resolvers/NextAiringResolver.cs @@ -1,17 +1,14 @@ using System; -using System.Collections.Generic; using System.Linq; using AutoMapper; -using NzbDrone.Api.QualityProfiles; -using NzbDrone.Core.Repository.Quality; namespace NzbDrone.Api.Resolvers { - public class NextAiringResolver : ValueResolver + public class NextAiringResolver : ValueResolver { - protected override DateTime? ResolveCore(Core.Episodes.Series source) + protected override DateTime? ResolveCore(Core.Tv.Series source) { - if(String.IsNullOrWhiteSpace(source.AirTime) || !source.NextAiring.HasValue) + if (String.IsNullOrWhiteSpace(source.AirTime) || !source.NextAiring.HasValue) return source.NextAiring; return source.NextAiring.Value.Add(Convert.ToDateTime(source.AirTime).TimeOfDay) diff --git a/NzbDrone.Api/Series/SeriesModule.cs b/NzbDrone.Api/Series/SeriesModule.cs index 6adb1189c..2f9bb9fb1 100644 --- a/NzbDrone.Api/Series/SeriesModule.cs +++ b/NzbDrone.Api/Series/SeriesModule.cs @@ -15,14 +15,14 @@ namespace NzbDrone.Api.Series { public class SeriesModule : NzbDroneApiModule { - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly ISeriesRepository _seriesRepository; private readonly JobController _jobProvider; - public SeriesModule(SeriesProvider seriesProvider,ISeriesRepository seriesRepository, JobController jobProvider) + public SeriesModule(ISeriesService seriesService,ISeriesRepository seriesRepository, JobController jobProvider) : base("/Series") { - _seriesProvider = seriesProvider; + _seriesService = seriesService; _seriesRepository = seriesRepository; _jobProvider = jobProvider; Get["/"] = x => AllSeries(); @@ -58,7 +58,7 @@ namespace NzbDrone.Api.Series //(we can just create the folder and it won't blow up if it already exists) //We also need to remove any special characters from the filename before attempting to create it - _seriesProvider.AddSeries("", request.Path, request.SeriesId, request.QualityProfileId, null); + _seriesService.AddSeries("", request.Path, request.SeriesId, request.QualityProfileId, null); _jobProvider.QueueJob(typeof(ImportNewSeriesJob)); return new Response { StatusCode = HttpStatusCode.Created }; diff --git a/NzbDrone.Common/EnsureThat/EnsureIntExtensions.cs b/NzbDrone.Common/EnsureThat/EnsureIntExtensions.cs index 154921611..39d3dea58 100644 --- a/NzbDrone.Common/EnsureThat/EnsureIntExtensions.cs +++ b/NzbDrone.Common/EnsureThat/EnsureIntExtensions.cs @@ -32,6 +32,15 @@ namespace NzbDrone.Common.EnsureThat return param; } + [DebuggerStepThrough] + public static Param IsGreaterThanZero(this Param param) + { + if (param.Value <= 0) + throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotGt.Inject(param.Value, 0)); + + return param; + } + [DebuggerStepThrough] public static Param IsGreaterOrEqualTo(this Param param, int limit) { diff --git a/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs index 01bf501ab..16a7bcd9c 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs @@ -80,7 +80,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(false); @@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(false); @@ -122,7 +122,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(false); @@ -143,7 +143,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(false); @@ -164,7 +164,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(false); @@ -185,7 +185,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(false); @@ -206,7 +206,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(false); @@ -227,7 +227,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(false); @@ -248,7 +248,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(true); @@ -269,7 +269,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(true); @@ -290,7 +290,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(true); @@ -311,7 +311,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(true); @@ -333,7 +333,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(true); @@ -355,7 +355,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(true); @@ -378,7 +378,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Mocker.GetMock().Setup(s => s.Get(1)).Returns(qualityType); - Mocker.GetMock().Setup( + Mocker.GetMock().Setup( s => s.IsFirstOrLastEpisodeOfSeason(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(true); diff --git a/NzbDrone.Core.Test/DecisionEngineTests/MonitoredEpisodeSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/MonitoredEpisodeSpecificationFixture.cs index 51226ce60..cb5183a33 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/MonitoredEpisodeSpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/MonitoredEpisodeSpecificationFixture.cs @@ -59,11 +59,11 @@ namespace NzbDrone.Core.Test.DecisionEngineTests var singleEpisodeList = new List { firstEpisode }; var doubleEpisodeList = new List { firstEpisode, secondEpisode }; - Mocker.GetMock().Setup(c => c.GetEpisodesByParseResult(parseResultSingle)).Returns(singleEpisodeList); - Mocker.GetMock().Setup(c => c.GetEpisodesByParseResult(parseResultMulti)).Returns(doubleEpisodeList); + Mocker.GetMock().Setup(c => c.GetEpisodesByParseResult(parseResultSingle)).Returns(singleEpisodeList); + Mocker.GetMock().Setup(c => c.GetEpisodesByParseResult(parseResultMulti)).Returns(doubleEpisodeList); - Mocker.GetMock().Setup(c => c.Get(parseResultMulti.CleanTitle)).Returns(fakeSeries); - Mocker.GetMock().Setup(c => c.Get(parseResultSingle.CleanTitle)).Returns(fakeSeries); + Mocker.GetMock().Setup(c => c.GetByTitle(parseResultMulti.CleanTitle)).Returns(fakeSeries); + Mocker.GetMock().Setup(c => c.GetByTitle(parseResultSingle.CleanTitle)).Returns(fakeSeries); } private void WithFirstEpisodeIgnored() @@ -96,7 +96,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests public void not_in_db_should_be_skipped() { Mocker.GetMock() - .Setup(p => p.Get(It.IsAny())) + .Setup(p => p.GetByTitle(It.IsAny())) .Returns(null); monitoredEpisodeSpecification.IsSatisfiedBy(parseResultMulti).Should().BeFalse(); diff --git a/NzbDrone.Core.Test/DecisionEngineTests/UpgradePossibleSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/UpgradePossibleSpecificationFixture.cs index 724e331a3..92cedd7f5 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/UpgradePossibleSpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/UpgradePossibleSpecificationFixture.cs @@ -39,10 +39,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests .Build(); _episode = Builder.CreateNew() - .With(e => e.EpisodeFileId = 0) .With(e => e.SeriesId = _series.SeriesId) .With(e => e.Series = _series) - .With(e => e.EpisodeFileId = _episodeFile.EpisodeFileId) .With(e => e.EpisodeFile = _episodeFile) .Build(); } @@ -51,7 +49,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests public void IsUpgradePossible_should_return_true_if_no_episode_file_exists() { var episode = Builder.CreateNew() - .With(e => e.EpisodeFileId = 0) + .With(e => e.EpisodeFile = null) .Build(); //Act diff --git a/NzbDrone.Core.Test/EpisodeStatusTest.cs b/NzbDrone.Core.Test/EpisodeStatusTest.cs index 2a815b648..33e333e01 100644 --- a/NzbDrone.Core.Test/EpisodeStatusTest.cs +++ b/NzbDrone.Core.Test/EpisodeStatusTest.cs @@ -23,13 +23,12 @@ namespace NzbDrone.Core.Test Episode episode = Builder.CreateNew() .With(e => e.AirDate = DateTime.Now.AddDays(offsetDays)) .With(e => e.Ignored = ignored) - .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = null) .Build(); if (hasEpisodes) { - episode.EpisodeFileId = 12; + episode.EpisodeFile = new EpisodeFile(); } Assert.AreEqual(status, episode.Status); @@ -43,14 +42,13 @@ namespace NzbDrone.Core.Test { Episode episode = Builder.CreateNew() .With(e => e.Ignored = ignored) - .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = DateTime.Now.AddDays(-2).AddHours(-1)) .With(e => e.AirDate = DateTime.Today.AddDays(-2)) .Build(); if (hasEpisodes) { - episode.EpisodeFileId = 12; + episode.EpisodeFile = new EpisodeFile(); } episode.Status.Should().Be(status); @@ -67,13 +65,12 @@ namespace NzbDrone.Core.Test Episode episode = Builder.CreateNew() .With(e => e.AirDate = DateTime.Now.AddDays(offsetDays)) .With(e => e.Ignored = ignored) - .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = DateTime.Now.AddHours(22)) .Build(); if (hasEpisodes) { - episode.EpisodeFileId = 12; + episode.EpisodeFile = new EpisodeFile(); } Assert.AreEqual(status, episode.Status); @@ -85,13 +82,12 @@ namespace NzbDrone.Core.Test Episode episode = Builder.CreateNew() .With(e => e.AirDate = DateTime.Now.AddDays(offsetDays)) .With(e => e.Ignored = ignored) - .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = null) .Build(); if (hasEpisodes) { - episode.EpisodeFileId = 12; + episode.EpisodeFile = new EpisodeFile(); } Assert.AreEqual(status, episode.Status); @@ -103,7 +99,6 @@ namespace NzbDrone.Core.Test Episode episode = Builder.CreateNew() .With(e => e.AirDate = DateTime.Now.AddDays(20)) .With(e => e.Ignored = false) - .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = null) .Build(); @@ -120,14 +115,13 @@ namespace NzbDrone.Core.Test { Episode episode = Builder.CreateNew() .With(e => e.Ignored = ignored) - .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = DateTime.Now.AddHours(22)) .With(e => e.PostDownloadStatus = postDownloadStatus) .Build(); if (hasEpisodes) { - episode.EpisodeFileId = 12; + episode.EpisodeFile = new EpisodeFile(); } Assert.AreEqual(status, episode.Status); diff --git a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs index 981603408..f743a1a83 100644 --- a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test.JobTests WithStrictMocker(); WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act @@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock() @@ -99,7 +99,7 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act @@ -129,10 +129,10 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); //Act @@ -163,10 +163,10 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList()); //Act @@ -205,10 +205,10 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5 }); //Act @@ -246,7 +246,7 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act @@ -285,7 +285,7 @@ namespace NzbDrone.Core.Test.JobTests //WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act @@ -325,7 +325,7 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index c5e8c3ce9..073124949 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -152,14 +152,14 @@ namespace NzbDrone.Core.Test.JobTests .Setup(p => p.GetSeriesFiles(seriesId)) .Returns(new List()); - Mocker.GetMock() - .Setup(p => p.GetSeasons(seriesId)) + Mocker.GetMock() + .Setup(p => p.GetSeasonNumbers(seriesId)) .Returns(new List { 0, 1, 2, 3, 4 }); Mocker.Resolve().AutoIgnoreSeasons(seriesId); - Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, It.IsAny(), It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, It.IsAny(), It.IsAny()), Times.Never()); } [Test] @@ -180,13 +180,13 @@ namespace NzbDrone.Core.Test.JobTests .Setup(p => p.GetSeriesFiles(seriesId)) .Returns(episodesFiles); - Mocker.GetMock() - .Setup(p => p.GetSeasons(seriesId)) + Mocker.GetMock() + .Setup(p => p.GetSeasonNumbers(seriesId)) .Returns(new List { 0, 1, 2 }); Mocker.Resolve().AutoIgnoreSeasons(seriesId); - Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny()), Times.Never()); } [Test] @@ -206,15 +206,15 @@ namespace NzbDrone.Core.Test.JobTests .Setup(p => p.GetSeriesFiles(seriesId)) .Returns(episodesFiles); - Mocker.GetMock() - .Setup(p => p.GetSeasons(seriesId)) + Mocker.GetMock() + .Setup(p => p.GetSeasonNumbers(seriesId)) .Returns(new List { 0, 1, 2 }); Mocker.Resolve().AutoIgnoreSeasons(seriesId); - Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 0, true), Times.Once()); - Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 1, true), Times.Never()); - Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 0, true), Times.Once()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 1, true), Times.Never()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny()), Times.Never()); } } diff --git a/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs index d6421ac02..d3c21adc4 100644 --- a/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Core.Test.JobTests //Setup var episodes = new List(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act @@ -86,7 +86,7 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.AirDate = DateTime.Today.AddDays(-35)) .Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock().Setup(c => c.Start(It.IsAny(), It.Is(d => d.GetPropertyValue("EpisodeId") >= 0))); @@ -122,7 +122,7 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act @@ -161,7 +161,7 @@ namespace NzbDrone.Core.Test.JobTests //WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act @@ -201,7 +201,7 @@ namespace NzbDrone.Core.Test.JobTests WithEnableBacklogSearching(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act diff --git a/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs index 41f0e54cb..0ac909d70 100644 --- a/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.AirDate = DateTime.Today.AddDays(-1)) .Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(_episodes); } @@ -92,7 +92,7 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.AirDate = DateTime.Today.AddDays(2)) .Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes); Mocker.GetMock() diff --git a/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs index d7841271a..c3a4ced3d 100644 --- a/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs @@ -25,10 +25,10 @@ namespace NzbDrone.Core.Test.JobTests var notification = new ProgressNotification("Series Search"); - Mocker.GetMock() - .Setup(c => c.GetSeasons(1)).Returns(seasons); + Mocker.GetMock() + .Setup(c => c.GetSeasonNumbers(1)).Returns(seasons); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.IsIgnored(It.IsAny(), It.IsAny())).Returns(false); Mocker.GetMock() @@ -52,8 +52,8 @@ namespace NzbDrone.Core.Test.JobTests var notification = new ProgressNotification("Series Search"); - Mocker.GetMock() - .Setup(c => c.GetSeasons(1)).Returns(seasons); + Mocker.GetMock() + .Setup(c => c.GetSeasonNumbers(1)).Returns(seasons); //Act Mocker.Resolve().Start(notification, new { SeriesId = 1 }); @@ -67,8 +67,8 @@ namespace NzbDrone.Core.Test.JobTests [Test] public void SeriesSearch_should_not_search_for_season_0() { - Mocker.GetMock() - .Setup(c => c.GetSeasons(It.IsAny())) + Mocker.GetMock() + .Setup(c => c.GetSeasonNumbers(It.IsAny())) .Returns(new List { 0, 1, 2 }); Mocker.Resolve().Start(MockNotification, new { SeriesId = 12 }); diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 19920a8ef..a51792ca9 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -236,7 +236,6 @@ - diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs index 2b04690bb..3be624d2e 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs @@ -88,7 +88,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests var episode = Builder.CreateListOfSize(1) .All() .With(e => e.SeriesId = seriesId) - .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId) + .With(e => e.EpisodeFile = episodeFile) .Build(); Mocker.GetMock().Setup(v => v.GetFileByPath(filename)) @@ -103,7 +103,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock().Setup(s => s.Get(It.IsAny())) .Returns(series); - Mocker.GetMock().Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId)) + Mocker.GetMock().Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId)) .Returns(episode); Mocker.GetMock().Setup(s => s.GetNewFilename(It.IsAny>(), series, QualityTypes.Unknown, false, It.IsAny())) diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs index 2342ae46e..a624b544e 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs @@ -49,7 +49,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(e => e.FileExists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByFileId(It.IsAny())) .Returns(new List()); @@ -63,7 +63,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests //Assert Mocker.VerifyAllMocks(); - Mocker.GetMock() + Mocker.GetMock() .Verify(e => e.GetEpisodesByFileId(It.IsAny()), Times.Exactly(10)); Mocker.GetMock() @@ -80,11 +80,11 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(e => e.FileExists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByFileId(It.IsAny())) - .Returns(new List { new Episode { EpisodeFileId = 10 }, new Episode { EpisodeFileId = 10 } }); + .Returns(new List { new Episode { EpisodeFile = new EpisodeFile { EpisodeFileId = 10 } }, new Episode { EpisodeFile = new EpisodeFile { EpisodeFileId = 10 } } }); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.UpdateEpisode(It.IsAny())); Mocker.GetMock() @@ -100,11 +100,11 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests //Assert Mocker.VerifyAllMocks(); - Mocker.GetMock() + Mocker.GetMock() .Verify(e => e.GetEpisodesByFileId(It.IsAny()), Times.Exactly(10)); - Mocker.GetMock() - .Verify(e => e.UpdateEpisode(It.Is(g=>g.EpisodeFileId == 0)), Times.Exactly(20)); + Mocker.GetMock() + .Verify(e => e.UpdateEpisode(It.Is(g => g.EpisodeFileId == 0)), Times.Exactly(20)); Mocker.GetMock() .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10)); diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs index f4a2bb0b0..bf6d88002 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs @@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests { _series = Builder .CreateNew() - .With(s => s.IsDaily = false) + .With(s => s.SeriesType = SeriesType.Standard) .Build(); } @@ -49,7 +49,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests public void WithDailySeries() { - _series.IsDaily = true; + _series.SeriesType = SeriesType.Daily; } [Test] @@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(p => p.Exists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode }); //Act @@ -94,7 +94,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests With80MBFile(); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode }); //Act @@ -124,7 +124,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(p => p.Exists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode }); //Act @@ -194,7 +194,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(p => p.Exists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetEpisodesByParseResult(It.IsAny())) .Returns(new List()); @@ -225,7 +225,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(p => p.Exists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode }); //Act @@ -257,7 +257,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(p => p.Exists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(fakeEpisodes); //Act @@ -290,7 +290,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(p => p.Exists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(fakeEpisodes); //Act @@ -328,7 +328,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(p => p.Exists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode1, fakeEpisode2 }); //Act @@ -348,8 +348,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeEpisode = Builder.CreateNew() - .With(e => e.EpisodeFileId = 0) - .With(e => e.EpisodeFile = null) .Build(); //Mocks @@ -359,7 +357,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(p => p.Exists(It.IsAny())) .Returns(false); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode}); //Act @@ -382,7 +380,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests With80MBFile(); - Mocker.GetMock().Setup(s => s.GetEpisodesByParseResult(It.IsAny())) + Mocker.GetMock().Setup(s => s.GetEpisodesByParseResult(It.IsAny())) .Returns(new List()); Mocker.GetMock().Setup(s => s.IsChildOfPath(path, series.Path)) @@ -390,7 +388,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.Resolve().ImportFile(series, path); - Mocker.Verify(s => s.GetEpisodesByParseResult(It.Is(p => p.SceneSource)), Times.Once()); + Mocker.Verify(s => s.GetEpisodesByParseResult(It.Is(p => p.SceneSource)), Times.Once()); } [Test] @@ -405,7 +403,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests With80MBFile(); - Mocker.GetMock().Setup(s => s.GetEpisodesByParseResult(It.IsAny())) + Mocker.GetMock().Setup(s => s.GetEpisodesByParseResult(It.IsAny())) .Returns(new List()); Mocker.GetMock().Setup(s => s.IsChildOfPath(path, series.Path)) @@ -413,7 +411,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.Resolve().ImportFile(series, path); - Mocker.Verify(s => s.GetEpisodesByParseResult(It.Is(p => p.SceneSource == false)), Times.Once()); + Mocker.Verify(s => s.GetEpisodesByParseResult(It.Is(p => p.SceneSource == false)), Times.Once()); } [Test] @@ -440,8 +438,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests public void should_import_if_file_size_is_under_70MB_but_runTime_over_3_minutes() { var fakeEpisode = Builder.CreateNew() - .With(e => e.EpisodeFileId = 0) - .With(e => e.EpisodeFile = null) .Build(); const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi"; @@ -458,7 +454,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(s => s.GetRunTime(path)) .Returns(600); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode }); var result = Mocker.Resolve().ImportFile(_series, path); @@ -473,8 +469,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests With80MBFile(); var fakeEpisode = Builder.CreateNew() - .With(e => e.EpisodeFileId = 0) - .With(e => e.EpisodeFile = null) .Build(); const string path = @"C:\Test\TV\30.rock.s01e01.pilot.avi"; @@ -487,7 +481,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(s => s.GetRunTime(path)) .Returns(60); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode }); var result = Mocker.Resolve().ImportFile(_series, path); @@ -502,8 +496,6 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests With80MBFile(); var fakeEpisode = Builder.CreateNew() - .With(e => e.EpisodeFileId = 0) - .With(e => e.EpisodeFile = null) .Build(); const string path = @"C:\Test\TV\30.rock.s00e01.pre-pilot.avi"; @@ -520,7 +512,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(s => s.GetRunTime(path)) .Returns(60); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByParseResult(It.IsAny())).Returns(new List { fakeEpisode }); var result = Mocker.Resolve().ImportFile(_series, path); @@ -560,16 +552,16 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock().Verify(p => p.Add(It.IsAny()), Times.Once()); //Get the count of episodes linked - var count = Mocker.GetMock().Object.GetEpisodesByParseResult(null).Count; + var count = Mocker.GetMock().Object.GetEpisodesByParseResult(null).Count; - Mocker.GetMock().Verify(p => p.UpdateEpisode(It.Is(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count)); + Mocker.GetMock().Verify(p => p.UpdateEpisode(It.Is(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count)); } private static void VerifySkipImport(EpisodeFile result, AutoMoqer Mocker) { result.Should().BeNull(); Mocker.GetMock().Verify(p => p.Add(It.IsAny()), Times.Never()); - Mocker.GetMock().Verify(p => p.UpdateEpisode(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.UpdateEpisode(It.IsAny()), Times.Never()); Mocker.GetMock().Verify(p => p.DeleteFile(It.IsAny()), Times.Never()); } } diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs index 29cac26c7..75e0ec1e3 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs @@ -50,7 +50,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(e => e.Get(fakeSeries.SeriesId)) .Returns(fakeSeries); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId)) .Returns(fakeEpisode); @@ -100,7 +100,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(e => e.Get(fakeSeries.SeriesId)) .Returns(fakeSeries); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId)) .Returns(fakeEpisode); @@ -163,7 +163,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(e => e.Get(fakeSeries.SeriesId)) .Returns(fakeSeries); - Mocker.GetMock() + Mocker.GetMock() .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId)) .Returns(fakeEpisode); diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs index dbcfe873b..9407f84d3 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs @@ -22,8 +22,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Mocker.GetMock() .Setup(c => c.Update(It.Is(s => s.LastDiskSync != null))).Verifiable(); - Mocker.GetMock() - .Setup(c => c.GetEpisodeBySeries(It.IsAny())) + Mocker.GetMock() + .Setup(c => c.GetEpisodeBySeries(It.IsAny())) .Returns(new List { new Episode() }); Mocker.GetMock() diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs index da6660802..aae6fb704 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs @@ -148,7 +148,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests { Quality = new QualityModel { Quality = QualityTypes.Bluray720p, Proper = false }, AirDate = new DateTime(2011, 12, 01), - Series = new Series { Title = "The Dailyshow", CleanTitle = Parser.NormalizeTitle("The Dailyshow"), IsDaily = true }, + Series = new Series { Title = "The Dailyshow", CleanTitle = Parser.NormalizeTitle("The Dailyshow"), SeriesType = SeriesType.Daily }, }; diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/DownloadProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/DownloadProviderFixture.cs index c2da04329..d441db880 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/DownloadProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/DownloadProviderFixture.cs @@ -41,12 +41,12 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests private EpisodeParseResult SetupParseResult() { var episodes = Builder.CreateListOfSize(2) - .TheFirst(1).With(s => s.EpisodeId = 12) - .TheNext(1).With(s => s.EpisodeId = 99) + .TheFirst(1).With(s => s.OID = 12) + .TheNext(1).With(s => s.OID = 99) .All().With(s => s.SeriesId = 5) .Build().ToList(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetEpisodesByParseResult(It.IsAny())).Returns(episodes); return Builder.CreateNew() @@ -104,10 +104,10 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests Mocker.GetMock() .Verify(s => s.Add(It.Is(h => h.EpisodeId == 99 && h.SeriesId == 5)), Times.Once()); - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.MarkEpisodeAsFetched(12)); - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.MarkEpisodeAsFetched(99)); Mocker.GetMock() @@ -139,10 +139,10 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests Mocker.GetMock() .Verify(s => s.Add(It.Is(h => h.EpisodeId == 99 && h.SeriesId == 5)), Times.Once()); - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.MarkEpisodeAsFetched(12)); - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.MarkEpisodeAsFetched(99)); Mocker.GetMock() @@ -165,7 +165,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests .Verify(s => s.Add(It.IsAny()), Times.Never()); - Mocker.GetMock() + Mocker.GetMock() .Verify(c => c.MarkEpisodeAsFetched(It.IsAny()), Times.Never()); Mocker.GetMock() @@ -242,7 +242,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests public string create_proper_sab_daily_titles(bool proper) { var series = Builder.CreateNew() - .With(c => c.IsDaily = true) + .With(c => c.SeriesType = SeriesType.Daily) .With(c => c.Title = "My Series Name") .Build(); diff --git a/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs index d011ab81b..4e6457355 100644 --- a/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/HistoryProviderTest.cs @@ -135,7 +135,7 @@ namespace NzbDrone.Core.Test.ProviderTests var history = Builder.CreateNew() .With(h => h.Quality = QualityTypes.Bluray720p) .With(h => h.IsProper = true) - .With(h => h.EpisodeId = historyEpisode.EpisodeId) + .With(h => h.EpisodeId = historyEpisode.OID) .Build(); Db.Insert(history); @@ -162,7 +162,7 @@ namespace NzbDrone.Core.Test.ProviderTests var history = Builder .CreateListOfSize(5) .All() - .With(h => h.EpisodeId = historyEpisode.EpisodeId) + .With(h => h.EpisodeId = historyEpisode.OID) .With(h => h.SeriesId = historyEpisode.SeriesId) .TheFirst(1) .With(h => h.Quality = QualityTypes.DVD) @@ -205,7 +205,7 @@ namespace NzbDrone.Core.Test.ProviderTests var history = Builder .CreateListOfSize(5) .All() - .With(h => h.EpisodeId = historyEpisode.EpisodeId) + .With(h => h.EpisodeId = historyEpisode.OID) .With(h => h.SeriesId = historyEpisode.SeriesId) .TheFirst(1) .With(h => h.Quality = QualityTypes.DVD) @@ -250,7 +250,7 @@ namespace NzbDrone.Core.Test.ProviderTests var history = new History { Date = DateTime.Now, - EpisodeId = episode.EpisodeId, + EpisodeId = episode.OID, SeriesId = episode.SeriesId, NzbTitle = "my title", Indexer = "Fake Indexer", diff --git a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTest.cs index ef5a71367..c85e2409b 100644 --- a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTest.cs @@ -83,7 +83,7 @@ namespace NzbDrone.Core.Test.ProviderTests { WithStrictMocker(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetEpisodeBySeries(12)) .Returns(new List()); diff --git a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs index 888ea370d..9e54e4865 100644 --- a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/CleanUpDatabaseFixture.cs @@ -96,7 +96,6 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests .All().With(c => c.GrabDate = DateTime.Now) .And(c => c.Ignored = false) .And(c => c.PostDownloadStatus = PostDownloadStatusType.NoError) - .And(c => c.EpisodeFileId = 0) .Build(); Db.InsertMany(episodes); diff --git a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs index 2db8ef181..3a2ca17c1 100644 --- a/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/MediaFileProviderTests/GetNewFilenameFixture.cs @@ -765,7 +765,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests var series = Builder .CreateNew() - .With(s => s.IsDaily = true) + .With(s => s.SeriesType = SeriesType.Daily) .With(s => s.Title = "The Daily Show with Jon Stewart") .Build(); @@ -794,7 +794,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests var series = Builder .CreateNew() - .With(s => s.IsDaily = true) + .With(s => s.SeriesType = SeriesType.Daily) .With(s => s.Title = "The Daily Show with Jon Stewart") .Build(); @@ -823,7 +823,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests var series = Builder .CreateNew() - .With(s => s.IsDaily = true) + .With(s => s.SeriesType = SeriesType.Daily) .With(s => s.Title = "The Daily Show with Jon Stewart") .Build(); diff --git a/NzbDrone.Core.Test/ProviderTests/Metadata/Xbmc_ForEpisodeFile_Fixture.cs b/NzbDrone.Core.Test/ProviderTests/Metadata/Xbmc_ForEpisodeFile_Fixture.cs index b408e3c83..53514b2cf 100644 --- a/NzbDrone.Core.Test/ProviderTests/Metadata/Xbmc_ForEpisodeFile_Fixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/Metadata/Xbmc_ForEpisodeFile_Fixture.cs @@ -104,7 +104,7 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata .With(e => e.EpisodeNumber = 1) .Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId)) .Returns(new List { episode }); } @@ -117,7 +117,7 @@ namespace NzbDrone.Core.Test.ProviderTests.Metadata .With(e => e.SeasonNumber = 1) .Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId)) .Returns(episodes.ToList()); } diff --git a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs index 8227d6eed..057692518 100644 --- a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs @@ -37,16 +37,14 @@ namespace NzbDrone.Core.Test.ProviderTests .All() .With(e => e.Series = series) .TheFirst(1) - .With(e => e.EpisodeFileId = 1) .With(e => e.EpisodeFile = episodeFiles[0]) .TheNext(1) - .With(e => e.EpisodeFileId = 2) .With(e => e.EpisodeFile = episodeFiles[1]) .Build(); WithStrictMocker(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() @@ -86,16 +84,14 @@ namespace NzbDrone.Core.Test.ProviderTests .All() .With(e => e.Series = series) .TheFirst(1) - .With(e => e.EpisodeFileId = 1) .With(e => e.EpisodeFile = episodeFiles[0]) .TheNext(1) - .With(e => e.EpisodeFileId = 2) .With(e => e.EpisodeFile = episodeFiles[1]) .Build(); WithStrictMocker(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() @@ -135,16 +131,14 @@ namespace NzbDrone.Core.Test.ProviderTests .All() .With(e => e.Series = series) .TheFirst(1) - .With(e => e.EpisodeFileId = 1) .With(e => e.EpisodeFile = episodeFiles[0]) .TheNext(1) - .With(e => e.EpisodeFileId = 2) .With(e => e.EpisodeFile = episodeFiles[1]) .Build(); WithStrictMocker(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() @@ -186,16 +180,14 @@ namespace NzbDrone.Core.Test.ProviderTests .All() .With(e => e.Series = series) .TheFirst(2) - .With(e => e.EpisodeFileId = 1) .With(e => e.EpisodeFile = episodeFiles[0]) .TheNext(1) - .With(e => e.EpisodeFileId = 2) .With(e => e.EpisodeFile = episodeFiles[1]) .Build(); WithStrictMocker(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() @@ -237,16 +229,14 @@ namespace NzbDrone.Core.Test.ProviderTests .All() .With(e => e.Series = series) .TheFirst(2) - .With(e => e.EpisodeFileId = 1) .With(e => e.EpisodeFile = episodeFiles[0]) .TheNext(1) - .With(e => e.EpisodeFileId = 2) .With(e => e.EpisodeFile = episodeFiles[1]) .Build(); WithStrictMocker(); - Mocker.GetMock() + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); Mocker.GetMock() diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs index 725513f84..70b591abb 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs @@ -48,7 +48,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests private void WithValidSeries() { Mocker.GetMock() - .Setup(c => c.Get(It.IsAny())) + .Setup(c => c.GetByTitle(It.IsAny())) .Returns(fakeSeries); Mocker.GetMock() @@ -99,7 +99,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests droppedFolder.Create(); //Act - Mocker.GetMock().Setup(s => s.Get(It.IsAny())).Returns(null).Verifiable(); + Mocker.GetMock().Setup(s => s.GetByTitle(It.IsAny())).Returns(null).Verifiable(); Mocker.Resolve().ProcessDownload(droppedFolder); //Assert @@ -115,7 +115,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\_unpack_The Office - S01E01 - Episode Title"); - Mocker.GetMock().Setup(s => s.Get("office")).Returns(null).Verifiable(); + Mocker.GetMock().Setup(s => s.GetByTitle("office")).Returns(null).Verifiable(); //Act Mocker.Resolve().ProcessDownload(droppedFolder); @@ -167,7 +167,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests var taggedFolder = @"C:\Test\Unsorted TV\_UnknownSeries_The Office - S01E01 - Episode Title"; //Act - Mocker.GetMock().Setup(s => s.Get("office")).Returns(null); + Mocker.GetMock().Setup(s => s.GetByTitle("office")).Returns(null); Mocker.GetMock().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder)); Mocker.Resolve().ProcessDownload(droppedFolder); @@ -193,7 +193,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Build(); //Act - Mocker.GetMock().Setup(s => s.Get("office")).Returns(fakeSeries); + Mocker.GetMock().Setup(s => s.GetByTitle("office")).Returns(fakeSeries); Mocker.GetMock().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(new List()); Mocker.GetMock().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder)); Mocker.GetMock().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes()); @@ -228,7 +228,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Build().ToList(); //Act - Mocker.GetMock().Setup(s => s.Get("office")).Returns(fakeSeries); + Mocker.GetMock().Setup(s => s.GetByTitle("office")).Returns(fakeSeries); Mocker.GetMock().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder)); Mocker.GetMock().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes()); Mocker.GetMock().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles); @@ -254,7 +254,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests WithOldWrite(); //Act - Mocker.GetMock().Setup(s => s.Get(It.IsAny())).Returns(null); + Mocker.GetMock().Setup(s => s.GetByTitle(It.IsAny())).Returns(null); Mocker.Resolve().ProcessDownload(droppedFolder); //Assert @@ -273,7 +273,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests var taggedFolder = TempFolder + @"\_UnknownSeries_The Office - S01E01 - Episode Title"; - Mocker.GetMock().Setup(s => s.Get(It.IsAny())).Returns(null); + Mocker.GetMock().Setup(s => s.GetByTitle(It.IsAny())).Returns(null); //Act Mocker.Resolve().ProcessDownload(droppedFolder); @@ -295,7 +295,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests WithImportedFiles(droppedFolder.FullName); - Mocker.GetMock().Setup(s => s.Get("office")).Returns(fakeSeries); + Mocker.GetMock().Setup(s => s.GetByTitle("office")).Returns(fakeSeries); Mocker.GetMock().Setup(s => s.CleanUpDropFolder(droppedFolder.FullName)); Mocker.GetMock().Setup(s => s.MoveEpisodeFile(It.IsAny(), true)).Returns(new EpisodeFile()); Mocker.GetMock().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes()); @@ -322,7 +322,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests var fakeEpisodeFiles = Builder.CreateListOfSize(2) .Build().ToList(); - Mocker.GetMock().Setup(s => s.Get(It.IsAny())).Returns(fakeSeries); + Mocker.GetMock().Setup(s => s.GetByTitle(It.IsAny())).Returns(fakeSeries); Mocker.GetMock().Setup(s => s.FolderExists(fakeSeries.Path)).Returns(true); Mocker.GetMock().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles); @@ -346,7 +346,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Build(); Mocker.GetMock() - .Setup(c => c.Get("rock")) + .Setup(c => c.GetByTitle("rock")) .Returns(series); Mocker.GetMock() @@ -381,7 +381,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests WithImportedFiles(downloadName.FullName); Mocker.GetMock() - .Setup(c => c.Get("rock")) + .Setup(c => c.GetByTitle("rock")) .Returns(fakeSeries); Mocker.GetMock() diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs index 383729efc..1cf32ce8a 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs @@ -62,7 +62,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Returns(true); Mocker.GetMock() - .Setup(c => c.Get(It.IsAny())) + .Setup(c => c.GetByTitle(It.IsAny())) .Returns(fakeSeries); Mocker.GetMock() @@ -105,7 +105,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Returns(files); Mocker.GetMock() - .Setup(c => c.Get(It.IsAny())) + .Setup(c => c.GetByTitle(It.IsAny())) .Returns(fakeSeries); Mocker.GetMock() diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs index b11a869fa..a7ccf8eb8 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs @@ -48,7 +48,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests private void WithValidSeries() { Mocker.GetMock() - .Setup(c => c.Get(It.IsAny())) + .Setup(c => c.GetByTitle(It.IsAny())) .Returns(fakeSeries); Mocker.GetMock() @@ -96,11 +96,11 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests var file = Path.Combine(TempFolder, "test.avi"); //Act - Mocker.GetMock().Setup(s => s.Get(It.IsAny())).Returns(null).Verifiable(); + Mocker.GetMock().Setup(s => s.GetByTitle(It.IsAny())).Returns(null).Verifiable(); Mocker.Resolve().ProcessVideoFile(file); //Assert - Mocker.GetMock().Verify(s => s.Get(It.IsAny()), Times.Once()); + Mocker.GetMock().Verify(s => s.GetByTitle(It.IsAny()), Times.Once()); ExceptionVerification.IgnoreWarns(); } @@ -112,7 +112,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests var file = Path.Combine(TempFolder, "test.avi"); //Act - Mocker.GetMock().Setup(s => s.Get(It.IsAny())).Returns(null); + Mocker.GetMock().Setup(s => s.GetByTitle(It.IsAny())).Returns(null); Mocker.Resolve().ProcessVideoFile(file); //Assert @@ -150,7 +150,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Build(); Mocker.GetMock() - .Setup(c => c.Get("rock")) + .Setup(c => c.GetByTitle("rock")) .Returns(series); Mocker.GetMock() @@ -183,7 +183,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests var downloadName = @"C:\Test\Drop\30.Rock.S01E01.Pilot.mkv"; Mocker.GetMock() - .Setup(c => c.Get("rock")) + .Setup(c => c.GetByTitle("rock")) .Returns(fakeSeries); Mocker.GetMock() diff --git a/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs index c69362b13..644addfac 100644 --- a/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs @@ -111,7 +111,7 @@ namespace NzbDrone.Core.Test.ProviderTests var fakeSeries = Builder.CreateListOfSize(5) .All() - .With(s => s.IsDaily = false) + .With(s => s.SeriesType = SeriesType.Standard) .Build(); Db.InsertMany(fakeSeries); @@ -126,7 +126,7 @@ namespace NzbDrone.Core.Test.ProviderTests //Assert var result = Db.Fetch(); - result.Where(s => s.IsDaily).Should().HaveCount(5); + result.Where(s => s.SeriesType == SeriesType.Daily).Should().HaveCount(5); } [Test] @@ -136,7 +136,7 @@ namespace NzbDrone.Core.Test.ProviderTests var fakeSeries = Builder.CreateListOfSize(5) .All() - .With(s => s.IsDaily = false) + .With(s => s.SeriesType = SeriesType.Standard) .TheFirst(1) .With(s => s.SeriesId = 10) .TheNext(1) @@ -157,8 +157,8 @@ namespace NzbDrone.Core.Test.ProviderTests //Assert var result = Db.Fetch(); - result.Where(s => !s.IsDaily).Should().HaveCount(3); - result.Where(s => s.IsDaily).Should().HaveCount(2); + result.Where(s => s.SeriesType == SeriesType.Standard).Should().HaveCount(3); + result.Where(s => s.SeriesType == SeriesType.Daily).Should().HaveCount(2); } [Test] @@ -168,10 +168,10 @@ namespace NzbDrone.Core.Test.ProviderTests var fakeSeries = Builder.CreateListOfSize(5) .All() - .With(s => s.IsDaily = false) + .With(s => s.SeriesType = SeriesType.Standard) .TheFirst(1) .With(s => s.SeriesId = 10) - .With(s => s.IsDaily = true) + .With(s => s.SeriesType = SeriesType.Daily) .TheNext(1) .With(s => s.SeriesId = 11) .TheNext(1) @@ -190,8 +190,8 @@ namespace NzbDrone.Core.Test.ProviderTests //Assert var result = Db.Fetch(); - result.Where(s => s.IsDaily).Should().HaveCount(3); - result.Where(s => !s.IsDaily).Should().HaveCount(2); + result.Where(s => s.SeriesType == SeriesType.Daily).Should().HaveCount(3); + result.Where(s => s.SeriesType == SeriesType.Standard).Should().HaveCount(2); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/SearchHistoryProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SearchHistoryProviderTest.cs index 33b4d5014..85e7cff13 100644 --- a/NzbDrone.Core.Test/ProviderTests/SearchHistoryProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SearchHistoryProviderTest.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.ProviderTests .Build().ToList(); _searchHistory = Builder.CreateNew() - .With(h => h.EpisodeId = _episode.EpisodeId) + .With(h => h.EpisodeId = _episode.OID) .With(h => h.SeriesId - _series.SeriesId) .With(h => h.SearchHistoryItems = items) .Build(); diff --git a/NzbDrone.Core.Test/ProviderTests/SearchTests/ProcessResultsFixture.cs b/NzbDrone.Core.Test/ProviderTests/SearchTests/ProcessResultsFixture.cs index 029f0e58b..332c4c8d7 100644 --- a/NzbDrone.Core.Test/ProviderTests/SearchTests/ProcessResultsFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/SearchTests/ProcessResultsFixture.cs @@ -51,7 +51,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests .CreateListOfSize(1) .Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetEpisodesByParseResult(It.IsAny())) .Returns(_episodes); } @@ -59,19 +59,19 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests private void WithMatchingSeries() { Mocker.GetMock() - .Setup(s => s.Get(It.IsAny())).Returns(_matchingSeries); + .Setup(s => s.GetByTitle(It.IsAny())).Returns(_matchingSeries); } private void WithMisMatchedSeries() { Mocker.GetMock() - .Setup(s => s.Get(It.IsAny())).Returns(_mismatchedSeries); + .Setup(s => s.GetByTitle(It.IsAny())).Returns(_mismatchedSeries); } private void WithNullSeries() { Mocker.GetMock() - .Setup(s => s.Get(It.IsAny())).Returns(_nullSeries); + .Setup(s => s.GetByTitle(It.IsAny())).Returns(_nullSeries); } private void WithSuccessfulDownload() diff --git a/NzbDrone.Core.Test/ProviderTests/SearchTests/TestSearch.cs b/NzbDrone.Core.Test/ProviderTests/SearchTests/TestSearch.cs index 428dd6408..2ed66672a 100644 --- a/NzbDrone.Core.Test/ProviderTests/SearchTests/TestSearch.cs +++ b/NzbDrone.Core.Test/ProviderTests/SearchTests/TestSearch.cs @@ -17,10 +17,10 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests { private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public TestSearch(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, DownloadProvider downloadProvider, + public TestSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerProvider indexerProvider, SceneMappingProvider sceneMappingProvider, AllowedDownloadSpecification allowedDownloadSpecification, SearchHistoryProvider searchHistoryProvider,ISeriesRepository seriesRepository) - : base(seriesProvider, seriesRepository, episodeProvider, downloadProvider, indexerProvider, sceneMappingProvider, + : base(seriesService, seriesRepository, episodeService, downloadProvider, indexerProvider, sceneMappingProvider, allowedDownloadSpecification, searchHistoryProvider) { } diff --git a/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/FindMatchingTvRageSeriesFixture.cs b/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/FindMatchingTvRageSeriesFixture.cs index 5ef6e7dfd..e67ea7607 100644 --- a/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/FindMatchingTvRageSeriesFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvRageMappingProviderTests/FindMatchingTvRageSeriesFixture.cs @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test.ProviderTests.TvRageMappingProviderTests .With(s => s.UtcOffset = -8) .Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.GetEpisode(_series.SeriesId, 1, 1)) .Returns(_episode); diff --git a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest.cs b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest.cs index 487d452ed..42b7a2b14 100644 --- a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest.cs @@ -29,13 +29,13 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).With(e => e.EpisodeFileId = 0).Build(); + .All().With(e => e.SeriesId = 1).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); //Act - var episode = Mocker.Resolve().GetEpisode(1); + var episode = Mocker.Resolve().GetEpisode(1); //Assert episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); @@ -53,14 +53,13 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeEpisodes = Builder.CreateNew() .With(e => e.SeriesId = 1) .With(e => e.EpisodeNumber = 1) - .And(e => e.SeasonNumber = 2) - .With(e => e.EpisodeFileId = 0).Build(); + .And(e => e.SeasonNumber = 2).Build(); Db.Insert(fakeSeries); Db.Insert(fakeEpisodes); //Act - var episode = Mocker.Resolve().GetEpisode(fakeSeries.SeriesId, 2, 1); + var episode = Mocker.Resolve().GetEpisode(fakeSeries.SeriesId, 2, 1); //Assert episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes); @@ -73,7 +72,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests WithRealDb(); //Act - var episode = Mocker.Resolve().GetEpisode(1, 1, 1); + var episode = Mocker.Resolve().GetEpisode(1, 1, 1); //Assert episode.Should().BeNull(); @@ -87,14 +86,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.SDTV).Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); Db.Insert(fakeFile); //Act - var episode = Mocker.Resolve().GetEpisode(1); + var episode = Mocker.Resolve().GetEpisode(1); //Assert episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); @@ -108,7 +107,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests { WithRealDb(); - Mocker.Resolve(); + Mocker.Resolve(); var fakeEpisodes = Builder.CreateListOfSize(5) .All().With(e => e.SeriesId = 1).Build(); @@ -118,9 +117,9 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests //Act - Mocker.Resolve().GetEpisode(1); + Mocker.Resolve().GetEpisode(1); } - + [Test] public void GetEpisodesBySeason_success() { @@ -139,7 +138,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.InsertMany(episodes); //Act - var seasonEposodes = Mocker.Resolve().GetEpisodesBySeason(12, 2); + var seasonEposodes = Mocker.Resolve().GetEpisodesBySeason(12, 2); //Assert Db.Fetch().Should().HaveCount(10); @@ -172,10 +171,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Returns(fakeEpisodes); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var actualCount = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList().Count; + var actualCount = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList().Count; Mocker.GetMock().VerifyAll(); actualCount.Should().Be(episodeCount); } @@ -207,10 +206,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var storedEpisodes = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var storedEpisodes = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); storedEpisodes.Should().HaveCount(10); storedEpisodes.Where(e => e.AirDate == null).Should().HaveCount(7); storedEpisodes.Where(e => e.AirDate != null).Should().HaveCount(3); @@ -247,10 +246,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Returns(fakeTvDbEpisodes); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var storedEpisodes = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var storedEpisodes = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); storedEpisodes.Should().HaveCount(1); storedEpisodes.Where(e => e.AirDate == null).Should().HaveCount(1); } @@ -285,10 +284,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); Mocker.GetMock().VerifyAll(); result.Should().HaveCount(episodeCount); result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue(); @@ -324,10 +323,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); result.Should().HaveCount(episodeCount - 3); result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title) || c.AirDate < DateTime.Now); } @@ -346,7 +345,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .With(e => e.EpisodeName = "Something") .TheFirst(3) .With(e => e.EpisodeName = "") - .With(e => e.FirstAired = new DateTime(1889,1,1)) + .With(e => e.FirstAired = new DateTime(1889, 1, 1)) .Build()) ).With(c => c.Id = seriesId).Build(); @@ -362,10 +361,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); result.Should().HaveCount(episodeCount - 3); result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title) || c.AirDate < DateTime.Now); } @@ -395,10 +394,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); result.Should().HaveSameCount(fakeEpisodes.Episodes); } @@ -428,10 +427,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); result.Should().HaveSameCount(fakeEpisodes.Episodes); } @@ -461,15 +460,15 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Setup(c => c.GetSeries(seriesId, true, false)) .Returns(fakeEpisodes); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.IsIgnored(seriesId, 0)) .Returns(true); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); Mocker.GetMock().VerifyAll(); result.Should().HaveCount(episodeCount); result.Where(e => e.Ignored).Should().HaveCount(episodeCount); @@ -497,7 +496,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert Mocker.GetMock().Verify(c => c.InsertMany(It.Is>(l => l.Count() == 5)), Times.Once()); @@ -531,7 +530,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Returns(currentEpisodes); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert Mocker.GetMock().Verify(c => c.InsertMany(It.Is>(l => l.Count() == 0)), Times.Once()); @@ -564,7 +563,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Returns(fakeTvDbResult); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert Mocker.VerifyAllMocks(); @@ -605,7 +604,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Returns(new List { localEpisode }); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert Mocker.VerifyAllMocks(); @@ -627,13 +626,13 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests { currentEpisodes.Add(new Episode { - TvDbEpisodeId = tvDbEpisode.Id, - EpisodeId = 99, - EpisodeFileId = 69, - Ignored = true, - Series = fakeSeries, - EpisodeNumber = tvDbEpisode.EpisodeNumber, - SeasonNumber = tvDbEpisode.SeasonNumber + TvDbEpisodeId = tvDbEpisode.Id, + OID = 99, + EpisodeFile = new EpisodeFile { EpisodeFileId = 69 }, + Ignored = true, + Series = fakeSeries, + EpisodeNumber = tvDbEpisode.EpisodeNumber, + SeasonNumber = tvDbEpisode.SeasonNumber }); } @@ -652,11 +651,11 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Callback>(ep => updatedEpisodes = ep.ToList()); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert updatedEpisodes.Should().HaveSameCount(tvdbSeries.Episodes); - updatedEpisodes.Should().OnlyContain(c => c.EpisodeId == 99); + updatedEpisodes.Should().OnlyContain(c => c.OID == 99); updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 69); updatedEpisodes.Should().OnlyContain(c => c.Ignored == true); } @@ -677,8 +676,8 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, - EpisodeId = 99, - EpisodeFileId = 69, + OID = 99, + EpisodeFile = new EpisodeFile { EpisodeFileId = 69 }, Ignored = true, Series = fakeSeries, EpisodeNumber = tvDbEpisode.EpisodeNumber + 1, @@ -701,7 +700,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Callback>(ep => updatedEpisodes = ep.ToList()); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 0); @@ -723,8 +722,8 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, - EpisodeId = 99, - EpisodeFileId = 69, + OID = 99, + EpisodeFile = new EpisodeFile { EpisodeFileId = 69 }, Ignored = true, Series = fakeSeries, EpisodeNumber = tvDbEpisode.EpisodeNumber, @@ -747,7 +746,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Callback>(ep => updatedEpisodes = ep.ToList()); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 0); @@ -794,15 +793,15 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Setup(c => c.GetSeries(seriesId, true, false)) .Returns(tvdbSeries); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.IsIgnored(seriesId, It.IsAny())) .Returns(true); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); Mocker.GetMock().VerifyAll(); result.Should().HaveCount(episodeCount); result.Where(e => e.Ignored).Should().HaveCount(episodeCount); @@ -820,15 +819,18 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(Builder.CreateNew().Build()); + var seriesRepo = Mocker.Resolve(); const int tvDbSeriesId = 71256; //act - var seriesProvider = Mocker.Resolve(); + var seriesProvider = Mocker.Resolve(); + + seriesProvider.AddSeries("Test Series", "c:\\test\\", tvDbSeriesId, 1, null); + - seriesProvider.AddSeries("Test Series","c:\\test\\", tvDbSeriesId, 1, null); - var episodeProvider = Mocker.Resolve(); - episodeProvider.RefreshEpisodeInfo(seriesProvider.ge(tvDbSeriesId)); + var episodeProvider = Mocker.Resolve(); + episodeProvider.RefreshEpisodeInfo(seriesRepo.Get(tvDbSeriesId)); //assert var episodes = episodeProvider.GetEpisodeBySeries(tvDbSeriesId); @@ -841,7 +843,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests WithRealDb(); //Act - var episode = Mocker.Resolve().GetEpisode(1, 1, 1); + var episode = Mocker.Resolve().GetEpisode(1, 1, 1); //Assert episode.Should().BeNull(); @@ -855,14 +857,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.SDTV).Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); Db.Insert(fakeFile); //Act - var episode = Mocker.Resolve().GetEpisode(1, 1, 1); + var episode = Mocker.Resolve().GetEpisode(1, 1, 1); //Assert episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); @@ -877,13 +879,13 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 0).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); //Act - var episode = Mocker.Resolve().GetEpisode(1, 1, 1); + var episode = Mocker.Resolve().GetEpisode(1, 1, 1); //Assert episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First()); @@ -899,14 +901,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.SDTV).Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); Db.Insert(fakeFile); //Act - var episode = Mocker.Resolve().GetEpisode(1, fakeEpisodes[0].AirDate.Value); + var episode = Mocker.Resolve().GetEpisode(1, fakeEpisodes[0].AirDate.Value); //Assert episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First()); @@ -921,13 +923,13 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 0).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).Build(); Db.InsertMany(fakeEpisodes); Db.Insert(fakeSeries); //Act - var episode = Mocker.Resolve().GetEpisode(1, fakeEpisodes[0].AirDate.Value); + var episode = Mocker.Resolve().GetEpisode(1, fakeEpisodes[0].AirDate.Value); //Assert episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First()); @@ -947,11 +949,11 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.InsertMany(fakeEpisodes); //Act - Mocker.Resolve().MarkEpisodeAsFetched(2); + Mocker.Resolve().MarkEpisodeAsFetched(2); var episodes = Db.Fetch(); //Assert - episodes.Where(e => e.EpisodeId == 2).Single().GrabDate.Should().BeWithin(TimeSpan.FromSeconds(5)).Before( + episodes.Where(e => e.OID == 2).Single().GrabDate.Should().BeWithin(TimeSpan.FromSeconds(5)).Before( DateTime.Now); episodes.Where(e => e.GrabDate == null).Should().HaveCount(4); @@ -979,12 +981,12 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .With(e => e.Ignored = false) .Build(); - Mocker.GetMock() + Mocker.GetMock() .Setup(s => s.IsIgnored(newEpisode.SeriesId, newEpisode.SeasonNumber)) .Returns(true); //Act - Mocker.Resolve().AddEpisode(newEpisode); + Mocker.Resolve().AddEpisode(newEpisode); //Assert var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); @@ -1018,7 +1020,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Build(); //Act - Mocker.Resolve().AddEpisode(newEpisode); + Mocker.Resolve().AddEpisode(newEpisode); //Assert var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); @@ -1054,7 +1056,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Build(); //Act - Mocker.Resolve().AddEpisode(newEpisode); + Mocker.Resolve().AddEpisode(newEpisode); //Assert var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); @@ -1080,7 +1082,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests episodes.ForEach(c => Db.Insert(c)); //Act - Mocker.Resolve().SetEpisodeIgnore(1, true); + Mocker.Resolve().SetEpisodeIgnore(1, true); //Assert var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); @@ -1106,7 +1108,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests episodes.ForEach(c => Db.Insert(c)); //Act - Mocker.Resolve().SetEpisodeIgnore(1, false); + Mocker.Resolve().SetEpisodeIgnore(1, false); //Assert var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); @@ -1133,7 +1135,6 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .With(c => c.AirDate = DateTime.Today.AddDays(-4)) .With(c => c.Ignored = true) .TheFirst(2) - .With(c => c.EpisodeFileId = 0) .Section(1, 2) .With(c => c.Ignored = false) .Build().ToList(); @@ -1143,7 +1144,6 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .With(c => c.SeriesId = 10) .With(c => c.SeasonNumber = 0) .With(c => c.AirDate = DateTime.Today.AddDays(-4)) - .With(c => c.EpisodeFileId = 0) .With(c => c.Ignored = false) .TheFirst(1).With(c => c.Ignored = true) .Build().ToList(); @@ -1153,7 +1153,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.InsertMany(specials); //Act - var missingFiles = Mocker.Resolve().EpisodesWithoutFiles(false); + var missingFiles = Mocker.Resolve().EpisodesWithoutFiles(false); //Assert missingFiles.Should().HaveCount(1); @@ -1178,7 +1178,6 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .With(c => c.AirDate = DateTime.Today.AddDays(-4)) .With(c => c.Ignored = true) .TheFirst(2) - .With(c => c.EpisodeFileId = 0) .Section(1, 2) .With(c => c.Ignored = false) .Build().ToList(); @@ -1188,7 +1187,6 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .With(c => c.SeriesId = 10) .With(c => c.SeasonNumber = 0) .With(c => c.AirDate = DateTime.Today.AddDays(-4)) - .With(c => c.EpisodeFileId = 0) .With(c => c.Ignored = false) .TheFirst(1) .With(c => c.Ignored = true) @@ -1199,7 +1197,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.InsertMany(specials); //Act - var missingFiles = Mocker.Resolve().EpisodesWithoutFiles(true); + var missingFiles = Mocker.Resolve().EpisodesWithoutFiles(true); //Assert missingFiles.Should().HaveCount(2); @@ -1229,7 +1227,6 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .With(c => c.AirDate = DateTime.Today.AddDays(-4)) .With(c => c.Ignored = true) .With(c => c.EpisodeFile = episodeFile) - .With(c => c.EpisodeFileId = episodeFile.EpisodeFileId) .Build().ToList(); Db.Insert(series); @@ -1237,7 +1234,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.InsertMany(episodes); //Act - var withFiles = Mocker.Resolve().EpisodesWithFiles(); + var withFiles = Mocker.Resolve().EpisodesWithFiles(); //Assert withFiles.Should().HaveCount(2); @@ -1268,14 +1265,13 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .With(c => c.SeasonNumber = 1) .With(c => c.AirDate = DateTime.Today.AddDays(-4)) .With(c => c.Ignored = true) - .With(c => c.EpisodeFileId = 0) .Build().ToList(); Db.Insert(series); Db.InsertMany(episodes); //Act - var withFiles = Mocker.Resolve().EpisodesWithFiles(); + var withFiles = Mocker.Resolve().EpisodesWithFiles(); //Assert withFiles.Should().HaveCount(0); @@ -1296,14 +1292,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .All() .With(c => c.SeriesId = 10) .With(c => c.SeasonNumber = 1) - .With(c => c.EpisodeFileId = 12345) + .With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 12345 }) .Build(); Db.Insert(series); Db.InsertMany(fakeEpisodes); //Act - var episodes = Mocker.Resolve().GetEpisodesByFileId(12345); + var episodes = Mocker.Resolve().GetEpisodesByFileId(12345); //Assert episodes.Should().HaveCount(2); @@ -1322,14 +1318,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeEpisode = Builder.CreateNew() .With(c => c.SeriesId = 10) .With(c => c.SeasonNumber = 1) - .With(c => c.EpisodeFileId = 12345) + .With(c => c.EpisodeFile = new EpisodeFile { EpisodeFileId = 12345 }) .Build(); Db.Insert(series); Db.Insert(fakeEpisode); //Act - var episodes = Mocker.Resolve().GetEpisodesByFileId(12345); + var episodes = Mocker.Resolve().GetEpisodesByFileId(12345); //Assert episodes.Should().HaveCount(1); @@ -1351,7 +1347,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.InsertMany(fakeEpisodes); //Act - var result = Mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 5); + var result = Mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 5); //Assert result.Should().BeFalse(); @@ -1371,7 +1367,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.InsertMany(fakeEpisodes); //Act - var result = Mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 1); + var result = Mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 1); //Assert result.Should().BeFalse(); @@ -1391,7 +1387,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.InsertMany(fakeEpisodes); //Act - var result = Mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 10); + var result = Mocker.Resolve().IsFirstOrLastEpisodeOfSeason(10, 1, 10); //Assert result.Should().BeFalse(); @@ -1422,10 +1418,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); - Mocker.GetMock().Setup(s => s.Get("officeus")).Returns(fakeSeries); + Mocker.GetMock().Setup(s => s.GetByTitle("officeus")).Returns(fakeSeries); //Act - Mocker.Resolve().SetPostDownloadStatus(fakeEpisodes.Select(e => e.EpisodeId).ToList(), postDownloadStatus); + Mocker.Resolve().SetPostDownloadStatus(fakeEpisodes.Select(e => e.OID).ToList(), postDownloadStatus); //Assert var result = Db.Fetch(); @@ -1454,10 +1450,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); - Mocker.GetMock().Setup(s => s.Get("officeus")).Returns(fakeSeries); + Mocker.GetMock().Setup(s => s.GetByTitle("officeus")).Returns(fakeSeries); //Act - Mocker.Resolve().SetPostDownloadStatus(new List { 300 }, postDownloadStatus); + Mocker.Resolve().SetPostDownloadStatus(new List { 300 }, postDownloadStatus); //Assert var result = Db.Fetch(); @@ -1468,7 +1464,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests [ExpectedException(typeof(ArgumentException))] public void SetPostDownloadStatus_should_throw_if_episode_list_is_empty() { - Mocker.Resolve().SetPostDownloadStatus(new List(), PostDownloadStatusType.Failed); + Mocker.Resolve().SetPostDownloadStatus(new List(), PostDownloadStatusType.Failed); } [Test] @@ -1508,10 +1504,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests .Returns(tvdbSeries); //Act - Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + Mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + var result = Mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); result.Should().HaveCount(episodeCount); result.Where(e => e.Ignored).Should().HaveCount(episodeCount - 1); result.Single(e => e.SeasonNumber == 1).Ignored.Should().BeFalse(); @@ -1525,14 +1521,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); var fakeFile = Builder.CreateNew().With(f => f.EpisodeFileId).With(c => c.Quality = QualityTypes.WEBDL1080p).Build(); var fakeEpisodes = Builder.CreateListOfSize(5) - .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFileId = 1).With(e => e.EpisodeFile = fakeFile).Build(); + .All().With(e => e.SeriesId = 1).TheFirst(1).With(e => e.EpisodeFile = new EpisodeFile { EpisodeFileId = 1 }).With(e => e.EpisodeFile = fakeFile).Build(); Db.Insert(fakeSeries); Db.InsertMany(fakeEpisodes); Db.Insert(fakeFile); //Act - var episode = Mocker.Resolve().GetEpisode(1); + var episode = Mocker.Resolve().GetEpisode(1); //Assert episode.EpisodeFile.Quality.Should().Be(QualityTypes.WEBDL1080p); diff --git a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs index ff85387f6..5a522d8bf 100644 --- a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs +++ b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(fakeEpisode); //Act - Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); + Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); //Assert var result = Db.Fetch(); @@ -81,7 +81,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(fakeEpisode); //Act - Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); + Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); //Assert var result = Db.Fetch(); @@ -115,7 +115,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(fakeEpisode); //Act - Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); + Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); //Assert var result = Db.Fetch(); @@ -153,7 +153,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(fakeEpisode); //Act - Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); + Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); //Assert var result = Db.Fetch(); @@ -206,7 +206,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(otherFakeEpisode); //Act - Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); + Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries); //Assert var result = Db.Fetch(); @@ -220,7 +220,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests var fakeSeries = Builder.CreateNew().Build(); - Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, new List()); + Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, new List()); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs index 1ea65784e..ac115f094 100644 --- a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs +++ b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs @@ -17,7 +17,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests // ReSharper disable InconsistentNaming public class EpisodeProviderTest_GetEpisodesByParseResult : SqlCeTest { - private EpisodeProvider episodeProvider; + private EpisodeService episodeService; private Series fakeSeries; private Series fakeDailySeries; @@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests fakeSeries = Builder.CreateNew().Build(); fakeDailySeries = Builder.CreateNew() - .With(c => c.IsDaily = true) + .With(c => c.SeriesType = SeriesType.Daily) .Build(); fakeEpisode = Builder.CreateNew() @@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests WithRealDb(); - episodeProvider = Mocker.Resolve(); + episodeService = Mocker.Resolve(); } [Test] @@ -71,7 +71,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests EpisodeNumbers = new List { fakeEpisode.EpisodeNumber } }; - var ep = episodeProvider.GetEpisodesByParseResult(parseResult); + var ep = episodeService.GetEpisodesByParseResult(parseResult); ep.Should().HaveCount(1); parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title); @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests EpisodeNumbers = new List { 10 } }; - var episode = episodeProvider.GetEpisodesByParseResult(parseResult); + var episode = episodeService.GetEpisodesByParseResult(parseResult); episode.Should().BeEmpty(); Db.Fetch().Should().HaveCount(0); @@ -105,7 +105,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests EpisodeNumbers = new List { 10 } }; - var episode = episodeProvider.GetEpisodesByParseResult(parseResult); + var episode = episodeService.GetEpisodesByParseResult(parseResult); episode.Should().BeEmpty(); Db.Fetch().Should().HaveCount(0); @@ -126,7 +126,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests EpisodeNumbers = new List { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber } }; - var ep = episodeProvider.GetEpisodesByParseResult(parseResult); + var ep = episodeService.GetEpisodesByParseResult(parseResult); ep.Should().HaveCount(2); Db.Fetch().Should().HaveCount(2); @@ -149,7 +149,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests EpisodeNumbers = new List { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber } }; - var ep = episodeProvider.GetEpisodesByParseResult(parseResult); + var ep = episodeService.GetEpisodesByParseResult(parseResult); ep.Should().BeEmpty(); Db.Fetch().Should().BeEmpty(); @@ -160,7 +160,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_null() { //Act - var episodes = episodeProvider.GetEpisodesByParseResult(new EpisodeParseResult()); + var episodes = episodeService.GetEpisodesByParseResult(new EpisodeParseResult()); //Assert episodes.Should().NotBeNull(); episodes.Should().BeEmpty(); @@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_empty() { //Act - var episodes = episodeProvider.GetEpisodesByParseResult(new EpisodeParseResult { EpisodeNumbers = new List() }); + var episodes = episodeService.GetEpisodesByParseResult(new EpisodeParseResult { EpisodeNumbers = new List() }); //Assert episodes.Should().NotBeNull(); episodes.Should().BeEmpty(); @@ -184,7 +184,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests Db.Insert(fakeDailyEpisode); //Act - var episodes = episodeProvider.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeDailySeries }); + var episodes = episodeService.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeDailySeries }); //Assert episodes.Should().HaveCount(1); @@ -196,7 +196,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests [Test] public void should_not_add_episode_when_episode_doesnt_exist() { - var episodes = episodeProvider.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeDailySeries }); + var episodes = episodeService.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeDailySeries }); //Assert episodes.Should().HaveCount(0); @@ -218,7 +218,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests EpisodeNumbers = new List { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber } }; - var ep = episodeProvider.GetEpisodesByParseResult(parseResult); + var ep = episodeService.GetEpisodesByParseResult(parseResult); ep.Should().HaveCount(2); Db.Fetch().Should().HaveCount(2); @@ -242,7 +242,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests EpisodeNumbers = new List { fakeEpisode.EpisodeNumber } }; - var ep = episodeProvider.GetEpisodesByParseResult(parseResult); + var ep = episodeService.GetEpisodesByParseResult(parseResult); ep.Should().HaveCount(1); Db.Fetch().Should().HaveCount(1); @@ -261,7 +261,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests AirDate = DateTime.Today }; - var ep = episodeProvider.GetEpisodesByParseResult(parseResult); + var ep = episodeService.GetEpisodesByParseResult(parseResult); ep.Should().BeEmpty(); ExceptionVerification.ExpectedWarns(1); diff --git a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/GetEpisodeBySceneNumberFixture.cs b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/GetEpisodeBySceneNumberFixture.cs index aa7cf63b6..e3d6741a7 100644 --- a/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/GetEpisodeBySceneNumberFixture.cs +++ b/NzbDrone.Core.Test/TvTests/EpisodeProviderTests/GetEpisodeBySceneNumberFixture.cs @@ -52,14 +52,14 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests [Test] public void should_return_null_if_no_episodes_in_db() { - Mocker.Resolve().GetEpisodeBySceneNumbering(_series.SeriesId, 1, 1).Should().BeNull(); + Mocker.Resolve().GetEpisodeBySceneNumbering(_series.SeriesId, 1, 1).Should().BeNull(); } [Test] public void should_return_null_if_no_matching_episode_is_found() { WithNullSceneNumbering(); - Mocker.Resolve().GetEpisodeBySceneNumbering(_series.SeriesId, 1, 1).Should().BeNull(); + Mocker.Resolve().GetEpisodeBySceneNumbering(_series.SeriesId, 1, 1).Should().BeNull(); } [Test] @@ -67,10 +67,10 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests { WithSceneNumbering(); - var result = Mocker.Resolve() + var result = Mocker.Resolve() .GetEpisodeBySceneNumbering(_series.SeriesId, _episode.SceneSeasonNumber, _episode.SceneEpisodeNumber); - result.EpisodeId.Should().Be(_episode.EpisodeId); + result.OID.Should().Be(_episode.OID); } } } diff --git a/NzbDrone.Core.Test/TvTests/SeasonProviderTest.cs b/NzbDrone.Core.Test/TvTests/SeasonProviderTest.cs index 14d6b0156..c46661c0f 100644 --- a/NzbDrone.Core.Test/TvTests/SeasonProviderTest.cs +++ b/NzbDrone.Core.Test/TvTests/SeasonProviderTest.cs @@ -33,7 +33,7 @@ namespace NzbDrone.Core.Test.TvTests var fakeEpisodes = Builder.CreateListOfSize(4) .All() .With(c => c.SeriesId = fakeSeason.SeriesId) - .With(c => c.SeasonNumber = fakeSeason.SeasonId) + .With(c => c.SeasonNumber = fakeSeason.OID) .With(c => c.Ignored = !ignoreFlag) .Build().ToList(); @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.TvTests var id = Db.Insert(fakeSeason); //Act - Mocker.Resolve().SetIgnore(fakeSeason.SeriesId, fakeSeason.SeasonNumber, ignoreFlag); + Mocker.Resolve().SetIgnore(fakeSeason.SeriesId, fakeSeason.SeasonNumber, ignoreFlag); //Assert var season = Db.SingleOrDefault(id); @@ -65,7 +65,7 @@ namespace NzbDrone.Core.Test.TvTests Db.Insert(fakeSeason); //Act - var result = Mocker.Resolve().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber); + var result = Mocker.Resolve().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber); //Assert result.Should().Be(ignoreFlag); @@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.TvTests [Test] public void IsIgnored_should_throw_an_exception_if_not_in_db() { - Assert.Throws(() => Mocker.Resolve().IsIgnored(10, 0)); + Assert.Throws(() => Mocker.Resolve().IsIgnored(10, 0)); } [Test] @@ -98,7 +98,7 @@ namespace NzbDrone.Core.Test.TvTests Db.InsertMany(episodes); //Act - var result = Mocker.Resolve().All(seriesId); + var result = Mocker.Resolve().GetSeasonBySeries(seriesId); //Assert result.Should().HaveCount(1); @@ -135,7 +135,7 @@ namespace NzbDrone.Core.Test.TvTests Db.InsertMany(episodes); //Act - var result = Mocker.Resolve().All(seriesId); + var result = Mocker.Resolve().GetSeasonBySeries(seriesId); //Assert result.Should().HaveCount(5); @@ -147,46 +147,7 @@ namespace NzbDrone.Core.Test.TvTests } } - [Test] - public void EnsureSeason_should_add_all_seasons_for_new_series() - { - var seasons = new[] { 0, 1, 2, 3, 4, 5 }; - Mocker.Resolve().EnsureSeasons(12, seasons); - - Mocker.Resolve().GetSeasons(12).SequenceEqual(seasons); - } - - [Test] - public void EnsureSeason_should_add_missing_seasons() - { - var seasonsA = new[] { 0, 1, 2, 3 }; - var seasonsB = new[] { 0, 1, 2, 3, 4, 5 }; - Mocker.Resolve().EnsureSeasons(12, seasonsA); - Mocker.Resolve().GetSeasons(12).SequenceEqual(seasonsA); - - Mocker.Resolve().EnsureSeasons(12, seasonsB); - Mocker.Resolve().GetSeasons(12).SequenceEqual(seasonsB); - } - - - [Test] - public void EnsureSeason_marks_season_zero_as_ignored() - { - var seasons = new[] { 0, 1, 2, 3 }; - - Mocker.Resolve().EnsureSeasons(12, seasons); - Db.Fetch().Should().Contain(c => c.SeasonNumber == 0 && c.Ignored); - } - - - [Test] - public void EnsureSeason_none_zero_seasons_arent_ignored() - { - var seasons = new[] { 1, 2, 3 }; - - Mocker.Resolve().EnsureSeasons(12, seasons); - Db.Fetch().Should().OnlyContain(c => c.Ignored == false); - } + [Test] public void GetSeason_should_return_seasons_for_specified_series_only() @@ -194,18 +155,15 @@ namespace NzbDrone.Core.Test.TvTests var seriesA = new[] { 1, 2, 3 }; var seriesB = new[] { 4, 5, 6 }; - Mocker.Resolve().EnsureSeasons(1, seriesA); - Mocker.Resolve().EnsureSeasons(2, seriesB); - - Mocker.Resolve().GetSeasons(1).Should().Equal(seriesA); - Mocker.Resolve().GetSeasons(2).Should().Equal(seriesB); + Mocker.Resolve().GetSeasonNumbers(1).Should().Equal(seriesA); + Mocker.Resolve().GetSeasonNumbers(2).Should().Equal(seriesB); } [Test] public void GetSeason_should_return_emptylist_if_series_doesnt_exist() { - Mocker.Resolve().GetSeasons(1).Should().BeEmpty(); + Mocker.Resolve().GetSeasonNumbers(1).Should().BeEmpty(); } } diff --git a/NzbDrone.Core.Test/TvTests/SeriesProviderTest.cs b/NzbDrone.Core.Test/TvTests/SeriesProviderTest.cs index 1945083a62167e923667792bb15348ac220911eb..657e399b5673960c67468f2fa4bc3eda049fc4c5 100644 GIT binary patch literal 3392 zcmeHJ%}(1u5bilr-eJYbk)oBLJyD1RL8&Y?5hX!AkScQQ32a%sVRs!G5KqRTkJMM_ z%sR$in{aNW_>ef>@0;Im#`*K|J2N7^X5+Q7aL2!j^!{_Zl|LJZ$H(uH20l8?giJt} zCo+T7o)`n#3YD7IgP|(vqsvrSKG4w}JSctpiWxo5&$LQ`_Z8ZnthOASYqb*S)HvK0 z&;*R{qTNc-pIJsRu$m)+PFBP)?bcJf#qheKp9AsBW*UCvkCxe7ikQVRGKP&o3ou0} z1ZIbf;-=f9{1iV|B8Fa0-xwz2OD$HB1vXUi?NOM6FJP&Ruu89cjP5b7oL42}P_~F} zA;0xdS7Wf3%T2V7mPfo&BEf)dwhTI@%}P9kC7Lw*-HZB(oGAX2wutP9Ewih$d6*!2|KQ`NH?0!tK8vKVYm~`CNO1TA1Xt6h zGH%)`Qq0dnGE@mjG@WKrI&@KL`ldedyqPgO?y;DMjuwQLhvp<*7qt&Mol3V06TBZu zIge0xxzk?Ytkhk{)MdZV<81yDV#~1?IW=$v>$);`HwEc7QtrAmn&v!@e0-xanV?8U z%AUdq6ZeEd(ffpR>}|<9g@Bq}m!?n2qYe{~miO^};0(^J6S~1ct@K><;LEhoSAWTo@EARsQrbwo-LHdv5JgJ@s@VE3Fb;k zhLEv)JaA7dQhM@rL3^UIG5XGIu^4;RSuHfkm@nYVnk#;RyGo}fsK?OIq&L62arYZT z<^EU4y`n5!bhSQXn+vHlhoLe8Rh*-kKNE;9z2%xvtoShNE{vFTW-EV+`L)E&$( z+lT#0`xo{cUc^I*vgJ$KWGcVdmPm>`Jm)(X9#a4N&wuAx7~eSkMV7PaKc7CKf4!3= zir6p@lQ{E!Vlhj@VY$ewF#cFvI}bm9ejB9ByL>qhqY+E>ooLSD{5Z>4%9|^0T)vLO z+&fQ$DZ5M35BmD&>(exe8T0|#8{F31_%%&#LwHcO>OOC$rqC6eC0Up!>B9ThJcz=4 zQB!chGPAEwpFDf!T(SNnNM|f{Mqw6QN6hKPLm*iQB#raSU4fcjDjq4`Y;tNQ-jCC&i79LV|2ps zx2PbS!scdacpK!y@_Z~?ev0#hBblV!A>9Pl!;g28GUz|{{+Dq-{LI|vh{kY_fkk zc(Z3-f~Pot*q*});dTk(|9JXDlYw)?Nsuu&Pv@*lCP3dA2T^9+qH}XR8u`#`AEXc1 z#=TCG$eCxX&w?z8&l8kX(yh|OArY=v5S?E09_nr(eJ_&X2bKajW~PreOOXB>QBifdbbQvB|Cnx9OXonCvr7$Nu~ zh!-xU9`c@977;9WvOGogFbnbt5V&*l{rmTbFz?@Y2(#jYjpBKj0}4WUj!XmmXD=Vd zxs%_XUiVP04xS(W-P$UaGBJvme_rYHvuDRciGGS0$R>jA6<5NOB-dWCEQxN}3lmL& zYfHT_>w6$gqK3=IxyPxqC&#f@>FJ&m&!ebHVCXDYhbGx|f1#h{2P3{&`{wm0$vhgl zUGL}MmYpQ?ICl@qMaAR1$4J^2jpJWR73>i-HCS5*`ePJ^IUF%r&p<-U~4Pz2O8e93I^qd1B~vz{~!!TWY({@Ve)PGLC!SQZ`f zGd_R*I0z#@9ILBg=0_~c{CpC`{%4jZE{cMv0%Xyh_+9_RZk8Zh^&Gz?6AUJ4a+ke0 zPH*N@Fj9V*gJQi3;v07MX~<@1q8+(z7cqL3tPpYN2ua`5IMGpa+Z*jU2T~H~oK*E3 z(QcGh<1j9W#ip}-;iq7=Q3bP{1}1^-2`H8cFQ`bjbFpv)jgSVFE?M9}PFF9x1PpP- z%r~aryR%O-FyGmzm{d0hb0-~qbgkh=LI($#{29enD1b^ z0?Ow>7-vqLI4okwI$5WVy3%``-qT_Y%ZURDZKYdq(VR_dcE*N zztQ<=N=ReQ{U*-~ZEH)ZQVUGz}C^m3lN8S2GM#R{aE0-8=-7Ck_PCof#GPx*0(c68U{me(LzLPpsGO$2n(wQX{l zEqX6@U6k91f+QTU-Hk!yYUBP}*vgM2ulrqo8p+8GA#h&3V@XN9q*gsJYk zR>(}b>GOvpIZR&Mp(9mk*y0We-ci!TReR?xEEC*FuS)Ali;}EPAdjhb1{3CBpbDH- z9zpFW9D*%mh%Lt`8Q2UW;Fhr< z9ZvYDh_cv-ZML`Zl>*~kB;8RwWjF+e%KJ4)Vah zVft-!-n6=Slo6w(LefeGpAmqeEtY?aCv0H$mm9+WMq~H5CSiSc-Sm{Of^!^&PHfC9 zV>K4B*it|N@M~o5Q|YlmRxPq<{8*`m1W)uvx(b911wMJ|UYQ2+HkSfg54-|cpo<`y z0s8W*KZm!X_Nq>hEuTQVLfwmyIIc`pL3SVAo-TsM)9u<9$cty!o>2WEj=LQ zg=QZ^fEDGT!2{bG;p!%pLage#`=W_407??Erndo2j20GjTrSpvc(RWKkMtO|$~0LW+0UrmyNOY+@quB+!;0b%cRR(*7l;+W*C3oi zE>SWH7Pfle2Z&YB?`(H@&|3~c5&;9!+(xvH9GZI-z?!N}4H-kK>m#nLod$~xqL;P~ z-HS1X^j4oj-xb*ciXUpQ&YX*qrKYvQuA;iYT7s8wYGl_Wer#y;t+9Ci54E!SZvQur zKD-7zi&ghSOT}VkgI3-SLw%r*lohI0TR5d)_Q2s(B(xb=u>w4evKlJ6ZSBGO{wSHc z-*t^rRV*V)!IbC%5SA=om}R8UQ?^EQDGIg7Qdn07KB-Q!0#=}-xMvz<8nnpAgTrPNj zRnzETV+6C-yblQbIf%x7YaXF=JC1^4A=;1M+gyP`+acJdkks6{Y=Dub7da ztF5i~RiW~`O>I3}#hn4A%*~9G9FlBtJBG^JggoTjA0N!-jT#K4u5m;$IvrkIYXj8!0NX|T`iC^qRSAXyos!bnyRCc6)F z4H|;)Xt1B`)EC~kpitT0EWCE^ z{m|O{=g8$8+sFFbZR%jvEkYI(lprB%Dmi2}UBF%xtwv>85 z)|A;NOM=9`N7~oUpEgyKUYA^%Rbf^vWmhcKZV>WUJk(h91V7=Hx3f>Mw>b0Jr(l>v z%JG)zdUCtukGNlwZ|j2C6~KR zmU0IP@+y?JvU_niAY-*p@8 zAYqrs<*6$I;#|Ifr6DoOqO;=fm(H6teqUw0n#jNLsYxdwA;5u7J}v>9KlZBOV3tMKgKUM80D3%-wZcns%?_ z4>4q7w{X|OU1Q@;!%JNf56z^}352x?+j@ylyDVs8nCT+I1f_0GwTv{iYYP=iY$}b& z>Sb-~t)izOq`S!?)x*Laa6!>pdlSHM>&EWiErI3$PZWSdw28&NZUn0JB4NcyuB{f1 zndJEU-I)9M?JC&io=@ub!EWzI7RtG`tRAOjrTJrb4rcZtocW>HZQkNuYhZ0)V41-W zL>bMfrmcjwkP&rkV0Y~h_w2jq>~>(gk;L-CfXCo|YTnxfB;h<|IFRldahTAC0+jd zfyOIu!o}0UY7*t%rygiy&#Ba%WfCHf(TDdsuvSD+_cdLfYei&B5rIQSABBW4c-sfp zAgzdS`DjIizn8C3z;8yVK;_Y5Z94-7gzwHm<{Ws6mQC z&_f)A4NSmSFzv;_cY}Qt;!UWer0K9CT7FBbSXA1{bg2nh{<_`Wg(GMfl1^t`Ad;3Z z&Fj)C4;nJ`_DW2)vj~7iEK00yHbE%~b&J1CE0xFz_2?C-Y6^@c!n1PIrv?)dTtYZW z(o)i9M)V=R2Y>llT!0w z)m$+T<#vi2D;l5^Qf`CZqs{CZ>EUgqH;|6`n2=t98h#_^Oo`q=)F`owFq{pYAxoL8 z`3sAaDLlY4jx>As;rE0T#UP4&eAPBY@FMV%Mt+{~WgoHpw8RZkszaDTAT4}ZuJR%t zVx%9^LkJYR;kRl^rA?B?>Q7%gw7t}Twu-;;06Ag0z?n1xcICM+qT5BHoA`^itGZ#q rQCsV{uf%QE_`!WP{(Qa0=^83Ei-D(bl<@V(U)oPgftCV~g985tO|Qw0 diff --git a/NzbDrone.Core.Test/dbBenchmark.cs b/NzbDrone.Core.Test/dbBenchmark.cs deleted file mode 100644 index b852311a0..000000000 --- a/NzbDrone.Core.Test/dbBenchmark.cs +++ /dev/null @@ -1,244 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading; - -using FizzWare.NBuilder; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common.AutoMoq; -using PetaPoco; - -namespace NzbDrone.Core.Test -{ - [TestFixture] - [Explicit] - [Category("Benchmark")] - // ReSharper disable InconsistentNaming - public class DbBenchmark : SqlCeTest - { - const int Episodes_Per_Season = 20; - private readonly List seasonsNumbers = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - private readonly List seriesIds = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; - private readonly List episodes = new List(); - private readonly List files = new List(); - private IDatabase db; - - - [TestFixtureSetUp] - public void Setup() - { - WithRealDb(); - - int currentFileId = 0; - - - var qulityProfile = new QualityProfile - { - Name = "TestProfile", - Allowed = new List { QualityTypes.DVD, QualityTypes.Bluray1080p }, - Cutoff = QualityTypes.DVD - }; - Db.Insert(qulityProfile); - - foreach (var _seriesId in seriesIds) - { - int seriesId = _seriesId; - var series = Builder.CreateNew() - .With(s => s.SeriesId = seriesId) - .With(s => s.Monitored = true) - .Build(); - - Db.Insert(series); - - foreach (var _seasonNumber in seasonsNumbers) - { - for (int i = 1; i <= Episodes_Per_Season; i++) - { - var epFileId = 0; - - if (i < 10) - { - var epFile = Builder.CreateNew() - .With(e => e.SeriesId = seriesId) - .And(e => e.SeasonNumber = _seasonNumber) - .And(e => e.Path = Guid.NewGuid().ToString()) - .Build(); - - files.Add(epFile); - - currentFileId++; - epFileId = currentFileId; - - } - - - var episode = Builder.CreateNew() - .With(e => e.SeriesId = seriesId) - .And(e => e.SeasonNumber = _seasonNumber) - .And(e => e.EpisodeNumber = i) - .And(e => e.Ignored = false) - .And(e => e.TvDbEpisodeId = episodes.Count + 1) - .And(e => e.EpisodeFileId = epFileId) - .And(e => e.AirDate = DateTime.Today.AddDays(-20)) - .Build(); - - episodes.Add(episode); - - - } - } - - } - - Db.InsertMany(episodes); - Db.InsertMany(files); - } - - - [Test] - public void get_episode_by_series_seasons_episode_x5000() - { - - Mocker.SetConstant(db); - Mocker.Resolve(); - - var epProvider = Mocker.Resolve(); - - Thread.Sleep(1000); - - var random = new Random(); - Console.WriteLine("Starting Test"); - - var sw = Stopwatch.StartNew(); - for (int i = 0; i < 5000; i++) - { - var ep = epProvider.GetEpisode(6, random.Next(2, 5), random.Next(2, Episodes_Per_Season - 10)); - ep.Series.Should().NotBeNull(); - } - - sw.Stop(); - - Console.WriteLine("Took " + sw.Elapsed); - } - - [Test] - public void get_episode_by_series_seasons_x1000() - { - - Mocker.SetConstant(db); - Mocker.Resolve(); - - var epProvider = Mocker.Resolve(); - - - Thread.Sleep(1000); - - - var random = new Random(); - Console.WriteLine("Starting Test"); - - var sw = Stopwatch.StartNew(); - for (int i = 0; i < 1000; i++) - { - epProvider.GetEpisodesBySeason(6, random.Next(2, 5)).Should().NotBeNull(); - } - - - sw.Stop(); - - Console.WriteLine("Took " + sw.Elapsed); - } - - [Test] - public void get_episode_file_count_x100() - { - - Mocker.SetConstant(db); - Mocker.Resolve(); - Mocker.Resolve(); - var mediaProvider = Mocker.Resolve(); - - - Thread.Sleep(1000); - - - var random = new Random(); - Console.WriteLine("Starting Test"); - - var sw = Stopwatch.StartNew(); - for (int i = 0; i < 100; i++) - { - mediaProvider.GetEpisodeFilesCount(random.Next(1, 5)).Should().NotBeNull(); - } - - - sw.Stop(); - - Console.WriteLine("Took " + sw.Elapsed); - } - - [Test] - public void get_episode_file_count_x1000() - { - - Mocker.SetConstant(db); - Mocker.Resolve(); - Mocker.Resolve(); - var mediaProvider = Mocker.Resolve(); - - - Thread.Sleep(1000); - - - var random = new Random(); - Console.WriteLine("Starting Test"); - - var sw = Stopwatch.StartNew(); - for (int i = 0; i < 1000; i++) - { - mediaProvider.GetEpisodeFilesCount(random.Next(1, 5)).Should().NotBeNull(); - } - - - sw.Stop(); - - Console.WriteLine("Took " + sw.Elapsed); - } - - - [Test] - public void get_season_count_x500() - { - - Mocker.SetConstant(db); - var provider = Mocker.Resolve(); - - - Thread.Sleep(1000); - - - var random = new Random(); - Console.WriteLine("Starting Test"); - - var sw = Stopwatch.StartNew(); - for (int i = 0; i < 500; i++) - { - provider.GetSeasons(random.Next(1, 10)).Should().HaveSameCount(seasonsNumbers); - } - - - sw.Stop(); - - Console.WriteLine("Took " + sw.Elapsed); - } - - - - } -} diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index 41bf23a8b..65563379d 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -11,6 +11,8 @@ namespace NzbDrone.Core.Datastore TModel Update(TModel model); TModel Upsert(TModel model); void Delete(int id); + IList InsertMany(IList model); + IList UpdateMany(IList model); } public class BasicRepository : IBasicRepository where TModel : ModelBase, new() @@ -44,6 +46,16 @@ namespace NzbDrone.Core.Datastore return ObjectDatabase.Update(model); } + public IList InsertMany(IList model) + { + return ObjectDatabase.InsertMany(model); + } + + public IList UpdateMany(IList model) + { + return ObjectDatabase.UpdateMany(model); + } + public TModel Upsert(TModel model) { if(model.OID == 0) diff --git a/NzbDrone.Core/Datastore/PetaPoco/EpisodeSeasonRelator.cs b/NzbDrone.Core/Datastore/PetaPoco/EpisodeSeasonRelator.cs index 5f726cdaf..7a0078997 100644 --- a/NzbDrone.Core/Datastore/PetaPoco/EpisodeSeasonRelator.cs +++ b/NzbDrone.Core/Datastore/PetaPoco/EpisodeSeasonRelator.cs @@ -22,7 +22,7 @@ namespace PetaPoco episode.EpisodeFile = (episode.EpisodeFileId == 0 ? null : episodeFile); // Is this the same season as the current one we're processing - if (_current != null && _current.SeasonId == season.SeasonId) + if (_current != null && _current.OID == season.OID) { // Yes, just add this post to the current author's collection of posts _current.Episodes.Add(episode); diff --git a/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs b/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs index 209ca0927..dafff152e 100644 --- a/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs +++ b/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs @@ -10,13 +10,13 @@ namespace NzbDrone.Core.DecisionEngine public class AcceptableSizeSpecification { private readonly QualityTypeProvider _qualityTypeProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public AcceptableSizeSpecification(QualityTypeProvider qualityTypeProvider, EpisodeProvider episodeProvider) + public AcceptableSizeSpecification(QualityTypeProvider qualityTypeProvider, EpisodeService episodeService) { _qualityTypeProvider = qualityTypeProvider; - _episodeProvider = episodeProvider; + _episodeService = episodeService; } public AcceptableSizeSpecification() @@ -56,7 +56,7 @@ namespace NzbDrone.Core.DecisionEngine //Check if there was only one episode parsed //and it is the first or last episode of the season if (subject.EpisodeNumbers != null && subject.EpisodeNumbers.Count == 1 && - _episodeProvider.IsFirstOrLastEpisodeOfSeason(series.SeriesId, + _episodeService.IsFirstOrLastEpisodeOfSeason(series.SeriesId, subject.SeasonNumber, subject.EpisodeNumbers[0])) { maxSize = maxSize * 2; diff --git a/NzbDrone.Core/DecisionEngine/MonitoredEpisodeSpecification.cs b/NzbDrone.Core/DecisionEngine/MonitoredEpisodeSpecification.cs index 84ad4e3fb..464f48116 100644 --- a/NzbDrone.Core/DecisionEngine/MonitoredEpisodeSpecification.cs +++ b/NzbDrone.Core/DecisionEngine/MonitoredEpisodeSpecification.cs @@ -8,15 +8,13 @@ namespace NzbDrone.Core.DecisionEngine { public class MonitoredEpisodeSpecification { - private readonly SeriesProvider _seriesProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly ISeriesRepository _seriesRepository; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public MonitoredEpisodeSpecification(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, ISeriesRepository seriesRepository) + public MonitoredEpisodeSpecification(EpisodeService episodeService, ISeriesRepository seriesRepository) { - _seriesProvider = seriesProvider; - _episodeProvider = episodeProvider; + _episodeService = episodeService; _seriesRepository = seriesRepository; } @@ -27,7 +25,7 @@ namespace NzbDrone.Core.DecisionEngine public virtual bool IsSatisfiedBy(EpisodeParseResult subject) { - var series = _seriesRepository.Get(subject.CleanTitle); + var series = _seriesRepository.GetByTitle(subject.CleanTitle); if (series == null) { @@ -43,7 +41,7 @@ namespace NzbDrone.Core.DecisionEngine return false; } - var episodes = _episodeProvider.GetEpisodesByParseResult(subject); + var episodes = _episodeService.GetEpisodesByParseResult(subject); subject.Episodes = episodes; //return monitored if any of the episodes are monitored diff --git a/NzbDrone.Core/DecisionEngine/UpgradeHistorySpecification.cs b/NzbDrone.Core/DecisionEngine/UpgradeHistorySpecification.cs index 36bb1f6e6..a3c3f78dd 100644 --- a/NzbDrone.Core/DecisionEngine/UpgradeHistorySpecification.cs +++ b/NzbDrone.Core/DecisionEngine/UpgradeHistorySpecification.cs @@ -8,14 +8,14 @@ namespace NzbDrone.Core.DecisionEngine { public class UpgradeHistorySpecification { - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly HistoryProvider _historyProvider; private readonly QualityUpgradeSpecification _qualityUpgradeSpecification; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public UpgradeHistorySpecification(EpisodeProvider episodeProvider, HistoryProvider historyProvider, QualityUpgradeSpecification qualityUpgradeSpecification) + public UpgradeHistorySpecification(EpisodeService episodeService, HistoryProvider historyProvider, QualityUpgradeSpecification qualityUpgradeSpecification) { - _episodeProvider = episodeProvider; + _episodeService = episodeService; _historyProvider = historyProvider; _qualityUpgradeSpecification = qualityUpgradeSpecification; } diff --git a/NzbDrone.Core/Instrumentation/LogInjectionModule.cs b/NzbDrone.Core/Instrumentation/LogInjectionModule.cs index d3df3a016..4d7ace9d5 100644 --- a/NzbDrone.Core/Instrumentation/LogInjectionModule.cs +++ b/NzbDrone.Core/Instrumentation/LogInjectionModule.cs @@ -12,6 +12,7 @@ namespace NzbDrone.Core.Instrumentation { registration.Preparing += OnComponentPreparing; } + static void OnComponentPreparing(object sender, PreparingEventArgs e) { e.Parameters = e.Parameters.Union(new[] @@ -19,7 +20,7 @@ namespace NzbDrone.Core.Instrumentation new ResolvedParameter((p, i) => p.ParameterType == typeof(Logger), (p,i)=> GetLogger(p.Member.DeclaringType)) }); } - + private static object GetLogger(Type type) { const string STRING_TO_REMOVE = "NzbDrone"; diff --git a/NzbDrone.Core/Jobs/BacklogSearchJob.cs b/NzbDrone.Core/Jobs/BacklogSearchJob.cs index 3e94737de..da0b2666c 100644 --- a/NzbDrone.Core/Jobs/BacklogSearchJob.cs +++ b/NzbDrone.Core/Jobs/BacklogSearchJob.cs @@ -13,17 +13,17 @@ namespace NzbDrone.Core.Jobs { public class BacklogSearchJob : IJob { - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly EpisodeSearchJob _episodeSearchJob; private readonly SeasonSearchJob _seasonSearchJob; private readonly ConfigProvider _configProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public BacklogSearchJob(EpisodeProvider episodeProvider, EpisodeSearchJob episodeSearchJob, + public BacklogSearchJob(EpisodeService episodeService, EpisodeSearchJob episodeSearchJob, SeasonSearchJob seasonSearchJob, ConfigProvider configProvider) { - _episodeProvider = episodeProvider; + _episodeService = episodeService; _episodeSearchJob = episodeSearchJob; _seasonSearchJob = seasonSearchJob; _configProvider = configProvider; @@ -60,7 +60,7 @@ namespace NzbDrone.Core.Jobs var seriesId = group.Key.SeriesId; var seasonNumber = group.Key.SeasonNumber; - var countInDb = _episodeProvider.GetEpisodeNumbersBySeason(seriesId, seasonNumber).Count; + var countInDb = _episodeService.GetEpisodeNumbersBySeason(seriesId, seasonNumber).Count; //Todo: Download a full season if more than n% is missing? @@ -83,7 +83,7 @@ namespace NzbDrone.Core.Jobs //Process the list of remaining episodes, 1 by 1 foreach (var episode in individualEpisodes) { - _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId}); + _episodeSearchJob.Start(notification, new { EpisodeId = episode.OID}); } } @@ -92,7 +92,7 @@ namespace NzbDrone.Core.Jobs if (!_configProvider.EnableBacklogSearching) { Logger.Trace("Backlog searching is not enabled, only running for explicitly enabled series."); - return _episodeProvider.EpisodesWithoutFiles(true).Where(e => + return _episodeService.EpisodesWithoutFiles(true).Where(e => e.Series.BacklogSetting == BacklogSettingType.Enable && e.Series.Monitored ).ToList(); @@ -101,7 +101,7 @@ namespace NzbDrone.Core.Jobs else { Logger.Trace("Backlog searching is enabled, skipping explicity disabled series."); - return _episodeProvider.EpisodesWithoutFiles(true).Where(e => + return _episodeService.EpisodesWithoutFiles(true).Where(e => e.Series.BacklogSetting != BacklogSettingType.Disable && e.Series.Monitored ).ToList(); diff --git a/NzbDrone.Core/Jobs/BannerDownloadJob.cs b/NzbDrone.Core/Jobs/BannerDownloadJob.cs index 1eacc1759..4718b2c79 100644 --- a/NzbDrone.Core/Jobs/BannerDownloadJob.cs +++ b/NzbDrone.Core/Jobs/BannerDownloadJob.cs @@ -13,16 +13,18 @@ namespace NzbDrone.Core.Jobs { public class BannerDownloadJob : IJob { - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly BannerProvider _bannerProvider; + private readonly ISeriesRepository _seriesRepository; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private const string BANNER_URL_PREFIX = "http://www.thetvdb.com/banners/"; - public BannerDownloadJob(SeriesProvider seriesProvider, BannerProvider bannerProvider) + public BannerDownloadJob(ISeriesService seriesService, BannerProvider bannerProvider, ISeriesRepository seriesRepository) { - _seriesProvider = seriesProvider; + _seriesService = seriesService; _bannerProvider = bannerProvider; + _seriesRepository = seriesRepository; } public BannerDownloadJob() @@ -45,7 +47,7 @@ namespace NzbDrone.Core.Jobs if (options != null) { - Series series = _seriesProvider.Get(options.SeriesId); + Series series = _seriesRepository.Get(options.SeriesId); if (series != null && !String.IsNullOrEmpty(series.BannerUrl)) { @@ -55,7 +57,7 @@ namespace NzbDrone.Core.Jobs return; } - var seriesInDb = _seriesProvider.All(); + var seriesInDb = _seriesRepository.All(); foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl))) { diff --git a/NzbDrone.Core/Jobs/ConvertEpisodeJob.cs b/NzbDrone.Core/Jobs/ConvertEpisodeJob.cs index 5c6390f17..12e8d00c5 100644 --- a/NzbDrone.Core/Jobs/ConvertEpisodeJob.cs +++ b/NzbDrone.Core/Jobs/ConvertEpisodeJob.cs @@ -13,16 +13,16 @@ namespace NzbDrone.Core.Jobs { private readonly HandbrakeProvider _handbrakeProvider; private readonly AtomicParsleyProvider _atomicParsleyProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); public ConvertEpisodeJob(HandbrakeProvider handbrakeProvider, AtomicParsleyProvider atomicParsleyProvider, - EpisodeProvider episodeProvider) + EpisodeService episodeService) { _handbrakeProvider = handbrakeProvider; _atomicParsleyProvider = atomicParsleyProvider; - _episodeProvider = episodeProvider; + _episodeService = episodeService; } public string Name @@ -41,7 +41,7 @@ namespace NzbDrone.Core.Jobs if (options == null || options.EpisodeId <= 0) throw new ArgumentNullException(options); - Episode episode = _episodeProvider.GetEpisode(options.EpisodeId); + Episode episode = _episodeService.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 9f60dbd8c..b662ab10b 100644 --- a/NzbDrone.Core/Jobs/DeleteSeriesJob.cs +++ b/NzbDrone.Core/Jobs/DeleteSeriesJob.cs @@ -10,15 +10,17 @@ namespace NzbDrone.Core.Jobs { public class DeleteSeriesJob : IJob { - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly RecycleBinProvider _recycleBinProvider; + private readonly ISeriesRepository _seriesRepository; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public DeleteSeriesJob(SeriesProvider seriesProvider, RecycleBinProvider recycleBinProvider) + public DeleteSeriesJob(ISeriesService seriesService, RecycleBinProvider recycleBinProvider, ISeriesRepository seriesRepository) { - _seriesProvider = seriesProvider; + _seriesService = seriesService; _recycleBinProvider = recycleBinProvider; + _seriesRepository = seriesRepository; } public string Name @@ -46,12 +48,12 @@ namespace NzbDrone.Core.Jobs { Logger.Trace("Deleting Series [{0}]", seriesId); - var series = _seriesProvider.Get(seriesId); + var series = _seriesRepository.Get(seriesId); var title = series.Title; notification.CurrentMessage = String.Format("Deleting '{0}' from database", title); - _seriesProvider.DeleteSeries(seriesId); + _seriesRepository.Delete(seriesId); notification.CurrentMessage = String.Format("Successfully deleted '{0}' from database", title); diff --git a/NzbDrone.Core/Jobs/DiskScanJob.cs b/NzbDrone.Core/Jobs/DiskScanJob.cs index ca5a559df..0dc6e9d40 100644 --- a/NzbDrone.Core/Jobs/DiskScanJob.cs +++ b/NzbDrone.Core/Jobs/DiskScanJob.cs @@ -13,17 +13,19 @@ namespace NzbDrone.Core.Jobs { public class DiskScanJob : IJob { - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly DiskScanProvider _diskScanProvider; private readonly ConfigProvider _configProvider; + private readonly ISeriesRepository _seriesRepository; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public DiskScanJob(SeriesProvider seriesProvider, DiskScanProvider diskScanProvider, - ConfigProvider configProvider) + public DiskScanJob(ISeriesService seriesService, DiskScanProvider diskScanProvider, + ConfigProvider configProvider, ISeriesRepository seriesRepository) { - _seriesProvider = seriesProvider; + _seriesService = seriesService; _diskScanProvider = diskScanProvider; _configProvider = configProvider; + _seriesRepository = seriesRepository; } public DiskScanJob() @@ -46,14 +48,14 @@ namespace NzbDrone.Core.Jobs if (options == null || options.SeriesId == 0) { if (_configProvider.IgnoreArticlesWhenSortingSeries) - seriesToScan = _seriesProvider.All().OrderBy(o => o.Title.IgnoreArticles()).ToList(); + seriesToScan = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList(); else - seriesToScan = _seriesProvider.All().OrderBy(o => o.Title).ToList(); + seriesToScan = _seriesRepository.All().OrderBy(o => o.Title).ToList(); } else { - seriesToScan = new List() { _seriesProvider.Get(options.SeriesId) }; + seriesToScan = new List() { _seriesRepository.Get(options.SeriesId) }; } foreach (var series in seriesToScan) diff --git a/NzbDrone.Core/Jobs/EpisodeSearchJob.cs b/NzbDrone.Core/Jobs/EpisodeSearchJob.cs index 590ab1d92..ff09c7e84 100644 --- a/NzbDrone.Core/Jobs/EpisodeSearchJob.cs +++ b/NzbDrone.Core/Jobs/EpisodeSearchJob.cs @@ -12,18 +12,18 @@ namespace NzbDrone.Core.Jobs { public class EpisodeSearchJob : IJob { - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly UpgradePossibleSpecification _upgradePossibleSpecification; private readonly EpisodeSearch _episodeSearch; private readonly DailyEpisodeSearch _dailyEpisodeSearch; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public EpisodeSearchJob(EpisodeProvider episodeProvider, UpgradePossibleSpecification upgradePossibleSpecification, + public EpisodeSearchJob(EpisodeService episodeService, UpgradePossibleSpecification upgradePossibleSpecification, EpisodeSearch episodeSearch, DailyEpisodeSearch dailyEpisodeSearch) { if(dailyEpisodeSearch == null) throw new ArgumentNullException("dailyEpisodeSearch"); - _episodeProvider = episodeProvider; + _episodeService = episodeService; _upgradePossibleSpecification = upgradePossibleSpecification; _episodeSearch = episodeSearch; _dailyEpisodeSearch = dailyEpisodeSearch; @@ -49,7 +49,7 @@ namespace NzbDrone.Core.Jobs if (options == null || options.EpisodeId <= 0) throw new ArgumentException("options"); - Episode episode = _episodeProvider.GetEpisode(options.EpisodeId); + Episode episode = _episodeService.GetEpisode(options.EpisodeId); if (episode == null) { @@ -64,7 +64,7 @@ namespace NzbDrone.Core.Jobs return; } - if (episode.Series.IsDaily) + if (episode.Series.SeriesType == SeriesType.Daily) { if (!episode.AirDate.HasValue) { diff --git a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs index 07bc74b71..4b924639d 100644 --- a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs +++ b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs @@ -15,32 +15,36 @@ namespace NzbDrone.Core.Jobs /// public class ImportNewSeriesJob : IJob { - private readonly SeriesProvider _seriesProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly ISeriesService _seriesService; + private readonly EpisodeService _episodeService; private readonly MediaFileProvider _mediaFileProvider; private readonly UpdateInfoJob _updateInfoJob; private readonly DiskScanJob _diskScanJob; private readonly BannerDownloadJob _bannerDownloadJob; - private readonly SeasonProvider _seasonProvider; + private readonly ISeasonRepository _seasonRepository; private readonly XemUpdateJob _xemUpdateJob; + private readonly ISeriesRepository _seriesRepository; + private readonly ISeasonService _seasonService; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private List _attemptedSeries; - public ImportNewSeriesJob(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, + public ImportNewSeriesJob(ISeriesService seriesService, EpisodeService episodeService, MediaFileProvider mediaFileProvider, UpdateInfoJob updateInfoJob, DiskScanJob diskScanJob, BannerDownloadJob bannerDownloadJob, - SeasonProvider seasonProvider, XemUpdateJob xemUpdateJob) + ISeasonRepository seasonRepository, XemUpdateJob xemUpdateJob, ISeriesRepository seriesRepository,ISeasonService seasonService) { - _seriesProvider = seriesProvider; - _episodeProvider = episodeProvider; + _seriesService = seriesService; + _episodeService = episodeService; _mediaFileProvider = mediaFileProvider; _updateInfoJob = updateInfoJob; _diskScanJob = diskScanJob; _bannerDownloadJob = bannerDownloadJob; - _seasonProvider = seasonProvider; + _seasonRepository = seasonRepository; _xemUpdateJob = xemUpdateJob; + _seriesRepository = seriesRepository; + _seasonService = seasonService; } public string Name @@ -61,7 +65,7 @@ namespace NzbDrone.Core.Jobs private void ScanSeries(ProgressNotification notification) { - var syncList = _seriesProvider.All().Where(s => s.LastInfoSync == null && !_attemptedSeries.Contains(s.SeriesId)).ToList(); + var syncList = _seriesRepository.All().Where(s => s.LastInfoSync == null && !_attemptedSeries.Contains(s.SeriesId)).ToList(); if (syncList.Count == 0) { return; @@ -77,7 +81,7 @@ namespace NzbDrone.Core.Jobs _updateInfoJob.Start(notification, new { SeriesId = currentSeries.SeriesId }); _diskScanJob.Start(notification, new { SeriesId = currentSeries.SeriesId }); - var updatedSeries = _seriesProvider.Get(currentSeries.SeriesId); + var updatedSeries = _seriesRepository.Get(currentSeries.SeriesId); AutoIgnoreSeasons(updatedSeries.SeriesId); //Download the banner for the new series @@ -105,14 +109,14 @@ namespace NzbDrone.Core.Jobs if (episodeFiles.Count() != 0) { - var seasons = _episodeProvider.GetSeasons(seriesId); + var seasons = _seasonRepository.GetSeasonNumbers(seriesId); var currentSeasons = seasons.Max(); foreach (var season in seasons) { if (season != currentSeasons && !episodeFiles.Any(e => e.SeasonNumber == season)) { - _seasonProvider.SetIgnore(seriesId, season, true); + _seasonService.SetIgnore(seriesId, season, true); } } } diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index dfb58c830..0a675c4aa 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Core.Jobs public void Init() { var currentJobs = All(); - _logger.Debug("Initializing jobs. Available: {0} Existing:{1}", _jobs.Count(), currentJobs.Count); + _logger.Debug("Initializing jobs. Available: {0} Existing:{1}", _jobs.Count(), currentJobs.Count()); foreach (var currentJob in currentJobs) { diff --git a/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs b/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs index dcfc81836..4ce9205eb 100644 --- a/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs +++ b/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs @@ -13,16 +13,16 @@ namespace NzbDrone.Core.Jobs { public class PastWeekBacklogSearchJob : IJob { - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly EpisodeSearchJob _episodeSearchJob; private readonly ConfigProvider _configProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public PastWeekBacklogSearchJob(EpisodeProvider episodeProvider, EpisodeSearchJob episodeSearchJob, + public PastWeekBacklogSearchJob(EpisodeService episodeService, EpisodeSearchJob episodeSearchJob, ConfigProvider configProvider) { - _episodeProvider = episodeProvider; + _episodeService = episodeService; _episodeSearchJob = episodeSearchJob; _configProvider = configProvider; } @@ -44,13 +44,13 @@ namespace NzbDrone.Core.Jobs Logger.Debug("Processing missing episodes from the past week, count: {0}", missingEpisodes.Count); foreach (var episode in missingEpisodes) { - _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId }); + _episodeSearchJob.Start(notification, new { EpisodeId = episode.OID }); } } public List GetMissingForEnabledSeries() { - return _episodeProvider.EpisodesWithoutFiles(true).Where(e => + return _episodeService.EpisodesWithoutFiles(true).Where(e => e.AirDate >= DateTime.Today.AddDays(-7) && e.Series.Monitored ).ToList(); diff --git a/NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs b/NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs index 7cdf3bba5..089348420 100644 --- a/NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs +++ b/NzbDrone.Core/Jobs/RecentBacklogSearchJob.cs @@ -13,16 +13,16 @@ namespace NzbDrone.Core.Jobs { public class RecentBacklogSearchJob : IJob { - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly EpisodeSearchJob _episodeSearchJob; private readonly ConfigProvider _configProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public RecentBacklogSearchJob(EpisodeProvider episodeProvider, EpisodeSearchJob episodeSearchJob, + public RecentBacklogSearchJob(EpisodeService episodeService, EpisodeSearchJob episodeSearchJob, ConfigProvider configProvider) { - _episodeProvider = episodeProvider; + _episodeService = episodeService; _episodeSearchJob = episodeSearchJob; _configProvider = configProvider; } @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Jobs Logger.Debug("Processing missing episodes from the last 30 days, count: {0}", missingEpisodes.Count); foreach (var episode in missingEpisodes) { - _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId }); + _episodeSearchJob.Start(notification, new { EpisodeId = episode.OID }); } } @@ -53,7 +53,7 @@ namespace NzbDrone.Core.Jobs if (!_configProvider.EnableBacklogSearching) { Logger.Trace("Backlog searching is not enabled, only running for explicitly enabled series."); - return _episodeProvider.EpisodesWithoutFiles(true).Where(e => + return _episodeService.EpisodesWithoutFiles(true).Where(e => e.AirDate >= DateTime.Today.AddDays(-30) && e.Series.BacklogSetting == BacklogSettingType.Enable && e.Series.Monitored @@ -62,8 +62,8 @@ namespace NzbDrone.Core.Jobs else { - Logger.Trace("Backlog searching is enabled, skipping explicity disabled series."); - return _episodeProvider.EpisodesWithoutFiles(true).Where(e => + Logger.Trace("Backlog searching is enabled, skipping explicitly disabled series."); + return _episodeService.EpisodesWithoutFiles(true).Where(e => e.AirDate >= DateTime.Today.AddDays(-30) && e.Series.BacklogSetting != BacklogSettingType.Disable && e.Series.Monitored diff --git a/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs b/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs index 80bc13513..f297ab7f9 100644 --- a/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs +++ b/NzbDrone.Core/Jobs/RefreshEpsiodeMetadata.cs @@ -12,17 +12,19 @@ namespace NzbDrone.Core.Jobs public class RefreshEpisodeMetadata : IJob { private readonly MediaFileProvider _mediaFileProvider; - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly MetadataProvider _metadataProvider; + private readonly ISeriesRepository _seriesRepository; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public RefreshEpisodeMetadata(MediaFileProvider mediaFileProvider, SeriesProvider seriesProvider, - MetadataProvider metadataProvider) + public RefreshEpisodeMetadata(MediaFileProvider mediaFileProvider, ISeriesService seriesService, + MetadataProvider metadataProvider,ISeriesRepository seriesRepository) { _mediaFileProvider = mediaFileProvider; - _seriesProvider = seriesProvider; + _seriesService = seriesService; _metadataProvider = metadataProvider; + _seriesRepository = seriesRepository; } public string Name @@ -40,10 +42,10 @@ namespace NzbDrone.Core.Jobs List seriesToRefresh; if (options == null || options.SeriesId <= 0) - seriesToRefresh = _seriesProvider.All().ToList(); + seriesToRefresh = _seriesRepository.All().ToList(); else - seriesToRefresh = new List { _seriesProvider.Get(options.SeriesId) }; + seriesToRefresh = new List { _seriesRepository.Get(options.SeriesId) }; foreach(var series in seriesToRefresh) { diff --git a/NzbDrone.Core/Jobs/RenameSeasonJob.cs b/NzbDrone.Core/Jobs/RenameSeasonJob.cs index 8d9855ab2..b3c09f8c7 100644 --- a/NzbDrone.Core/Jobs/RenameSeasonJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeasonJob.cs @@ -13,20 +13,20 @@ namespace NzbDrone.Core.Jobs private readonly MediaFileProvider _mediaFileProvider; private readonly DiskScanProvider _diskScanProvider; private readonly ExternalNotificationProvider _externalNotificationProvider; - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly MetadataProvider _metadataProvider; private readonly ISeriesRepository _seriesRepository; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public RenameSeasonJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider, - ExternalNotificationProvider externalNotificationProvider, SeriesProvider seriesProvider, + ExternalNotificationProvider externalNotificationProvider, ISeriesService seriesService, MetadataProvider metadataProvider,ISeriesRepository seriesRepository) { _mediaFileProvider = mediaFileProvider; _diskScanProvider = diskScanProvider; _externalNotificationProvider = externalNotificationProvider; - _seriesProvider = seriesProvider; + _seriesService = seriesService; _metadataProvider = metadataProvider; _seriesRepository = seriesRepository; } diff --git a/NzbDrone.Core/Jobs/RenameSeriesJob.cs b/NzbDrone.Core/Jobs/RenameSeriesJob.cs index 2df88b474..ded5ad566 100644 --- a/NzbDrone.Core/Jobs/RenameSeriesJob.cs +++ b/NzbDrone.Core/Jobs/RenameSeriesJob.cs @@ -14,20 +14,20 @@ namespace NzbDrone.Core.Jobs private readonly MediaFileProvider _mediaFileProvider; private readonly DiskScanProvider _diskScanProvider; private readonly ExternalNotificationProvider _externalNotificationProvider; - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly MetadataProvider _metadataProvider; private readonly ISeriesRepository _seriesRepository; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); public RenameSeriesJob(MediaFileProvider mediaFileProvider, DiskScanProvider diskScanProvider, - ExternalNotificationProvider externalNotificationProvider, SeriesProvider seriesProvider, + ExternalNotificationProvider externalNotificationProvider, ISeriesService seriesService, MetadataProvider metadataProvider,ISeriesRepository seriesRepository) { _mediaFileProvider = mediaFileProvider; _diskScanProvider = diskScanProvider; _externalNotificationProvider = externalNotificationProvider; - _seriesProvider = seriesProvider; + _seriesService = seriesService; _metadataProvider = metadataProvider; _seriesRepository = seriesRepository; } diff --git a/NzbDrone.Core/Jobs/SeasonSearchJob.cs b/NzbDrone.Core/Jobs/SeasonSearchJob.cs index 21a4e884c..a460a8947 100644 --- a/NzbDrone.Core/Jobs/SeasonSearchJob.cs +++ b/NzbDrone.Core/Jobs/SeasonSearchJob.cs @@ -13,16 +13,16 @@ namespace NzbDrone.Core.Jobs { private readonly SearchProvider _searchProvider; private readonly EpisodeSearchJob _episodeSearchJob; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); public SeasonSearchJob(SearchProvider searchProvider, EpisodeSearchJob episodeSearchJob, - EpisodeProvider episodeProvider) + EpisodeService episodeService) { _searchProvider = searchProvider; _episodeSearchJob = episodeSearchJob; - _episodeProvider = episodeProvider; + _episodeService = episodeService; } public SeasonSearchJob() @@ -57,7 +57,7 @@ namespace NzbDrone.Core.Jobs // return; Logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber); - List episodes = _episodeProvider.GetEpisodesBySeason(options.SeriesId, options.SeasonNumber); + List episodes = _episodeService.GetEpisodesBySeason(options.SeriesId, options.SeasonNumber); if (episodes == null || episodes.Count == 0) { @@ -68,11 +68,11 @@ namespace NzbDrone.Core.Jobs if (episodes.Count == successes.Count) return; - var missingEpisodes = episodes.Select(e => e.EpisodeId).Except(successes).ToList(); + var missingEpisodes = episodes.Select(e => e.OID).Except(successes).ToList(); - foreach (var episode in episodes.Where(e => !e.Ignored && missingEpisodes.Contains(e.EpisodeId)).OrderBy(o => o.EpisodeNumber)) + foreach (var episode in episodes.Where(e => !e.Ignored && missingEpisodes.Contains(e.OID)).OrderBy(o => o.EpisodeNumber)) { - _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId }); + _episodeSearchJob.Start(notification, new { EpisodeId = episode.OID }); } } } diff --git a/NzbDrone.Core/Jobs/SeriesSearchJob.cs b/NzbDrone.Core/Jobs/SeriesSearchJob.cs index 60e232d51..6bb06e923 100644 --- a/NzbDrone.Core/Jobs/SeriesSearchJob.cs +++ b/NzbDrone.Core/Jobs/SeriesSearchJob.cs @@ -12,15 +12,14 @@ namespace NzbDrone.Core.Jobs public class SeriesSearchJob : IJob { private readonly SeasonSearchJob _seasonSearchJob; - private readonly SeasonProvider _seasonProvider; + private readonly ISeasonRepository _seasonRepository; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public SeriesSearchJob(SeasonSearchJob seasonSearchJob, - SeasonProvider seasonProvider) + public SeriesSearchJob(SeasonSearchJob seasonSearchJob, ISeasonRepository seasonRepository) { _seasonSearchJob = seasonSearchJob; - _seasonProvider = seasonProvider; + _seasonRepository = seasonRepository; } public string Name @@ -39,11 +38,11 @@ namespace NzbDrone.Core.Jobs throw new ArgumentException("options.SeriesId"); logger.Debug("Getting seasons from database for series: {0}", options.SeriesId); - IList seasons = _seasonProvider.GetSeasons(options.SeriesId); + IList seasons = _seasonRepository.GetSeasonBySeries(options.SeriesId); foreach (var season in seasons.Where(s => s > 0)) { - if (!_seasonProvider.IsIgnored(options.SeriesId, season)) + if (!_seasonRepository.IsIgnored(options.SeriesId, season)) { _seasonSearchJob.Start(notification, new { SeriesId = options.SeriesId, SeasonNumber = season }); } diff --git a/NzbDrone.Core/Jobs/UpdateInfoJob.cs b/NzbDrone.Core/Jobs/UpdateInfoJob.cs index 729314506..01ae91e56 100644 --- a/NzbDrone.Core/Jobs/UpdateInfoJob.cs +++ b/NzbDrone.Core/Jobs/UpdateInfoJob.cs @@ -13,18 +13,18 @@ namespace NzbDrone.Core.Jobs { public class UpdateInfoJob : IJob { - private readonly SeriesProvider _seriesProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly ISeriesService _seriesService; + private readonly EpisodeService _episodeService; private readonly ReferenceDataProvider _referenceDataProvider; private readonly ConfigProvider _configProvider; private readonly ISeriesRepository _seriesRepository; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public UpdateInfoJob(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, + public UpdateInfoJob(ISeriesService seriesService, EpisodeService episodeService, ReferenceDataProvider referenceDataProvider, ConfigProvider configProvider, ISeriesRepository seriesRepository) { - _seriesProvider = seriesProvider; - _episodeProvider = episodeProvider; + _seriesService = seriesService; + _episodeService = episodeService; _referenceDataProvider = referenceDataProvider; _configProvider = configProvider; _seriesRepository = seriesRepository; @@ -69,8 +69,8 @@ namespace NzbDrone.Core.Jobs try { notification.CurrentMessage = "Updating " + series.Title; - _seriesProvider.UpdateSeriesInfo(series.SeriesId); - _episodeProvider.RefreshEpisodeInfo(series); + _seriesService.UpdateSeriesInfo(series.SeriesId); + _episodeService.RefreshEpisodeInfo(series); notification.CurrentMessage = "Update completed for " + series.Title; } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index d45a7444e..5c319928a 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -302,6 +302,8 @@ + + @@ -354,7 +356,7 @@ - + @@ -455,7 +457,7 @@ Code - + Code diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index b66c4b2fe..7141a992f 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -16,9 +16,9 @@ namespace NzbDrone.Core.Providers private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly string[] mediaExtentions = new[] { ".mkv", ".avi", ".wmv", ".mp4", ".mpg", ".mpeg", ".xvid", ".flv", ".mov", ".rm", ".rmvb", ".divx", ".dvr-ms", ".ts", ".ogm", ".m4v", ".strm" }; private readonly DiskProvider _diskProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly MediaFileProvider _mediaFileProvider; - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly ExternalNotificationProvider _externalNotificationProvider; private readonly DownloadProvider _downloadProvider; private readonly SignalRProvider _signalRProvider; @@ -27,15 +27,15 @@ namespace NzbDrone.Core.Providers private readonly MediaInfoProvider _mediaInfoProvider; private readonly ISeriesRepository _seriesRepository; - public DiskScanProvider(DiskProvider diskProvider, EpisodeProvider episodeProvider, - SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider, + public DiskScanProvider(DiskProvider diskProvider, EpisodeService episodeService, + ISeriesService seriesService, MediaFileProvider mediaFileProvider, ExternalNotificationProvider externalNotificationProvider, DownloadProvider downloadProvider, SignalRProvider signalRProvider, ConfigProvider configProvider, - RecycleBinProvider recycleBinProvider, MediaInfoProvider mediaInfoProvider,ISeriesRepository seriesRepository) + RecycleBinProvider recycleBinProvider, MediaInfoProvider mediaInfoProvider, ISeriesRepository seriesRepository) { _diskProvider = diskProvider; - _episodeProvider = episodeProvider; - _seriesProvider = seriesProvider; + _episodeService = episodeService; + _seriesService = seriesService; _mediaFileProvider = mediaFileProvider; _externalNotificationProvider = externalNotificationProvider; _downloadProvider = downloadProvider; @@ -74,7 +74,7 @@ namespace NzbDrone.Core.Providers return new List(); } - if (_episodeProvider.GetEpisodeBySeries(series.SeriesId).Count == 0) + if (_episodeService.GetEpisodeBySeries(series.SeriesId).Count == 0) { Logger.Debug("Series {0} has no episodes. skipping", series.Title); return new List(); @@ -122,7 +122,7 @@ namespace NzbDrone.Core.Providers var size = _diskProvider.GetSize(filePath); var runTime = _mediaInfoProvider.GetRunTime(filePath); - if(series.IsDaily || parseResult.SeasonNumber > 0) + if (series.SeriesType == SeriesType.Daily || parseResult.SeasonNumber > 0) { if (size < Constants.IgnoreFileSize && runTime < 180) { @@ -137,7 +137,7 @@ namespace NzbDrone.Core.Providers parseResult.SeriesTitle = series.Title; //replaces the nasty path as title to help with logging parseResult.Series = series; - var episodes = _episodeProvider.GetEpisodesByParseResult(parseResult); + var episodes = _episodeService.GetEpisodesByParseResult(parseResult); if (episodes.Count <= 0) { @@ -173,14 +173,14 @@ namespace NzbDrone.Core.Providers //Todo: We shouldn't actually import the file until we confirm its the only one we want. //Todo: Separate episodeFile creation from importing (pass file to import to import) - var fileId = _mediaFileProvider.Add(episodeFile); + _mediaFileProvider.Add(episodeFile); //Link file to all episodes foreach (var ep in episodes) { - ep.EpisodeFileId = fileId; + ep.EpisodeFile = episodeFile; ep.PostDownloadStatus = PostDownloadStatusType.NoError; - _episodeProvider.UpdateEpisode(ep); + _episodeService.UpdateEpisode(ep); Logger.Debug("Linking [{0}] > [{1}]", filePath, ep); } @@ -193,7 +193,7 @@ namespace NzbDrone.Core.Providers throw new ArgumentNullException("episodeFile"); var series = _seriesRepository.Get(episodeFile.SeriesId); - var episodes = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId); + var episodes = _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId); string newFileName = _mediaFileProvider.GetNewFilename(episodes, series, episodeFile.Quality, episodeFile.Proper, episodeFile); var newFile = _mediaFileProvider.CalculateFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); @@ -204,7 +204,7 @@ namespace NzbDrone.Core.Providers return null; } - if(!_diskProvider.FileExists(episodeFile.Path)) + if (!_diskProvider.FileExists(episodeFile.Path)) { Logger.Error("Episode file path does not exist, {0}", episodeFile.Path); return null; @@ -231,7 +231,7 @@ namespace NzbDrone.Core.Providers var parseResult = Parser.ParsePath(episodeFile.Path); parseResult.Series = series; - parseResult.Quality = new QualityModel{ Quality = episodeFile.Quality, Proper = episodeFile.Proper }; + parseResult.Quality = new QualityModel { Quality = episodeFile.Quality, Proper = episodeFile.Proper }; parseResult.Episodes = episodes; var message = _downloadProvider.GetDownloadTitle(parseResult); @@ -239,9 +239,9 @@ namespace NzbDrone.Core.Providers if (newDownload) { _externalNotificationProvider.OnDownload(message, series); - - foreach(var episode in episodes) - _signalRProvider.UpdateEpisodeStatus(episode.EpisodeId, EpisodeStatusType.Ready, parseResult.Quality); + + foreach (var episode in episodes) + _signalRProvider.UpdateEpisodeStatus(episode.OID, EpisodeStatusType.Ready, parseResult.Quality); } else { @@ -261,19 +261,19 @@ namespace NzbDrone.Core.Providers { try { - if(!_diskProvider.FileExists(episodeFile.Path)) + if (!_diskProvider.FileExists(episodeFile.Path)) { Logger.Trace("File [{0}] no longer exists on disk. removing from db", episodeFile.Path); //Set the EpisodeFileId for each episode attached to this file to 0 - foreach(var episode in _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId)) + foreach (var episode in _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId)) { - Logger.Trace("Setting EpisodeFileId for Episode: [{0}] to 0", episode.EpisodeId); - episode.EpisodeFileId = 0; + Logger.Trace("Detaching episode {0} from file.", episode.OID); + episode.EpisodeFile = null; episode.Ignored = _configProvider.AutoIgnorePreviouslyDownloadedEpisodes; episode.GrabDate = null; episode.PostDownloadStatus = PostDownloadStatusType.Unknown; - _episodeProvider.UpdateEpisode(episode); + _episodeService.UpdateEpisode(episode); } //Delete it from the DB @@ -295,7 +295,7 @@ namespace NzbDrone.Core.Providers var filesOnDisk = GetVideoFiles(path); - foreach(var file in filesOnDisk) + foreach (var file in filesOnDisk) { try { diff --git a/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs b/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs index 70c80358f..5347a73e0 100644 --- a/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs +++ b/NzbDrone.Core/Providers/DownloadClients/NzbgetProvider.cs @@ -11,6 +11,7 @@ using NzbDrone.Common; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Nzbget; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Tv; namespace NzbDrone.Core.Providers.DownloadClients { @@ -41,7 +42,7 @@ namespace NzbDrone.Core.Providers.DownloadClients var matchingTitleWithQuality = matchigTitle.Where(q => q.ParseResult.Quality >= newParseResult.Quality); - if (newParseResult.Series.IsDaily) + if (newParseResult.Series.SeriesType == SeriesType.Daily) { return matchingTitleWithQuality.Any(q => q.ParseResult.AirDate.Value.Date == newParseResult.AirDate.Value.Date); } diff --git a/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs b/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs index 30d0b392e..d7c74502c 100644 --- a/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs +++ b/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs @@ -11,6 +11,7 @@ using NzbDrone.Common; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Sabnzbd; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Tv; namespace NzbDrone.Core.Providers.DownloadClients { @@ -40,7 +41,7 @@ namespace NzbDrone.Core.Providers.DownloadClients var matchingTitleWithQuality = matchigTitle.Where(q => q.ParseResult.Quality >= newParseResult.Quality); - if (newParseResult.Series.IsDaily) + if (newParseResult.Series.SeriesType == SeriesType.Daily) { return matchingTitleWithQuality.Any(q => q.ParseResult.AirDate.Value.Date == newParseResult.AirDate.Value.Date); } diff --git a/NzbDrone.Core/Providers/DownloadProvider.cs b/NzbDrone.Core/Providers/DownloadProvider.cs index a8edd1ce6..0dfa6373d 100644 --- a/NzbDrone.Core/Providers/DownloadProvider.cs +++ b/NzbDrone.Core/Providers/DownloadProvider.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.Providers { private readonly SabProvider _sabProvider; private readonly HistoryProvider _historyProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly ExternalNotificationProvider _externalNotificationProvider; private readonly ConfigProvider _configProvider; private readonly BlackholeProvider _blackholeProvider; @@ -25,14 +25,14 @@ namespace NzbDrone.Core.Providers private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public DownloadProvider(SabProvider sabProvider, HistoryProvider historyProvider, - EpisodeProvider episodeProvider, ExternalNotificationProvider externalNotificationProvider, + EpisodeService episodeService, ExternalNotificationProvider externalNotificationProvider, ConfigProvider configProvider, BlackholeProvider blackholeProvider, SignalRProvider signalRProvider, PneumaticProvider pneumaticProvider, NzbgetProvider nzbgetProvider) { _sabProvider = sabProvider; _historyProvider = historyProvider; - _episodeProvider = episodeProvider; + _episodeService = episodeService; _externalNotificationProvider = externalNotificationProvider; _configProvider = configProvider; _blackholeProvider = blackholeProvider; @@ -66,16 +66,16 @@ namespace NzbDrone.Core.Providers IsProper = parseResult.Quality.Proper, Quality = parseResult.Quality.Quality, NzbTitle = parseResult.OriginalString, - EpisodeId = episode.EpisodeId, + EpisodeId = episode.OID, SeriesId = episode.SeriesId, NzbInfoUrl = parseResult.NzbInfoUrl, ReleaseGroup = parseResult.ReleaseGroup, }; _historyProvider.Add(history); - _episodeProvider.MarkEpisodeAsFetched(episode.EpisodeId); + _episodeService.MarkEpisodeAsFetched(episode.OID); - _signalRProvider.UpdateEpisodeStatus(episode.EpisodeId, EpisodeStatusType.Downloading, null); + _signalRProvider.UpdateEpisodeStatus(episode.OID, EpisodeStatusType.Downloading, null); } _externalNotificationProvider.OnGrab(downloadTitle); @@ -124,7 +124,7 @@ namespace NzbDrone.Core.Providers return seasonResult; } - if (parseResult.Series.IsDaily) + if (parseResult.Series.SeriesType == SeriesType.Daily) { var dailyResult = String.Format("{0} - {1:yyyy-MM-dd} - {2} [{3}]", seriesTitle, parseResult.AirDate, parseResult.Episodes.First().Title, parseResult.Quality.Quality); diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index 5cb7b8f1b..bdbcf254c 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -18,11 +18,11 @@ namespace NzbDrone.Core.Providers private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly ConfigProvider _configProvider; private readonly IDatabase _database; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; - public MediaFileProvider(EpisodeProvider episodeProvider, ConfigProvider configProvider, IDatabase database) + public MediaFileProvider(EpisodeService episodeService, ConfigProvider configProvider, IDatabase database) { - _episodeProvider = episodeProvider; + _episodeService = episodeService; _configProvider = configProvider; _database = database; } @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Providers public virtual Tuple GetEpisodeFilesCount(int seriesId) { - var allEpisodes = _episodeProvider.GetEpisodeBySeries(seriesId).ToList(); + var allEpisodes = _episodeService.GetEpisodeBySeries(seriesId).ToList(); var episodeTotal = allEpisodes.Where(e => !e.Ignored && e.AirDate != null && e.AirDate <= DateTime.Today).ToList(); var avilableEpisodes = episodeTotal.Where(e => e.EpisodeFileId > 0).ToList(); @@ -173,7 +173,7 @@ namespace NzbDrone.Core.Providers result += series.Title + separatorStyle.Pattern; } - if(!series.IsDaily) + if (series.SeriesType == SeriesType.Standard) { result += numberStyle.Pattern.Replace("%0e", String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber)); diff --git a/NzbDrone.Core/Providers/Metadata/MetadataBase.cs b/NzbDrone.Core/Providers/Metadata/MetadataBase.cs index 1d685897a..6892d93b8 100644 --- a/NzbDrone.Core/Providers/Metadata/MetadataBase.cs +++ b/NzbDrone.Core/Providers/Metadata/MetadataBase.cs @@ -15,15 +15,15 @@ namespace NzbDrone.Core.Providers.Metadata protected readonly ConfigProvider _configProvider; protected readonly DiskProvider _diskProvider; protected readonly BannerProvider _bannerProvider; - protected readonly EpisodeProvider _episodeProvider; + protected readonly EpisodeService _episodeService; protected MetadataBase(ConfigProvider configProvider, DiskProvider diskProvider, - BannerProvider bannerProvider, EpisodeProvider episodeProvider) + BannerProvider bannerProvider, EpisodeService episodeService) { _configProvider = configProvider; _diskProvider = diskProvider; _bannerProvider = bannerProvider; - _episodeProvider = episodeProvider; + _episodeService = episodeService; _logger = LogManager.GetLogger(GetType().ToString()); } diff --git a/NzbDrone.Core/Providers/Metadata/Xbmc.cs b/NzbDrone.Core/Providers/Metadata/Xbmc.cs index 034ac15bd..14e51c56a 100644 --- a/NzbDrone.Core/Providers/Metadata/Xbmc.cs +++ b/NzbDrone.Core/Providers/Metadata/Xbmc.cs @@ -17,8 +17,8 @@ namespace NzbDrone.Core.Providers.Metadata public class Xbmc : MetadataBase { public Xbmc(ConfigProvider configProvider, DiskProvider diskProvider, - BannerProvider bannerProvider, EpisodeProvider episodeProvider) - : base(configProvider, diskProvider, bannerProvider, episodeProvider) + BannerProvider bannerProvider, EpisodeService episodeService) + : base(configProvider, diskProvider, bannerProvider, episodeService) { } @@ -113,7 +113,7 @@ namespace NzbDrone.Core.Providers.Metadata public override void CreateForEpisodeFile(EpisodeFile episodeFile, TvdbSeries tvDbSeries) { //Create filename.tbn and filename.nfo - var episodes = _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId); + var episodes = _episodeService.GetEpisodesByFileId(episodeFile.EpisodeFileId); if (!episodes.Any()) { diff --git a/NzbDrone.Core/Providers/MisnamedProvider.cs b/NzbDrone.Core/Providers/MisnamedProvider.cs index 4d529f430..8fc3d9576 100644 --- a/NzbDrone.Core/Providers/MisnamedProvider.cs +++ b/NzbDrone.Core/Providers/MisnamedProvider.cs @@ -14,21 +14,21 @@ namespace NzbDrone.Core.Providers public class MisnamedProvider { private readonly MediaFileProvider _mediaFileProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public MisnamedProvider(MediaFileProvider mediaFileProvider, EpisodeProvider episodeProvider) + public MisnamedProvider(MediaFileProvider mediaFileProvider, EpisodeService episodeService) { _mediaFileProvider = mediaFileProvider; - _episodeProvider = episodeProvider; + _episodeService = episodeService; } public virtual List MisnamedFiles(int pageNumber, int pageSize, out int totalItems) { var misnamedFiles = new List(); - var episodesWithFiles = _episodeProvider.EpisodesWithFiles().GroupBy(e => e.EpisodeFileId).ToList(); + var episodesWithFiles = _episodeService.EpisodesWithFiles().GroupBy(e => e.EpisodeFileId).ToList(); totalItems = episodesWithFiles.Count(); var stopwatch = new Stopwatch(); stopwatch.Start(); diff --git a/NzbDrone.Core/Providers/PostDownloadProvider.cs b/NzbDrone.Core/Providers/PostDownloadProvider.cs index 658e2427c..24adcbbc4 100644 --- a/NzbDrone.Core/Providers/PostDownloadProvider.cs +++ b/NzbDrone.Core/Providers/PostDownloadProvider.cs @@ -16,16 +16,16 @@ namespace NzbDrone.Core.Providers private static readonly Regex StatusRegex = new Regex(@"^_[\w_]*_", RegexOptions.Compiled); private readonly DiskProvider _diskProvider; private readonly DiskScanProvider _diskScanProvider; - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly MetadataProvider _metadataProvider; private readonly ISeriesRepository _seriesRepository; public PostDownloadProvider(DiskProvider diskProvider, DiskScanProvider diskScanProvider, - SeriesProvider seriesProvider, MetadataProvider metadataProvider,ISeriesRepository seriesRepository) + ISeriesService seriesService, MetadataProvider metadataProvider,ISeriesRepository seriesRepository) { _diskProvider = diskProvider; _diskScanProvider = diskScanProvider; - _seriesProvider = seriesProvider; + _seriesService = seriesService; _metadataProvider = metadataProvider; _seriesRepository = seriesRepository; } @@ -79,7 +79,7 @@ namespace NzbDrone.Core.Providers } string seriesName = Parser.ParseSeriesName(RemoveStatusFromFolderName(subfolderInfo.Name)); - var series = _seriesRepository.Get(seriesName); + var series = _seriesRepository.GetByTitle(seriesName); if (series == null) { @@ -149,7 +149,7 @@ namespace NzbDrone.Core.Providers } var seriesName = Parser.ParseSeriesName(Path.GetFileNameWithoutExtension(videoFile)); - var series = _seriesRepository.Get(seriesName); + var series = _seriesRepository.GetByTitle(seriesName); if (series == null) { diff --git a/NzbDrone.Core/Providers/Search/DailyEpisodeSearch.cs b/NzbDrone.Core/Providers/Search/DailyEpisodeSearch.cs index 0c5c81c05..52d0a45fe 100644 --- a/NzbDrone.Core/Providers/Search/DailyEpisodeSearch.cs +++ b/NzbDrone.Core/Providers/Search/DailyEpisodeSearch.cs @@ -18,10 +18,10 @@ namespace NzbDrone.Core.Providers.Search private readonly ISeriesRepository _seriesRepository; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public DailyEpisodeSearch(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, DownloadProvider downloadProvider, IndexerProvider indexerProvider, + public DailyEpisodeSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerProvider indexerProvider, SceneMappingProvider sceneMappingProvider, AllowedDownloadSpecification allowedDownloadSpecification, SearchHistoryProvider searchHistoryProvider, ISeriesRepository seriesRepository) - : base(seriesProvider, seriesRepository, episodeProvider, downloadProvider, indexerProvider, sceneMappingProvider, + : base(seriesService, seriesRepository, episodeService, downloadProvider, indexerProvider, sceneMappingProvider, allowedDownloadSpecification, searchHistoryProvider) { _seriesRepository = seriesRepository; diff --git a/NzbDrone.Core/Providers/Search/EpisodeSearch.cs b/NzbDrone.Core/Providers/Search/EpisodeSearch.cs index 2a0250fd6..787bbd036 100644 --- a/NzbDrone.Core/Providers/Search/EpisodeSearch.cs +++ b/NzbDrone.Core/Providers/Search/EpisodeSearch.cs @@ -17,10 +17,10 @@ namespace NzbDrone.Core.Providers.Search { private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public EpisodeSearch(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, DownloadProvider downloadProvider, IndexerProvider indexerProvider, + public EpisodeSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerProvider indexerProvider, SceneMappingProvider sceneMappingProvider, AllowedDownloadSpecification allowedDownloadSpecification, SearchHistoryProvider searchHistoryProvider, ISeriesRepository seriesRepository) - : base(seriesProvider,seriesRepository, episodeProvider, downloadProvider, indexerProvider, sceneMappingProvider, + : base(seriesService,seriesRepository, episodeService, downloadProvider, indexerProvider, sceneMappingProvider, allowedDownloadSpecification, searchHistoryProvider) { } diff --git a/NzbDrone.Core/Providers/Search/PartialSeasonSearch.cs b/NzbDrone.Core/Providers/Search/PartialSeasonSearch.cs index 80f0b1bb5..b90931d05 100644 --- a/NzbDrone.Core/Providers/Search/PartialSeasonSearch.cs +++ b/NzbDrone.Core/Providers/Search/PartialSeasonSearch.cs @@ -17,10 +17,10 @@ namespace NzbDrone.Core.Providers.Search { private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public PartialSeasonSearch(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, DownloadProvider downloadProvider, IndexerProvider indexerProvider, + public PartialSeasonSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerProvider indexerProvider, SceneMappingProvider sceneMappingProvider, AllowedDownloadSpecification allowedDownloadSpecification, SearchHistoryProvider searchHistoryProvider,ISeriesRepository seriesRepository) - : base(seriesProvider, seriesRepository, episodeProvider, downloadProvider, indexerProvider, sceneMappingProvider, + : base(seriesService, seriesRepository, episodeService, downloadProvider, indexerProvider, sceneMappingProvider, allowedDownloadSpecification, searchHistoryProvider) { } diff --git a/NzbDrone.Core/Providers/Search/SearchBase.cs b/NzbDrone.Core/Providers/Search/SearchBase.cs index 8c2c0a823..b7ede3587 100644 --- a/NzbDrone.Core/Providers/Search/SearchBase.cs +++ b/NzbDrone.Core/Providers/Search/SearchBase.cs @@ -1,23 +1,21 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Text.RegularExpressions; using NLog; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.DecisionEngine; -using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Search; namespace NzbDrone.Core.Providers.Search { public abstract class SearchBase { - protected readonly SeriesProvider _seriesProvider; + protected readonly ISeriesService _seriesService; private readonly ISeriesRepository _seriesRepository; - protected readonly EpisodeProvider _episodeProvider; + protected readonly EpisodeService _episodeService; protected readonly DownloadProvider _downloadProvider; protected readonly IndexerProvider _indexerProvider; protected readonly SceneMappingProvider _sceneMappingProvider; @@ -26,14 +24,14 @@ namespace NzbDrone.Core.Providers.Search private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - protected SearchBase(SeriesProvider seriesProvider,ISeriesRepository seriesRepository, EpisodeProvider episodeProvider, DownloadProvider downloadProvider, + protected SearchBase(ISeriesService seriesService,ISeriesRepository seriesRepository, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerProvider indexerProvider, SceneMappingProvider sceneMappingProvider, AllowedDownloadSpecification allowedDownloadSpecification, SearchHistoryProvider searchHistoryProvider) { - _seriesProvider = seriesProvider; + _seriesService = seriesService; _seriesRepository = seriesRepository; - _episodeProvider = episodeProvider; + _episodeService = episodeService; _downloadProvider = downloadProvider; _indexerProvider = indexerProvider; _sceneMappingProvider = sceneMappingProvider; @@ -107,7 +105,7 @@ namespace NzbDrone.Core.Providers.Search items.Add(item); logger.Trace("Analysing report " + episodeParseResult); - episodeParseResult.Series = _seriesRepository.Get(episodeParseResult.CleanTitle); + episodeParseResult.Series = _seriesRepository.GetByTitle(episodeParseResult.CleanTitle); if(episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId) { @@ -115,9 +113,9 @@ namespace NzbDrone.Core.Providers.Search continue; } - episodeParseResult.Episodes = _episodeProvider.GetEpisodesByParseResult(episodeParseResult); + episodeParseResult.Episodes = _episodeService.GetEpisodesByParseResult(episodeParseResult); - if (searchResult.Successes.Intersect(episodeParseResult.Episodes.Select(e => e.EpisodeId)).Any()) + if (searchResult.Successes.Intersect(episodeParseResult.Episodes.Select(e => e.OID)).Any()) { item.SearchError = ReportRejectionType.Skipped; continue; @@ -132,7 +130,7 @@ namespace NzbDrone.Core.Providers.Search if(item.SearchError == ReportRejectionType.None) { if(DownloadReport(notification, episodeParseResult, item)) - searchResult.Successes.AddRange(episodeParseResult.Episodes.Select(e => e.EpisodeId)); + searchResult.Successes.AddRange(episodeParseResult.Episodes.Select(e => e.OID)); } } catch(Exception e) diff --git a/NzbDrone.Core/Providers/SearchHistoryProvider.cs b/NzbDrone.Core/Providers/SearchHistoryProvider.cs index 291204495..c6330eff5 100644 --- a/NzbDrone.Core/Providers/SearchHistoryProvider.cs +++ b/NzbDrone.Core/Providers/SearchHistoryProvider.cs @@ -13,20 +13,20 @@ namespace NzbDrone.Core.Providers public class SearchHistoryProvider { private readonly IDatabase _database; - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; private readonly DownloadProvider _downloadProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private readonly ISeriesRepository _seriesRepository; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public SearchHistoryProvider(IDatabase database, SeriesProvider seriesProvider, - DownloadProvider downloadProvider, EpisodeProvider episodeProvider, ISeriesRepository seriesRepository) + public SearchHistoryProvider(IDatabase database, ISeriesService seriesService, + DownloadProvider downloadProvider, EpisodeService episodeService, ISeriesRepository seriesRepository) { _database = database; - _seriesProvider = seriesProvider; + _seriesService = seriesService; _downloadProvider = downloadProvider; - _episodeProvider = episodeProvider; + _episodeService = episodeService; _seriesRepository = seriesRepository; } @@ -113,7 +113,7 @@ namespace NzbDrone.Core.Providers parseResult.NzbUrl = item.NzbUrl; parseResult.Series = series; parseResult.Indexer = item.Indexer; - parseResult.Episodes = _episodeProvider.GetEpisodesByParseResult(parseResult); + parseResult.Episodes = _episodeService.GetEpisodesByParseResult(parseResult); parseResult.SceneSource = true; logger.Info("Forcing Download of: {0}", item.ReportTitle); diff --git a/NzbDrone.Core/Providers/SearchProvider.cs b/NzbDrone.Core/Providers/SearchProvider.cs index eae5f9125..09fb6768c 100644 --- a/NzbDrone.Core/Providers/SearchProvider.cs +++ b/NzbDrone.Core/Providers/SearchProvider.cs @@ -16,18 +16,18 @@ namespace NzbDrone.Core.Providers { public class SearchProvider { - private readonly SeriesProvider _seriesProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly ISeriesService _seriesService; + private readonly EpisodeService _episodeService; private readonly PartialSeasonSearch _partialSeasonSearch; private readonly ISeriesRepository _seriesRepository; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public SearchProvider(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, + public SearchProvider(ISeriesService seriesService, EpisodeService episodeService, PartialSeasonSearch partialSeasonSearch,ISeriesRepository seriesRepository) { - _seriesProvider = seriesProvider; - _episodeProvider = episodeProvider; + _seriesService = seriesService; + _episodeService = episodeService; _partialSeasonSearch = partialSeasonSearch; _seriesRepository = seriesRepository; } @@ -46,14 +46,14 @@ namespace NzbDrone.Core.Providers return new List(); } - if (series.IsDaily) + if (series.SeriesType == SeriesType.Daily) { logger.Trace("Daily series detected, skipping season search: {0}", series.Title); return new List(); } logger.Debug("Getting episodes from database for series: {0} and season: {1}", seriesId, seasonNumber); - var episodes = _episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber); + var episodes = _episodeService.GetEpisodesBySeason(seriesId, seasonNumber); if (episodes == null || episodes.Count == 0) { @@ -75,13 +75,13 @@ namespace NzbDrone.Core.Providers return new List(); } - if (series.IsDaily) + if (series.SeriesType == SeriesType.Daily) { logger.Trace("Daily series detected, skipping season search: {0}", series.Title); return new List(); } - var episodes = _episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber); + var episodes = _episodeService.GetEpisodesBySeason(seriesId, seasonNumber); if (episodes == null || episodes.Count == 0) { diff --git a/NzbDrone.Core/Providers/TvRageMappingProvider.cs b/NzbDrone.Core/Providers/TvRageMappingProvider.cs index aae8fde35..6b8c76ca8 100644 --- a/NzbDrone.Core/Providers/TvRageMappingProvider.cs +++ b/NzbDrone.Core/Providers/TvRageMappingProvider.cs @@ -13,16 +13,16 @@ namespace NzbDrone.Core.Providers { private readonly SceneMappingProvider _sceneMappingProvider; private readonly TvRageProvider _tvRageProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeService _episodeService; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public TvRageMappingProvider(SceneMappingProvider sceneMappingProvider, - TvRageProvider tvRageProvider, EpisodeProvider episodeProvider) + TvRageProvider tvRageProvider, EpisodeService episodeService) { _sceneMappingProvider = sceneMappingProvider; _tvRageProvider = tvRageProvider; - _episodeProvider = episodeProvider; + _episodeService = episodeService; } public TvRageMappingProvider() @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Providers public Series FindMatchingTvRageSeries(Series series) { - var firstEpisode = _episodeProvider.GetEpisode(series.SeriesId, 1, 1); + var firstEpisode = _episodeService.GetEpisode(series.SeriesId, 1, 1); var cleanName = _sceneMappingProvider.GetCleanName(series.SeriesId); var results = _tvRageProvider.SearchSeries(series.Title); diff --git a/NzbDrone.Core/Providers/XemProvider.cs b/NzbDrone.Core/Providers/XemProvider.cs index 1c1bac1aa..cfcd8cf79 100644 --- a/NzbDrone.Core/Providers/XemProvider.cs +++ b/NzbDrone.Core/Providers/XemProvider.cs @@ -10,18 +10,18 @@ namespace NzbDrone.Core.Providers { public class XemProvider { - private readonly SeriesProvider _seriesProvider; - private readonly EpisodeProvider _episodeProvider; + private readonly ISeriesService _seriesService; + private readonly EpisodeService _episodeService; private readonly XemCommunicationProvider _xemCommunicationProvider; private readonly ISeriesRepository _seriesRepository; private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); - public XemProvider(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, + public XemProvider(ISeriesService seriesService, EpisodeService episodeService, XemCommunicationProvider xemCommunicationProvider,ISeriesRepository seriesRepository) { - _seriesProvider = seriesProvider; - _episodeProvider = episodeProvider; + _seriesService = seriesService; + _episodeService = episodeService; _xemCommunicationProvider = xemCommunicationProvider; _seriesRepository = seriesRepository; } @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Providers return; } - var episodes = _episodeProvider.GetEpisodeBySeries(series.SeriesId); + var episodes = _episodeService.GetEpisodeBySeries(series.SeriesId); foreach (var mapping in mappings) { @@ -110,7 +110,7 @@ namespace NzbDrone.Core.Providers } _logger.Trace("Committing scene numbering mappings to database for: {0}", series.Title); - _episodeProvider.UpdateEpisodes(episodesToUpdate); + _episodeService.UpdateEpisodes(episodesToUpdate); _logger.Trace("Setting UseSceneMapping for {0}", series.Title); series.UseSceneNumbering = true; diff --git a/NzbDrone.Core/RootFolders/RootFolderService.cs b/NzbDrone.Core/RootFolders/RootFolderService.cs index 1121c0d88..64a91dff9 100644 --- a/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -25,14 +25,14 @@ namespace NzbDrone.Core.RootFolders private readonly IBasicRepository _rootFolderRepository; private readonly DiskProvider _diskProvider; private readonly ISeriesRepository _seriesRepository; - private readonly SeriesProvider _seriesProvider; + private readonly ISeriesService _seriesService; - public RootFolderService(IBasicRepository rootFolderRepository, SeriesProvider seriesProvider, DiskProvider diskProvider,ISeriesRepository seriesRepository) + public RootFolderService(IBasicRepository rootFolderRepository, ISeriesService seriesService, DiskProvider diskProvider,ISeriesRepository seriesRepository) { _rootFolderRepository = rootFolderRepository; _diskProvider = diskProvider; _seriesRepository = seriesRepository; - _seriesProvider = seriesProvider; + _seriesService = seriesService; } public virtual List All() diff --git a/NzbDrone.Core/Tv/Episode.cs b/NzbDrone.Core/Tv/Episode.cs index dd5c46436..c0f374677 100644 --- a/NzbDrone.Core/Tv/Episode.cs +++ b/NzbDrone.Core/Tv/Episode.cs @@ -1,17 +1,15 @@ using System.Linq; using System; +using NzbDrone.Core.Datastore; using NzbDrone.Core.Model; namespace NzbDrone.Core.Tv { - public class Episode + public class Episode : ModelBase { - public int EpisodeId { get; set; } - public int? TvDbEpisodeId { get; set; } public int SeriesId { get; set; } - public int EpisodeFileId { get; set; } public int SeasonNumber { get; set; } public int EpisodeNumber { get; set; } public string Title { get; set; } @@ -25,6 +23,23 @@ namespace NzbDrone.Core.Tv public DateTime? GrabDate { get; set; } + + public bool HasFile + { + get { return EpisodeFile != null; } + } + + public int EpisodeFileId + { + get + { + if (!HasFile) return 0; + return EpisodeFile.EpisodeFileId; + } + } + + + public EpisodeStatusType Status { get @@ -64,7 +79,7 @@ namespace NzbDrone.Core.Tv { string seriesTitle = Series == null ? "[NULL]" : Series.Title; - if (Series != null && Series.IsDaily && AirDate.HasValue) + if (Series != null && Series.SeriesType == SeriesType.Daily && AirDate.HasValue) return string.Format("{0} - {1:yyyy-MM-dd}", seriesTitle, AirDate.Value); return string.Format("{0} - S{1:00}E{2:00}", seriesTitle, SeasonNumber, EpisodeNumber); diff --git a/NzbDrone.Core/Tv/EpisodeProvider.cs b/NzbDrone.Core/Tv/EpisodeProvider.cs deleted file mode 100644 index 9433d3ca6..000000000 --- a/NzbDrone.Core/Tv/EpisodeProvider.cs +++ /dev/null @@ -1,476 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NLog; -using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; -using PetaPoco; -using TvdbLib.Data; - -namespace NzbDrone.Core.Tv -{ - public class EpisodeProvider - { - - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - - private readonly TvDbProvider _tvDbProvider; - private readonly SeasonProvider _seasonProvider; - private readonly IDatabase _database; - - public EpisodeProvider(IDatabase database, TvDbProvider tvDbProviderProvider, - SeasonProvider seasonProvider) - { - _tvDbProvider = tvDbProviderProvider; - _seasonProvider = seasonProvider; - _database = database; - } - - public EpisodeProvider() - { - } - - public virtual void AddEpisode(Episode episode) - { - //If Season is ignored ignore this episode - episode.Ignored = _seasonProvider.IsIgnored(episode.SeriesId, episode.SeasonNumber); - - _database.Insert(episode); - } - - public virtual Episode GetEpisode(long id) - { - var episode = _database.Fetch(@"SELECT * FROM Episodes - INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId - LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId - WHERE EpisodeId = @0", id).Single(); - - if (episode.EpisodeFileId == 0) - episode.EpisodeFile = null; - - return episode; - } - - public virtual Episode GetEpisode(int seriesId, int seasonNumber, int episodeNumber) - { - var episode = _database.Fetch(@"SELECT * FROM Episodes - INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId - LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId - WHERE Episodes.SeriesId = @0 AND Episodes.SeasonNumber = @1 AND Episodes.EpisodeNumber = @2", seriesId, seasonNumber, episodeNumber).SingleOrDefault(); - - if (episode == null) - return null; - - if (episode.EpisodeFileId == 0) - episode.EpisodeFile = null; - - return episode; - } - - public virtual Episode GetEpisode(int seriesId, DateTime date) - { - var episode = _database.Fetch(@"SELECT * FROM Episodes - INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId - LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId - WHERE Episodes.SeriesId = @0 AND AirDate = @1", seriesId, date.Date).SingleOrDefault(); - - if (episode == null) - return null; - - if (episode.EpisodeFileId == 0) - episode.EpisodeFile = null; - - return episode; - } - - public virtual IList GetEpisodeBySeries(long seriesId) - { - var episodes = _database.Fetch(@"SELECT * FROM Episodes - INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId - LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId - WHERE Episodes.SeriesId = @0", seriesId); - - foreach (var episode in episodes) - { - if (episode.EpisodeFileId == 0) - episode.EpisodeFile = null; - } - - return episodes; - } - - public virtual IList GetEpisodesBySeason(long seriesId, int seasonNumber) - { - var episodes = _database.Fetch(@"SELECT * FROM Episodes - INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId - LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId - WHERE Episodes.SeriesId = @0 AND Episodes.SeasonNumber = @1", seriesId, seasonNumber); - - foreach (var episode in episodes) - { - if (episode.EpisodeFileId == 0) - episode.EpisodeFile = null; - } - - return episodes; - } - - public virtual void MarkEpisodeAsFetched(int episodeId) - { - logger.Trace("Marking episode {0} as fetched.", episodeId); - _database.Execute("UPDATE Episodes SET GrabDate=@0 WHERE EpisodeId=@1", DateTime.Now, episodeId); - } - - public virtual IList GetEpisodesByParseResult(EpisodeParseResult parseResult) - { - //Disabling auto add, need to make it a lot more conservative. - var autoAddNew = false; - - var result = new List(); - - if (parseResult.AirDate.HasValue) - { - if (!parseResult.Series.IsDaily) - { - //Todo: Collect this as a Series we want to treat as a daily series, or possible parsing error - logger.Warn("Found daily-style episode for non-daily series: {0}. {1}", parseResult.Series.Title, parseResult.OriginalString); - return new List(); - } - - var episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value); - - if (episodeInfo == null && autoAddNew) - { - logger.Info("Episode {0} doesn't exist in db. adding it now. {1}", parseResult, parseResult.OriginalString); - episodeInfo = new Episode - { - SeriesId = parseResult.Series.SeriesId, - AirDate = parseResult.AirDate.Value, - Title = "TBD", - Overview = String.Empty - }; - - var episodesInSeries = GetEpisodeBySeries(parseResult.Series.SeriesId); - - //Find the current season number - var maxSeasonNumber = episodesInSeries.Select(s => s.SeasonNumber).MaxOrDefault(); - - //Set the season number - episodeInfo.SeasonNumber = (maxSeasonNumber == 0) ? 1 : maxSeasonNumber; - - //Find the latest episode number - var maxEpisodeNumber = episodesInSeries - .Where(w => w.SeasonNumber == episodeInfo.SeasonNumber) - .Select(s => s.EpisodeNumber).MaxOrDefault(); - - //Set the episode number to max + 1 - episodeInfo.EpisodeNumber = maxEpisodeNumber + 1; - - AddEpisode(episodeInfo); - } - if (episodeInfo != null) - { - result.Add(episodeInfo); - parseResult.EpisodeTitle = episodeInfo.Title; - } - - return result; - } - - if (parseResult.EpisodeNumbers == null) - return result; - - //Set it to empty before looping through the episode numbers - parseResult.EpisodeTitle = String.Empty; - - foreach (var episodeNumber in parseResult.EpisodeNumbers) - { - Episode episodeInfo = null; - - if (parseResult.SceneSource && parseResult.Series.UseSceneNumbering) - episodeInfo = GetEpisodeBySceneNumbering(parseResult.Series.SeriesId, parseResult.SeasonNumber, episodeNumber); - - if (episodeInfo == null) - { - episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.SeasonNumber, episodeNumber); - if (episodeInfo == null && parseResult.AirDate != null) - { - episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value); - } - } - - //if still null we should add the temp episode - if (episodeInfo == null && autoAddNew) - { - logger.Info("Episode {0} doesn't exist in db. adding it now. {1}", parseResult, parseResult.OriginalString); - episodeInfo = new Episode - { - SeriesId = parseResult.Series.SeriesId, - AirDate = DateTime.Now.Date, - EpisodeNumber = episodeNumber, - SeasonNumber = parseResult.SeasonNumber, - Title = "TBD", - Overview = String.Empty, - }; - - if (parseResult.EpisodeNumbers.Count == 1 && parseResult.EpisodeNumbers.First() == 0) - episodeInfo.Ignored = true; - - AddEpisode(episodeInfo); - } - - if (episodeInfo != null) - { - result.Add(episodeInfo); - - if (parseResult.Series.UseSceneNumbering) - { - logger.Info("Using Scene to TVDB Mapping for: {0} - Scene: {1}x{2:00} - TVDB: {3}x{4:00}", - parseResult.Series.Title, - episodeInfo.SceneSeasonNumber, - episodeInfo.SceneEpisodeNumber, - episodeInfo.SeasonNumber, - episodeInfo.EpisodeNumber); - } - - if (parseResult.EpisodeNumbers.Count == 1) - { - parseResult.EpisodeTitle = episodeInfo.Title.Trim(); - } - else - { - parseResult.EpisodeTitle = Parser.CleanupEpisodeTitle(episodeInfo.Title); - } - } - else - { - logger.Debug("Unable to find {0}", parseResult); - } - } - - return result; - } - - public virtual IList EpisodesWithoutFiles(bool includeSpecials) - { - var episodes = _database.Query(@"SELECT Episodes.*, Series.* FROM Episodes - INNER JOIN Series - ON Episodes.SeriesId = Series.SeriesId - WHERE (EpisodeFileId=0 OR EpisodeFileId=NULL) AND Ignored = 0 AND AirDate<=@0", - DateTime.Now.Date); - if (!includeSpecials) - return episodes.Where(e => e.SeasonNumber > 0).ToList(); - - return episodes.ToList(); - } - - public virtual IList GetEpisodesByFileId(int episodeFileId) - { - return _database.Fetch(@"SELECT * FROM Episodes - INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId - WHERE EpisodeFileId = @0", episodeFileId); - } - - public virtual IList EpisodesWithFiles() - { - var episodes = _database.Fetch(@"SELECT Episodes.*, Series.*, EpisodeFiles.* FROM Episodes - INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId - INNER JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId"); - - return episodes; - } - - public virtual void RefreshEpisodeInfo(Series series) - { - logger.Trace("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); - var successCount = 0; - var failCount = 0; - - var tvdbEpisodes = _tvDbProvider.GetSeries(series.SeriesId, true) - .Episodes - .Where(episode => !string.IsNullOrWhiteSpace(episode.EpisodeName) || - (episode.FirstAired < DateTime.Now.AddDays(2) && episode.FirstAired.Year > 1900)) - .ToList(); - - var seriesEpisodes = GetEpisodeBySeries(series.SeriesId); - var updateList = new List(); - var newList = new List(); - - _seasonProvider.EnsureSeasons(series.SeriesId, tvdbEpisodes.Select(c => c.SeasonNumber).Distinct()); - - foreach (var episode in tvdbEpisodes.OrderBy(e => e.SeasonNumber).ThenBy(e => e.EpisodeNumber)) - { - try - { - logger.Trace("Updating info for [{0}] - S{1:00}E{2:00}", series.Title, episode.SeasonNumber, episode.EpisodeNumber); - - //first check using tvdbId, this should cover cases when and episode number in a season is changed - var episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.TvDbEpisodeId == episode.Id); - - //not found, try using season/episode number - if (episodeToUpdate == null) - { - episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber); - } - - if (episodeToUpdate == null) - { - episodeToUpdate = new Episode(); - newList.Add(episodeToUpdate); - - //If it is Episode Zero Ignore it (specials, sneak peeks.) - if (episode.EpisodeNumber == 0 && episode.SeasonNumber != 1) - { - episodeToUpdate.Ignored = true; - } - else - { - episodeToUpdate.Ignored = _seasonProvider.IsIgnored(series.SeriesId, episode.SeasonNumber); - } - } - else - { - updateList.Add(episodeToUpdate); - } - - if ((episodeToUpdate.EpisodeNumber != episode.EpisodeNumber || - episodeToUpdate.SeasonNumber != episode.SeasonNumber) && - episodeToUpdate.EpisodeFileId > 0) - { - logger.Info("Unlinking episode file because TheTVDB changed the epsiode number..."); - - _database.Delete(episodeToUpdate.EpisodeFileId); - episodeToUpdate.EpisodeFileId = 0; - } - - episodeToUpdate.SeriesId = series.SeriesId; - episodeToUpdate.TvDbEpisodeId = episode.Id; - episodeToUpdate.EpisodeNumber = episode.EpisodeNumber; - episodeToUpdate.SeasonNumber = episode.SeasonNumber; - episodeToUpdate.AbsoluteEpisodeNumber = episode.AbsoluteNumber; - episodeToUpdate.Title = episode.EpisodeName; - - episodeToUpdate.Overview = episode.Overview.Truncate(3500); - - if (episode.FirstAired.Year > 1900) - episodeToUpdate.AirDate = episode.FirstAired.Date; - else - episodeToUpdate.AirDate = null; - - successCount++; - } - catch (Exception e) - { - logger.FatalException(String.Format("An error has occurred while updating episode info for series {0}", series.Title), e); - failCount++; - } - } - - _database.InsertMany(newList); - _database.UpdateMany(updateList); - - if (failCount != 0) - { - logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", - series.Title, successCount, failCount); - } - else - { - logger.Info("Finished episode refresh for series: {0}.", series.Title); - } - - DeleteEpisodesNotInTvdb(series, tvdbEpisodes); - } - - public virtual void UpdateEpisode(Episode episode) - { - _database.Update(episode); - } - - public virtual IList GetSeasons(int seriesId) - { - return _database.Fetch("SELECT DISTINCT SeasonNumber FROM Episodes WHERE SeriesId=@0", seriesId).OrderBy(c => c).ToList(); - } - - public virtual IList GetEpisodeNumbersBySeason(int seriesId, int seasonNumber) - { - return _database.Fetch("SELECT EpisodeNumber FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber).OrderBy(c => c).ToList(); - } - - public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored) - { - _database.Execute(@"UPDATE Episodes SET Ignored = @0 - WHERE EpisodeId = @1", - isIgnored, episodeId); - - logger.Info("Ignore flag for Episode:{0} was set to {1}", episodeId, isIgnored); - } - - public virtual bool IsFirstOrLastEpisodeOfSeason(int seriesId, int seasonNumber, int episodeNumber) - { - var episodes = GetEpisodesBySeason(seriesId, seasonNumber).OrderBy(e => e.EpisodeNumber); - - if (!episodes.Any()) - return false; - - //Ensure that this is either the first episode - //or is the last episode in a season that has 10 or more episodes - if (episodes.First().EpisodeNumber == episodeNumber || (episodes.Count() >= 10 && episodes.Last().EpisodeNumber == episodeNumber)) - return true; - - return false; - } - - public virtual void DeleteEpisodesNotInTvdb(Series series, IList tvdbEpisodes) - { - logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.SeriesId)); - - if (!tvdbEpisodes.Any()) return; - - //Delete Episodes not matching TvDbIds for this series - var tvDbIds = tvdbEpisodes.Select(e => e.Id); - var tvDbIdString = String.Join(", ", tvDbIds); - - var tvDbIdQuery = String.Format("DELETE FROM Episodes WHERE SeriesId = {0} AND TvDbEpisodeId > 0 AND TvDbEpisodeId NOT IN ({1})", - series.SeriesId, tvDbIdString); - - _database.Execute(tvDbIdQuery); - - logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.SeriesId); - } - - public virtual void SetPostDownloadStatus(List episodeIds, PostDownloadStatusType postDownloadStatus) - { - if (episodeIds.Count == 0) throw new ArgumentException("episodeIds should contain one or more episode ids."); - - var episodeIdString = String.Join(", ", episodeIds); - - var episodeIdQuery = String.Format(@"UPDATE Episodes SET PostDownloadStatus = {0} - WHERE EpisodeId IN ({1})", (int)postDownloadStatus, episodeIdString); - - logger.Trace("Updating PostDownloadStatus for all episodeIds in {0}", episodeIdString); - _database.Execute(episodeIdQuery); - } - - public virtual void UpdateEpisodes(List episodes) - { - _database.UpdateMany(episodes); - } - - public virtual Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber) - { - var episode = _database.Fetch(@"SELECT * FROM Episodes - INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId - LEFT JOIN EpisodeFiles ON Episodes.EpisodeFileId = EpisodeFiles.EpisodeFileId - WHERE Episodes.SeriesId = @0 AND Episodes.SceneSeasonNumber = @1 AND Episodes.SceneEpisodeNumber = @2", seriesId, seasonNumber, episodeNumber).SingleOrDefault(); - - if (episode == null) - return null; - - if (episode.EpisodeFileId == 0) - episode.EpisodeFile = null; - - return episode; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeasonProvider.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs similarity index 58% rename from NzbDrone.Core/Tv/SeasonProvider.cs rename to NzbDrone.Core/Tv/EpisodeRepository.cs index 54490c086a326422a712ce6f431bcfacd606fba9..2d7ecf95ad5ee5c710b821ff556a3564ed4339da 100644 GIT binary patch literal 6489 zcmeHIU2oGc6y>>6|AY53rP37fJm@6GU__dRpcQ*|oLgq(+Qm*L6}113Z|pQq+O(te z1<85x=e_qFpL-9%2AS>$hi+Z>xc~k5IFCSG^ z;#HI6N(oCE6IB7T6);YP31b8_`Qi0?#;jsonO0#P?At&NJVOs#SfeYjDdriah7aep z!~`{_dBs*URz^cAy4az*EoJ%WzK%9-l6}s9*p5Nz=hOgEo#~_%7S?!4@JupzCXn(5 zSAZ=beURNX0={IhXcf0;6a=;GDJ3a!RhIE z&>LP3=iw3b-WQsrbA^tSoT#?#-VIcJNKgl>-KQsSdH;-OmmeNUxED8i5ILI?Sqafm zJ#M7Ip{zi;ESv`)3B-pphYflV)DzW2s@gfpH0bxv^8{sM(TEKt)CNV7^94!H`ag#5 zk)9^-R-4<8QkR*b(J*T?ft^@dUx(7g`<>Rp1@Bx028I$zo;G;MhUzqK^YDpIre8>5-Jz)bRh_qew}V zzm}~)fdSHsNb2~zyWf2&S1Dh@Ty zDc0#6r4?{;g{(~1Od}}GG~JQN=7MK0K>C*`A+xW(**`GO=#1>wce#|v^_|gRC4(+m zX8_GpuT~De!i@(^vl&wef6m>iaLZn-Y;Rf})VIn@-CBp|jX|k!p%10BXWQ10cv{_ZpVsnj{kAReYlU!`1M1F>U`R{`xoQK(VH^TU|N4v9LKyf!<$N1c4Rin)G&c^z~n z(J;E3!XTbZ;}I<^_$Ys#QF!j3#t-g9!ROzjr-*h|A$fmOD)01wKS%G~#&5<+VuXq)f+4PU+Y1wFlO7lX%w99?XQuAXQfS1RFNt!l|ST zC+AUXQ&ef81Qr=vg5b`_51WgvbN<8T-4?Wf&E=MSE!{RN--cSfmk%ZcRmz0XS4?t^ z!AP>Zv(xWKKCj6^H!?Fx;l`1hu1!4g|GgeWlcPCgEO+Q{2q<06S zbGaLm_lJT|5qX^cnrut8ZZoDfyM_!pv#c++d z$|X8F8yVGuIO6#;N;ad)DSkT~{^?x9uQcJQ+#Dvk;{C0ZQ*+-1YCFi1FA&uEN)x`! zTu-IRlueTmbCfP1c(bFMepRQXsX)u^_HpOCL7w-tqcACAnTZ82|4MgF_)3Na@ebx^r(0_97ZH8m;!$lJOl my|%x!Ps>2dK+8bOK+8bOK+8bOK+8bOK+8bOK+C}YhJo*rOOe9> diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs new file mode 100644 index 000000000..a402948e4 --- /dev/null +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -0,0 +1,360 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NLog; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers; +using TvdbLib.Data; + +namespace NzbDrone.Core.Tv +{ + public interface IEpisodeService + { + void AddEpisode(Episode episode); + Episode GetEpisode(int id); + Episode GetEpisode(int seriesId, int seasonNumber, int episodeNumber); + Episode GetEpisode(int seriesId, DateTime date); + IList GetEpisodeBySeries(int seriesId); + IList GetEpisodesBySeason(int seriesId, int seasonNumber); + void MarkEpisodeAsFetched(int episodeId); + IList GetEpisodesByParseResult(EpisodeParseResult parseResult); + IList EpisodesWithoutFiles(bool includeSpecials); + IList GetEpisodesByFileId(int episodeFileId); + IList EpisodesWithFiles(); + void RefreshEpisodeInfo(Series series); + void UpdateEpisode(Episode episode); + IList GetEpisodeNumbersBySeason(int seriesId, int seasonNumber); + void SetEpisodeIgnore(int episodeId, bool isIgnored); + bool IsFirstOrLastEpisodeOfSeason(int seriesId, int seasonNumber, int episodeNumber); + void DeleteEpisodesNotInTvdb(Series series, IList tvdbEpisodes); + void SetPostDownloadStatus(List episodeIds, PostDownloadStatusType postDownloadStatus); + void UpdateEpisodes(List episodes); + Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber); + } + + public class EpisodeService : IEpisodeService + { + + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + + private readonly TvDbProvider _tvDbProvider; + private readonly ISeasonRepository _seasonRepository; + private readonly EpisodeRepository _episodeRepository; + + public EpisodeService(TvDbProvider tvDbProviderProvider, ISeasonRepository seasonRepository, EpisodeRepository episodeRepository) + { + _tvDbProvider = tvDbProviderProvider; + _seasonRepository = seasonRepository; + _episodeRepository = episodeRepository; + } + + public void AddEpisode(Episode episode) + { + episode.Ignored = _seasonRepository.IsIgnored(episode.SeriesId, episode.SeasonNumber); + _episodeRepository.Insert(episode); + } + + public virtual Episode GetEpisode(int id) + { + return _episodeRepository.Get(id); + } + + public virtual Episode GetEpisode(int seriesId, int seasonNumber, int episodeNumber) + { + return _episodeRepository.Get(seriesId, seasonNumber, episodeNumber); + } + + public virtual Episode GetEpisode(int seriesId, DateTime date) + { + return _episodeRepository.Get(seriesId, date); + } + + public virtual IList GetEpisodeBySeries(int seriesId) + { + return _episodeRepository.GetEpisodes(seriesId); + } + + public virtual IList GetEpisodesBySeason(int seriesId, int seasonNumber) + { + return _episodeRepository.GetEpisodes(seriesId, seasonNumber); + } + + public virtual void MarkEpisodeAsFetched(int episodeId) + { + logger.Trace("Marking episode {0} as fetched.", episodeId); + var episode = _episodeRepository.Get(episodeId); + episode.GrabDate = DateTime.UtcNow; + _episodeRepository.Update(episode); + } + + public virtual IList GetEpisodesByParseResult(EpisodeParseResult parseResult) + { + var result = new List(); + + if (parseResult.AirDate.HasValue) + { + if (parseResult.Series.SeriesType == SeriesType.Standard) + { + //Todo: Collect this as a Series we want to treat as a daily series, or possible parsing error + logger.Warn("Found daily-style episode for non-daily series: {0}. {1}", parseResult.Series.Title, parseResult.OriginalString); + return new List(); + } + + var episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value); + + if (episodeInfo != null) + { + result.Add(episodeInfo); + parseResult.EpisodeTitle = episodeInfo.Title; + } + + return result; + } + + if (parseResult.EpisodeNumbers == null) + return result; + + //Set it to empty before looping through the episode numbers + parseResult.EpisodeTitle = String.Empty; + + foreach (var episodeNumber in parseResult.EpisodeNumbers) + { + Episode episodeInfo = null; + + if (parseResult.SceneSource && parseResult.Series.UseSceneNumbering) + episodeInfo = GetEpisodeBySceneNumbering(parseResult.Series.SeriesId, parseResult.SeasonNumber, episodeNumber); + + if (episodeInfo == null) + { + episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.SeasonNumber, episodeNumber); + if (episodeInfo == null && parseResult.AirDate != null) + { + episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value); + } + } + + if (episodeInfo != null) + { + result.Add(episodeInfo); + + if (parseResult.Series.UseSceneNumbering) + { + logger.Info("Using Scene to TVDB Mapping for: {0} - Scene: {1}x{2:00} - TVDB: {3}x{4:00}", + parseResult.Series.Title, + episodeInfo.SceneSeasonNumber, + episodeInfo.SceneEpisodeNumber, + episodeInfo.SeasonNumber, + episodeInfo.EpisodeNumber); + } + + if (parseResult.EpisodeNumbers.Count == 1) + { + parseResult.EpisodeTitle = episodeInfo.Title.Trim(); + } + else + { + parseResult.EpisodeTitle = Parser.CleanupEpisodeTitle(episodeInfo.Title); + } + } + else + { + logger.Debug("Unable to find {0}", parseResult); + } + } + + return result; + } + + public virtual IList EpisodesWithoutFiles(bool includeSpecials) + { + return _episodeRepository.EpisodesWithoutFiles(includeSpecials); + } + + public virtual IList GetEpisodesByFileId(int episodeFileId) + { + return _episodeRepository.GetEpisodeByFileId(episodeFileId); + } + + public virtual IList EpisodesWithFiles() + { + return _episodeRepository.EpisodesWithFiles(); + } + + public virtual void RefreshEpisodeInfo(Series series) + { + logger.Trace("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); + var successCount = 0; + var failCount = 0; + + var tvdbEpisodes = _tvDbProvider.GetSeries(series.SeriesId, true) + .Episodes + .Where(episode => !string.IsNullOrWhiteSpace(episode.EpisodeName) || + (episode.FirstAired < DateTime.Now.AddDays(2) && episode.FirstAired.Year > 1900)) + .ToList(); + + var seriesEpisodes = GetEpisodeBySeries(series.SeriesId); + var updateList = new List(); + var newList = new List(); + + foreach (var episode in tvdbEpisodes.OrderBy(e => e.SeasonNumber).ThenBy(e => e.EpisodeNumber)) + { + try + { + logger.Trace("Updating info for [{0}] - S{1:00}E{2:00}", series.Title, episode.SeasonNumber, episode.EpisodeNumber); + + //first check using tvdbId, this should cover cases when and episode number in a season is changed + var episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.TvDbEpisodeId == episode.Id); + + //not found, try using season/episode number + if (episodeToUpdate == null) + { + episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber); + } + + if (episodeToUpdate == null) + { + episodeToUpdate = new Episode(); + newList.Add(episodeToUpdate); + + //If it is Episode Zero Ignore it (specials, sneak peeks.) + if (episode.EpisodeNumber == 0 && episode.SeasonNumber != 1) + { + episodeToUpdate.Ignored = true; + } + else + { + episodeToUpdate.Ignored = _seasonRepository.IsIgnored(series.SeriesId, episode.SeasonNumber); + } + } + else + { + updateList.Add(episodeToUpdate); + } + + if ((episodeToUpdate.EpisodeNumber != episode.EpisodeNumber || + episodeToUpdate.SeasonNumber != episode.SeasonNumber) && + episodeToUpdate.EpisodeFileId > 0) + { + logger.Info("Unlinking episode file because TheTVDB changed the epsiode number..."); + episodeToUpdate.EpisodeFile = null; + } + + episodeToUpdate.SeriesId = series.SeriesId; + episodeToUpdate.TvDbEpisodeId = episode.Id; + episodeToUpdate.EpisodeNumber = episode.EpisodeNumber; + episodeToUpdate.SeasonNumber = episode.SeasonNumber; + episodeToUpdate.AbsoluteEpisodeNumber = episode.AbsoluteNumber; + episodeToUpdate.Title = episode.EpisodeName; + + episodeToUpdate.Overview = episode.Overview.Truncate(3500); + + if (episode.FirstAired.Year > 1900) + episodeToUpdate.AirDate = episode.FirstAired.Date; + else + episodeToUpdate.AirDate = null; + + successCount++; + } + catch (Exception e) + { + logger.FatalException(String.Format("An error has occurred while updating episode info for series {0}", series.Title), e); + failCount++; + } + } + + _episodeRepository.InsertMany(newList); + _episodeRepository.UpdateMany(updateList); + + if (failCount != 0) + { + logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", + series.Title, successCount, failCount); + } + else + { + logger.Info("Finished episode refresh for series: {0}.", series.Title); + } + + DeleteEpisodesNotInTvdb(series, tvdbEpisodes); + } + + public virtual void UpdateEpisode(Episode episode) + { + _episodeRepository.Update(episode); + } + + + public virtual IList GetEpisodeNumbersBySeason(int seriesId, int seasonNumber) + { + return GetEpisodesBySeason(seriesId, seasonNumber).Select(c => c.OID).ToList(); + } + + public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored) + { + var episode = _episodeRepository.Get(episodeId); + episode.Ignored = isIgnored; + _episodeRepository.Update(episode); + + logger.Info("Ignore flag for Episode:{0} was set to {1}", episodeId, isIgnored); + } + + public virtual bool IsFirstOrLastEpisodeOfSeason(int seriesId, int seasonNumber, int episodeNumber) + { + var episodes = GetEpisodesBySeason(seriesId, seasonNumber).OrderBy(e => e.EpisodeNumber); + + if (!episodes.Any()) + return false; + + //Ensure that this is either the first episode + //or is the last episode in a season that has 10 or more episodes + if (episodes.First().EpisodeNumber == episodeNumber || (episodes.Count() >= 10 && episodes.Last().EpisodeNumber == episodeNumber)) + return true; + + return false; + } + + public virtual void DeleteEpisodesNotInTvdb(Series series, IList tvdbEpisodes) + { + logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.SeriesId)); + + if (!tvdbEpisodes.Any()) return; + + var seriesEpisodeIds = _episodeRepository.GetEpisodes(series.SeriesId).Select(c => c.OID); + + var toBeDeleted = seriesEpisodeIds.Except(tvdbEpisodes.Select(e => e.Id)); + + foreach (var id in toBeDeleted) + { + _episodeRepository.Delete(id); + } + + logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.SeriesId); + } + + public virtual void SetPostDownloadStatus(List episodeIds, PostDownloadStatusType postDownloadStatus) + { + if (episodeIds.Count == 0) throw new ArgumentException("episodeIds should contain one or more episode ids."); + + + foreach (var episodeId in episodeIds) + { + var episode = _episodeRepository.Get(episodeId); + episode.PostDownloadStatus = postDownloadStatus; + _episodeRepository.Update(episode); + } + + + logger.Trace("Updating PostDownloadStatus for {0} episode(s) to {1}", episodeIds.Count, postDownloadStatus); + } + + public virtual void UpdateEpisodes(List episodes) + { + _episodeRepository.UpdateMany(episodes); + } + + public virtual Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber) + { + return _episodeRepository.GetEpisodeBySceneNumbering(seriesId, seasonNumber, episodeNumber); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Tv/Season.cs b/NzbDrone.Core/Tv/Season.cs index a7d39f541..2bda45ed1 100644 --- a/NzbDrone.Core/Tv/Season.cs +++ b/NzbDrone.Core/Tv/Season.cs @@ -1,13 +1,12 @@ using System.Linq; using System; using System.Collections.Generic; -using PetaPoco; +using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Tv { - public class Season + public class Season : ModelBase { - public int SeasonId { get; set; } public int SeriesId { get; set; } public int SeasonNumber { get; set; } public Boolean Ignored { get; set; } diff --git a/NzbDrone.Core/Tv/SeasonRepository.cs b/NzbDrone.Core/Tv/SeasonRepository.cs new file mode 100644 index 000000000..471c6cc55 --- /dev/null +++ b/NzbDrone.Core/Tv/SeasonRepository.cs @@ -0,0 +1,49 @@ +using System.Collections.Generic; +using System.Linq; +using NLog; +using NzbDrone.Core.Datastore; +using PetaPoco; + +namespace NzbDrone.Core.Tv +{ + public interface ISeasonRepository : IBasicRepository + { + IList GetSeasonNumbers(int seriesId); + Season Get(int seriesId, int seasonNumber); + bool IsIgnored(int seriesId, int seasonNumber); + List GetSeasonBySeries(int seriesId); + } + + public class SeasonRepository : BasicRepository, ISeasonRepository + { + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + + private readonly IDatabase _database; + + public SeasonRepository(IObjectDatabase database) + : base(database) + { + } + + public IList GetSeasonNumbers(int seriesId) + { + return Queryable.Where(c => c.SeriesId == seriesId).Select(c => c.SeasonNumber).ToList(); + } + + public Season Get(int seriesId, int seasonNumber) + { + return Queryable.Single(c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber); + } + + public bool IsIgnored(int seriesId, int seasonNumber) + { + return Queryable.Single(c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber).Ignored; + } + + public List GetSeasonBySeries(int seriesId) + { + return Queryable.Where(c => c.SeriesId == seriesId).ToList(); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeasonService.cs b/NzbDrone.Core/Tv/SeasonService.cs new file mode 100644 index 0000000000000000000000000000000000000000..7f85bfc15e77359b5277fef18b27ff912afede68 GIT binary patch literal 4916 zcmeH`Pix~a5XJW#$afGqxe&x|k6GGF{}CuTH0`-4_Sh9Tl2?)q+2HTq8B49)BxPB8 zDo7XGV&=`$PtUEDs$%P%b+G04QvLZoowUQ=>Rwm)F`X!}1>1-m*y``*+Gqv*N*myh z-E^{_P8hDH-PAH?QaLasRW8>ctX69jv2=!!&oGDk0AdR_}_QFSz!E&k=CF|rd5m;q5}Rqx*FAE41z zI&F6B*_(+wVg4}supOaQVAyj#Jh9SS9NGL}FbklfcsP38mFS~)rgzXO-Wc#NY#QHZMKJAmhp24k4b zFk_AaE{CA8vKAH73PVC+TkL=KAuo&lubw&0_UHX editedSeries); + } + + public class SeriesService : ISeriesService { private readonly ISeriesRepository _seriesRepository; private readonly ConfigProvider _configProvider; private readonly TvDbProvider _tvDbProvider; - private readonly SceneMappingProvider _sceneNameMappingProvider; - private readonly BannerProvider _bannerProvider; private readonly MetadataProvider _metadataProvider; private readonly TvRageMappingProvider _tvRageMappingProvider; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - private static readonly Regex TimeRegex = new Regex(@"^(?