2010-10-21 01:49:23 +00:00
|
|
|
|
using System;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
using System.Linq.Expressions;
|
2011-04-10 00:14:51 +00:00
|
|
|
|
using AutoMoq;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
2010-10-21 01:49:23 +00:00
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using Moq;
|
2011-04-25 22:27:03 +00:00
|
|
|
|
using Moq.Linq;
|
2010-10-21 01:49:23 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2010-10-21 01:49:23 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class MediaFileProviderTests
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
2010-10-24 07:46:58 +00:00
|
|
|
|
[Description("Verifies that a new file imported properly")]
|
|
|
|
|
public void import_new_file()
|
2010-10-21 01:49:23 +00:00
|
|
|
|
{
|
|
|
|
|
//Arrange
|
2010-10-24 07:46:58 +00:00
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//Constants
|
2010-10-30 02:46:32 +00:00
|
|
|
|
const string fileName = @"WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
2010-10-24 07:46:58 +00:00
|
|
|
|
const int seasonNumber = 3;
|
|
|
|
|
const int episodeNumner = 01;
|
|
|
|
|
const int size = 12345;
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew().With(c => c.SeriesId = fakeSeries.SeriesId).Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-04-10 00:14:51 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<IRepository>()
|
2011-04-10 02:44:01 +00:00
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<IRepository>()
|
2011-04-10 02:44:01 +00:00
|
|
|
|
.Setup(r => r.Add(It.IsAny<EpisodeFile>())).Returns(0).Verifiable();
|
2010-10-21 01:49:23 +00:00
|
|
|
|
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
2011-04-10 02:44:01 +00:00
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns(fakeEpisode).
|
|
|
|
|
Verifiable();
|
2010-10-21 01:49:23 +00:00
|
|
|
|
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<DiskProvider>()
|
2011-04-10 02:44:01 +00:00
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
2010-10-21 01:49:23 +00:00
|
|
|
|
|
|
|
|
|
|
2011-04-25 21:23:02 +00:00
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
|
mocker.GetMock<IRepository>().VerifyAll();
|
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Once());
|
|
|
|
|
mocker.GetMock<EpisodeProvider>().VerifyAll();
|
|
|
|
|
mocker.GetMock<DiskProvider>().VerifyAll();
|
|
|
|
|
|
|
|
|
|
//Currently can't verify this since the list of episodes are loaded
|
|
|
|
|
//Dynamically by SubSonic
|
|
|
|
|
//Assert.AreEqual(fakeEpisode, result.Episodes[0]);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(fakeEpisode.SeriesId, result.SeriesId);
|
|
|
|
|
Assert.AreEqual(QualityTypes.BDRip, result.Quality);
|
|
|
|
|
Assert.AreEqual(Parser.NormalizePath(fileName), result.Path);
|
|
|
|
|
Assert.AreEqual(size, result.Size);
|
|
|
|
|
Assert.AreEqual(false, result.Proper);
|
|
|
|
|
Assert.AreNotEqual(new DateTime(), result.DateAdded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Description("Verifies that a new file imported properly")]
|
|
|
|
|
public void import_new_daily_file()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//Constants
|
|
|
|
|
const string fileName = @"2011.01.10 - Denis Leary - HD TV.mkv";
|
|
|
|
|
DateTime airDate = new DateTime(2011, 01, 10);
|
|
|
|
|
const int size = 12345;
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew().With(c => c.SeriesId = fakeSeries.SeriesId).Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
|
.Setup(r => r.Add(It.IsAny<EpisodeFile>())).Returns(0).Verifiable();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, airDate)).Returns(fakeEpisode).
|
|
|
|
|
Verifiable();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
2010-10-21 01:49:23 +00:00
|
|
|
|
//Act
|
2011-04-10 00:14:51 +00:00
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
2010-10-21 01:49:23 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2010-10-24 07:46:58 +00:00
|
|
|
|
Assert.IsNotNull(result);
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<IRepository>().VerifyAll();
|
2011-04-10 02:44:01 +00:00
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Once());
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<EpisodeProvider>().VerifyAll();
|
|
|
|
|
mocker.GetMock<DiskProvider>().VerifyAll();
|
2010-10-21 01:49:23 +00:00
|
|
|
|
|
2011-03-30 06:18:35 +00:00
|
|
|
|
//Currently can't verify this since the list of episodes are loaded
|
|
|
|
|
//Dynamically by SubSonic
|
|
|
|
|
//Assert.AreEqual(fakeEpisode, result.Episodes[0]);
|
2011-04-04 04:54:58 +00:00
|
|
|
|
|
2010-10-24 07:46:58 +00:00
|
|
|
|
Assert.AreEqual(fakeEpisode.SeriesId, result.SeriesId);
|
2011-04-25 21:37:53 +00:00
|
|
|
|
Assert.AreEqual(QualityTypes.HDTV, result.Quality);
|
2010-10-24 07:46:58 +00:00
|
|
|
|
Assert.AreEqual(Parser.NormalizePath(fileName), result.Path);
|
|
|
|
|
Assert.AreEqual(size, result.Size);
|
|
|
|
|
Assert.AreEqual(false, result.Proper);
|
|
|
|
|
Assert.AreNotEqual(new DateTime(), result.DateAdded);
|
2010-10-21 01:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
2011-04-25 22:27:03 +00:00
|
|
|
|
[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);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-25 21:37:53 +00:00
|
|
|
|
[Test]
|
|
|
|
|
[Description("Verifies that a new file imported properly")]
|
|
|
|
|
public void import_sample_file()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//Constants
|
|
|
|
|
const string fileName = @"2011.01.10 - Denis Leary - sample - HD TV.mkv";
|
|
|
|
|
DateTime airDate = new DateTime(2011, 01, 10);
|
|
|
|
|
const int size = 12345;
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew().With(c => c.SeriesId = fakeSeries.SeriesId).Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
|
.Setup(r => r.Add(It.IsAny<EpisodeFile>())).Returns(0).Verifiable();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, airDate)).Returns(fakeEpisode).
|
|
|
|
|
Verifiable();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(result);
|
2011-04-25 22:27:03 +00:00
|
|
|
|
}
|
2011-04-25 21:37:53 +00:00
|
|
|
|
|
2010-10-21 01:49:23 +00:00
|
|
|
|
[Test]
|
2010-10-24 07:46:58 +00:00
|
|
|
|
[Description("Verifies that an existing file will skip import")]
|
|
|
|
|
public void import_existing_file()
|
2010-10-21 01:49:23 +00:00
|
|
|
|
{
|
2010-10-24 07:46:58 +00:00
|
|
|
|
//Arrange
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//Constants
|
|
|
|
|
const string fileName = "WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
|
|
2011-04-10 00:14:51 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
mocker.GetMock<IRepository>(MockBehavior.Strict)
|
2011-04-10 02:44:01 +00:00
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(true).Verifiable();
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<EpisodeProvider>(MockBehavior.Strict);
|
|
|
|
|
mocker.GetMock<DiskProvider>(MockBehavior.Strict);
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-04-10 00:14:51 +00:00
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<IRepository>().VerifyAll();
|
|
|
|
|
mocker.GetMock<EpisodeProvider>().VerifyAll();
|
|
|
|
|
mocker.GetMock<DiskProvider>(MockBehavior.Strict).VerifyAll();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
Assert.IsNull(result);
|
2011-04-10 02:44:01 +00:00
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Never());
|
2010-10-21 01:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2010-10-24 07:46:58 +00:00
|
|
|
|
[Description("Verifies that a file with no episode is skipped")]
|
|
|
|
|
public void import_file_with_no_episode()
|
2010-10-21 01:49:23 +00:00
|
|
|
|
{
|
2010-10-24 07:46:58 +00:00
|
|
|
|
//Arrange
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//Constants
|
2011-04-19 06:47:17 +00:00
|
|
|
|
const string fileName = "WEEDS.S03E01.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
|
2010-10-24 07:46:58 +00:00
|
|
|
|
const int seasonNumber = 3;
|
|
|
|
|
const int episodeNumner = 01;
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-04-10 00:14:51 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
mocker.GetMock<IRepository>(MockBehavior.Strict)
|
2011-04-10 02:44:01 +00:00
|
|
|
|
.Setup(r => r.Exists(It.IsAny<Expression<Func<EpisodeFile, Boolean>>>())).Returns(false).Verifiable();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<EpisodeProvider>(MockBehavior.Strict)
|
2011-04-10 02:44:01 +00:00
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns<Episode>(null).
|
|
|
|
|
Verifiable();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<DiskProvider>(MockBehavior.Strict);
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-04-10 00:14:51 +00:00
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.VerifyAllMocks();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
Assert.IsNull(result);
|
2011-04-10 02:44:01 +00:00
|
|
|
|
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Never());
|
2010-10-21 01:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|