From e547792020aafc3581e6d0467f732fb0e6705342 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 28 May 2011 20:37:19 -0700 Subject: [PATCH] More episode update fixes, tests --- NzbDrone.Core.Test/EpisodeProviderTest.cs | 145 ++++++++++++++++----- NzbDrone.Core/Providers/EpisodeProvider.cs | Bin 9658 -> 10102 bytes 2 files changed, 116 insertions(+), 29 deletions(-) diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 3d8d096e4..3cae3f3fb 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -66,11 +66,14 @@ namespace NzbDrone.Core.Test const int seriesId = 71663; var fakeEpisodes = Builder.CreateNew() .With(c => c.Episodes = new List(Builder.CreateListOfSize(6). - WhereAll().Have(l => l.Language = new TvdbLanguage(0, "eng", "a")) - .WhereTheFirst(3).Have(d => d.SeasonNumber = 1).And(d => d.SeasonId = 11) - .AndTheRemaining().Have(d => d.SeasonNumber = 2).And(d => d.SeasonId = 22) - .Build()) - ).With(c => c.Id = seriesId).Build(); + WhereAll().Have( + l => l.Language = new TvdbLanguage(0, "eng", "a")) + .WhereTheFirst(3).Have(d => d.SeasonNumber = 1).And( + d => d.SeasonId = 11) + .AndTheRemaining().Have(d => d.SeasonNumber = 2).And( + d => d.SeasonId = 22) + .Build()) + ).With(c => c.Id = seriesId).Build(); var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); @@ -97,7 +100,7 @@ namespace NzbDrone.Core.Test const int seriesId = 71663; var fakeEpisodes = Builder.CreateNew() .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) - ).With(c => c.Id = seriesId).Build(); + ).With(c => c.Id = seriesId).Build(); var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); @@ -113,8 +116,10 @@ namespace NzbDrone.Core.Test mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - mocker.GetMock().Verify(c => c.AddMany(It.Is>(e => e.Count() == fakeEpisodes.Episodes.Count)), Times.Once()); - mocker.GetMock().Verify(c => c.UpdateMany(It.Is>(e => e.Count() == 0)), Times.AtMostOnce()); + mocker.GetMock().Verify( + c => c.AddMany(It.Is>(e => e.Count() == fakeEpisodes.Episodes.Count)), Times.Once()); + mocker.GetMock().Verify(c => c.UpdateMany(It.Is>(e => e.Count() == 0)), + Times.AtMostOnce()); mocker.VerifyAllMocks(); } @@ -125,7 +130,7 @@ namespace NzbDrone.Core.Test const int seriesId = 71663; var fakeEpisodes = Builder.CreateNew() .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) - ).With(c => c.Id = seriesId).Build(); + ).With(c => c.Id = seriesId).Build(); var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); @@ -144,22 +149,106 @@ namespace NzbDrone.Core.Test mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - mocker.GetMock().Verify(c => c.AddMany(It.Is>(e => e.Count() == 0)), Times.AtMostOnce()); - mocker.GetMock().Verify(c => c.UpdateMany(It.Is>(e => e.Count() == fakeEpisodes.Episodes.Count)), Times.Once()); + mocker.GetMock().Verify(c => c.AddMany(It.Is>(e => e.Count() == 0)), + Times.AtMostOnce()); + mocker.GetMock().Verify( + c => c.UpdateMany(It.Is>(e => e.Count() == fakeEpisodes.Episodes.Count)), + Times.Once()); mocker.VerifyAllMocks(); } + [Test] + public void should_try_to_get_existing_episode_using_tvdbid_first() + { + const int seriesId = 71663; + var fakeEpisodes = Builder.CreateNew() + .With(c => c.Id = seriesId) + .With(c => c.Episodes = new List( + Builder.CreateListOfSize(1) + .WhereAll().Have(g => g.Id = 99) + .Build()) + ) + .Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + + var mocker = new AutoMoqer(); + + var repo = MockLib.GetEmptyRepository(); + repo.Add( + Builder.CreateNew().With(c => c.TvDbEpisodeId = fakeEpisodes.Episodes[0].Id).Build()); + mocker.SetConstant(repo); + + mocker.GetMock(MockBehavior.Strict) + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + mocker.VerifyAllMocks(); + Assert.Count(1, repo.All()); + } + + [Test] + public void should_try_to_get_existing_episode_using_tvdbid_first_then_season_episode() + { + const int seriesId = 71663; + var fakeEpisodes = Builder.CreateNew() + .With(c => c.Id = seriesId) + .With(c => c.Episodes = new List{ + Builder.CreateNew() + .With(g => g.Id = 99) + .With(g => g.SeasonNumber = 4) + .With(g => g.EpisodeNumber = 15) + .With(g=>g.SeriesId = seriesId) + .Build() + }) + .Build(); + + var localEpisode = Builder.CreateNew() + .With(c => c.SeriesId = seriesId) + .With(c => c.SeasonNumber = 4) + .With(c => c.EpisodeNumber = 15) + .Build(); + + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + + var mocker = new AutoMoqer(); + + var repo = MockLib.GetEmptyRepository(); + repo.Add(localEpisode); + mocker.SetConstant(repo); + + mocker.GetMock(MockBehavior.Strict) + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + mocker.VerifyAllMocks(); + Assert.Count(1, repo.All()); + } + + [Test] public void existing_episodes_keep_their_episodeId_file_id() { const int seriesId = 71663; var faketvDbResponse = Builder.CreateNew() .With(c => c.Episodes = new List(Builder.CreateListOfSize(5).Build()) - ).With(c => c.Id = seriesId).Build(); + ).With(c => c.Id = seriesId).Build(); var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - var fakeEpisode = Builder.CreateNew().With(c => c.EpisodeFileId = 69).And(c => c.EpisodeId = 99).Build(); + var fakeEpisode = + Builder.CreateNew().With(c => c.EpisodeFileId = 69).And(c => c.EpisodeId = 99).Build(); var mocker = new AutoMoqer(); @@ -178,27 +267,28 @@ namespace NzbDrone.Core.Test .Returns(faketvDbResponse.Episodes.Count) .Callback>(r => updatedEpisodes = r); - - - //Act mocker.Resolve().RefreshEpisodeInfo(fakeSeries); //Assert - mocker.GetMock().Verify(c => c.AddMany(It.Is>(e => e.Count() == 0)), Times.AtMostOnce()); - mocker.GetMock().Verify(c => c.UpdateMany(It.Is>(e => e.Count() == faketvDbResponse.Episodes.Count)), Times.Once()); - mocker.GetMock().Verify(c => c.UpdateMany(It.Is>(e => e.Where(g => g.EpisodeFileId == 69).Count() == faketvDbResponse.Episodes.Count)), Times.Once()); + mocker.GetMock().Verify(c => c.AddMany(It.Is>(e => e.Count() == 0)), + Times.AtMostOnce()); + mocker.GetMock().Verify( + c => c.UpdateMany(It.Is>(e => e.Count() == faketvDbResponse.Episodes.Count)), + Times.Once()); + mocker.GetMock().Verify( + c => + c.UpdateMany( + It.Is>( + e => e.Where(g => g.EpisodeFileId == 69).Count() == faketvDbResponse.Episodes.Count)), + Times.Once()); Assert.Count(faketvDbResponse.Episodes.Count, updatedEpisodes); - Assert.ForAll( updatedEpisodes, c=> Assert.AreEqual(99,c.EpisodeId )); - Assert.ForAll( updatedEpisodes, c=> Assert.AreEqual(69,c.EpisodeFileId )); - - + Assert.ForAll(updatedEpisodes, c => Assert.AreEqual(99, c.EpisodeId)); + Assert.ForAll(updatedEpisodes, c => Assert.AreEqual(69, c.EpisodeFileId)); } - - [Test] [Explicit] public void Add_daily_show_episodes() @@ -219,8 +309,5 @@ namespace NzbDrone.Core.Test var episodes = episodeProvider.GetEpisodeBySeries(tvDbSeriesId); Assert.IsNotEmpty(episodes); } - - - } -} \ No newline at end of file +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index bbb93628090c1049da453005ac39b4590a60d138..05f3d33ab49f6061bd2bf91e9113999e1993c6d9 100644 GIT binary patch delta 272 zcmY+9u};H45JbB)6c*HslXdb3NY>QKm!u z6LoAQ6tp{fZ)P|5zYpt`sHxI=wK+Z(wGR-EDQZgA0p1|1-@B zn^>JpwdN2p4=oQfn&p1j&aMB~4*rkvQ~Fc~BcaBVq_w(AKiOfr&W_Ku-WS0J626R} Sci%r;2UFJda-hG)o1-oDyI_+5 delta 39 vcmez7x66A&2md4ivB~^`-0Z0ZnZ@}jsgo51ttKmricQ`i5WiVkC|VQ%8Kex@