2011-05-22 16:53:21 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
using System;
|
2011-05-18 05:32:23 +00:00
|
|
|
|
using System.Collections.Generic;
|
2011-06-07 06:29:07 +00:00
|
|
|
|
using System.IO;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
using System.Linq.Expressions;
|
2011-05-18 05:32:23 +00:00
|
|
|
|
using System.Linq;
|
2011-04-10 00:14:51 +00:00
|
|
|
|
using AutoMoq;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using FluentAssertions;
|
2010-10-21 01:49:23 +00:00
|
|
|
|
using Moq;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using NUnit.Framework;
|
2011-06-07 06:29:07 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
2011-05-18 05:32:23 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
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;
|
2011-05-18 05:32:23 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2010-10-21 01:49:23 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-19 03:55:35 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-06-17 03:29:39 +00:00
|
|
|
|
using PetaPoco;
|
2010-10-21 01:49:23 +00:00
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-19 03:55:35 +00:00
|
|
|
|
public class MediaFileProviderTests : TestBase
|
2010-10-21 01:49:23 +00:00
|
|
|
|
{
|
|
|
|
|
[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
|
2011-05-21 02:06:56 +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;
|
2011-05-21 02:06:56 +00:00
|
|
|
|
const int episodeNumner = 1;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
const int size = 12345;
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
2011-06-04 01:56:53 +00:00
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(c => c.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.With(c => c.SeasonNumber = seasonNumber)
|
|
|
|
|
.Build();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
//Mocks
|
2011-04-10 00:14:51 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
2011-05-21 02:06:56 +00:00
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(12345).Verifiable();
|
|
|
|
|
|
2011-06-17 03:29:39 +00:00
|
|
|
|
var database = mocker.GetMock<IDatabase>(MockBehavior.Strict);
|
2011-06-17 04:12:14 +00:00
|
|
|
|
database.Setup(r => r.Exists<EpisodeFile>(It.IsAny<string>(), It.IsAny<object>())).Returns(false).Verifiable();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
database.Setup(r => r.Insert(It.IsAny<EpisodeFile>())).Returns(1).Verifiable();
|
2011-05-21 02:06:56 +00:00
|
|
|
|
|
2010-10-21 01:49:23 +00:00
|
|
|
|
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<EpisodeProvider>()
|
2011-05-21 02:06:56 +00:00
|
|
|
|
.Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns(fakeEpisode);
|
|
|
|
|
|
2011-04-25 21:23:02 +00:00
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNotNull(result);
|
2011-06-17 03:29:39 +00:00
|
|
|
|
mocker.GetMock<IDatabase>().Verify(r => r.Insert(result), Times.Once());
|
2011-05-21 02:06:56 +00:00
|
|
|
|
mocker.VerifyAllMocks();
|
2011-04-25 21:23:02 +00:00
|
|
|
|
|
2011-06-04 01:56:53 +00:00
|
|
|
|
result.SeasonNumber.Should().Be(fakeEpisode.SeasonNumber);
|
|
|
|
|
|
2011-04-25 21:23:02 +00:00
|
|
|
|
Assert.AreEqual(fakeEpisode.SeriesId, result.SeriesId);
|
2011-05-23 17:20:43 +00:00
|
|
|
|
Assert.AreEqual(QualityTypes.DVD, result.Quality);
|
2011-04-25 21:23:02 +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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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";
|
2011-05-19 03:55:35 +00:00
|
|
|
|
var airDate = new DateTime(2011, 01, 10);
|
2011-04-25 21:23:02 +00:00
|
|
|
|
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();
|
|
|
|
|
|
2011-06-17 03:29:39 +00:00
|
|
|
|
var database = mocker.GetMock<IDatabase>(MockBehavior.Strict);
|
2011-06-17 04:12:14 +00:00
|
|
|
|
database.Setup(r => r.Exists<EpisodeFile>(It.IsAny<string>(), It.IsAny<object>())).Returns(false).Verifiable();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
database.Setup(r => r.Insert(It.IsAny<EpisodeFile>())).Returns(1).Verifiable();
|
2011-04-25 21:23:02 +00:00
|
|
|
|
|
|
|
|
|
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-06-17 03:29:39 +00:00
|
|
|
|
mocker.GetMock<IDatabase>().VerifyAll();
|
|
|
|
|
mocker.GetMock<IDatabase>().Verify(r => r.Insert(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
|
2011-05-24 04:12:54 +00:00
|
|
|
|
//Assert.AreEqual(fakeEpisode, result.EpisodeNumbers[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
|
|
|
|
}
|
|
|
|
|
|
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 size = 12345;
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
var fakeEpisodeFile = Builder<EpisodeFile>.CreateNew().With(s => s.SeriesId = fakeSeries.SeriesId).Build();
|
2011-04-25 22:27:03 +00:00
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 03:29:39 +00:00
|
|
|
|
mocker.GetMock<IDatabase>(MockBehavior.Strict)
|
2011-06-17 04:12:14 +00:00
|
|
|
|
.Setup(r => r.Exists<EpisodeFile>(It.IsAny<string>(), It.IsAny<object>())).Returns(true).Verifiable();
|
2011-04-25 22:27:03 +00:00
|
|
|
|
|
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(size).Verifiable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportFile(fakeSeries, fileName);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
mocker.VerifyAllMocks();
|
2011-06-04 01:56:53 +00:00
|
|
|
|
result.Should().BeNull();
|
2011-04-25 22:27:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-20 02:12:36 +00:00
|
|
|
|
[Test]
|
|
|
|
|
[Description("Verifies that a un-parsable file isn't imported")]
|
|
|
|
|
public void import_unparsable_file()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//Constants
|
|
|
|
|
const string fileName = @"WEEDS.avi";
|
|
|
|
|
const int size = 12345;
|
|
|
|
|
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-17 03:29:39 +00:00
|
|
|
|
mocker.GetMock<IDatabase>(MockBehavior.Strict)
|
2011-06-17 04:12:14 +00:00
|
|
|
|
.Setup(r => r.Exists<EpisodeFile>(It.IsAny<string>(), It.IsAny<object>())).Returns(false).Verifiable();
|
2011-05-20 02:12:36 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
ExceptionVerification.ExcpectedWarns(1);
|
|
|
|
|
}
|
|
|
|
|
|
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";
|
2011-05-19 03:55:35 +00:00
|
|
|
|
var airDate = new DateTime(2011, 01, 10);
|
2011-04-25 21:37:53 +00:00
|
|
|
|
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();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
mocker.GetMock<IDatabase>(MockBehavior.Strict)
|
2011-06-17 04:12:14 +00:00
|
|
|
|
.Setup(r => r.Exists<EpisodeFile>(It.IsAny<string>(), It.IsAny<object>())).Returns(true).Verifiable();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
|
2011-04-10 00:14:51 +00:00
|
|
|
|
mocker.GetMock<EpisodeProvider>(MockBehavior.Strict);
|
2011-04-26 00:43:34 +00:00
|
|
|
|
mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(500000).Verifiable();
|
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
|
|
|
|
|
Assert.IsNull(result);
|
2011-06-17 03:29:39 +00:00
|
|
|
|
mocker.GetMock<IDatabase>().Verify(r => r.Insert(result), Times.Never());
|
2011-04-26 00:43:34 +00:00
|
|
|
|
mocker.VerifyAllMocks();
|
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();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
mocker.GetMock<IDatabase>(MockBehavior.Strict)
|
2011-06-17 04:12:14 +00:00
|
|
|
|
.Setup(r => r.Exists<EpisodeFile>(It.IsAny<string>(), It.IsAny<object>())).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-26 00:43:34 +00:00
|
|
|
|
mocker.GetMock<DiskProvider>(MockBehavior.Strict)
|
|
|
|
|
.Setup(e => e.GetSize(fileName)).Returns(90000000000);
|
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());
|
2011-05-19 03:55:35 +00:00
|
|
|
|
ExceptionVerification.ExcpectedWarns(1);
|
2010-10-21 01:49:23 +00:00
|
|
|
|
}
|
2011-05-18 05:32:23 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void scan_series_should_update_last_scan_date()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.UpdateSeries(It.Is<Series>(s => s.LastDiskSync != null))).Verifiable();
|
|
|
|
|
|
|
|
|
|
mocker.Resolve<MediaFileProvider>().Scan(new Series());
|
|
|
|
|
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void scan_media_job_should_not_scan_new_series()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-05-27 06:03:57 +00:00
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(2)
|
2011-05-23 05:51:46 +00:00
|
|
|
|
.WhereTheFirst(1).Has(c => c.Episodes = new List<Episode>())
|
|
|
|
|
.AndTheNext(1).Has(c => c.Episodes = Builder<Episode>.CreateListOfSize(10).Build())
|
2011-05-27 06:03:57 +00:00
|
|
|
|
.Build();
|
2011-05-18 05:32:23 +00:00
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
2011-05-23 05:51:46 +00:00
|
|
|
|
.Setup(c => c.GetAllSeries()).Returns(fakeSeries);
|
|
|
|
|
|
2011-05-18 05:32:23 +00:00
|
|
|
|
mocker.GetMock<MediaFileProvider>(MockBehavior.Strict)
|
2011-05-23 05:51:46 +00:00
|
|
|
|
.Setup(c => c.Scan(fakeSeries.ToList()[1])).Returns(new List<EpisodeFile>()).Verifiable();
|
2011-05-18 05:32:23 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
mocker.Resolve<DiskScanJob>().Start(new ProgressNotification("test"), 0);
|
2011-05-18 05:32:23 +00:00
|
|
|
|
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-06-04 01:56:53 +00:00
|
|
|
|
public void get_series_files()
|
2011-05-18 05:32:23 +00:00
|
|
|
|
{
|
2011-06-04 01:56:53 +00:00
|
|
|
|
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
|
|
|
|
.WhereAll().Have(s => s.SeriesId = 12).Build();
|
2011-05-18 05:32:23 +00:00
|
|
|
|
|
2011-06-04 01:56:53 +00:00
|
|
|
|
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
|
|
|
|
.WhereAll().Have(s => s.SeriesId = 20).Build();
|
2011-05-18 05:32:23 +00:00
|
|
|
|
|
2011-06-04 01:56:53 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
|
|
|
|
|
var database = MockLib.GetEmptyDatabase(true);
|
|
|
|
|
|
|
|
|
|
foreach (var file in firstSeriesFiles)
|
|
|
|
|
database.Insert(file);
|
|
|
|
|
|
|
|
|
|
foreach (var file in secondSeriesFiles)
|
|
|
|
|
database.Insert(file);
|
|
|
|
|
|
|
|
|
|
mocker.SetConstant(database);
|
2011-06-02 21:06:46 +00:00
|
|
|
|
|
2011-06-04 01:56:53 +00:00
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().GetSeriesFiles(12);
|
2011-05-18 05:32:23 +00:00
|
|
|
|
|
|
|
|
|
|
2011-06-04 01:56:53 +00:00
|
|
|
|
result.Should().HaveSameCount(firstSeriesFiles);
|
2011-05-18 05:32:23 +00:00
|
|
|
|
}
|
2011-06-07 06:29:07 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Description("Verifies that a new download will import successfully")]
|
|
|
|
|
public void import_new_download_success()
|
|
|
|
|
{
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.Title = "30 Rock")
|
|
|
|
|
.With(s => s.Path = @"C:\Test\TV\30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.With(e => e.EpisodeFileId = 0)
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumber = 5)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
var diskProvider = mocker.GetMock<DiskProvider>();
|
|
|
|
|
diskProvider.Setup(d => d.GetFiles(It.IsAny<string>(), "*.*", SearchOption.AllDirectories)).Returns(new string[] { @"C:\Test\30 Rock - 1x05 - Episode Title\30.Rock.S01E05.Gibberish.XviD.avi" });
|
|
|
|
|
diskProvider.Setup(d => d.GetSize(It.IsAny<string>())).Returns(90000000000);
|
|
|
|
|
diskProvider.Setup(d => d.CreateDirectory(It.IsAny<string>())).Returns("ok");
|
|
|
|
|
diskProvider.Setup(d => d.RenameFile(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
|
diskProvider.Setup(d => d.GetExtension(It.IsAny<string>())).Returns(".avi");
|
|
|
|
|
|
|
|
|
|
var episodeProvider = mocker.GetMock<EpisodeProvider>();
|
|
|
|
|
episodeProvider.Setup(e => e.GetEpisodes(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> {fakeEpisode});
|
|
|
|
|
episodeProvider.Setup(e => e.GetEpisode(fakeSeries.SeriesId, 1, 5)).Returns(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
var configProvider = mocker.GetMock<ConfigProvider>();
|
|
|
|
|
configProvider.SetupGet(c => c.UseSeasonFolder).Returns(true);
|
|
|
|
|
configProvider.SetupGet(c => c.SeasonFolderFormat).Returns(@"Season %0s");
|
|
|
|
|
configProvider.SetupGet(c => c.SeriesName).Returns(true);
|
|
|
|
|
configProvider.SetupGet(c => c.EpisodeName).Returns(true);
|
|
|
|
|
configProvider.SetupGet(c => c.AppendQuality).Returns(true);
|
|
|
|
|
configProvider.SetupGet(c => c.SeparatorStyle).Returns(0);
|
|
|
|
|
configProvider.SetupGet(c => c.NumberStyle).Returns(2);
|
|
|
|
|
configProvider.SetupGet(c => c.ReplaceSpaces).Returns(false);
|
|
|
|
|
|
2011-06-17 03:29:39 +00:00
|
|
|
|
var database = mocker.GetMock<IDatabase>(MockBehavior.Strict);
|
2011-06-17 04:12:14 +00:00
|
|
|
|
database.Setup(r => r.Exists<EpisodeFile>(It.IsAny<string>(), It.IsAny<object>())).Returns(false).Verifiable();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
database.Setup(r => r.Insert(It.IsAny<EpisodeFile>())).Returns(1).Verifiable();
|
2011-06-07 06:29:07 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportNewFiles(@"C:\Test\30 Rock - 1x05 - Episode Title", fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
Assert.AreEqual(1, result.Count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Description("Verifies that a new download will import successfully, deletes previous episode")]
|
|
|
|
|
public void import_new_download_success_delete_equal_quality()
|
|
|
|
|
{
|
|
|
|
|
//Fakes
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(s => s.Title = "30 Rock")
|
|
|
|
|
.With(s => s.Path = @"C:\Test\TV\30 Rock")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.With(e => e.SeasonNumber = 1)
|
|
|
|
|
.With(e => e.EpisodeNumber = 5)
|
|
|
|
|
.With(e => e.EpisodeFileId = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisodeFile = Builder<EpisodeFile>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.With(e => e.EpisodeFileId = 1)
|
|
|
|
|
.With(e => e.Quality = QualityTypes.SDTV)
|
|
|
|
|
.With(e => e.Episodes = new List<Episode>{ fakeEpisode })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
fakeEpisode.EpisodeFile = fakeEpisodeFile;
|
|
|
|
|
|
|
|
|
|
//Mocks
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
var diskProvider = mocker.GetMock<DiskProvider>();
|
|
|
|
|
diskProvider.Setup(d => d.GetFiles(It.IsAny<string>(), "*.*", SearchOption.AllDirectories)).Returns(new string[] { @"C:\Test\30 Rock - 1x05 - Episode Title\30.Rock.S01E05.Gibberish.XviD.avi" });
|
|
|
|
|
diskProvider.Setup(d => d.GetSize(It.IsAny<string>())).Returns(90000000000);
|
|
|
|
|
diskProvider.Setup(d => d.CreateDirectory(It.IsAny<string>())).Returns("ok");
|
|
|
|
|
diskProvider.Setup(d => d.RenameFile(It.IsAny<string>(), It.IsAny<string>()));
|
|
|
|
|
diskProvider.Setup(d => d.GetExtension(It.IsAny<string>())).Returns(".avi");
|
|
|
|
|
|
|
|
|
|
var episodeProvider = mocker.GetMock<EpisodeProvider>();
|
|
|
|
|
episodeProvider.Setup(e => e.GetEpisodes(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode });
|
|
|
|
|
episodeProvider.Setup(e => e.GetEpisode(fakeSeries.SeriesId, 1, 5)).Returns(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
var configProvider = mocker.GetMock<ConfigProvider>();
|
|
|
|
|
configProvider.SetupGet(c => c.UseSeasonFolder).Returns(true);
|
|
|
|
|
configProvider.SetupGet(c => c.SeasonFolderFormat).Returns(@"Season %0s");
|
|
|
|
|
configProvider.SetupGet(c => c.SeriesName).Returns(true);
|
|
|
|
|
configProvider.SetupGet(c => c.EpisodeName).Returns(true);
|
|
|
|
|
configProvider.SetupGet(c => c.AppendQuality).Returns(true);
|
|
|
|
|
configProvider.SetupGet(c => c.SeparatorStyle).Returns(0);
|
|
|
|
|
configProvider.SetupGet(c => c.NumberStyle).Returns(2);
|
|
|
|
|
configProvider.SetupGet(c => c.ReplaceSpaces).Returns(false);
|
|
|
|
|
|
2011-06-17 03:29:39 +00:00
|
|
|
|
var database = mocker.GetMock<IDatabase>(MockBehavior.Strict);
|
2011-06-17 04:12:14 +00:00
|
|
|
|
database.Setup(r => r.Exists<EpisodeFile>(It.IsAny<string>(), It.IsAny<object>())).Returns(false).Verifiable();
|
2011-06-17 03:29:39 +00:00
|
|
|
|
database.Setup(r => r.Insert(It.IsAny<EpisodeFile>())).Returns(1);
|
|
|
|
|
database.Setup(r => r.Delete<EpisodeFile>(It.IsAny<int>())).Returns(1);
|
2011-06-07 06:29:07 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().ImportNewFiles(@"C:\Test\30 Rock - 1x05 - Episode Title", fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
Assert.AreEqual(1, result.Count);
|
|
|
|
|
}
|
2010-10-21 01:49:23 +00:00
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|