fix bug where info update from tvdb would overwrite our own data, fileid, date flags ...

pull/4/head
kay.one 14 years ago
parent 5faeccf098
commit c8252495af

@ -4,6 +4,7 @@ using AutoMoq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using MbUnit.Framework; using MbUnit.Framework;
using Moq; using Moq;
using Moq.Linq;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
@ -125,6 +126,47 @@ namespace NzbDrone.Core.Test
} }
[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<Series>.CreateNew().Build();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(c => c.SeriesId = fakeSeries.SeriesId)
.With(c => c.EpisodeFileId = 12).Build();
//Mocks
var mocker = new AutoMoqer();
mocker.GetMock<IRepository>(MockBehavior.Strict)
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(true).Verifiable();
//mocker.GetMock<EpisodeProvider>()
// .Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns(fakeEpisode)
// .Verifiable();
mocker.GetMock<DiskProvider>()
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
//Act
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
//Assert
mocker.VerifyAllMocks();
Assert.IsNull(result);
}
[Test] [Test]
[Description("Verifies that a new file imported properly")] [Description("Verifies that a new file imported properly")]
public void import_sample_file() public void import_sample_file()
@ -161,7 +203,7 @@ namespace NzbDrone.Core.Test
//Assert //Assert
Assert.IsNull(result); Assert.IsNull(result);
} }
[Test] [Test]
[Description("Verifies that an existing file will skip import")] [Description("Verifies that an existing file will skip import")]

@ -183,14 +183,20 @@ namespace NzbDrone.Core.Providers
SeasonId = episode.SeasonId, SeasonId = episode.SeasonId,
SeasonNumber = episode.SeasonNumber, SeasonNumber = episode.SeasonNumber,
SeriesId = seriesId, SeriesId = seriesId,
Title = episode.EpisodeName Title = episode.EpisodeName,
LastInfoSync = DateTime.Now
}; };
var existingEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber); var existingEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
if (existingEpisode != null) 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.EpisodeId = existingEpisode.EpisodeId;
newEpisode.EpisodeFileId = existingEpisode.EpisodeFileId;
newEpisode.LastDiskSync = existingEpisode.LastDiskSync;
newEpisode.Status = existingEpisode.Status;
updateList.Add(newEpisode); updateList.Add(newEpisode);
} }
else else

Loading…
Cancel
Save