2011-05-22 19:53:21 +03:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
using System;
|
2011-05-18 08:32:23 +03:00
|
|
|
using System.Collections.Generic;
|
2011-06-07 09:29:07 +03:00
|
|
|
using System.IO;
|
2011-06-18 05:00:44 +03:00
|
|
|
using System.Linq.Expressions;
|
2011-04-10 03:14:51 +03:00
|
|
|
using AutoMoq;
|
2010-10-24 10:46:58 +03:00
|
|
|
using FizzWare.NBuilder;
|
2011-06-03 00:06:46 +03:00
|
|
|
using FluentAssertions;
|
2010-10-21 04:49:23 +03:00
|
|
|
using Moq;
|
2011-06-03 00:06:46 +03:00
|
|
|
using NUnit.Framework;
|
2011-06-07 09:29:07 +03:00
|
|
|
using NzbDrone.Core.Model;
|
2011-05-18 08:32:23 +03:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
2010-10-21 04:49:23 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 06:50:12 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-05-18 08:32:23 +03:00
|
|
|
using NzbDrone.Core.Providers.Jobs;
|
2010-10-21 04:49:23 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-19 06:55:35 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-06-17 06:29:39 +03:00
|
|
|
using PetaPoco;
|
2010-10-21 04:49:23 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-19 06:55:35 +03:00
|
|
|
public class MediaFileProviderTests : TestBase
|
2010-10-21 04:49:23 +03:00
|
|
|
{
|
2011-05-18 08:32:23 +03:00
|
|
|
[Test]
|
2011-06-04 04:56:53 +03:00
|
|
|
public void get_series_files()
|
2011-05-18 08:32:23 +03:00
|
|
|
{
|
2011-06-04 04:56:53 +03:00
|
|
|
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All().With(s => s.SeriesId = 12).Build();
|
2011-05-18 08:32:23 +03:00
|
|
|
|
2011-06-04 04:56:53 +03:00
|
|
|
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All().With(s => s.SeriesId = 20).Build();
|
2011-05-18 08:32:23 +03:00
|
|
|
|
2011-06-04 04:56:53 +03:00
|
|
|
var mocker = new AutoMoqer();
|
2011-06-17 06:29:39 +03:00
|
|
|
|
|
|
|
var database = MockLib.GetEmptyDatabase(true);
|
|
|
|
|
|
|
|
|
2011-06-22 08:44:57 +03:00
|
|
|
database.InsertMany(firstSeriesFiles);
|
|
|
|
database.InsertMany(secondSeriesFiles);
|
2011-06-17 06:29:39 +03:00
|
|
|
|
|
|
|
mocker.SetConstant(database);
|
2011-06-03 00:06:46 +03:00
|
|
|
|
2011-06-04 04:56:53 +03:00
|
|
|
var result = mocker.Resolve<MediaFileProvider>().GetSeriesFiles(12);
|
2011-05-18 08:32:23 +03:00
|
|
|
|
|
|
|
|
2011-06-04 04:56:53 +03:00
|
|
|
result.Should().HaveSameCount(firstSeriesFiles);
|
2011-05-18 08:32:23 +03:00
|
|
|
}
|
2011-06-07 09:29:07 +03:00
|
|
|
|
2011-08-22 03:48:37 +03:00
|
|
|
[Test]
|
|
|
|
public void get_season_files()
|
|
|
|
{
|
|
|
|
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(s => s.SeriesId = 12)
|
|
|
|
.With(s => s.SeasonNumber = 1)
|
2011-08-22 03:48:37 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(s => s.SeriesId = 12)
|
|
|
|
.With(s => s.SeasonNumber = 2)
|
2011-08-22 03:48:37 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
var database = MockLib.GetEmptyDatabase(true);
|
|
|
|
|
|
|
|
database.InsertMany(firstSeriesFiles);
|
|
|
|
database.InsertMany(secondSeriesFiles);
|
|
|
|
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().GetSeasonFiles(12, 1);
|
|
|
|
|
|
|
|
result.Should().HaveSameCount(firstSeriesFiles);
|
|
|
|
}
|
|
|
|
|
2011-06-18 07:08:17 +03:00
|
|
|
[Test]
|
|
|
|
public void Scan_series_should_skip_series_with_no_episodes()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-06-22 08:44:57 +03:00
|
|
|
|
2011-06-18 07:08:17 +03:00
|
|
|
mocker.GetMock<EpisodeProvider>()
|
|
|
|
.Setup(c => c.GetEpisodeBySeries(12))
|
|
|
|
.Returns(new List<Episode>());
|
|
|
|
|
2011-06-21 09:34:45 +03:00
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
.Setup(e => e.RepairLinks()).Returns(0);
|
|
|
|
mocker.GetMock<MediaFileProvider>()
|
|
|
|
.Setup(e => e.DeleteOrphaned()).Returns(0);
|
|
|
|
|
|
|
|
|
2011-06-18 07:08:17 +03:00
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.SeriesId = 12).Build();
|
|
|
|
|
|
|
|
//Act
|
2011-06-20 06:04:08 +03:00
|
|
|
mocker.Resolve<DiskScanProvider>().Scan(series);
|
2011-06-18 07:08:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-06-21 02:46:54 +03:00
|
|
|
[Test]
|
|
|
|
[TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV]", "Law & Order- Criminal Intent - S10E07 - Icarus [HDTV]")]
|
|
|
|
public void CleanFileName(string name, string expectedName)
|
|
|
|
{
|
|
|
|
//Act
|
|
|
|
var result = MediaFileProvider.CleanFilename(name);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.AreEqual(expectedName, result);
|
|
|
|
}
|
2011-06-21 04:49:16 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CleanEpisodesWithNonExistantFiles()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(10).Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var database = MockLib.GetEmptyDatabase(true);
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
database.InsertMany(episodes);
|
|
|
|
|
|
|
|
//Act
|
2011-06-21 09:34:45 +03:00
|
|
|
var removedLinks = mocker.Resolve<MediaFileProvider>().RepairLinks();
|
2011-06-21 04:49:16 +03:00
|
|
|
var result = database.Fetch<Episode>();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().HaveSameCount(episodes);
|
|
|
|
result.Should().OnlyContain(e => e.EpisodeFileId == 0);
|
2011-06-21 09:34:45 +03:00
|
|
|
removedLinks.Should().Be(10);
|
2011-06-22 09:34:33 +03:00
|
|
|
}
|
2011-06-21 04:49:16 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DeleteOrphanedEpisodeFiles()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(5).Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var database = MockLib.GetEmptyDatabase(true);
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
database.InsertMany(episodes);
|
|
|
|
database.InsertMany(episodeFiles);
|
|
|
|
|
|
|
|
//Act
|
2011-06-21 09:34:45 +03:00
|
|
|
mocker.Resolve<MediaFileProvider>().DeleteOrphaned();
|
2011-06-21 04:49:16 +03:00
|
|
|
var result = database.Fetch<EpisodeFile>();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().HaveCount(5);
|
|
|
|
result.Should().OnlyContain(e => e.EpisodeFileId > 0);
|
|
|
|
}
|
2011-06-22 06:40:24 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
[TestCase("30 Rock - S01E05 - Episode Title", 1, true, "Season %0s", @"C:\Test\30 Rock\Season 01\30 Rock - S01E05 - Episode Title.mkv")]
|
|
|
|
[TestCase("30 Rock - S01E05 - Episode Title", 1, true, "Season %s", @"C:\Test\30 Rock\Season 1\30 Rock - S01E05 - Episode Title.mkv")]
|
|
|
|
[TestCase("30 Rock - S01E05 - Episode Title", 1, false, "Season %0s", @"C:\Test\30 Rock\30 Rock - S01E05 - Episode Title.mkv")]
|
|
|
|
[TestCase("30 Rock - S01E05 - Episode Title", 1, false, "Season %s", @"C:\Test\30 Rock\30 Rock - S01E05 - Episode Title.mkv")]
|
|
|
|
[TestCase("30 Rock - S01E05 - Episode Title", 1, true, "ReallyUglySeasonFolder %s", @"C:\Test\30 Rock\ReallyUglySeasonFolder 1\30 Rock - S01E05 - Episode Title.mkv")]
|
|
|
|
public void CalculateFilePath_SeasonFolder_SingleNumber(string filename, int seasonNumber, bool useSeasonFolder, string seasonFolderFormat, string expectedPath)
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.Title = "30 Rock")
|
|
|
|
.With(s => s.Path = @"C:\Test\30 Rock")
|
|
|
|
.With(s => s.SeasonFolder = useSeasonFolder)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-07-08 06:36:02 +03:00
|
|
|
mocker.GetMock<ConfigProvider>().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat);
|
2011-06-22 06:40:24 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<MediaFileProvider>().CalculateFilePath(fakeSeries, 1, filename, ".mkv");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.AreEqual(expectedPath, result.FullName);
|
|
|
|
}
|
2011-06-22 10:26:36 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DeleteEpisodeFile()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10).Build();
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
var database = MockLib.GetEmptyDatabase(true);
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
database.InsertMany(episodeFiles);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<MediaFileProvider>().Delete(1);
|
|
|
|
var result = database.Fetch<EpisodeFile>();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().HaveCount(9);
|
|
|
|
result.Should().NotContain(e => e.EpisodeFileId == 1);
|
|
|
|
}
|
2010-10-21 04:49:23 +03:00
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|