diff --git a/30 Rock - 6x18 - Murphy Brown Lied to Us [SDTV].strm b/30 Rock - 6x18 - Murphy Brown Lied to Us [SDTV].strm
new file mode 100644
index 000000000..334bfaf3f
--- /dev/null
+++ b/30 Rock - 6x18 - Murphy Brown Lied to Us [SDTV].strm
@@ -0,0 +1 @@
+plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb=C:\Test\Pneumatic\30 Rock - 6x18 - Murphy Brown Lied to Us [SDTV].nzb&nzbname=30 Rock - 6x18 - Murphy Brown Lied to Us [SDTV]
\ No newline at end of file
diff --git a/30 Rock - 6x19 - Live from Studio 6H (East Coast) [SDTV] [Proper].strm b/30 Rock - 6x19 - Live from Studio 6H (East Coast) [SDTV] [Proper].strm
new file mode 100644
index 000000000..809d0cd9e
--- /dev/null
+++ b/30 Rock - 6x19 - Live from Studio 6H (East Coast) [SDTV] [Proper].strm
@@ -0,0 +1 @@
+plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb=C:\Test\Pneumatic\30 Rock - 6x19 - Live from Studio 6H (East Coast) [SDTV] [Proper].nzb&nzbname=30 Rock - 6x19 - Live from Studio 6H (East Coast) [SDTV] [Proper]
\ No newline at end of file
diff --git a/30 Rock - 6x21 - The Return of Avery Jessup [SDTV].strm b/30 Rock - 6x21 - The Return of Avery Jessup [SDTV].strm
new file mode 100644
index 000000000..3039a5c59
--- /dev/null
+++ b/30 Rock - 6x21 - The Return of Avery Jessup [SDTV].strm
@@ -0,0 +1 @@
+plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb=C:\Test\Pneumatic\30 Rock - 6x21 - The Return of Avery Jessup [SDTV].nzb&nzbname=30 Rock - 6x21 - The Return of Avery Jessup [SDTV]
\ No newline at end of file
diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs
index 66b7414bf..a0e10589a 100644
--- a/NzbDrone.Common/DiskProvider.cs
+++ b/NzbDrone.Common/DiskProvider.cs
@@ -42,6 +42,14 @@ namespace NzbDrone.Common
.Max(c => c.LastWriteTimeUtc);
}
+ public virtual DateTime GetLastFileWrite(string path)
+ {
+ if (!FileExists(path))
+ throw new FileNotFoundException("File doesn't exist: " + path);
+
+ return new FileInfo(path).LastWriteTimeUtc;
+ }
+
public virtual bool FolderExists(string path)
{
return Directory.Exists(path);
@@ -209,5 +217,13 @@ namespace NzbDrone.Common
{
return String.Equals(firstPath.NormalizePath(), secondPath.NormalizePath(), StringComparison.InvariantCultureIgnoreCase);
}
+
+ public virtual long GetFileSize(string path)
+ {
+ if (!FileExists(path))
+ throw new FileNotFoundException("File doesn't exist: " + path);
+
+ return new FileInfo(path).Length;
+ }
}
}
\ No newline at end of file
diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
index 78d59655d..695e3e405 100644
--- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
+++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
@@ -114,8 +114,15 @@
+
+
+
+
+
+
+
@@ -139,9 +146,9 @@
-
+
-
+
@@ -157,9 +164,9 @@
-
+
-
+
diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest.cs
deleted file mode 100644
index 8973b29c0..000000000
--- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest.cs
+++ /dev/null
@@ -1,376 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Linq.Expressions;
-using FizzWare.NBuilder;
-using FluentAssertions;
-using Moq;
-using NUnit.Framework;
-using NzbDrone.Common;
-using NzbDrone.Core.Model;
-using NzbDrone.Core.Providers;
-using NzbDrone.Core.Providers.Core;
-using NzbDrone.Core.Repository;
-using NzbDrone.Core.Repository.Quality;
-using NzbDrone.Core.Test.Framework;
-using NzbDrone.Test.Common;
-using NzbDrone.Test.Common.AutoMoq;
-
-namespace NzbDrone.Core.Test.ProviderTests
-{
- // ReSharper disable InconsistentNaming
- public class DiskScanProviderTest : CoreTest
- {
- [Test]
- public void scan_series_should_update_the_last_scan_date()
- {
-
-
- Mocker.GetMock()
- .Setup(c => c.UpdateSeries(It.Is(s => s.LastDiskSync != null))).Verifiable();
-
- Mocker.GetMock()
- .Setup(c => c.GetEpisodeBySeries(It.IsAny()))
- .Returns(new List { new Episode() });
-
- Mocker.GetMock()
- .Setup(c => c.FolderExists(It.IsAny()))
- .Returns(true);
-
- Mocker.GetMock()
- .Setup(c => c.GetSeriesFiles(It.IsAny()))
- .Returns(new List());
-
- Mocker.Resolve().Scan(new Series());
-
- Mocker.VerifyAllMocks();
-
- }
-
- [Test]
- public void cleanup_should_skip_existing_files()
- {
- WithStrictMocker();
- var episodes = Builder.CreateListOfSize(10).Build();
-
- Mocker.GetMock()
- .Setup(e => e.FileExists(It.IsAny()))
- .Returns(true);
-
-
- //Act
- Mocker.Resolve().CleanUp(episodes);
-
- //Assert
- Mocker.VerifyAllMocks();
- }
-
- [Test]
- public void cleanup_should_delete_none_existing_files()
- {
- WithStrictMocker();
- var episodes = Builder.CreateListOfSize(10).Build();
-
- Mocker.GetMock()
- .Setup(e => e.FileExists(It.IsAny()))
- .Returns(false);
-
- Mocker.GetMock()
- .Setup(e => e.GetEpisodesByFileId(It.IsAny()))
- .Returns(new List());
-
- Mocker.GetMock()
- .Setup(e => e.Delete(It.IsAny()));
-
-
- //Act
- Mocker.Resolve().CleanUp(episodes);
-
- //Assert
- Mocker.VerifyAllMocks();
-
- Mocker.GetMock()
- .Verify(e => e.GetEpisodesByFileId(It.IsAny()), Times.Exactly(10));
-
- Mocker.GetMock()
- .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10));
-
- }
-
- [Test]
- public void cleanup_should_delete_none_existing_files_remove_links_to_episodes()
- {
- WithStrictMocker();
- var episodes = Builder.CreateListOfSize(10).Build();
-
- Mocker.GetMock()
- .Setup(e => e.FileExists(It.IsAny()))
- .Returns(false);
-
- Mocker.GetMock()
- .Setup(e => e.GetEpisodesByFileId(It.IsAny()))
- .Returns(new List { new Episode { EpisodeFileId = 10 }, new Episode { EpisodeFileId = 10 } });
-
- Mocker.GetMock()
- .Setup(e => e.UpdateEpisode(It.IsAny()));
-
- Mocker.GetMock()
- .Setup(e => e.Delete(It.IsAny()));
-
- Mocker.GetMock()
- .SetupGet(s => s.AutoIgnorePreviouslyDownloadedEpisodes)
- .Returns(true);
-
- //Act
- Mocker.Resolve().CleanUp(episodes);
-
- //Assert
- Mocker.VerifyAllMocks();
-
- Mocker.GetMock()
- .Verify(e => e.GetEpisodesByFileId(It.IsAny()), Times.Exactly(10));
-
- Mocker.GetMock()
- .Verify(e => e.UpdateEpisode(It.Is(g=>g.EpisodeFileId == 0)), Times.Exactly(20));
-
- Mocker.GetMock()
- .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10));
-
- Mocker.GetMock()
- .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10));
-
- }
-
- [Test]
- public void scan_series_should_log_warning_if_path_doesnt_exist_on_disk()
- {
- //Setup
- WithStrictMocker();
-
- var series = Builder.CreateNew()
- .With(s => s.Path = @"C:\Test\TV\SeriesName\")
- .Build();
-
-
- Mocker.GetMock()
- .Setup(c => c.CleanUpDatabase());
-
-
- Mocker.GetMock()
- .Setup(c => c.FolderExists(series.Path))
- .Returns(false);
-
- //Act
- Mocker.Resolve().Scan(series, series.Path);
-
- //Assert
- Mocker.VerifyAllMocks();
- ExceptionVerification.ExpectedWarns(1);
- }
-
- [Test]
- public void move_should_not_move_file_if_source_and_destination_are_the_same_path()
- {
- var fakeSeries = Builder.CreateNew()
- .With(s => s.SeriesId = 5)
- .With(s => s.Title = "30 Rock")
- .Build();
-
- var fakeEpisode = Builder.CreateListOfSize(1)
- .All()
- .With(e => e.SeriesId = fakeSeries.SeriesId)
- .With(e => e.SeasonNumber = 1)
- .With(e => e.EpisodeNumber = 1)
- .Build();
-
- const string filename = @"30 Rock - S01E01 - TBD";
- var fi = new FileInfo(Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".avi"));
-
- var file = Builder.CreateNew()
- .With(f => f.SeriesId = fakeSeries.SeriesId)
- .With(f => f.Path = fi.FullName)
- .Build();
-
- Mocker.GetMock()
- .Setup(e => e.GetSeries(fakeSeries.SeriesId))
- .Returns(fakeSeries);
-
- Mocker.GetMock()
- .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
- .Returns(fakeEpisode);
-
- Mocker.GetMock()
- .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries.Title, It.IsAny(), It.IsAny(), It.IsAny()))
- .Returns(filename);
-
- Mocker.GetMock()
- .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".avi"))
- .Returns(fi);
-
- //Act
- var result = Mocker.Resolve().MoveEpisodeFile(file, false);
-
- //Assert
- result.Should().BeNull();
- }
-
- [Test]
- public void CleanUpDropFolder_should_do_nothing_if_no_files_are_found()
- {
- //Setup
- var folder = @"C:\Test\DropDir\The Office";
-
- Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
- .Returns(new string[0]);
-
- //Act
- Mocker.Resolve().CleanUpDropFolder(folder);
-
- //Assert
- Mocker.GetMock().Verify(v => v.GetFileByPath(It.IsAny()), Times.Never());
- }
-
- [Test]
- public void CleanUpDropFolder_should_do_nothing_if_no_conflicting_files_are_found()
- {
- //Setup
- var folder = @"C:\Test\DropDir\The Office";
- var filename = Path.Combine(folder, "NotAProblem.avi");
-
- var episodeFile = Builder.CreateNew()
- .With(f => f.Path = filename.NormalizePath())
- .With(f => f.SeriesId = 12345)
- .Build();
-
- Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
- .Returns(new string[] { filename });
-
- Mocker.GetMock().Setup(s => s.GetFileByPath(filename))
- .Returns(() => null);
-
- //Act
- Mocker.Resolve().CleanUpDropFolder(folder);
-
- //Assert
- Mocker.GetMock().Verify(v => v.GetFileByPath(filename), Times.Once());
- Mocker.GetMock().Verify(v => v.GetSeries(It.IsAny()), Times.Never());
- }
-
- [Test]
- public void CleanUpDropFolder_should_move_file_if_a_conflict_is_found()
- {
- //Setup
- var folder = @"C:\Test\DropDir\The Office";
- var filename = Path.Combine(folder, "Problem.avi");
- var seriesId = 12345;
- var newFilename = "S01E01 - Title";
- var newFilePath = @"C:\Test\TV\The Office\Season 01\S01E01 - Title.avi";
-
- var episodeFile = Builder.CreateNew()
- .With(f => f.Path = filename.NormalizePath())
- .With(f => f.SeriesId = seriesId)
- .Build();
-
- var series = Builder.CreateNew()
- .With(s => s.SeriesId = seriesId)
- .With(s => s.Title = "The Office")
- .Build();
-
- var episode = Builder.CreateListOfSize(1)
- .All()
- .With(e => e.SeriesId = seriesId)
- .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId)
- .Build();
-
- Mocker.GetMock().Setup(v => v.GetFileByPath(filename))
- .Returns(() => null);
-
- Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
- .Returns(new string[] { filename });
-
- Mocker.GetMock().Setup(s => s.GetFileByPath(filename))
- .Returns(episodeFile);
-
- Mocker.GetMock().Setup(s => s.GetSeries(It.IsAny()))
- .Returns(series);
-
- Mocker.GetMock().Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId))
- .Returns(episode);
-
- Mocker.GetMock().Setup(s => s.GetNewFilename(It.IsAny>(), series.Title, QualityTypes.Unknown, false, It.IsAny()))
- .Returns(newFilename);
-
- Mocker.GetMock().Setup(s => s.CalculateFilePath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
- .Returns(new FileInfo(newFilePath));
-
- Mocker.GetMock().Setup(s => s.MoveFile(episodeFile.Path, newFilePath));
-
- //Act
- Mocker.Resolve().CleanUpDropFolder(folder);
-
- //Assert
- Mocker.GetMock().Verify(v => v.GetFileByPath(filename), Times.Once());
- Mocker.GetMock().Verify(v => v.MoveFile(filename.NormalizePath(), newFilePath), Times.Once());
- }
-
- [Test]
- public void MoveEpisodeFile_should_use_EpisodeFiles_quality()
- {
- var fakeSeries = Builder.CreateNew()
- .With(s => s.SeriesId = 5)
- .With(s => s.Title = "30 Rock")
- .Build();
-
- var fakeEpisode = Builder.CreateListOfSize(1)
- .All()
- .With(e => e.SeriesId = fakeSeries.SeriesId)
- .With(e => e.SeasonNumber = 1)
- .With(e => e.EpisodeNumber = 1)
- .Build();
-
- const string filename = @"30 Rock - S01E01 - TBD";
- var fi = new FileInfo(Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".mkv"));
- var currentFilename = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", "30.Rock.S01E01.Test.WED-DL.mkv");
- const string message = "30 Rock - 1x01 - [WEBDL]";
-
- var file = Builder.CreateNew()
- .With(f => f.SeriesId = fakeSeries.SeriesId)
- .With(f => f.Path = currentFilename)
- .With(f => f.Quality = QualityTypes.WEBDL)
- .With(f => f.Proper = false)
- .Build();
-
- Mocker.GetMock()
- .Setup(e => e.GetSeries(fakeSeries.SeriesId))
- .Returns(fakeSeries);
-
- Mocker.GetMock()
- .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
- .Returns(fakeEpisode);
-
- Mocker.GetMock()
- .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries.Title, It.IsAny(), It.IsAny(), It.IsAny()))
- .Returns(filename);
-
- Mocker.GetMock()
- .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
- .Returns(fi);
-
- Mocker.GetMock()
- .Setup(s => s.GetDownloadTitle(It.Is(e => e.Quality == new Quality{ QualityType = QualityTypes.WEBDL, Proper = false })))
- .Returns(message);
-
- Mocker.GetMock()
- .Setup(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny()));
-
- //Act
- var result = Mocker.Resolve().MoveEpisodeFile(file, true);
-
- //Assert
- result.Should().NotBeNull();
- Mocker.GetMock()
- .Verify(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny()), Times.Once());
- }
- }
-}
diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs
new file mode 100644
index 000000000..87d308148
--- /dev/null
+++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Linq.Expressions;
+using FizzWare.NBuilder;
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Common;
+using NzbDrone.Core.Model;
+using NzbDrone.Core.Providers;
+using NzbDrone.Core.Providers.Core;
+using NzbDrone.Core.Repository;
+using NzbDrone.Core.Repository.Quality;
+using NzbDrone.Core.Test.Framework;
+using NzbDrone.Test.Common;
+using NzbDrone.Test.Common.AutoMoq;
+
+namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
+{
+ // ReSharper disable InconsistentNaming
+ public class CleanUpDropFolderFixture : CoreTest
+ {
+ [Test]
+ public void should_do_nothing_if_no_files_are_found()
+ {
+ //Setup
+ var folder = @"C:\Test\DropDir\The Office";
+
+ Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
+ .Returns(new string[0]);
+
+ //Act
+ Mocker.Resolve().CleanUpDropFolder(folder);
+
+ //Assert
+ Mocker.GetMock().Verify(v => v.GetFileByPath(It.IsAny()), Times.Never());
+ }
+
+ [Test]
+ public void should_do_nothing_if_no_conflicting_files_are_found()
+ {
+ //Setup
+ var folder = @"C:\Test\DropDir\The Office";
+ var filename = Path.Combine(folder, "NotAProblem.avi");
+
+ var episodeFile = Builder.CreateNew()
+ .With(f => f.Path = filename.NormalizePath())
+ .With(f => f.SeriesId = 12345)
+ .Build();
+
+ Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
+ .Returns(new string[] { filename });
+
+ Mocker.GetMock().Setup(s => s.GetFileByPath(filename))
+ .Returns(() => null);
+
+ //Act
+ Mocker.Resolve().CleanUpDropFolder(folder);
+
+ //Assert
+ Mocker.GetMock().Verify(v => v.GetFileByPath(filename), Times.Once());
+ Mocker.GetMock().Verify(v => v.GetSeries(It.IsAny()), Times.Never());
+ }
+
+ [Test]
+ public void should_move_file_if_a_conflict_is_found()
+ {
+ //Setup
+ var folder = @"C:\Test\DropDir\The Office";
+ var filename = Path.Combine(folder, "Problem.avi");
+ var seriesId = 12345;
+ var newFilename = "S01E01 - Title";
+ var newFilePath = @"C:\Test\TV\The Office\Season 01\S01E01 - Title.avi";
+
+ var episodeFile = Builder.CreateNew()
+ .With(f => f.Path = filename.NormalizePath())
+ .With(f => f.SeriesId = seriesId)
+ .Build();
+
+ var series = Builder.CreateNew()
+ .With(s => s.SeriesId = seriesId)
+ .With(s => s.Title = "The Office")
+ .Build();
+
+ var episode = Builder.CreateListOfSize(1)
+ .All()
+ .With(e => e.SeriesId = seriesId)
+ .With(e => e.EpisodeFileId = episodeFile.EpisodeFileId)
+ .Build();
+
+ Mocker.GetMock().Setup(v => v.GetFileByPath(filename))
+ .Returns(() => null);
+
+ Mocker.GetMock().Setup(s => s.GetFiles(folder, SearchOption.AllDirectories))
+ .Returns(new string[] { filename });
+
+ Mocker.GetMock().Setup(s => s.GetFileByPath(filename))
+ .Returns(episodeFile);
+
+ Mocker.GetMock().Setup(s => s.GetSeries(It.IsAny()))
+ .Returns(series);
+
+ Mocker.GetMock().Setup(s => s.GetEpisodesByFileId(episodeFile.EpisodeFileId))
+ .Returns(episode);
+
+ Mocker.GetMock().Setup(s => s.GetNewFilename(It.IsAny>(), series.Title, QualityTypes.Unknown, false, It.IsAny()))
+ .Returns(newFilename);
+
+ Mocker.GetMock().Setup(s => s.CalculateFilePath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
+ .Returns(new FileInfo(newFilePath));
+
+ Mocker.GetMock().Setup(s => s.MoveFile(episodeFile.Path, newFilePath));
+
+ //Act
+ Mocker.Resolve().CleanUpDropFolder(folder);
+
+ //Assert
+ Mocker.GetMock().Verify(v => v.GetFileByPath(filename), Times.Once());
+ Mocker.GetMock().Verify(v => v.MoveFile(filename.NormalizePath(), newFilePath), Times.Once());
+ }
+ }
+}
diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs
new file mode 100644
index 000000000..236fda84c
--- /dev/null
+++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpFixture.cs
@@ -0,0 +1,116 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Linq.Expressions;
+using FizzWare.NBuilder;
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Common;
+using NzbDrone.Core.Model;
+using NzbDrone.Core.Providers;
+using NzbDrone.Core.Providers.Core;
+using NzbDrone.Core.Repository;
+using NzbDrone.Core.Repository.Quality;
+using NzbDrone.Core.Test.Framework;
+using NzbDrone.Test.Common;
+using NzbDrone.Test.Common.AutoMoq;
+
+namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
+{
+ // ReSharper disable InconsistentNaming
+ public class CleanUpFixture : CoreTest
+ {
+ [Test]
+ public void should_skip_existing_files()
+ {
+ var episodes = Builder.CreateListOfSize(10).Build();
+
+ Mocker.GetMock()
+ .Setup(e => e.FileExists(It.IsAny()))
+ .Returns(true);
+
+
+ //Act
+ Mocker.Resolve().CleanUp(episodes);
+
+ //Assert
+ Mocker.VerifyAllMocks();
+ }
+
+ [Test]
+ public void should_delete_none_existing_files()
+ {
+ var episodes = Builder.CreateListOfSize(10).Build();
+
+ Mocker.GetMock()
+ .Setup(e => e.FileExists(It.IsAny()))
+ .Returns(false);
+
+ Mocker.GetMock()
+ .Setup(e => e.GetEpisodesByFileId(It.IsAny()))
+ .Returns(new List());
+
+ Mocker.GetMock()
+ .Setup(e => e.Delete(It.IsAny()));
+
+
+ //Act
+ Mocker.Resolve().CleanUp(episodes);
+
+ //Assert
+ Mocker.VerifyAllMocks();
+
+ Mocker.GetMock()
+ .Verify(e => e.GetEpisodesByFileId(It.IsAny()), Times.Exactly(10));
+
+ Mocker.GetMock()
+ .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10));
+
+ }
+
+ [Test]
+ public void should_delete_none_existing_files_remove_links_to_episodes()
+ {
+ var episodes = Builder.CreateListOfSize(10).Build();
+
+ Mocker.GetMock()
+ .Setup(e => e.FileExists(It.IsAny()))
+ .Returns(false);
+
+ Mocker.GetMock()
+ .Setup(e => e.GetEpisodesByFileId(It.IsAny()))
+ .Returns(new List { new Episode { EpisodeFileId = 10 }, new Episode { EpisodeFileId = 10 } });
+
+ Mocker.GetMock()
+ .Setup(e => e.UpdateEpisode(It.IsAny()));
+
+ Mocker.GetMock()
+ .Setup(e => e.Delete(It.IsAny()));
+
+ Mocker.GetMock()
+ .SetupGet(s => s.AutoIgnorePreviouslyDownloadedEpisodes)
+ .Returns(true);
+
+ //Act
+ Mocker.Resolve().CleanUp(episodes);
+
+ //Assert
+ Mocker.VerifyAllMocks();
+
+ Mocker.GetMock()
+ .Verify(e => e.GetEpisodesByFileId(It.IsAny()), Times.Exactly(10));
+
+ Mocker.GetMock()
+ .Verify(e => e.UpdateEpisode(It.Is(g=>g.EpisodeFileId == 0)), Times.Exactly(20));
+
+ Mocker.GetMock()
+ .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10));
+
+ Mocker.GetMock()
+ .Verify(e => e.Delete(It.IsAny()), Times.Exactly(10));
+
+ }
+ }
+}
diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs
new file mode 100644
index 000000000..13973bfe8
--- /dev/null
+++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Linq.Expressions;
+using FizzWare.NBuilder;
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Common;
+using NzbDrone.Core.Model;
+using NzbDrone.Core.Providers;
+using NzbDrone.Core.Providers.Core;
+using NzbDrone.Core.Repository;
+using NzbDrone.Core.Repository.Quality;
+using NzbDrone.Core.Test.Framework;
+using NzbDrone.Test.Common;
+using NzbDrone.Test.Common.AutoMoq;
+
+namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
+{
+ // ReSharper disable InconsistentNaming
+ public class GetVideoFilesFixture : CoreTest
+ {
+ private string[] _files;
+
+ [SetUp]
+ public void Setup()
+ {
+ _files = new string[]
+ {
+ @"C:\Test\30 Rock1.mkv",
+ @"C:\Test\30 Rock2.avi",
+ @"C:\Test\30 Rock3.mp4",
+ @"C:\Test\30 Rock4.wmv",
+ @"C:\Test\movie.exe"
+ };
+
+ Mocker.GetMock()
+ .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories))
+ .Returns(_files);
+ }
+
+ [Test]
+ public void should_check_all_directories()
+ {
+ var path = @"C:\Test\";
+
+ Mocker.Resolve().GetVideoFiles(path);
+
+ Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once());
+ Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never());
+ }
+
+ [Test]
+ public void should_check_all_directories_when_allDirectories_is_true()
+ {
+ var path = @"C:\Test\";
+
+ Mocker.Resolve().GetVideoFiles(path, true);
+
+ Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once());
+ Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never());
+ }
+
+ [Test]
+ public void should_check_top_level_directory_only_when_allDirectories_is_false()
+ {
+ var path = @"C:\Test\";
+
+ Mocker.Resolve().GetVideoFiles(path, false);
+
+ Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never());
+ Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once());
+ }
+
+ [Test]
+ public void should_return_video_files_only()
+ {
+ var path = @"C:\Test\";
+
+ Mocker.Resolve().GetVideoFiles(path).Should().HaveCount(4);
+ }
+ }
+}
diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs
similarity index 99%
rename from NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs
rename to NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs
index 9298ec064..f6549b075 100644
--- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTest_ImportFile.cs
+++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ImportFileFixture.cs
@@ -15,10 +15,10 @@ using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
-namespace NzbDrone.Core.Test.ProviderTests
+namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{
// ReSharper disable InconsistentNaming
- public class DiskScanProviderTest_ImportFile : CoreTest
+ public class ImportFileFixture : CoreTest
{
[Test]
public void import_new_file_should_succeed()
diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs
new file mode 100644
index 000000000..a45f4fab3
--- /dev/null
+++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs
@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Linq.Expressions;
+using FizzWare.NBuilder;
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Common;
+using NzbDrone.Core.Model;
+using NzbDrone.Core.Providers;
+using NzbDrone.Core.Providers.Core;
+using NzbDrone.Core.Repository;
+using NzbDrone.Core.Repository.Quality;
+using NzbDrone.Core.Test.Framework;
+using NzbDrone.Test.Common;
+using NzbDrone.Test.Common.AutoMoq;
+
+namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
+{
+ // ReSharper disable InconsistentNaming
+ public class MoveEpisodeFileFixture : CoreTest
+ {
+ [Test]
+ public void should_not_move_file_if_source_and_destination_are_the_same_path()
+ {
+ var fakeSeries = Builder.CreateNew()
+ .With(s => s.SeriesId = 5)
+ .With(s => s.Title = "30 Rock")
+ .Build();
+
+ var fakeEpisode = Builder.CreateListOfSize(1)
+ .All()
+ .With(e => e.SeriesId = fakeSeries.SeriesId)
+ .With(e => e.SeasonNumber = 1)
+ .With(e => e.EpisodeNumber = 1)
+ .Build();
+
+ const string filename = @"30 Rock - S01E01 - TBD";
+ var fi = new FileInfo(Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".avi"));
+
+ var file = Builder.CreateNew()
+ .With(f => f.SeriesId = fakeSeries.SeriesId)
+ .With(f => f.Path = fi.FullName)
+ .Build();
+
+ Mocker.GetMock()
+ .Setup(e => e.GetSeries(fakeSeries.SeriesId))
+ .Returns(fakeSeries);
+
+ Mocker.GetMock()
+ .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
+ .Returns(fakeEpisode);
+
+ Mocker.GetMock()
+ .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries.Title, It.IsAny(), It.IsAny(), It.IsAny()))
+ .Returns(filename);
+
+ Mocker.GetMock()
+ .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".avi"))
+ .Returns(fi);
+
+ //Act
+ var result = Mocker.Resolve().MoveEpisodeFile(file, false);
+
+ //Assert
+ result.Should().BeNull();
+ }
+
+ [Test]
+ public void should_use_EpisodeFiles_quality()
+ {
+ var fakeSeries = Builder.CreateNew()
+ .With(s => s.SeriesId = 5)
+ .With(s => s.Title = "30 Rock")
+ .Build();
+
+ var fakeEpisode = Builder.CreateListOfSize(1)
+ .All()
+ .With(e => e.SeriesId = fakeSeries.SeriesId)
+ .With(e => e.SeasonNumber = 1)
+ .With(e => e.EpisodeNumber = 1)
+ .Build();
+
+ const string filename = @"30 Rock - S01E01 - TBD";
+ var fi = new FileInfo(Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", filename + ".mkv"));
+ var currentFilename = Path.Combine(@"C:\Test\TV\30 Rock\Season 01\", "30.Rock.S01E01.Test.WED-DL.mkv");
+ const string message = "30 Rock - 1x01 - [WEBDL]";
+
+ var file = Builder.CreateNew()
+ .With(f => f.SeriesId = fakeSeries.SeriesId)
+ .With(f => f.Path = currentFilename)
+ .With(f => f.Quality = QualityTypes.WEBDL)
+ .With(f => f.Proper = false)
+ .Build();
+
+ Mocker.GetMock()
+ .Setup(e => e.GetSeries(fakeSeries.SeriesId))
+ .Returns(fakeSeries);
+
+ Mocker.GetMock()
+ .Setup(e => e.GetEpisodesByFileId(file.EpisodeFileId))
+ .Returns(fakeEpisode);
+
+ Mocker.GetMock()
+ .Setup(e => e.GetNewFilename(fakeEpisode, fakeSeries.Title, It.IsAny(), It.IsAny(), It.IsAny()))
+ .Returns(filename);
+
+ Mocker.GetMock()
+ .Setup(e => e.CalculateFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv"))
+ .Returns(fi);
+
+ Mocker.GetMock()
+ .Setup(s => s.GetDownloadTitle(It.Is(e => e.Quality == new Quality{ QualityType = QualityTypes.WEBDL, Proper = false })))
+ .Returns(message);
+
+ Mocker.GetMock()
+ .Setup(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny()));
+
+ //Act
+ var result = Mocker.Resolve().MoveEpisodeFile(file, true);
+
+ //Assert
+ result.Should().NotBeNull();
+ Mocker.GetMock()
+ .Verify(e => e.OnDownload("30 Rock - 1x01 - [WEBDL]", It.IsAny()), Times.Once());
+ }
+ }
+}
diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs
new file mode 100644
index 000000000..2c1d22613
--- /dev/null
+++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/ScanFixture.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Linq.Expressions;
+using FizzWare.NBuilder;
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Common;
+using NzbDrone.Core.Model;
+using NzbDrone.Core.Providers;
+using NzbDrone.Core.Providers.Core;
+using NzbDrone.Core.Repository;
+using NzbDrone.Core.Repository.Quality;
+using NzbDrone.Core.Test.Framework;
+using NzbDrone.Test.Common;
+using NzbDrone.Test.Common.AutoMoq;
+
+namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
+{
+ // ReSharper disable InconsistentNaming
+ public class ScanFixture : CoreTest
+ {
+ [Test]
+ public void series_should_update_the_last_scan_date()
+ {
+
+
+ Mocker.GetMock()
+ .Setup(c => c.UpdateSeries(It.Is(s => s.LastDiskSync != null))).Verifiable();
+
+ Mocker.GetMock()
+ .Setup(c => c.GetEpisodeBySeries(It.IsAny()))
+ .Returns(new List { new Episode() });
+
+ Mocker.GetMock()
+ .Setup(c => c.FolderExists(It.IsAny()))
+ .Returns(true);
+
+ Mocker.GetMock()
+ .Setup(c => c.GetSeriesFiles(It.IsAny()))
+ .Returns(new List());
+
+ Mocker.Resolve().Scan(new Series());
+
+ Mocker.VerifyAllMocks();
+
+ }
+
+ [Test]
+ public void series_should_log_warning_if_path_doesnt_exist_on_disk()
+ {
+ //Setup
+ WithStrictMocker();
+
+ var series = Builder.CreateNew()
+ .With(s => s.Path = @"C:\Test\TV\SeriesName\")
+ .Build();
+
+
+ Mocker.GetMock()
+ .Setup(c => c.CleanUpDatabase());
+
+
+ Mocker.GetMock()
+ .Setup(c => c.FolderExists(series.Path))
+ .Returns(false);
+
+ //Act
+ Mocker.Resolve().Scan(series, series.Path);
+
+ //Assert
+ Mocker.VerifyAllMocks();
+ ExceptionVerification.ExpectedWarns(1);
+ }
+ }
+}
diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/PneumaticProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/PneumaticProviderFixture.cs
new file mode 100644
index 000000000..7949c5ca5
--- /dev/null
+++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/PneumaticProviderFixture.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Common;
+using NzbDrone.Core.Providers.Core;
+using NzbDrone.Core.Providers.DownloadClients;
+using NzbDrone.Core.Test.Framework;
+using NzbDrone.Test.Common;
+
+namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests
+{
+ [TestFixture]
+ public class PneumaticProviderFixture : CoreTest
+ {
+ private const string nzbUrl = "http://www.nzbs.com/url";
+ private const string title = "some_nzb_title";
+ private const string pneumaticFolder = @"d:\nzb\pneumatic\";
+ private const string nzbPath = @"d:\nzb\blackhole\some_nzb_title.nzb";
+
+ [SetUp]
+ public void Setup()
+ {
+ Mocker.GetMock().SetupGet(c => c.BlackholeDirectory).Returns(pneumaticFolder);
+ }
+
+ private void WithExistingFile()
+ {
+ Mocker.GetMock().Setup(c => c.FileExists(nzbPath)).Returns(true);
+ }
+
+ private void WithFailedDownload()
+ {
+ Mocker.GetMock().Setup(c => c.DownloadFile(It.IsAny(), It.IsAny())).Throws(new WebException());
+ }
+
+ [Test]
+ public void should_download_file_if_it_doesnt_exist()
+ {
+ Mocker.Resolve().DownloadNzb(nzbUrl, title).Should().BeTrue();
+
+ Mocker.GetMock().Verify(c => c.DownloadFile(nzbUrl, nzbPath),Times.Once());
+ }
+
+ [Test]
+ public void should_not_download_file_if_it_doesn_exist()
+ {
+ WithExistingFile();
+
+ Mocker.Resolve().DownloadNzb(nzbUrl, title).Should().BeTrue();
+
+ Mocker.GetMock().Verify(c => c.DownloadFile(It.IsAny(), It.IsAny()), Times.Never());
+ }
+
+ [Test]
+ public void should_return_false_on_failed_download()
+ {
+ WithFailedDownload();
+
+ Mocker.Resolve().DownloadNzb(nzbUrl, title).Should().BeFalse();
+
+ ExceptionVerification.ExpectedWarns(1);
+ }
+
+ [Test]
+ public void should_skip_if_full_season_download()
+ {
+ Mocker.Resolve().DownloadNzb(nzbUrl, "30 Rock - Season 1").Should().BeFalse();
+ ExceptionVerification.ExpectedErrors(1);
+ }
+
+
+ }
+}
diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/PostDownloadProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/GetFolderNameWithStatusFixture.cs
similarity index 97%
rename from NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/PostDownloadProviderFixture.cs
rename to NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/GetFolderNameWithStatusFixture.cs
index 501d56d84..1e45f27ba 100644
--- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/PostDownloadProviderFixture.cs
+++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/GetFolderNameWithStatusFixture.cs
@@ -13,7 +13,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
- public class PostDownloadProviderFixture : CoreTest
+ public class GetFolderNameWithStatusFixture : CoreTest
{
[TestCase(@"c:\_NzbDrone_InvalidEpisode_Title", @"c:\_UnknownSeries_Title", PostDownloadStatusType.UnknownSeries)]
[TestCase(@"c:\Title", @"c:\_Failed_Title", PostDownloadStatusType.Failed)]
diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs
similarity index 87%
rename from NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadProviderFixture.cs
rename to NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs
index 484e07209..be2b61fd4 100644
--- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadProviderFixture.cs
+++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs
@@ -18,7 +18,7 @@ using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
{
[TestFixture]
- public class ProcessDownloadProviderFixture : CoreTest
+ public class ProcessDownloadFixture : CoreTest
{
Series fakeSeries;
@@ -328,51 +328,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
}
[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.GetDirectories(It.IsAny