mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-18 21:35:51 -04:00
sample folder moved to new testcop style.
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
[TestFixture]
|
||||
public class DownloadedEpisodesImportServiceFixture : CoreTest<DownloadedEpisodesImportService>
|
||||
{
|
||||
private string[] _subFolders = new[] { "c:\\root\\foldername".AsOsAgnostic() };
|
||||
private string[] _videoFiles = new[] { "c:\\root\\foldername\\video.ext".AsOsAgnostic() };
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(_videoFiles);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
||||
.Returns(_subFolders);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
|
||||
.Returns("c:\\drop\\".AsOsAgnostic());
|
||||
|
||||
Mocker.GetMock<IImportApprovedEpisodes>()
|
||||
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), true))
|
||||
.Returns(new List<ImportDecision>());
|
||||
}
|
||||
|
||||
private void GivenValidSeries()
|
||||
{
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.GetSeries(It.IsAny<String>()))
|
||||
.Returns(Builder<Series>.CreateNew().Build());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_search_for_series_using_folder_name()
|
||||
{
|
||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||
|
||||
|
||||
Mocker.GetMock<IParsingService>().Verify(c => c.GetSeries("foldername"), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_import_if_dropfolder_doesnt_exist()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.FolderExists(It.IsAny<string>())).Returns(false);
|
||||
|
||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Verify(c => c.GetDirectories(It.IsAny<string>()), Times.Never());
|
||||
Mocker.GetMock<IDiskProvider>().Verify(c => c.GetFiles(It.IsAny<string>(), It.IsAny<SearchOption>()), Times.Never());
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_file_is_in_use_by_another_process()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
||||
.Returns(true);
|
||||
|
||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||
|
||||
VerifyNoImport();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_import_if_folder_is_a_series_path()
|
||||
{
|
||||
Mocker.GetMock<ISeriesService>()
|
||||
.Setup(s => s.SeriesPathExists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<IDiskScanService>()
|
||||
.Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(new string[0]);
|
||||
|
||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Verify(v => v.GetSeries(It.IsAny<String>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_delete_folder_if_no_files_were_imported()
|
||||
{
|
||||
Mocker.GetMock<IImportApprovedEpisodes>()
|
||||
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), false))
|
||||
.Returns(new List<ImportDecision>());
|
||||
|
||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.GetFolderSize(It.IsAny<String>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_folder_if_files_were_imported()
|
||||
{
|
||||
GivenValidSeries();
|
||||
|
||||
var localEpisode = new LocalEpisode();
|
||||
|
||||
var imported = new List<ImportDecision>();
|
||||
imported.Add(new ImportDecision(localEpisode));
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Setup(s => s.GetImportDecisions(It.IsAny<IEnumerable<String>>(), It.IsAny<Series>(), true))
|
||||
.Returns(imported);
|
||||
|
||||
Mocker.GetMock<IImportApprovedEpisodes>()
|
||||
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), true))
|
||||
.Returns(imported);
|
||||
|
||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.DeleteFolder(It.IsAny<String>(), true), Times.Once());
|
||||
}
|
||||
|
||||
[TestCase("_UNPACK_")]
|
||||
[TestCase("_FAILED_")]
|
||||
public void should_remove_unpack_from_folder_name(string prefix)
|
||||
{
|
||||
var folderName = "30.rock.s01e01.pilot.hdtv-lol";
|
||||
var folders = new[] { String.Format(@"C:\Test\Unsorted\{0}{1}", prefix, folderName).AsOsAgnostic() };
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetDirectories(It.IsAny<string>()))
|
||||
.Returns(folders);
|
||||
|
||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Verify(v => v.GetSeries(folderName), Times.Once());
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Verify(v => v.GetSeries(It.Is<String>(s => s.StartsWith(prefix))), Times.Never());
|
||||
}
|
||||
|
||||
private void VerifyNoImport()
|
||||
{
|
||||
Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true),
|
||||
Times.Never());
|
||||
}
|
||||
|
||||
private void VerifyImport()
|
||||
{
|
||||
Mocker.GetMock<IImportApprovedEpisodes>().Verify(c => c.Import(It.IsAny<List<ImportDecision>>(), true),
|
||||
Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
||||
{
|
||||
[TestFixture]
|
||||
public class ImportDecisionMakerFixture : CoreTest<ImportDecisionMaker>
|
||||
{
|
||||
private List<string> _videoFiles;
|
||||
private LocalEpisode _localEpisode;
|
||||
private Series _series;
|
||||
|
||||
private Mock<IImportDecisionEngineSpecification> _pass1;
|
||||
private Mock<IImportDecisionEngineSpecification> _pass2;
|
||||
private Mock<IImportDecisionEngineSpecification> _pass3;
|
||||
|
||||
private Mock<IImportDecisionEngineSpecification> _fail1;
|
||||
private Mock<IImportDecisionEngineSpecification> _fail2;
|
||||
private Mock<IImportDecisionEngineSpecification> _fail3;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_pass1 = new Mock<IImportDecisionEngineSpecification>();
|
||||
_pass2 = new Mock<IImportDecisionEngineSpecification>();
|
||||
_pass3 = new Mock<IImportDecisionEngineSpecification>();
|
||||
|
||||
_fail1 = new Mock<IImportDecisionEngineSpecification>();
|
||||
_fail2 = new Mock<IImportDecisionEngineSpecification>();
|
||||
_fail3 = new Mock<IImportDecisionEngineSpecification>();
|
||||
|
||||
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
||||
_pass1.Setup(c => c.RejectionReason).Returns("_pass1");
|
||||
|
||||
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
||||
_pass2.Setup(c => c.RejectionReason).Returns("_pass2");
|
||||
|
||||
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
||||
_pass3.Setup(c => c.RejectionReason).Returns("_pass3");
|
||||
|
||||
|
||||
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
||||
_fail1.Setup(c => c.RejectionReason).Returns("_fail1");
|
||||
|
||||
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
||||
_fail2.Setup(c => c.RejectionReason).Returns("_fail2");
|
||||
|
||||
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
||||
_fail3.Setup(c => c.RejectionReason).Returns("_fail3");
|
||||
|
||||
_videoFiles = new List<string> { @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV.avi" };
|
||||
_series = new Series();
|
||||
_localEpisode = new LocalEpisode { Series = _series, Path = @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV.avi" };
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(c => c.GetEpisodes(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
|
||||
.Returns(_localEpisode);
|
||||
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<int>()))
|
||||
.Returns(_videoFiles);
|
||||
|
||||
}
|
||||
|
||||
private void GivenSpecifications(params Mock<IImportDecisionEngineSpecification>[] mocks)
|
||||
{
|
||||
Mocker.SetConstant<IEnumerable<IRejectWithReason>>(mocks.Select(c => c.Object));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_all_specifications()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
||||
|
||||
Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
||||
|
||||
_fail1.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_fail2.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_fail3.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_pass1.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_pass2.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
_pass3.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_rejected_if_single_specs_fail()
|
||||
{
|
||||
GivenSpecifications(_fail1);
|
||||
|
||||
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
||||
|
||||
result.Single().Approved.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_rejected_if_one_of_specs_fail()
|
||||
{
|
||||
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
|
||||
|
||||
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
||||
|
||||
result.Single().Approved.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_pass_if_all_specs_pass()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3);
|
||||
|
||||
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
||||
|
||||
result.Single().Approved.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_same_number_of_rejections_as_specs_that_failed()
|
||||
{
|
||||
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
||||
|
||||
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
||||
result.Single().Rejections.Should().HaveCount(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void failed_parse_shouldnt_blowup_the_process()
|
||||
{
|
||||
GivenSpecifications(_pass1);
|
||||
|
||||
Mocker.GetMock<IParsingService>().Setup(c => c.GetEpisodes(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
|
||||
.Throws<TestException>();
|
||||
|
||||
_videoFiles = new List<String>
|
||||
{
|
||||
"The.Office.S03E115.DVDRip.XviD-OSiTV",
|
||||
"The.Office.S03E115.DVDRip.XviD-OSiTV",
|
||||
"The.Office.S03E115.DVDRip.XviD-OSiTV"
|
||||
};
|
||||
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<int>()))
|
||||
.Returns(_videoFiles);
|
||||
|
||||
Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Verify(c => c.GetEpisodes(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()), Times.Exactly(_videoFiles.Count));
|
||||
|
||||
ExceptionVerification.ExpectedErrors(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
{
|
||||
[TestFixture]
|
||||
public class FreeSpaceSpecificationFixture : CoreTest<FreeSpaceSpecification>
|
||||
{
|
||||
private Series _series;
|
||||
private LocalEpisode _localEpisode;
|
||||
private String _rootFolder;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_rootFolder = @"C:\Test\TV".AsOsAgnostic();
|
||||
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesType = SeriesTypes.Standard)
|
||||
.With(s => s.Path = Path.Combine(_rootFolder, "30 Rock"))
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
|
||||
Episodes = episodes,
|
||||
Series = _series
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenFileSize(long size)
|
||||
{
|
||||
_localEpisode.Size = size;
|
||||
}
|
||||
|
||||
private void GivenFreeSpace(long? size)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetAvailableSpace(It.IsAny<String>()))
|
||||
.Returns(size);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_reject_when_there_isnt_enough_disk_space()
|
||||
{
|
||||
GivenFileSize(100.Megabytes());
|
||||
GivenFreeSpace(80.Megabytes());
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_reject_when_there_isnt_enough_space_for_file_plus_100mb_padding()
|
||||
{
|
||||
GivenFileSize(100.Megabytes());
|
||||
GivenFreeSpace(150.Megabytes());
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_accept_when_there_is_enough_disk_space()
|
||||
{
|
||||
GivenFileSize(100.Megabytes());
|
||||
GivenFreeSpace(1.Gigabytes());
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_series_paths_parent_for_free_space_check()
|
||||
{
|
||||
GivenFileSize(100.Megabytes());
|
||||
GivenFreeSpace(1.Gigabytes());
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.GetAvailableSpace(_rootFolder), Times.Once());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_pass_if_free_space_is_null()
|
||||
{
|
||||
GivenFileSize(100.Megabytes());
|
||||
GivenFreeSpace(null);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_pass_if_exception_is_thrown()
|
||||
{
|
||||
GivenFileSize(100.Megabytes());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetAvailableSpace(It.IsAny<String>()))
|
||||
.Throws(new TestException());
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
using System.IO;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotInUseSpecificationFixture : CoreTest<NotInUseSpecification>
|
||||
{
|
||||
private LocalEpisode _localEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi".AsOsAgnostic(),
|
||||
Size = 100,
|
||||
Series = Builder<Series>.CreateNew().Build()
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenChildOfSeries()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.IsParent(_localEpisode.Series.Path, _localEpisode.Path))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void GivenNewFile()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.IsParent(_localEpisode.Series.Path, _localEpisode.Path))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_file_is_under_series_folder()
|
||||
{
|
||||
GivenChildOfSeries();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_check_for_file_in_use_if_child_of_series_folder()
|
||||
{
|
||||
GivenChildOfSeries();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.IsFileLocked(It.IsAny<FileInfo>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_file_is_in_use()
|
||||
{
|
||||
GivenNewFile();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.IsFileLocked(It.IsAny<FileInfo>()))
|
||||
.Returns(true);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_file_is_not_in_use()
|
||||
{
|
||||
GivenNewFile();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.IsFileLocked(It.IsAny<FileInfo>()))
|
||||
.Returns(false);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotSampleSpecificationFixture : CoreTest<NotSampleSpecification>
|
||||
{
|
||||
private Series _series;
|
||||
private LocalEpisode _localEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesType = SeriesTypes.Standard)
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
|
||||
Episodes = episodes,
|
||||
Series = _series
|
||||
};
|
||||
}
|
||||
|
||||
private void WithDailySeries()
|
||||
{
|
||||
_series.SeriesType = SeriesTypes.Daily;
|
||||
}
|
||||
|
||||
private void WithSeasonZero()
|
||||
{
|
||||
_localEpisode.Episodes[0].SeasonNumber = 0;
|
||||
}
|
||||
|
||||
private void WithFileSize(long size)
|
||||
{
|
||||
_localEpisode.Size = size;
|
||||
}
|
||||
|
||||
private void WithLength(int minutes)
|
||||
{
|
||||
Mocker.GetMock<IVideoFileInfoReader>()
|
||||
.Setup(s => s.GetRunTime(It.IsAny<String>()))
|
||||
.Returns(new TimeSpan(0, 0, minutes, 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_series_is_daily()
|
||||
{
|
||||
WithDailySeries();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_season_zero()
|
||||
{
|
||||
WithSeasonZero();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_undersize_and_under_length()
|
||||
{
|
||||
WithFileSize(10.Megabytes());
|
||||
WithLength(1);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_undersize()
|
||||
{
|
||||
WithFileSize(10.Megabytes());
|
||||
WithLength(10);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_under_length()
|
||||
{
|
||||
WithFileSize(100.Megabytes());
|
||||
WithLength(1);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_over_size_and_length()
|
||||
{
|
||||
WithFileSize(100.Megabytes());
|
||||
WithLength(10);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_check_lenght_if_file_is_large_enough()
|
||||
{
|
||||
WithFileSize(100.Megabytes());
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
|
||||
Mocker.GetMock<IVideoFileInfoReader>().Verify(c => c.GetRunTime(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_log_error_if_run_time_is_0_and_under_sample_size()
|
||||
{
|
||||
WithFileSize(40.Megabytes());
|
||||
WithLength(0);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_check_for_flv_file()
|
||||
{
|
||||
_localEpisode.Path = @"C:\Test\some.show.s01e01.flv";
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
|
||||
Mocker.GetMock<IVideoFileInfoReader>().Verify(c => c.GetRunTime(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotUnpackingSpecificationFixture : CoreTest<NotUnpackingSpecification>
|
||||
{
|
||||
private LocalEpisode _localEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(s => s.DownloadClientWorkingFolders)
|
||||
.Returns("_UNPACK_|_FAILED_");
|
||||
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Path = @"C:\Test\Unsorted TV\30.rock\30.rock.s01e01.avi".AsOsAgnostic(),
|
||||
Size = 100,
|
||||
Series = Builder<Series>.CreateNew().Build()
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenInWorkingFolder()
|
||||
{
|
||||
_localEpisode.Path = @"C:\Test\Unsorted TV\_UNPACK_30.rock\30.rock.s01e01.avi".AsOsAgnostic();
|
||||
}
|
||||
|
||||
private void GivenLastWriteTimeUtc(DateTime time)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetLastFileWrite(It.IsAny<string>()))
|
||||
.Returns(time);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_not_in_working_folder()
|
||||
{
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_in_old_working_folder()
|
||||
{
|
||||
GivenInWorkingFolder();
|
||||
GivenLastWriteTimeUtc(DateTime.UtcNow.AddHours(-1));
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_in_working_folder_and_last_write_time_was_recent()
|
||||
{
|
||||
GivenInWorkingFolder();
|
||||
GivenLastWriteTimeUtc(DateTime.UtcNow);
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Marr.Data;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpgradeSpecificationFixture : CoreTest<UpgradeSpecification>
|
||||
{
|
||||
private Series _series;
|
||||
private LocalEpisode _localEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesType = SeriesTypes.Standard)
|
||||
.Build();
|
||||
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Path = @"C:\Test\30 Rock\30.rock.s01e01.avi",
|
||||
Quality = new QualityModel(Quality.HDTV720p, false)
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_no_existing_episodeFile()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 0)
|
||||
.With(e => e.EpisodeFile = null)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_no_existing_episodeFile_for_multi_episodes()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 0)
|
||||
.With(e => e.EpisodeFile = null)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_upgrade_for_existing_episodeFile()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.SDTV, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_upgrade_for_existing_episodeFile_for_multi_episodes()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.SDTV, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.Bluray720p, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile_for_multi_episodes()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.Bluray720p, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_an_upgrade_for_one_existing_episodeFile_for_multi_episode()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.SDTV, false)
|
||||
}))
|
||||
.TheNext(1)
|
||||
.With(e => e.EpisodeFileId = 2)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.Bluray720p, false)
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
[TestFixture]
|
||||
public class ImportApprovedEpisodesFixture : CoreTest<ImportApprovedEpisodes>
|
||||
{
|
||||
private List<ImportDecision> _rejectedDecisions;
|
||||
private List<ImportDecision> _approvedDecisions;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_rejectedDecisions = new List<ImportDecision>();
|
||||
_approvedDecisions = new List<ImportDecision>();
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(5)
|
||||
.Build();
|
||||
|
||||
_rejectedDecisions.Add(new ImportDecision(new LocalEpisode(), "Rejected!"));
|
||||
_rejectedDecisions.Add(new ImportDecision(new LocalEpisode(), "Rejected!"));
|
||||
_rejectedDecisions.Add(new ImportDecision(new LocalEpisode(), "Rejected!"));
|
||||
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
_approvedDecisions.Add(new ImportDecision
|
||||
(
|
||||
new LocalEpisode
|
||||
{
|
||||
Series = series,
|
||||
Episodes = new List<Episode> {episode},
|
||||
Path = @"C:\Test\TV\30 Rock\30 Rock - S01E01 - Pilit.avi".AsOsAgnostic(),
|
||||
Quality = new QualityModel(Quality.Bluray720p)
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
Mocker.GetMock<IUpgradeMediaFiles>()
|
||||
.Setup(s => s.UpgradeEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<LocalEpisode>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_empty_list_if_there_are_no_approved_decisions()
|
||||
{
|
||||
Subject.Import(_rejectedDecisions).Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_import_each_approved()
|
||||
{
|
||||
Subject.Import(_approvedDecisions).Should().HaveCount(5);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_only_import_approved()
|
||||
{
|
||||
var all = new List<ImportDecision>();
|
||||
all.AddRange(_rejectedDecisions);
|
||||
all.AddRange(_approvedDecisions);
|
||||
|
||||
Subject.Import(all).Should().HaveCount(5);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_only_import_each_episode_once()
|
||||
{
|
||||
var all = new List<ImportDecision>();
|
||||
all.AddRange(_approvedDecisions);
|
||||
all.Add(new ImportDecision(_approvedDecisions.First().LocalEpisode));
|
||||
|
||||
Subject.Import(all).Should().HaveCount(5);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_move_new_downloads()
|
||||
{
|
||||
Subject.Import(new List<ImportDecision> {_approvedDecisions.First()}, true);
|
||||
|
||||
Mocker.GetMock<IUpgradeMediaFiles>()
|
||||
.Verify(v => v.UpgradeEpisodeFile(It.IsAny<EpisodeFile>(), _approvedDecisions.First().LocalEpisode),
|
||||
Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_publish_EpisodeImportedEvent_for_new_downloads()
|
||||
{
|
||||
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
|
||||
|
||||
Mocker.GetMock<IMessageAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.IsAny<EpisodeImportedEvent>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_move_existing_files()
|
||||
{
|
||||
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() });
|
||||
|
||||
Mocker.GetMock<IUpgradeMediaFiles>()
|
||||
.Verify(v => v.UpgradeEpisodeFile(It.IsAny<EpisodeFile>(), _approvedDecisions.First().LocalEpisode),
|
||||
Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_trigger_EpisodeImportedEvent_for_existing_files()
|
||||
{
|
||||
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() });
|
||||
|
||||
Mocker.GetMock<IMessageAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.IsAny<EpisodeImportedEvent>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
[TestFixture]
|
||||
public class MediaFileRepositoryFixture : DbTest<MediaFileRepository, EpisodeFile>
|
||||
{
|
||||
[Test]
|
||||
public void get_files_by_series()
|
||||
{
|
||||
var files = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(c => c.Id = 0)
|
||||
.With(c => c.Quality =new QualityModel(Quality.Bluray720p))
|
||||
.Random(4)
|
||||
.With(s => s.SeriesId = 12)
|
||||
.BuildListOfNew();
|
||||
|
||||
|
||||
Db.InsertMany(files);
|
||||
|
||||
var seriesFiles = Subject.GetFilesBySeries(12);
|
||||
|
||||
seriesFiles.Should().HaveCount(4);
|
||||
seriesFiles.Should().OnlyContain(c => c.SeriesId == 12);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database()
|
||||
{
|
||||
Subject.GetFileByPath(@"C:\Test\EpisodeFile.avi").Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void exists_should_return_false_if_file_doesnt_exist()
|
||||
{
|
||||
Subject.Exists(@"C:\Test\EpisodeFile.avi").Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetFileByPath_should_return_EpisodeFile_if_file_exists_in_database()
|
||||
{
|
||||
var path = @"C:\Test\EpisodeFile.avi".AsOsAgnostic();
|
||||
|
||||
var episodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(f => f.Id = 0)
|
||||
.With(f => f.Path = path.CleanFilePath())
|
||||
.Build();
|
||||
|
||||
Subject.Insert(episodeFile);
|
||||
|
||||
var file = Subject.GetFileByPath(path);
|
||||
|
||||
//Resolve
|
||||
file.Should().NotBeNull();
|
||||
file.Path.Should().Be(path.CleanFilePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
[TestFixture]
|
||||
public class MediaFileServiceTest : CoreTest<MediaFileService>
|
||||
{
|
||||
|
||||
[Test]
|
||||
[TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p]",
|
||||
"Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]")]
|
||||
public void CleanFileName(string name, string expectedName)
|
||||
{
|
||||
FileNameBuilder.CleanFilename(name).Should().Be(expectedName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void filter_should_return_all_files_if_no_existing_files()
|
||||
{
|
||||
var files = new List<string>()
|
||||
{
|
||||
"c:\\file1.avi".AsOsAgnostic(),
|
||||
"c:\\file2.avi".AsOsAgnostic(),
|
||||
"c:\\file3.avi".AsOsAgnostic()
|
||||
};
|
||||
|
||||
Mocker.GetMock<IMediaFileRepository>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
|
||||
|
||||
Subject.FilterExistingFiles(files, 10).Should().BeEquivalentTo(files);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void filter_should_return_none_if_all_files_exist()
|
||||
{
|
||||
var files = new List<string>()
|
||||
{
|
||||
"c:\\file1.avi".AsOsAgnostic(),
|
||||
"c:\\file2.avi".AsOsAgnostic(),
|
||||
"c:\\file3.avi".AsOsAgnostic()
|
||||
};
|
||||
|
||||
Mocker.GetMock<IMediaFileRepository>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(files.Select(f => new EpisodeFile { Path = f }).ToList());
|
||||
|
||||
|
||||
Subject.FilterExistingFiles(files, 10).Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void filter_should_return_none_existing_files()
|
||||
{
|
||||
var files = new List<string>()
|
||||
{
|
||||
"c:\\file1.avi".AsOsAgnostic(),
|
||||
"c:\\file2.avi".AsOsAgnostic(),
|
||||
"c:\\file3.avi".AsOsAgnostic()
|
||||
};
|
||||
|
||||
Mocker.GetMock<IMediaFileRepository>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<EpisodeFile>
|
||||
{
|
||||
new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()}
|
||||
});
|
||||
|
||||
|
||||
Subject.FilterExistingFiles(files, 10).Should().HaveCount(2);
|
||||
Subject.FilterExistingFiles(files, 10).Should().NotContain("c:\\file2.avi".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void filter_should_return_none_existing_files_ignoring_case()
|
||||
{
|
||||
WindowsOnly();
|
||||
|
||||
var files = new List<string>()
|
||||
{
|
||||
"c:\\file1.avi".AsOsAgnostic(),
|
||||
"c:\\FILE2.avi".AsOsAgnostic(),
|
||||
"c:\\file3.avi".AsOsAgnostic()
|
||||
};
|
||||
|
||||
Mocker.GetMock<IMediaFileRepository>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<EpisodeFile>
|
||||
{
|
||||
new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()}
|
||||
});
|
||||
|
||||
|
||||
Subject.FilterExistingFiles(files, 10).Should().HaveCount(2);
|
||||
Subject.FilterExistingFiles(files, 10).Should().NotContain("c:\\file2.avi".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void filter_should_return_none_existing_files_not_ignoring_case()
|
||||
{
|
||||
LinuxOnly();
|
||||
|
||||
var files = new List<string>()
|
||||
{
|
||||
"c:\\file1.avi".AsOsAgnostic(),
|
||||
"c:\\FILE2.avi".AsOsAgnostic(),
|
||||
"c:\\file3.avi".AsOsAgnostic()
|
||||
};
|
||||
|
||||
Mocker.GetMock<IMediaFileRepository>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<EpisodeFile>
|
||||
{
|
||||
new EpisodeFile{Path = "c:\\file2.avi".AsOsAgnostic()}
|
||||
});
|
||||
|
||||
Subject.FilterExistingFiles(files, 10).Should().HaveCount(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void filter_should_not_change_casing()
|
||||
{
|
||||
var files = new List<string>()
|
||||
{
|
||||
"c:\\FILE1.avi".AsOsAgnostic()
|
||||
};
|
||||
|
||||
Mocker.GetMock<IMediaFileRepository>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
|
||||
Subject.FilterExistingFiles(files, 10).Should().HaveCount(1);
|
||||
Subject.FilterExistingFiles(files, 10).Should().NotContain(files.First().ToLower());
|
||||
Subject.FilterExistingFiles(files, 10).Should().Contain(files.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
public class MediaFileTableCleanupServiceFixture : CoreTest<MediaFileTableCleanupService>
|
||||
{
|
||||
private const string DELETED_PATH = "ANY FILE WITH THIS PATH IS CONSIDERED DELETED!";
|
||||
private List<Episode> _episodes;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_episodes = Builder<Episode>.CreateListOfSize(10)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Mocker.GetMock<ISeriesService>()
|
||||
.Setup(s => s.GetSeries(It.IsAny<Int32>()))
|
||||
.Returns(Builder<Series>.CreateNew().Build());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(e => e.FileExists(It.Is<String>(c => c != DELETED_PATH)))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(_episodes);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.IsParent(It.IsAny<String>(), It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void GivenEpisodeFiles(IEnumerable<EpisodeFile> episodeFiles)
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetFilesBySeries(It.IsAny<int>()))
|
||||
.Returns(episodeFiles.ToList());
|
||||
}
|
||||
|
||||
private void GivenFilesAreNotAttachedToEpisode()
|
||||
{
|
||||
_episodes.ForEach(e => e.EpisodeFileId = 0);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(_episodes);
|
||||
}
|
||||
|
||||
private void GivenFileIsNotInSeriesFolder()
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.IsParent(It.IsAny<String>(), It.IsAny<String>()))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_files_that_exist_in_disk()
|
||||
{
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.Build();
|
||||
|
||||
GivenEpisodeFiles(episodeFiles);
|
||||
|
||||
Subject.Execute(new CleanMediaFileDb(0));
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Verify(c => c.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_none_existing_files()
|
||||
{
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.Random(2)
|
||||
.With(c => c.Path = DELETED_PATH)
|
||||
.Build();
|
||||
|
||||
GivenEpisodeFiles(episodeFiles);
|
||||
|
||||
Subject.Execute(new CleanMediaFileDb(0));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>().Verify(c => c.Delete(It.Is<EpisodeFile>(e => e.Path == DELETED_PATH), false), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_files_that_dont_belong_to_any_episodes()
|
||||
{
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.Random(10)
|
||||
.With(c => c.Path = "ExistingPath")
|
||||
.Build();
|
||||
|
||||
GivenEpisodeFiles(episodeFiles);
|
||||
GivenFilesAreNotAttachedToEpisode();
|
||||
|
||||
Subject.Execute(new CleanMediaFileDb(0));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>().Verify(c => c.Delete(It.IsAny<EpisodeFile>(), false), Times.Exactly(10));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_files_that_do_not_belong_to_the_series_path()
|
||||
{
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.Random(10)
|
||||
.With(c => c.Path = "ExistingPath")
|
||||
.Build();
|
||||
|
||||
GivenEpisodeFiles(episodeFiles);
|
||||
GivenFileIsNotInSeriesFolder();
|
||||
|
||||
Subject.Execute(new CleanMediaFileDb(0));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>().Verify(c => c.Delete(It.IsAny<EpisodeFile>(), false), Times.Exactly(10));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_unlink_episode_when_episodeFile_does_not_exist()
|
||||
{
|
||||
GivenEpisodeFiles(new List<EpisodeFile>());
|
||||
|
||||
Subject.Execute(new CleanMediaFileDb(0));
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Verify(c => c.UpdateEpisode(It.Is<Episode>(e => e.EpisodeFileId == 0)), Times.Exactly(10));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_update_episode_when_episodeFile_exists()
|
||||
{
|
||||
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(10)
|
||||
.Random(10)
|
||||
.With(c => c.Path = "ExistingPath")
|
||||
.Build();
|
||||
|
||||
GivenEpisodeFiles(episodeFiles);
|
||||
|
||||
Subject.Execute(new CleanMediaFileDb(0));
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Verify(c => c.UpdateEpisode(It.IsAny<Episode>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
public class RenameEpisodeFileServiceFixture : CoreTest<RenameEpisodeFileService>
|
||||
{
|
||||
private Series _series;
|
||||
private List<EpisodeFile> _episodeFiles;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.Build();
|
||||
|
||||
_episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.SeriesId = _series.Id)
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Mocker.GetMock<ISeriesService>()
|
||||
.Setup(s => s.GetSeries(_series.Id))
|
||||
.Returns(_series);
|
||||
}
|
||||
|
||||
private void GivenNoEpisodeFiles()
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesBySeries(_series.Id))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesBySeason(_series.Id, _episodeFiles.First().SeasonNumber))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
}
|
||||
|
||||
private void GivenEpisodeFiles()
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesBySeries(_series.Id))
|
||||
.Returns(_episodeFiles);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesBySeason(_series.Id, _episodeFiles.First().SeasonNumber))
|
||||
.Returns(_episodeFiles);
|
||||
}
|
||||
|
||||
private void GivenMovedFiles()
|
||||
{
|
||||
Mocker.GetMock<IMoveEpisodeFiles>()
|
||||
.Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), _series));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_publish_event_if_no_files_to_rename()
|
||||
{
|
||||
GivenNoEpisodeFiles();
|
||||
|
||||
Subject.Execute(new RenameSeriesCommand(_series.Id));
|
||||
|
||||
Mocker.GetMock<IMessageAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.IsAny<SeriesRenamedEvent>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_publish_event_if_no_files_are_renamed()
|
||||
{
|
||||
GivenEpisodeFiles();
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>()
|
||||
.Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<Series>()))
|
||||
.Throws(new SameFilenameException("Same file name", "Filename"));
|
||||
|
||||
Subject.Execute(new RenameSeriesCommand(_series.Id));
|
||||
|
||||
Mocker.GetMock<IMessageAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.IsAny<SeriesRenamedEvent>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_publish_event_if_files_are_renamed()
|
||||
{
|
||||
GivenEpisodeFiles();
|
||||
GivenMovedFiles();
|
||||
|
||||
Subject.Execute(new RenameSeriesCommand(_series.Id));
|
||||
|
||||
Mocker.GetMock<IMessageAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.IsAny<SeriesRenamedEvent>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_moved_files()
|
||||
{
|
||||
GivenEpisodeFiles();
|
||||
GivenMovedFiles();
|
||||
|
||||
Subject.Execute(new RenameSeriesCommand(_series.Id));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(v => v.Update(It.IsAny<EpisodeFile>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void rename_season_should_get_episodefiles_for_season()
|
||||
{
|
||||
GivenEpisodeFiles();
|
||||
GivenMovedFiles();
|
||||
|
||||
Subject.Execute(new RenameSeasonCommand(_series.Id, _episodeFiles.First().SeasonNumber));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(v => v.GetFilesBySeries(_series.Id), Times.Never());
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(v => v.GetFilesBySeason(_series.Id, _episodeFiles.First().SeasonNumber), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void rename_series_should_get_episodefiles_for_series()
|
||||
{
|
||||
GivenEpisodeFiles();
|
||||
GivenMovedFiles();
|
||||
|
||||
Subject.Execute(new RenameSeriesCommand(_series.Id));
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(v => v.GetFilesBySeries(_series.Id), Times.Once());
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Verify(v => v.GetFilesBySeason(_series.Id, _episodeFiles.First().SeasonNumber), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Marr.Data;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
public class UpgradeMediaFileServiceFixture : CoreTest<UpgradeMediaFileService>
|
||||
{
|
||||
private EpisodeFile _episodeFile;
|
||||
private LocalEpisode _localEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_localEpisode = new LocalEpisode();
|
||||
|
||||
_episodeFile = Builder<EpisodeFile>
|
||||
.CreateNew()
|
||||
.Build();
|
||||
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FileExists(It.IsAny<string>()))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void GivenSingleEpisodeWithSingleEpisodeFile()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Id = 1,
|
||||
Path = @"C:\Test\30 Rock\Season 01\30.rock.s01e01.avi",
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void GivenMultipleEpisodesWithSingleEpisodeFile()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Id = 1,
|
||||
Path = @"C:\Test\30 Rock\Season 01\30.rock.s01e01.avi",
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void GivenMultipleEpisodesWithMultipleEpisodeFiles()
|
||||
{
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Id = 1,
|
||||
Path = @"C:\Test\30 Rock\Season 01\30.rock.s01e01.avi",
|
||||
}))
|
||||
.TheNext(1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Id = 2,
|
||||
Path = @"C:\Test\30 Rock\Season 01\30.rock.s01e02.avi",
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_single_episode_file_once()
|
||||
{
|
||||
GivenSingleEpisodeWithSingleEpisodeFile();
|
||||
|
||||
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
|
||||
|
||||
Mocker.GetMock<IRecycleBinProvider>().Verify(v => v.DeleteFile(It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_the_same_episode_file_only_once()
|
||||
{
|
||||
GivenMultipleEpisodesWithSingleEpisodeFile();
|
||||
|
||||
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
|
||||
|
||||
Mocker.GetMock<IRecycleBinProvider>().Verify(v => v.DeleteFile(It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_multiple_different_episode_files()
|
||||
{
|
||||
GivenMultipleEpisodesWithMultipleEpisodeFiles();
|
||||
|
||||
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
|
||||
|
||||
Mocker.GetMock<IRecycleBinProvider>().Verify(v => v.DeleteFile(It.IsAny<string>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_episode_file_from_database()
|
||||
{
|
||||
GivenSingleEpisodeWithSingleEpisodeFile();
|
||||
|
||||
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(It.IsAny<EpisodeFile>(), true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_existing_file_fromdb_if_file_doesnt_exist()
|
||||
{
|
||||
GivenSingleEpisodeWithSingleEpisodeFile();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FileExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
|
||||
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
|
||||
|
||||
Mocker.GetMock<IMediaFileService>().Verify(v => v.Delete(_localEpisode.Episodes.Single().EpisodeFile.Value, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_try_to_recyclebin_existing_file_if_file_doesnt_exist()
|
||||
{
|
||||
GivenSingleEpisodeWithSingleEpisodeFile();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.FileExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
|
||||
Subject.UpgradeEpisodeFile(_episodeFile, _localEpisode);
|
||||
|
||||
Mocker.GetMock<IRecycleBinProvider>().Verify(v => v.DeleteFile(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user