2011-05-22 16:53:21 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-20 23:42:17 +00:00
|
|
|
|
|
2011-05-22 16:53:21 +00:00
|
|
|
|
using System;
|
2012-01-19 03:57:27 +00:00
|
|
|
|
using System.IO;
|
2011-05-20 03:47:07 +00:00
|
|
|
|
using System.Linq;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using FluentAssertions;
|
2011-05-20 03:47:07 +00:00
|
|
|
|
using Moq;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using NUnit.Framework;
|
2011-11-13 04:07:06 +00:00
|
|
|
|
using NzbDrone.Common;
|
2011-04-09 21:35:13 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-05-20 03:47:07 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-09 21:35:13 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-05-19 03:55:35 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-04-09 21:35:13 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-05-19 03:55:35 +00:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 07:27:16 +00:00
|
|
|
|
public class RootDirProviderTest : CoreTest
|
2011-04-09 21:35:13 +00:00
|
|
|
|
{
|
2012-01-19 03:57:27 +00:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
}
|
2011-06-02 21:06:46 +00:00
|
|
|
|
|
2012-01-19 03:57:27 +00:00
|
|
|
|
private void WithNoneExistingFolder()
|
2011-04-09 21:35:13 +00:00
|
|
|
|
{
|
2012-01-19 03:57:27 +00:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
2011-06-17 15:27:18 +00:00
|
|
|
|
|
2012-01-19 03:57:27 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void GetRootDir_should_return_all_existing_roots()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
2012-01-19 03:57:27 +00:00
|
|
|
|
Db.Insert(new RootDir { Path = @"C:\TV" });
|
|
|
|
|
Db.Insert(new RootDir { Path = @"C:\TV2" });
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
2012-01-19 03:57:27 +00:00
|
|
|
|
var result = Mocker.Resolve<RootDirProvider>().GetAll();
|
|
|
|
|
result.Should().HaveCount(2);
|
2011-04-09 21:35:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 03:57:27 +00:00
|
|
|
|
|
2011-06-13 03:56:10 +00:00
|
|
|
|
[TestCase("D:\\TV Shows\\")]
|
|
|
|
|
[TestCase("//server//folder")]
|
2012-01-19 03:57:27 +00:00
|
|
|
|
public void should_be_able_to_add_root_dir(string path)
|
2011-04-09 21:35:13 +00:00
|
|
|
|
{
|
2012-01-19 03:57:27 +00:00
|
|
|
|
WithRealDb();
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
2011-06-02 21:06:46 +00:00
|
|
|
|
rootDirProvider.Add(new RootDir { Path = path });
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var rootDirs = rootDirProvider.GetAll();
|
2011-06-02 21:06:46 +00:00
|
|
|
|
rootDirs.Should().HaveCount(1);
|
2012-01-19 03:57:27 +00:00
|
|
|
|
rootDirs.First().Path.Should().Be(path);
|
2011-04-09 21:35:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-19 03:57:27 +00:00
|
|
|
|
public void should_throw_if_folder_being_added_doesnt_exist()
|
2011-04-09 21:35:13 +00:00
|
|
|
|
{
|
2012-01-19 03:57:27 +00:00
|
|
|
|
WithNoneExistingFolder();
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
2012-01-19 03:57:27 +00:00
|
|
|
|
Assert.Throws<DirectoryNotFoundException>(() => rootDirProvider.Add(new RootDir { Path = "C:\\TEST" }));
|
2011-04-09 21:35:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 03:57:27 +00:00
|
|
|
|
|
2011-04-09 21:35:13 +00:00
|
|
|
|
[Test]
|
2012-01-19 03:57:27 +00:00
|
|
|
|
public void should_be_able_to_remove_root_dir()
|
2011-04-09 21:35:13 +00:00
|
|
|
|
{
|
2012-01-19 03:57:27 +00:00
|
|
|
|
WithRealDb();
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
2012-01-19 03:57:27 +00:00
|
|
|
|
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
|
|
|
|
|
rootDirProvider.Add(new RootDir { Path = @"C:\TV2" });
|
|
|
|
|
rootDirProvider.Remove(1);
|
2011-04-09 21:35:13 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2012-01-19 03:57:27 +00:00
|
|
|
|
var rootDirs = rootDirProvider.GetAll();
|
|
|
|
|
rootDirs.Should().HaveCount(1);
|
2011-04-09 21:35:13 +00:00
|
|
|
|
}
|
2011-05-20 03:47:07 +00:00
|
|
|
|
|
2012-01-19 03:57:27 +00:00
|
|
|
|
|
2011-05-20 03:47:07 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void None_existing_folder_returns_empty_list()
|
|
|
|
|
{
|
2012-01-19 03:57:27 +00:00
|
|
|
|
WithNoneExistingFolder();
|
2011-05-20 03:47:07 +00:00
|
|
|
|
|
2012-01-19 03:57:27 +00:00
|
|
|
|
const string path = "d:\\bad folder";
|
2011-05-20 03:47:07 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var result = Mocker.Resolve<RootDirProvider>().GetUnmappedFolders(path);
|
2011-05-20 03:47:07 +00:00
|
|
|
|
|
2011-06-23 06:56:17 +00:00
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
|
result.Should().BeEmpty();
|
2012-01-19 03:57:27 +00:00
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectories(It.IsAny<String>()), Times.Never());
|
2011-05-20 03:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-19 03:57:27 +00:00
|
|
|
|
public void GetUnmappedFolders_throw_on_empty_folders()
|
2011-05-20 03:47:07 +00:00
|
|
|
|
{
|
2012-01-19 03:57:27 +00:00
|
|
|
|
Assert.Throws<ArgumentException>(() => Mocker.Resolve<RootDirProvider>().GetUnmappedFolders(""));
|
2011-05-20 03:47:07 +00:00
|
|
|
|
}
|
2011-06-13 03:56:10 +00:00
|
|
|
|
|
|
|
|
|
[TestCase("")]
|
|
|
|
|
[TestCase(null)]
|
|
|
|
|
[TestCase("BAD PATH")]
|
|
|
|
|
public void invalid_folder_path_throws_on_add(string path)
|
|
|
|
|
{
|
2012-01-19 03:57:27 +00:00
|
|
|
|
Assert.Throws<ArgumentException>(() =>
|
|
|
|
|
Mocker.Resolve<RootDirProvider>().Add(new RootDir { Id = 0, Path = path })
|
|
|
|
|
);
|
2011-06-13 03:56:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 05:04:55 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void adding_duplicated_root_folder_should_throw()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
|
|
|
|
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
|
|
|
|
|
Assert.Throws<InvalidOperationException>(() => rootDirProvider.Add(new RootDir { Path = @"C:\TV" }));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 21:35:13 +00:00
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|