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