mirror of https://github.com/Radarr/Radarr
Removed Episodes list from EpisodeFile object.
This commit is contained in:
parent
cbfbb87926
commit
56fdf1a040
|
@ -18,202 +18,6 @@ namespace NzbDrone.Core.Test
|
|||
// ReSharper disable InconsistentNaming
|
||||
public class DiskScanProviderTest : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void import_new_file_should_succeed()
|
||||
{
|
||||
const string newFile = @"WEEDS.S03E01.DUAL.dvd.HELLYWOOD.avi";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisode = Builder<Episode>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, mocker, fakeEpisode, 12345);
|
||||
|
||||
}
|
||||
|
||||
[TestCase(QualityTypes.SDTV, false)]
|
||||
[TestCase(QualityTypes.DVD, true)]
|
||||
[TestCase(QualityTypes.HDTV, false)]
|
||||
public void import_new_file_with_better_same_quality_should_succeed(QualityTypes currentFileQuality, bool currentFileProper)
|
||||
{
|
||||
const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv";
|
||||
const int size = 12345;
|
||||
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(g => g.Quality = (QualityTypes)currentFileQuality)
|
||||
.And(g => g.Proper = currentFileProper).Build()
|
||||
).Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
|
||||
|
||||
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, mocker, fakeEpisode, size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
|
||||
[TestCase("WEEDS.S03E01.DUAL.SDTV.XviD.AC3.-HELLYWOOD.avi")]
|
||||
public void import_new_file_episode_has_same_or_better_quality_should_skip(string fileName)
|
||||
{
|
||||
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisode = Builder<Episode>.CreateNew()
|
||||
.With(c => c.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(e => e.Quality = QualityTypes.Bluray720p).Build()
|
||||
)
|
||||
.Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void import_unparsable_file_should_skip()
|
||||
{
|
||||
const string fileName = @"WEEDS.avi";
|
||||
const int size = 12345;
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
ExceptionVerification.ExcpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_sample_file_should_skip()
|
||||
{
|
||||
const string fileName = @"2011.01.10 - Denis Leary - sample - HD TV.mkv";
|
||||
const int size = 12345;
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_existing_file_should_skip()
|
||||
{
|
||||
const string fileName = "WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_file_with_no_episode_in_db_should_skip()
|
||||
{
|
||||
//Constants
|
||||
const string fileName = "WEEDS.S03E01.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
||||
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<DiskProvider>(MockBehavior.Strict)
|
||||
.Setup(e => e.GetSize(fileName)).Returns(90000000000);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void scan_series_should_update_last_scan_date()
|
||||
|
@ -239,28 +43,99 @@ namespace NzbDrone.Core.Test
|
|||
}
|
||||
|
||||
|
||||
|
||||
private static void VerifyFileImport(EpisodeFile result, AutoMoqer mocker, Episode fakeEpisode, int size)
|
||||
[Test]
|
||||
public void cleanup_should_skip_existing_files()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.FileExists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
//Act
|
||||
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
||||
|
||||
//Assert
|
||||
mocker.VerifyAllMocks();
|
||||
result.Should().NotBeNull();
|
||||
result.SeriesId.Should().Be(fakeEpisode.SeriesId);
|
||||
result.Size.Should().Be(size);
|
||||
result.DateAdded.Should().HaveDay(DateTime.Now.Day);
|
||||
mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Once());
|
||||
|
||||
//Get the count of episodes linked
|
||||
var count = mocker.GetMock<EpisodeProvider>().Object.GetEpisodesByParseResult(null, false).Count;
|
||||
|
||||
mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count));
|
||||
}
|
||||
|
||||
private static void VerifySkipImport(EpisodeFile result, AutoMoqer mocker)
|
||||
[Test]
|
||||
public void cleanup_should_delete_none_existing_files()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.FileExists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(e => e.Delete(It.IsAny<int>()));
|
||||
|
||||
|
||||
//Act
|
||||
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
||||
|
||||
//Assert
|
||||
mocker.VerifyAllMocks();
|
||||
result.Should().BeNull();
|
||||
mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never());
|
||||
mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void cleanup_should_delete_none_existing_files_remove_links_to_episodes()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
var episodes = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.FileExists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByFileId(It.IsAny<int>()))
|
||||
.Returns(new List<Episode> { new Episode { EpisodeFileId = 10 }, new Episode { EpisodeFileId = 10 } });
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.UpdateEpisode(It.IsAny<Episode>()));
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(e => e.Delete(It.IsAny<int>()));
|
||||
|
||||
|
||||
//Act
|
||||
mocker.Resolve<DiskScanProvider>().CleanUp(episodes);
|
||||
|
||||
//Assert
|
||||
mocker.VerifyAllMocks();
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Verify(e => e.GetEpisodesByFileId(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Verify(e => e.UpdateEpisode(It.Is<Episode>(g=>g.EpisodeFileId == 0)), Times.Exactly(20));
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Verify(e => e.Delete(It.IsAny<int>()), Times.Exactly(10));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,241 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AutoMoq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
{
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class DiskScanProviderTest_ImportFile : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void import_new_file_should_succeed()
|
||||
{
|
||||
const string newFile = @"WEEDS.S03E01.DUAL.dvd.HELLYWOOD.avi";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisode = Builder<Episode>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, mocker, fakeEpisode, 12345);
|
||||
|
||||
}
|
||||
|
||||
[TestCase(QualityTypes.SDTV, false)]
|
||||
[TestCase(QualityTypes.DVD, true)]
|
||||
[TestCase(QualityTypes.HDTV, false)]
|
||||
public void import_new_file_with_better_same_quality_should_succeed(QualityTypes currentFileQuality, bool currentFileProper)
|
||||
{
|
||||
const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv";
|
||||
const int size = 12345;
|
||||
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(g => g.Quality = (QualityTypes)currentFileQuality)
|
||||
.And(g => g.Proper = currentFileProper).Build()
|
||||
).Build();
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(newFile)).Returns(12345).Verifiable();
|
||||
|
||||
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
|
||||
|
||||
//Assert
|
||||
VerifyFileImport(result, mocker, fakeEpisode, size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
|
||||
[TestCase("WEEDS.S03E01.DUAL.SDTV.XviD.AC3.-HELLYWOOD.avi")]
|
||||
public void import_new_file_episode_has_same_or_better_quality_should_skip(string fileName)
|
||||
{
|
||||
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
var fakeEpisode = Builder<Episode>.CreateNew()
|
||||
.With(c => c.EpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(e => e.Quality = QualityTypes.Bluray720p).Build()
|
||||
)
|
||||
.Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(new List<Episode> { fakeEpisode });
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void import_unparsable_file_should_skip()
|
||||
{
|
||||
const string fileName = @"WEEDS.avi";
|
||||
const int size = 12345;
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
ExceptionVerification.ExcpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_sample_file_should_skip()
|
||||
{
|
||||
const string fileName = @"2011.01.10 - Denis Leary - sample - HD TV.mkv";
|
||||
const int size = 12345;
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>())).Returns(false);
|
||||
|
||||
mocker.GetMock<DiskProvider>()
|
||||
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_existing_file_should_skip()
|
||||
{
|
||||
const string fileName = "WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void import_file_with_no_episode_in_db_should_skip()
|
||||
{
|
||||
//Constants
|
||||
const string fileName = "WEEDS.S03E01.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
||||
|
||||
//Fakes
|
||||
var fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
//Mocks
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.GetMock<MediaFileProvider>()
|
||||
.Setup(p => p.Exists(It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
|
||||
mocker.GetMock<DiskProvider>(MockBehavior.Strict)
|
||||
.Setup(e => e.GetSize(fileName)).Returns(90000000000);
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
|
||||
|
||||
//Assert
|
||||
VerifySkipImport(result, mocker);
|
||||
}
|
||||
|
||||
private static void VerifyFileImport(EpisodeFile result, AutoMoqer mocker, Episode fakeEpisode, int size)
|
||||
{
|
||||
mocker.VerifyAllMocks();
|
||||
result.Should().NotBeNull();
|
||||
result.SeriesId.Should().Be(fakeEpisode.SeriesId);
|
||||
result.Size.Should().Be(size);
|
||||
result.DateAdded.Should().HaveDay(DateTime.Now.Day);
|
||||
mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Once());
|
||||
|
||||
//Get the count of episodes linked
|
||||
var count = mocker.GetMock<EpisodeProvider>().Object.GetEpisodesByParseResult(null, false).Count;
|
||||
|
||||
mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == result.EpisodeFileId)), Times.Exactly(count));
|
||||
}
|
||||
|
||||
private static void VerifySkipImport(EpisodeFile result, AutoMoqer mocker)
|
||||
{
|
||||
mocker.VerifyAllMocks();
|
||||
result.Should().BeNull();
|
||||
mocker.GetMock<MediaFileProvider>().Verify(p => p.Add(It.IsAny<EpisodeFile>()), Times.Never());
|
||||
mocker.GetMock<EpisodeProvider>().Verify(p => p.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ using NLog;
|
|||
using NLog.Config;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
|
@ -146,5 +147,22 @@ namespace NzbDrone.Core.Test
|
|||
Assert.AreEqual(ex.ToString(), logItem.Exception);
|
||||
ExceptionVerification.ExcpectedErrors(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void null_string_as_arg_should_not_fail()
|
||||
{
|
||||
//setup
|
||||
|
||||
Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
var epFile = new EpisodeFile();
|
||||
Logger.Trace("File {0} no longer exists on disk. removing from database.", epFile.Path);
|
||||
|
||||
epFile.Path.Should().BeNull();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -38,11 +38,9 @@ namespace NzbDrone.Core.Test
|
|||
|
||||
var database = MockLib.GetEmptyDatabase(true);
|
||||
|
||||
foreach (var file in firstSeriesFiles)
|
||||
database.Insert(file);
|
||||
|
||||
foreach (var file in secondSeriesFiles)
|
||||
database.Insert(file);
|
||||
database.InsertMany(firstSeriesFiles);
|
||||
database.InsertMany(secondSeriesFiles);
|
||||
|
||||
mocker.SetConstant(database);
|
||||
|
||||
|
@ -56,7 +54,7 @@ namespace NzbDrone.Core.Test
|
|||
public void Scan_series_should_skip_series_with_no_episodes()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.GetEpisodeBySeries(12))
|
||||
.Returns(new List<Episode>());
|
||||
|
|
|
@ -85,8 +85,9 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
||||
<Compile Include="DiskScanProviderTest.cs" />
|
||||
<Compile Include="EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
||||
<Compile Include="DiskScanProviderTest_ImportFile.cs" />
|
||||
<Compile Include="FluentTest.cs" />
|
||||
<Compile Include="LogProviderTest.cs" />
|
||||
<Compile Include="UpcomingEpisodesProviderTest.cs" />
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
using System;
|
||||
using NzbDrone.Core.Model;
|
||||
|
||||
namespace NzbDrone.Core.Helpers
|
||||
{
|
||||
public static class EpisodeRenameHelper
|
||||
{
|
||||
public static string GetNewName(EpisodeRenameModel erm)
|
||||
{
|
||||
//Todo: Get the users preferred naming convention instead of hard-coding it
|
||||
|
||||
if (erm.EpisodeFile.Episodes.Count == 1)
|
||||
{
|
||||
return String.Format("{0} - S{1:00}E{2:00} - {3}", erm.SeriesName,
|
||||
erm.EpisodeFile.Episodes[0].SeasonNumber, erm.EpisodeFile.Episodes[0].EpisodeNumber,
|
||||
erm.EpisodeFile.Episodes[0].Title);
|
||||
}
|
||||
|
||||
var epNumberString = String.Empty;
|
||||
var epNameString = String.Empty;
|
||||
|
||||
foreach (var episode in erm.EpisodeFile.Episodes)
|
||||
{
|
||||
epNumberString = epNumberString + String.Format("E{0:00}", episode.EpisodeNumber);
|
||||
epNameString = epNameString + String.Format("+ {0}", episode.Title).Trim(' ', '+');
|
||||
}
|
||||
|
||||
return String.Format("{0} - S{1:00}E{2} - {3}", erm.SeriesName, erm.EpisodeFile.Episodes[0].SeasonNumber,
|
||||
epNumberString, epNameString);
|
||||
}
|
||||
|
||||
public static string GetSeasonFolder(int seasonNumber, string seasonFolderFormat)
|
||||
{
|
||||
return seasonFolderFormat.Replace("%s", seasonNumber.ToString()).Replace("%0s", seasonNumber.ToString("00"));
|
||||
}
|
||||
|
||||
public static string GetNameForNotify(EpisodeRenameModel erm)
|
||||
{
|
||||
if (erm.EpisodeFile.Episodes.Count == 1)
|
||||
{
|
||||
return String.Format("{0} - S{1:00}E{2:00} - {3}", erm.SeriesName,
|
||||
erm.EpisodeFile.Episodes[0].SeasonNumber, erm.EpisodeFile.Episodes[0].EpisodeNumber,
|
||||
erm.EpisodeFile.Episodes[0].Title);
|
||||
}
|
||||
|
||||
var epNumberString = String.Empty;
|
||||
var epNameString = String.Empty;
|
||||
|
||||
foreach (var episode in erm.EpisodeFile.Episodes)
|
||||
{
|
||||
epNumberString = epNumberString + String.Format("E{0:00}", episode.EpisodeNumber);
|
||||
epNameString = epNameString + String.Format("+ {0}", episode.Title).Trim(' ', '+');
|
||||
}
|
||||
|
||||
return String.Format("{0} - S{1:00}E{2} - {3}", erm.SeriesName, erm.EpisodeFile.Episodes[0].SeasonNumber,
|
||||
epNumberString, epNameString);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -180,7 +180,6 @@
|
|||
<Compile Include="Datastore\Migrations\Migration20110616.cs" />
|
||||
<Compile Include="Datastore\SqliteProvider.cs" />
|
||||
<Compile Include="Fluent.cs" />
|
||||
<Compile Include="Helpers\EpisodeRenameHelper.cs" />
|
||||
<Compile Include="Helpers\EpisodeSortingHelper.cs" />
|
||||
<Compile Include="Helpers\FileSizeFormatHelpercs.cs" />
|
||||
<Compile Include="Instrumentation\LogProvider.cs" />
|
||||
|
|
|
@ -179,7 +179,7 @@ namespace NzbDrone.Core.Providers
|
|||
Logger.Trace("File {0} no longer exists on disk. removing from database.", episodeFile.Path);
|
||||
|
||||
//Set the EpisodeFileId for each episode attached to this file to 0
|
||||
foreach (var episode in episodeFile.Episodes)
|
||||
foreach (var episode in _episodeProvider.GetEpisodesByFileId(episodeFile.EpisodeFileId))
|
||||
{
|
||||
episode.EpisodeFileId = 0;
|
||||
_episodeProvider.UpdateEpisode(episode);
|
||||
|
|
|
@ -19,12 +19,6 @@ namespace NzbDrone.Core.Repository
|
|||
public long Size { get; set; }
|
||||
public DateTime DateAdded { get; set; }
|
||||
|
||||
[Ignore]
|
||||
public IList<Episode> Episodes { get; set; }
|
||||
|
||||
[Ignore]
|
||||
public Series Series { get; set; }
|
||||
|
||||
[Ignore]
|
||||
public Model.Quality QualityWrapper
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue