From c8252495af38e5ba1298e71834c0e6e54841869f Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 25 Apr 2011 15:27:03 -0700 Subject: [PATCH] fix bug where info update from tvdb would overwrite our own data, fileid, date flags ... --- NzbDrone.Core.Test/MediaFileProviderTests.cs | 44 +++++++++++++++++++- NzbDrone.Core/Providers/EpisodeProvider.cs | 8 +++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index 8fbeef10d..5edce8ae7 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -4,6 +4,7 @@ using FizzWare.NBuilder; using MbUnit.Framework; using Moq; +using Moq.Linq; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; @@ -125,6 +126,47 @@ public void import_new_daily_file() } + [Test] + [Description("Verifies that a new file imported properly")] + public void import_existing_season_file() + { + //Arrange + ///////////////////////////////////////// + + //Constants + const string fileName = @"WEEDS.S03E01.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi"; + const int seasonNumber = 3; + const int episodeNumner = 1; + const int size = 12345; + + //Fakes + var fakeSeries = Builder.CreateNew().Build(); + var fakeEpisode = Builder.CreateNew() + .With(c => c.SeriesId = fakeSeries.SeriesId) + .With(c => c.EpisodeFileId = 12).Build(); + + //Mocks + var mocker = new AutoMoqer(); + + mocker.GetMock(MockBehavior.Strict) + .Setup(r => r.Exists(It.IsAny>>())).Returns(true).Verifiable(); + + //mocker.GetMock() + // .Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns(fakeEpisode) + // .Verifiable(); + + mocker.GetMock() + .Setup(e => e.GetSize(fileName)).Returns(size).Verifiable(); + + + //Act + var result = mocker.Resolve().ImportFile(fakeSeries, fileName); + + //Assert + mocker.VerifyAllMocks(); + Assert.IsNull(result); + } + [Test] [Description("Verifies that a new file imported properly")] public void import_sample_file() @@ -161,7 +203,7 @@ public void import_sample_file() //Assert Assert.IsNull(result); - } + } [Test] [Description("Verifies that an existing file will skip import")] diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 6870c35b3..4d5202c0f 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -183,14 +183,20 @@ public virtual void RefreshEpisodeInfo(int seriesId) SeasonId = episode.SeasonId, SeasonNumber = episode.SeasonNumber, SeriesId = seriesId, - Title = episode.EpisodeName + Title = episode.EpisodeName, + LastInfoSync = DateTime.Now + }; var existingEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber); if (existingEpisode != null) { + //TODO: Write test for this, possibly make it future proof, we should only copy fields that come from tvdb newEpisode.EpisodeId = existingEpisode.EpisodeId; + newEpisode.EpisodeFileId = existingEpisode.EpisodeFileId; + newEpisode.LastDiskSync = existingEpisode.LastDiskSync; + newEpisode.Status = existingEpisode.Status; updateList.Add(newEpisode); } else