From 45549fa50b6e4730452e0e4c32386ffa000e4e18 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 19 Jun 2011 20:25:24 -0700 Subject: [PATCH] Fixed attach series issue and null episodes. --- NzbDrone.Core.Test/EpisodeProviderTest.cs | 59 ++++++++++++++++++++++ NzbDrone.Core/Providers/EpisodeProvider.cs | 1 + 2 files changed, 60 insertions(+) diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index c931c8a93..466612259 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -45,6 +45,51 @@ public void GetEpisodes_exists() episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries); } + + [Test] + public void GetEpisodes_by_season_episode_exists() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + var fakeEpisodes = Builder.CreateNew() + .With(e => e.SeriesId = fakeSeries.SeriesId) + .With(e => e.EpisodeNumber = 1) + .And(e => e.SeasonNumber = 2).Build(); + + + db.Insert(fakeEpisodes); + + mocker.GetMock() + .Setup(p => p.GetSeries(1)) + .Returns(fakeSeries); + + //Act + var episode = mocker.Resolve().GetEpisode(fakeSeries.SeriesId, 2, 1); + + //Assert + episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes); + episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries); + } + + [Test] + public void GetEpisodes_by_season_episode_doesnt_exists() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + + + //Act + var episode = mocker.Resolve().GetEpisode(1, 1, 1); + + //Assert + episode.Should().BeNull(); + } + [Test] [ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")] public void GetEpisodes_invalid_series() @@ -103,6 +148,20 @@ public void AttachSeries_list_success() returnedSeries.Should().BeEquivalentTo(fakeEpisodes); } + [Test] + public void AttachSeries_null_episode_should_return_null() + { + var mocker = new AutoMoqer(); + + Episode episode = null; + + //Act + var result = mocker.Resolve().AttachSeries(episode); + + //Assert + result.Should().BeNull(); + } + [Test] public void AttachSeries_single_success() { diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 006d1d8e9..16e965abc 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -236,6 +236,7 @@ public IList AttachSeries(IList episodes) public Episode AttachSeries(Episode episode) { + if (episode == null) return episode; episode.Series = _seriesProvider.GetSeries(episode.SeriesId); return episode; }