1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00
Radarr/NzbDrone.Core.Test/MediaFileTests/DropFolderImportServiceFixture.cs

79 lines
2.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
2013-05-16 02:25:51 +02:00
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.MediaFiles.Events;
2013-04-18 01:32:53 +02:00
using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
2013-07-12 07:57:24 +02:00
namespace NzbDrone.Core.Test.MediaFileTests
{
[TestFixture]
2013-05-16 02:10:48 +02:00
public class DropFolderImportServiceFixture : CoreTest<DownloadedEpisodesImportService>
{
private EpisodeFile _fakeEpisodeFile;
private string[] _subFolders = new[] { "c:\\root\\foldername" };
private string[] _videoFiles = new[] { "c:\\root\\foldername\\video.ext" };
[SetUp]
public void Setup()
{
_fakeEpisodeFile = Builder<EpisodeFile>.CreateNew().Build();
2013-04-15 07:27:32 +02:00
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(_videoFiles);
2013-05-11 01:53:50 +02:00
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
.Returns(_subFolders);
2013-05-16 02:25:51 +02:00
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
.Returns("c:\\drop\\");
}
[Test]
public void should_import_file()
{
2013-06-09 08:20:38 +02:00
Subject.ProcessDownloadedEpisodesFolder();
VerifyImport();
}
[Test]
public void should_search_for_series_using_folder_name()
{
2013-06-09 08:20:38 +02:00
Subject.ProcessDownloadedEpisodesFolder();
2013-04-18 01:32:53 +02:00
Mocker.GetMock<IParsingService>().Verify(c => c.GetSeries("foldername"), Times.Once());
}
[Test]
public void should_skip_if_file_is_in_use_by_another_process()
{
2013-05-11 01:53:50 +02:00
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
.Returns(true);
2013-06-09 08:20:38 +02:00
Subject.ProcessDownloadedEpisodesFolder();
VerifyNoImport();
}
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());
}
}
}