From 1b10002ed8916e4594f6629de757bac19a7e0ad5 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 25 May 2014 18:47:54 -0700 Subject: [PATCH] Fixed: Specials will be ignored if no specials existed previously --- .../NzbDrone.Core.Test.csproj | 1 + .../TvTests/RefreshSeriesServiceFixture.cs | 81 +++++++++++++++++++ src/NzbDrone.Core/Tv/RefreshSeriesService.cs | 6 ++ 3 files changed, 88 insertions(+) create mode 100644 src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 2e7790ae8..52e2d0867 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -233,6 +233,7 @@ + diff --git a/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs b/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs new file mode 100644 index 000000000..7e263b235 --- /dev/null +++ b/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.MetadataSource; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Tv.Commands; +using NzbDrone.Test.Common; + +namespace NzbDrone.Core.Test.TvTests +{ + [TestFixture] + public class RefreshSeriesServiceFixture : CoreTest + { + private Series _series; + + [SetUp] + public void Setup() + { + var season1 = Builder.CreateNew() + .With(s => s.SeasonNumber = 1) + .Build(); + + _series = Builder.CreateNew() + .With(s => s.Seasons = new List + { + season1 + }) + .Build(); + + Mocker.GetMock() + .Setup(s => s.GetSeries(_series.Id)) + .Returns(_series); + + + } + + private void GivenNewSeriesInfo(Series series) + { + Mocker.GetMock() + .Setup(s => s.GetSeriesInfo(It.IsAny())) + .Returns(new Tuple>(series, new List())); + } + + [Test] + public void should_monitor_new_seasons_automatically() + { + var series = _series.JsonClone(); + series.Seasons.Add(Builder.CreateNew() + .With(s => s.SeasonNumber = 2) + .Build()); + + GivenNewSeriesInfo(series); + + Subject.Execute(new RefreshSeriesCommand(_series.Id)); + + Mocker.GetMock() + .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 2).Monitored == true))); + } + + [Test] + public void should_not_monitor_new_special_season_automatically() + { + var series = _series.JsonClone(); + series.Seasons.Add(Builder.CreateNew() + .With(s => s.SeasonNumber = 0) + .Build()); + + GivenNewSeriesInfo(series); + + Subject.Execute(new RefreshSeriesCommand(_series.Id)); + + Mocker.GetMock() + .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 0).Monitored == false))); + } + } +} diff --git a/src/NzbDrone.Core/Tv/RefreshSeriesService.cs b/src/NzbDrone.Core/Tv/RefreshSeriesService.cs index 81b2f6ae8..5390d0502 100644 --- a/src/NzbDrone.Core/Tv/RefreshSeriesService.cs +++ b/src/NzbDrone.Core/Tv/RefreshSeriesService.cs @@ -101,6 +101,12 @@ private List UpdateSeasons(Series series, Series seriesInfo) //Todo: Should this should use the previous season's monitored state? if (existingSeason == null) { + if (season.SeasonNumber == 0) + { + season.Monitored = false; + continue; + } + _logger.Debug("New season ({0}) for series: [{1}] {2}, setting monitored to true", season.SeasonNumber, series.TvdbId, series.Title); season.Monitored = true; }