using System; using System.Collections.Generic; using System.Linq; using System.Text; using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Test.TvTests.SeasonServiceTests { [TestFixture] public class HandleEpisodeInfoDeletedEventFixture : CoreTest { private List _seasons; private List _episodes; [SetUp] public void Setup() { _seasons = Builder .CreateListOfSize(1) .All() .With(s => s.SeriesId = 1) .Build() .ToList(); _episodes = Builder .CreateListOfSize(1) .All() .With(e => e.SeasonNumber = _seasons.First().SeasonNumber) .With(s => s.SeriesId = _seasons.First().SeasonNumber) .Build() .ToList(); Mocker.GetMock() .Setup(s => s.GetSeasonBySeries(It.IsAny())) .Returns(_seasons); Mocker.GetMock() .Setup(s => s.GetEpisodesBySeason(It.IsAny(), _seasons.First().SeasonNumber)) .Returns(_episodes); } private void GivenAbandonedSeason() { Mocker.GetMock() .Setup(s => s.GetEpisodesBySeason(It.IsAny(), _seasons.First().SeasonNumber)) .Returns(new List()); } [Test] public void should_not_delete_when_season_is_still_valid() { Subject.Handle(new EpisodeInfoDeletedEvent(_episodes)); Mocker.GetMock() .Verify(v => v.Delete(It.IsAny()), Times.Never()); } [Test] public void should_delete_season_if_no_episodes_exist_in_that_season() { GivenAbandonedSeason(); Subject.Handle(new EpisodeInfoDeletedEvent(_episodes)); Mocker.GetMock() .Verify(v => v.Delete(It.IsAny()), Times.Once()); } [Test] public void should_only_delete_a_season_once() { _episodes = Builder .CreateListOfSize(5) .All() .With(e => e.SeasonNumber = _seasons.First().SeasonNumber) .With(s => s.SeriesId = _seasons.First().SeasonNumber) .Build() .ToList(); GivenAbandonedSeason(); Subject.Handle(new EpisodeInfoDeletedEvent(_episodes)); Mocker.GetMock() .Verify(v => v.Delete(It.IsAny()), Times.Once()); } } }