You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
6.4 KiB
199 lines
6.4 KiB
13 years ago
|
// ReSharper disable RedundantUsingDirective
|
||
13 years ago
|
|
||
12 years ago
|
using System.Linq;
|
||
13 years ago
|
using System;
|
||
14 years ago
|
using System.Collections.Generic;
|
||
14 years ago
|
using FizzWare.NBuilder;
|
||
14 years ago
|
using FluentAssertions;
|
||
14 years ago
|
using Moq;
|
||
14 years ago
|
using NUnit.Framework;
|
||
13 years ago
|
using NzbDrone.Common;
|
||
12 years ago
|
using NzbDrone.Core.Configuration;
|
||
12 years ago
|
using NzbDrone.Core.MediaFiles;
|
||
12 years ago
|
using NzbDrone.Core.Qualities;
|
||
12 years ago
|
using NzbDrone.Core.Tv;
|
||
14 years ago
|
using NzbDrone.Core.Providers;
|
||
14 years ago
|
using NzbDrone.Core.Test.Framework;
|
||
14 years ago
|
|
||
12 years ago
|
namespace NzbDrone.Core.Test.MediaFileTests
|
||
14 years ago
|
{
|
||
|
[TestFixture]
|
||
|
// ReSharper disable InconsistentNaming
|
||
12 years ago
|
public class MediaFileServiceTest : SqlCeTest
|
||
14 years ago
|
{
|
||
14 years ago
|
[Test]
|
||
14 years ago
|
public void get_series_files()
|
||
14 years ago
|
{
|
||
14 years ago
|
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||
12 years ago
|
.All()
|
||
12 years ago
|
.With(c => c.Quality = Quality.SDTV)
|
||
12 years ago
|
.With(s => s.SeriesId = 12).Build();
|
||
14 years ago
|
|
||
14 years ago
|
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||
12 years ago
|
.All()
|
||
12 years ago
|
.With(c => c.Quality = Quality.SDTV)
|
||
12 years ago
|
.With(s => s.SeriesId = 20).Build();
|
||
14 years ago
|
|
||
13 years ago
|
|
||
14 years ago
|
|
||
12 years ago
|
WithRealDb();
|
||
14 years ago
|
|
||
|
|
||
12 years ago
|
Db.InsertMany(firstSeriesFiles);
|
||
|
Db.InsertMany(secondSeriesFiles);
|
||
14 years ago
|
|
||
12 years ago
|
var result = Mocker.Resolve<IMediaFileService>().GetFilesBySeries(12);
|
||
14 years ago
|
|
||
|
|
||
14 years ago
|
result.Should().HaveSameCount(firstSeriesFiles);
|
||
14 years ago
|
}
|
||
14 years ago
|
|
||
13 years ago
|
[Test]
|
||
|
public void get_season_files()
|
||
|
{
|
||
|
var firstSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||
13 years ago
|
.All()
|
||
12 years ago
|
.With(c => c.Quality = Quality.SDTV)
|
||
13 years ago
|
.With(s => s.SeriesId = 12)
|
||
|
.With(s => s.SeasonNumber = 1)
|
||
13 years ago
|
.Build();
|
||
|
|
||
|
var secondSeriesFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||
13 years ago
|
.All()
|
||
12 years ago
|
.With(c => c.Quality = Quality.SDTV)
|
||
13 years ago
|
.With(s => s.SeriesId = 12)
|
||
|
.With(s => s.SeasonNumber = 2)
|
||
13 years ago
|
.Build();
|
||
|
|
||
13 years ago
|
|
||
12 years ago
|
WithRealDb();
|
||
13 years ago
|
|
||
12 years ago
|
Db.InsertMany(firstSeriesFiles);
|
||
|
Db.InsertMany(secondSeriesFiles);
|
||
13 years ago
|
|
||
12 years ago
|
var result = Mocker.Resolve<IMediaFileService>().GetFilesBySeason(12, 1);
|
||
13 years ago
|
|
||
|
result.Should().HaveSameCount(firstSeriesFiles);
|
||
|
}
|
||
|
|
||
14 years ago
|
[Test]
|
||
|
public void Scan_series_should_skip_series_with_no_episodes()
|
||
|
{
|
||
13 years ago
|
WithStrictMocker();
|
||
14 years ago
|
|
||
12 years ago
|
Mocker.GetMock<IEpisodeService>()
|
||
14 years ago
|
.Setup(c => c.GetEpisodeBySeries(12))
|
||
|
.Returns(new List<Episode>());
|
||
|
|
||
14 years ago
|
|
||
13 years ago
|
Mocker.GetMock<DiskProvider>()
|
||
13 years ago
|
.Setup(c => c.FolderExists(It.IsAny<string>()))
|
||
|
.Returns(true);
|
||
13 years ago
|
|
||
14 years ago
|
var series = Builder<Series>.CreateNew()
|
||
12 years ago
|
.With(s => s.Id = 12).Build();
|
||
14 years ago
|
|
||
|
//Act
|
||
13 years ago
|
Mocker.Resolve<DiskScanProvider>().Scan(series);
|
||
14 years ago
|
|
||
|
//Assert
|
||
13 years ago
|
Mocker.VerifyAllMocks();
|
||
14 years ago
|
|
||
|
}
|
||
|
|
||
14 years ago
|
[Test]
|
||
12 years ago
|
[TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p]", "Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]")]
|
||
14 years ago
|
public void CleanFileName(string name, string expectedName)
|
||
|
{
|
||
|
//Act
|
||
12 years ago
|
var result = MediaFileService.CleanFilename(name);
|
||
14 years ago
|
|
||
|
//Assert
|
||
|
Assert.AreEqual(expectedName, result);
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
[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();
|
||
|
|
||
13 years ago
|
|
||
12 years ago
|
Mocker.GetMock<IConfigService>().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat);
|
||
14 years ago
|
|
||
|
//Act
|
||
12 years ago
|
var result = Mocker.Resolve<IMediaFileService>().CalculateFilePath(fakeSeries, 1, filename, ".mkv");
|
||
14 years ago
|
|
||
|
//Assert
|
||
|
Assert.AreEqual(expectedPath, result.FullName);
|
||
|
}
|
||
14 years ago
|
|
||
|
[Test]
|
||
|
public void DeleteEpisodeFile()
|
||
|
{
|
||
|
//Setup
|
||
12 years ago
|
var episodeFiles = Builder<EpisodeFile>
|
||
|
.CreateListOfSize(10)
|
||
|
.All()
|
||
12 years ago
|
.With(c => c.Quality = Quality.SDTV)
|
||
12 years ago
|
.Build();
|
||
14 years ago
|
|
||
13 years ago
|
|
||
12 years ago
|
WithRealDb();
|
||
|
Db.InsertMany(episodeFiles);
|
||
14 years ago
|
|
||
|
//Act
|
||
12 years ago
|
Mocker.Resolve<IMediaFileService>().Delete(1);
|
||
12 years ago
|
var result = Db.Fetch<EpisodeFile>();
|
||
14 years ago
|
|
||
|
//Assert
|
||
|
result.Should().HaveCount(9);
|
||
12 years ago
|
result.Should().NotContain(e => e.Id == 1);
|
||
14 years ago
|
}
|
||
13 years ago
|
|
||
|
[Test]
|
||
|
public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database()
|
||
|
{
|
||
|
//Setup
|
||
|
WithRealDb();
|
||
|
|
||
|
//Act
|
||
12 years ago
|
var result = Mocker.Resolve<IMediaFileService>().GetFileByPath(@"C:\Test\EpisodeFile.avi");
|
||
13 years ago
|
|
||
|
//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()
|
||
12 years ago
|
.With(c => c.Quality = Quality.SDTV)
|
||
13 years ago
|
.With(f => f.Path = path.NormalizePath())
|
||
|
.Build();
|
||
|
|
||
|
var episodeFileId = Convert.ToInt32(Db.Insert(episodeFile));
|
||
|
|
||
|
//Act
|
||
12 years ago
|
var result = Mocker.Resolve<IMediaFileService>().GetFileByPath(path);
|
||
13 years ago
|
|
||
|
//Resolve
|
||
|
result.Should().NotBeNull();
|
||
|
result.Path.Should().Be(path.NormalizePath());
|
||
12 years ago
|
result.Id.Should().Be(episodeFileId);
|
||
13 years ago
|
}
|
||
14 years ago
|
}
|
||
14 years ago
|
}
|