2011-10-22 22:28:59 -07:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-20 16:42:17 -07:00
|
|
|
|
2012-01-16 20:05:36 -08:00
|
|
|
using System;
|
2011-05-17 22:32:23 -07:00
|
|
|
using System.Collections.Generic;
|
2011-11-13 16:22:18 -08:00
|
|
|
|
2010-10-24 00:46:58 -07:00
|
|
|
using FizzWare.NBuilder;
|
2011-06-02 14:06:46 -07:00
|
|
|
using FluentAssertions;
|
2010-10-20 18:49:23 -07:00
|
|
|
using Moq;
|
2011-06-02 14:06:46 -07:00
|
|
|
using NUnit.Framework;
|
2011-11-12 20:07:06 -08:00
|
|
|
using NzbDrone.Common;
|
2013-02-18 22:01:03 -08:00
|
|
|
using NzbDrone.Core.Tv;
|
2012-01-16 20:05:36 -08:00
|
|
|
using NzbDrone.Core.Model;
|
2010-10-20 18:49:23 -07:00
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-03 20:50:12 -07:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2010-10-20 18:49:23 -07:00
|
|
|
using NzbDrone.Core.Repository;
|
2012-10-13 17:36:16 -07:00
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-18 20:55:35 -07:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-13 16:22:18 -08:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2010-10-20 18:49:23 -07:00
|
|
|
|
2011-10-20 16:42:17 -07:00
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2010-10-20 18:49:23 -07:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-02 12:54:03 -08:00
|
|
|
public class MediaFileProviderTest : SqlCeTest
|
2010-10-20 18:49:23 -07:00
|
|
|
{
|
2011-05-17 22:32:23 -07:00
|
|
|
[Test]
|
2011-06-03 18:56:53 -07:00
|
|
|
public void get_series_files()
|
2011-05-17 22:32:23 -07:00
|
|
|
{
|
2011-06-03 18:56:53 -07:00
|
|
|
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
2012-10-13 17:36:16 -07:00
|
|
|
.All()
|
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
|
|
|
.With(s => s.SeriesId = 12).Build();
|
2011-05-17 22:32:23 -07:00
|
|
|
|
2011-06-03 18:56:53 -07:00
|
|
|
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
2012-10-13 17:36:16 -07:00
|
|
|
.All()
|
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
|
|
|
.With(s => s.SeriesId = 20).Build();
|
2011-05-17 22:32:23 -07:00
|
|
|
|
2012-01-16 20:05:36 -08:00
|
|
|
|
2011-06-16 20:29:39 -07:00
|
|
|
|
2013-01-19 15:55:58 -08:00
|
|
|
WithRealDb();
|
2011-06-16 20:29:39 -07:00
|
|
|
|
|
|
|
|
2013-01-19 15:55:58 -08:00
|
|
|
Db.InsertMany(firstSeriesFiles);
|
|
|
|
Db.InsertMany(secondSeriesFiles);
|
2011-06-02 14:06:46 -07:00
|
|
|
|
2011-12-14 20:15:53 -08:00
|
|
|
var result = Mocker.Resolve<MediaFileProvider>().GetSeriesFiles(12);
|
2011-05-17 22:32:23 -07:00
|
|
|
|
|
|
|
|
2011-06-03 18:56:53 -07:00
|
|
|
result.Should().HaveSameCount(firstSeriesFiles);
|
2011-05-17 22:32:23 -07:00
|
|
|
}
|
2011-06-06 23:29:07 -07:00
|
|
|
|
2011-08-21 17:48:37 -07:00
|
|
|
[Test]
|
|
|
|
public void get_season_files()
|
|
|
|
{
|
|
|
|
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
2011-10-18 14:46:06 -07:00
|
|
|
.All()
|
2012-10-13 17:36:16 -07:00
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
2011-10-18 14:46:06 -07:00
|
|
|
.With(s => s.SeriesId = 12)
|
|
|
|
.With(s => s.SeasonNumber = 1)
|
2011-08-21 17:48:37 -07:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
2011-10-18 14:46:06 -07:00
|
|
|
.All()
|
2012-10-13 17:36:16 -07:00
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
2011-10-18 14:46:06 -07:00
|
|
|
.With(s => s.SeriesId = 12)
|
|
|
|
.With(s => s.SeasonNumber = 2)
|
2011-08-21 17:48:37 -07:00
|
|
|
.Build();
|
|
|
|
|
2012-01-16 20:05:36 -08:00
|
|
|
|
2013-01-19 15:55:58 -08:00
|
|
|
WithRealDb();
|
2011-08-21 17:48:37 -07:00
|
|
|
|
2013-01-19 15:55:58 -08:00
|
|
|
Db.InsertMany(firstSeriesFiles);
|
|
|
|
Db.InsertMany(secondSeriesFiles);
|
2011-08-21 17:48:37 -07:00
|
|
|
|
2011-12-14 20:15:53 -08:00
|
|
|
var result = Mocker.Resolve<MediaFileProvider>().GetSeasonFiles(12, 1);
|
2011-08-21 17:48:37 -07:00
|
|
|
|
|
|
|
result.Should().HaveSameCount(firstSeriesFiles);
|
|
|
|
}
|
|
|
|
|
2011-06-17 21:08:17 -07:00
|
|
|
[Test]
|
|
|
|
public void Scan_series_should_skip_series_with_no_episodes()
|
|
|
|
{
|
2011-12-14 20:15:53 -08:00
|
|
|
WithStrictMocker();
|
2011-06-21 22:44:57 -07:00
|
|
|
|
2013-02-21 16:47:09 -08:00
|
|
|
Mocker.GetMock<IEpisodeService>()
|
2011-06-17 21:08:17 -07:00
|
|
|
.Setup(c => c.GetEpisodeBySeries(12))
|
|
|
|
.Returns(new List<Episode>());
|
|
|
|
|
2011-12-14 20:15:53 -08:00
|
|
|
Mocker.GetMock<MediaFileProvider>()
|
2012-01-16 20:05:36 -08:00
|
|
|
.Setup(e => e.CleanUpDatabase());
|
2011-10-22 16:28:57 -07:00
|
|
|
|
2011-06-20 23:34:45 -07:00
|
|
|
|
2011-12-14 20:15:53 -08:00
|
|
|
Mocker.GetMock<DiskProvider>()
|
2011-10-22 16:28:57 -07:00
|
|
|
.Setup(c => c.FolderExists(It.IsAny<string>()))
|
|
|
|
.Returns(true);
|
2012-01-16 20:05:36 -08:00
|
|
|
|
2011-06-17 21:08:17 -07:00
|
|
|
var series = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.SeriesId = 12).Build();
|
|
|
|
|
|
|
|
//Act
|
2011-12-14 20:15:53 -08:00
|
|
|
Mocker.Resolve<DiskScanProvider>().Scan(series);
|
2011-06-17 21:08:17 -07:00
|
|
|
|
|
|
|
//Assert
|
2011-12-14 20:15:53 -08:00
|
|
|
Mocker.VerifyAllMocks();
|
2011-06-17 21:08:17 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-06-20 16:46:54 -07:00
|
|
|
[Test]
|
2012-12-31 19:45:57 -08:00
|
|
|
[TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p]", "Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]")]
|
2011-06-20 16:46:54 -07:00
|
|
|
public void CleanFileName(string name, string expectedName)
|
|
|
|
{
|
|
|
|
//Act
|
|
|
|
var result = MediaFileProvider.CleanFilename(name);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.AreEqual(expectedName, result);
|
|
|
|
}
|
2011-06-20 18:49:16 -07:00
|
|
|
|
2011-06-21 20:40:24 -07: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();
|
|
|
|
|
2012-01-16 20:05:36 -08:00
|
|
|
|
2011-12-14 20:15:53 -08:00
|
|
|
Mocker.GetMock<ConfigProvider>().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat);
|
2011-06-21 20:40:24 -07:00
|
|
|
|
|
|
|
//Act
|
2011-12-14 20:15:53 -08:00
|
|
|
var result = Mocker.Resolve<MediaFileProvider>().CalculateFilePath(fakeSeries, 1, filename, ".mkv");
|
2011-06-21 20:40:24 -07:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.AreEqual(expectedPath, result.FullName);
|
|
|
|
}
|
2011-06-22 00:26:36 -07:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DeleteEpisodeFile()
|
|
|
|
{
|
|
|
|
//Setup
|
2012-10-13 17:36:16 -07:00
|
|
|
var episodeFiles = Builder<EpisodeFile>
|
|
|
|
.CreateListOfSize(10)
|
|
|
|
.All()
|
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
|
|
|
.Build();
|
2011-06-22 00:26:36 -07:00
|
|
|
|
2012-01-16 20:05:36 -08:00
|
|
|
|
2013-01-19 15:55:58 -08:00
|
|
|
WithRealDb();
|
|
|
|
Db.InsertMany(episodeFiles);
|
2011-06-22 00:26:36 -07:00
|
|
|
|
|
|
|
//Act
|
2011-12-14 20:15:53 -08:00
|
|
|
Mocker.Resolve<MediaFileProvider>().Delete(1);
|
2013-01-19 15:55:58 -08:00
|
|
|
var result = Db.Fetch<EpisodeFile>();
|
2011-06-22 00:26:36 -07:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().HaveCount(9);
|
|
|
|
result.Should().NotContain(e => e.EpisodeFileId == 1);
|
|
|
|
}
|
2012-04-17 14:44:20 -07:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = Mocker.Resolve<MediaFileProvider>().GetFileByPath(@"C:\Test\EpisodeFile.avi");
|
|
|
|
|
|
|
|
//Resolve
|
|
|
|
result.Should().BeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetFileByPath_should_return_EpisodeFile_if_file_exists_in_database()
|
|
|
|
{
|
|
|
|
var path = @"C:\Test\EpisodeFile.avi";
|
|
|
|
|
|
|
|
//Setup
|
|
|
|
WithRealDb();
|
|
|
|
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
2012-10-13 17:36:16 -07:00
|
|
|
.With(c => c.Quality = QualityTypes.SDTV)
|
2012-04-17 14:44:20 -07:00
|
|
|
.With(f => f.Path = path.NormalizePath())
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var episodeFileId = Convert.ToInt32(Db.Insert(episodeFile));
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = Mocker.Resolve<MediaFileProvider>().GetFileByPath(path);
|
|
|
|
|
|
|
|
//Resolve
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
result.Path.Should().Be(path.NormalizePath());
|
|
|
|
result.EpisodeFileId.Should().Be(episodeFileId);
|
|
|
|
}
|
2010-10-20 18:49:23 -07:00
|
|
|
}
|
2011-04-09 19:44:01 -07:00
|
|
|
}
|