using System; using System.Collections.Generic; using System.IO; using System.Linq; using FizzWare.NBuilder; using Marr.Data; using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests { [TestFixture] public class ProcessDropDirectoryFixture : CoreTest { Series fakeSeries; [SetUp] public void Setup() { fakeSeries = Builder.CreateNew() .With(s => s.RootFolder = new LazyLoaded(new RootFolder { Path = @"C:\Test\TV" })) .With(s => s.FolderName = "30 Rock") .Build(); } private void WithLotsOfFreeDiskSpace() { Mocker.GetMock().Setup(s => s.FreeDiskSpace(It.IsAny())).Returns(1000000000); } [Test] public void ProcessDropFolder_should_only_process_folders_that_arent_known_series_folders() { WithLotsOfFreeDiskSpace(); var subFolders = new[] { @"c:\drop\episode1", @"c:\drop\episode2", @"c:\drop\episode3", @"c:\drop\episode4" }; Mocker.GetMock() .Setup(c => c.GetVideoFiles(It.IsAny(), false)) .Returns(new List()); Mocker.GetMock() .Setup(c => c.GetDirectories(It.IsAny())) .Returns(subFolders); Mocker.GetMock() .Setup(c => c.SeriesPathExists(subFolders[1])) .Returns(true); Mocker.GetMock() .Setup(c => c.GetByTitle(It.IsAny())) .Returns(fakeSeries); Mocker.GetMock() .Setup(c => c.Scan(It.IsAny(), It.IsAny())) .Returns(new List()); Mocker.GetMock() .Setup(c => c.GetDirectorySize(It.IsAny())) .Returns(10); Mocker.GetMock() .Setup(c => c.FolderExists(It.IsAny())) .Returns(true); Mocker.Resolve().ProcessDropFolder(@"C:\drop\"); Mocker.GetMock().Verify(c => c.Scan(It.IsAny(), subFolders[0]), Times.Once()); Mocker.GetMock().Verify(c => c.Scan(It.IsAny(), subFolders[1]), Times.Never()); Mocker.GetMock().Verify(c => c.Scan(It.IsAny(), subFolders[2]), Times.Once()); Mocker.GetMock().Verify(c => c.Scan(It.IsAny(), subFolders[3]), Times.Once()); } [Test] public void ProcessDropFolder_should_process_individual_video_files_in_drop_folder() { WithLotsOfFreeDiskSpace(); var files = new List { @"c:\drop\30 Rock - episode1.avi", @"c:\drop\30 Rock - episode2.mkv", @"c:\drop\30 Rock - episode3.mp4", @"c:\drop\30 Rock - episode4.wmv" }; Mocker.GetMock() .Setup(c => c.GetVideoFiles(It.IsAny(), false)) .Returns(files); Mocker.GetMock() .Setup(c => c.GetByTitle(It.IsAny())) .Returns(fakeSeries); Mocker.GetMock() .Setup(c => c.Scan(It.IsAny(), It.IsAny())) .Returns(new List()); Mocker.GetMock() .Setup(c => c.GetDirectorySize(It.IsAny())) .Returns(10); Mocker.GetMock() .Setup(c => c.FolderExists(It.IsAny())) .Returns(true); Mocker.Resolve().ProcessDropFolder(@"C:\drop\"); Mocker.GetMock().Verify(c => c.ImportFile(It.IsAny(), It.IsAny()), Times.Exactly(4)); } } }