|
|
@ -17,6 +17,7 @@ using NzbDrone.Core.Providers.Jobs;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
using PetaPoco;
|
|
|
|
using SubSonic.Repository;
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
@ -51,24 +52,20 @@ namespace NzbDrone.Core.Test
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
var database = mocker.GetMock<IDatabase>(MockBehavior.Strict);
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
|
|
|
database.Setup(r => r.Single<int>(It.IsAny<string>(), It.IsAny<object>())).Returns(0).Verifiable();
|
|
|
|
|
|
|
|
database.Setup(r => r.Insert(It.IsAny<EpisodeFile>())).Returns(1).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
|
|
|
|
.Setup(r => r.Add(It.IsAny<EpisodeFile>())).Returns(0).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns(fakeEpisode);
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
//Assert
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Once());
|
|
|
|
mocker.GetMock<IDatabase>().Verify(r => r.Insert(result), Times.Once());
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
|
|
|
|
|
|
|
result.SeasonNumber.Should().Be(fakeEpisode.SeasonNumber);
|
|
|
|
result.SeasonNumber.Should().Be(fakeEpisode.SeasonNumber);
|
|
|
@ -99,10 +96,9 @@ namespace NzbDrone.Core.Test
|
|
|
|
//Mocks
|
|
|
|
//Mocks
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
var database = mocker.GetMock<IDatabase>(MockBehavior.Strict);
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
|
|
|
database.Setup(r => r.Single<int>(It.IsAny<string>(), It.IsAny<object>())).Returns(0).Verifiable();
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
database.Setup(r => r.Insert(It.IsAny<EpisodeFile>())).Returns(1).Verifiable();
|
|
|
|
.Setup(r => r.Add(It.IsAny<EpisodeFile>())).Returns(0).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, airDate)).Returns(fakeEpisode).
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, airDate)).Returns(fakeEpisode).
|
|
|
@ -117,8 +113,8 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
//Assert
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
mocker.GetMock<IRepository>().VerifyAll();
|
|
|
|
mocker.GetMock<IDatabase>().VerifyAll();
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Once());
|
|
|
|
mocker.GetMock<IDatabase>().Verify(r => r.Insert(result), Times.Once());
|
|
|
|
mocker.GetMock<EpisodeProvider>().VerifyAll();
|
|
|
|
mocker.GetMock<EpisodeProvider>().VerifyAll();
|
|
|
|
mocker.GetMock<DiskProvider>().VerifyAll();
|
|
|
|
mocker.GetMock<DiskProvider>().VerifyAll();
|
|
|
|
|
|
|
|
|
|
|
@ -147,12 +143,13 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
//Fakes
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
var fakeEpisodeFile = Builder<EpisodeFile>.CreateNew().With(s => s.SeriesId = fakeSeries.SeriesId).Build();
|
|
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
//Mocks
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>(MockBehavior.Strict)
|
|
|
|
mocker.GetMock<IDatabase>(MockBehavior.Strict)
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(true).Verifiable();
|
|
|
|
.Setup(r => r.Single<int>(It.IsAny<string>(), It.IsAny<object>())).Returns(1).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
@ -183,13 +180,12 @@ namespace NzbDrone.Core.Test
|
|
|
|
//Mocks
|
|
|
|
//Mocks
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>(MockBehavior.Strict)
|
|
|
|
mocker.GetMock<IDatabase>(MockBehavior.Strict)
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
|
|
|
.Setup(r => r.Single<int>(It.IsAny<string>(), It.IsAny<object>())).Returns(0).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
|
|
|
|
|
|
|
|
|
|
@ -252,8 +248,9 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
//Mocks
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.GetMock<IRepository>(MockBehavior.Strict)
|
|
|
|
mocker.GetMock<IDatabase>(MockBehavior.Strict)
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(true).Verifiable();
|
|
|
|
.Setup(r => r.Single<int>(It.IsAny<string>(), It.IsAny<object>())).Returns(1).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>(MockBehavior.Strict);
|
|
|
|
mocker.GetMock<EpisodeProvider>(MockBehavior.Strict);
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(500000).Verifiable();
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(500000).Verifiable();
|
|
|
@ -264,7 +261,7 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
//Assert
|
|
|
|
Assert.IsNull(result);
|
|
|
|
Assert.IsNull(result);
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Never());
|
|
|
|
mocker.GetMock<IDatabase>().Verify(r => r.Insert(result), Times.Never());
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -285,8 +282,8 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
//Mocks
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.GetMock<IRepository>(MockBehavior.Strict)
|
|
|
|
mocker.GetMock<IDatabase>(MockBehavior.Strict)
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
|
|
|
.Setup(r => r.Single<int>(It.IsAny<string>(), It.IsAny<object>())).Returns(0).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>(MockBehavior.Strict)
|
|
|
|
mocker.GetMock<EpisodeProvider>(MockBehavior.Strict)
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns<Episode>(null).
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns<Episode>(null).
|
|
|
@ -320,7 +317,6 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void scan_media_job_should_not_scan_new_series()
|
|
|
|
public void scan_media_job_should_not_scan_new_series()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -350,10 +346,16 @@ namespace NzbDrone.Core.Test
|
|
|
|
.WhereAll().Have(s => s.SeriesId = 20).Build();
|
|
|
|
.WhereAll().Have(s => s.SeriesId = 20).Build();
|
|
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var repo = MockLib.GetEmptyRepository(true);
|
|
|
|
|
|
|
|
repo.AddMany(firstSeriesFiles);
|
|
|
|
var database = MockLib.GetEmptyDatabase(true);
|
|
|
|
repo.AddMany(secondSeriesFiles);
|
|
|
|
|
|
|
|
mocker.SetConstant(repo);
|
|
|
|
foreach (var file in firstSeriesFiles)
|
|
|
|
|
|
|
|
database.Insert(file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var file in secondSeriesFiles)
|
|
|
|
|
|
|
|
database.Insert(file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
|
|
|
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().GetSeriesFiles(12);
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().GetSeriesFiles(12);
|
|
|
|
|
|
|
|
|
|
|
@ -402,9 +404,9 @@ namespace NzbDrone.Core.Test
|
|
|
|
configProvider.SetupGet(c => c.NumberStyle).Returns(2);
|
|
|
|
configProvider.SetupGet(c => c.NumberStyle).Returns(2);
|
|
|
|
configProvider.SetupGet(c => c.ReplaceSpaces).Returns(false);
|
|
|
|
configProvider.SetupGet(c => c.ReplaceSpaces).Returns(false);
|
|
|
|
|
|
|
|
|
|
|
|
var repo = mocker.GetMock<IRepository>();
|
|
|
|
var database = mocker.GetMock<IDatabase>(MockBehavior.Strict);
|
|
|
|
repo.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
|
|
|
database.Setup(r => r.Single<int>(It.IsAny<string>(), It.IsAny<object>())).Returns(0).Verifiable();
|
|
|
|
repo.Setup(r => r.Add<EpisodeFile>(It.IsAny<EpisodeFile>())).Returns(1);
|
|
|
|
database.Setup(r => r.Insert(It.IsAny<EpisodeFile>())).Returns(1).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportNewFiles(@"C:\Test\30 Rock - 1x05 - Episode Title", fakeSeries);
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportNewFiles(@"C:\Test\30 Rock - 1x05 - Episode Title", fakeSeries);
|
|
|
@ -464,9 +466,10 @@ namespace NzbDrone.Core.Test
|
|
|
|
configProvider.SetupGet(c => c.NumberStyle).Returns(2);
|
|
|
|
configProvider.SetupGet(c => c.NumberStyle).Returns(2);
|
|
|
|
configProvider.SetupGet(c => c.ReplaceSpaces).Returns(false);
|
|
|
|
configProvider.SetupGet(c => c.ReplaceSpaces).Returns(false);
|
|
|
|
|
|
|
|
|
|
|
|
var repo = mocker.GetMock<IRepository>();
|
|
|
|
var database = mocker.GetMock<IDatabase>(MockBehavior.Strict);
|
|
|
|
repo.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
|
|
|
database.Setup(r => r.Single<int>(It.IsAny<string>(), It.IsAny<object>())).Returns(0).Verifiable();
|
|
|
|
repo.Setup(r => r.Add<EpisodeFile>(It.IsAny<EpisodeFile>())).Returns(1);
|
|
|
|
database.Setup(r => r.Insert(It.IsAny<EpisodeFile>())).Returns(1);
|
|
|
|
|
|
|
|
database.Setup(r => r.Delete<EpisodeFile>(It.IsAny<int>())).Returns(1);
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportNewFiles(@"C:\Test\30 Rock - 1x05 - Episode Title", fakeSeries);
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportNewFiles(@"C:\Test\30 Rock - 1x05 - Episode Title", fakeSeries);
|
|
|
|