using System; using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Common.Extensions; using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; using NzbDrone.Core.Tv.Commands; 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 newSeriesInfo = _series.JsonClone(); newSeriesInfo.Seasons.Add(Builder.CreateNew() .With(s => s.SeasonNumber = 2) .Build()); GivenNewSeriesInfo(newSeriesInfo); 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))); } [Test] public void should_update_tvrage_id_if_changed() { var newSeriesInfo = _series.JsonClone(); newSeriesInfo.TvRageId = _series.TvRageId + 1; GivenNewSeriesInfo(newSeriesInfo); Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() .Verify(v => v.UpdateSeries(It.Is(s => s.TvRageId == newSeriesInfo.TvRageId))); } } }