From 38790e9f9c3d20738dfde26e7f163640b2f6c416 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 24 Nov 2011 00:28:20 -0800 Subject: [PATCH] GetEpisodesByParseResult will properly handle Daily episodes. --- ...deProviderTest_GetEpisodesByParseResult.cs | 54 +++++++++++++++++++ .../InventoryProvider_IsMonitoredTest.cs | 28 ++++++++++ NzbDrone.Core/Providers/EpisodeProvider.cs | 24 +++++++++ 3 files changed, 106 insertions(+) diff --git a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs index c0e57037e..0db4ffd3b 100644 --- a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs @@ -1,16 +1,19 @@ // ReSharper disable RedundantUsingDirective +using System; using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; +using Moq; using NUnit.Framework; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common.AutoMoq; +using PetaPoco; namespace NzbDrone.Core.Test.ProviderTests { @@ -255,6 +258,57 @@ namespace NzbDrone.Core.Test.ProviderTests episodes.Should().BeEmpty(); } + [Test] + public void GetEpisodeParseResult_should_return_single_episode_when_air_date_is_provided() + { + //Setup + var fakeEpisode = Builder.CreateListOfSize(1) + .All() + .With(e => e.AirDate = DateTime.Today) + .Build() + .ToList(); + + var fakeSeries = Builder.CreateNew() + .With(s => s.SeriesId = 1) + .Build(); + + Mocker.GetMock().Setup(s => s.Fetch(It.IsAny(), It.IsAny())) + .Returns(fakeEpisode); + + //Act + var episodes = Mocker.Resolve() + .GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries }, true); + + //Assert + episodes.Should().HaveCount(1); + episodes.First().AirDate.Should().Be(DateTime.Today); + + Mocker.GetMock().Verify(v=> v.Insert(It.IsAny()), Times.Never()); + } + + [Test] + public void GetEpisodeParseResult_get_daily_should_add_new_episode() + { + //Setup + var fakeSeries = Builder.CreateNew() + .With(s => s.SeriesId = 1) + .Build(); + + Mocker.GetMock().Setup(s => s.Fetch(It.IsAny(), It.IsAny())) + .Returns(new List()); + + Mocker.GetMock().Setup(s => s.Insert(It.IsAny())) + .Returns(1); + + //Act + var episodes = Mocker.Resolve() + .GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries }, true); + + //Assert + episodes.Should().HaveCount(1); + episodes.First().AirDate.Should().Be(DateTime.Today); + Mocker.GetMock().Verify(v => v.Insert(It.IsAny()), Times.Once()); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsMonitoredTest.cs b/NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsMonitoredTest.cs index 2911231c9..125718c5c 100644 --- a/NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsMonitoredTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/InventoryProvider_IsMonitoredTest.cs @@ -25,6 +25,7 @@ namespace NzbDrone.Core.Test.ProviderTests private Episode episode; private Episode episode2; private EpisodeParseResult parseResultSingle; + private EpisodeParseResult parseResultDaily; [SetUp] public void Setup() @@ -49,6 +50,14 @@ namespace NzbDrone.Core.Test.ProviderTests AirDate = DateTime.Now.AddDays(-12).Date, }; + parseResultDaily = new EpisodeParseResult() + { + CleanTitle = "Title", + Language = LanguageType.English, + Quality = new Quality(QualityTypes.Bluray720p, true), + AirDate = DateTime.Now.AddDays(-12).Date, + }; + episode = Builder.CreateNew() .With(c => c.EpisodeNumber = parseResultMulti.EpisodeNumbers[0]) @@ -239,6 +248,25 @@ namespace NzbDrone.Core.Test.ProviderTests mocker.VerifyAllMocks(); } + [Test] + public void IsMonitored_daily_not_ignored_should_return_true() + { + var mocker = new AutoMoqer(MockBehavior.Strict); + + mocker.GetMock() + .Setup(p => p.FindSeries(It.IsAny())) + .Returns(series); + + mocker.GetMock() + .Setup(p => p.GetEpisodesByParseResult(It.IsAny(), true)) + .Returns(new List { episode }); + + episode.Ignored = false; + + var result = mocker.Resolve().IsMonitored(parseResultDaily); + //Assert + result.Should().BeTrue(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index a740800d5..ae522868f 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -125,6 +125,30 @@ namespace NzbDrone.Core.Providers { var result = new List(); + if (parseResult.AirDate.HasValue) + { + var episodeInfo = GetEpisode(parseResult.Series.SeriesId, parseResult.AirDate.Value); + + //if still null we should add the temp episode + if (episodeInfo == null && autoAddNew) + { + Logger.Debug("Episode {0} doesn't exist in db. adding it now.", parseResult); + episodeInfo = new Episode + { + SeriesId = parseResult.Series.SeriesId, + AirDate = parseResult.AirDate.Value, + Title = "TBD", + Overview = String.Empty, + }; + + AddEpisode(episodeInfo); + } + + //Add to Result and Return (There will only be one episode to return) + result.Add(episodeInfo); + return result; + } + if (parseResult.EpisodeNumbers == null) return result;