|
|
@ -1,6 +1,7 @@
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
using FluentAssertions;
|
|
|
|
using FluentAssertions;
|
|
|
@ -19,120 +20,107 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
public class RootDirProviderTest : CoreTest
|
|
|
|
public class RootDirProviderTest : CoreTest
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
|
|
|
public void Setup()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
|
|
|
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
|
|
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
private void WithNoneExistingFolder()
|
|
|
|
public void GetRootDirs()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
|
|
|
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
|
|
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var emptyDatabase = TestDbHelper.GetEmptyDatabase();
|
|
|
|
[Test]
|
|
|
|
Mocker.SetConstant(emptyDatabase);
|
|
|
|
public void GetRootDir_should_return_all_existing_roots()
|
|
|
|
emptyDatabase.Insert(new RootDir { Path = @"C:\TV" });
|
|
|
|
{
|
|
|
|
emptyDatabase.Insert(new RootDir { Path = @"C:\TV2" });
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
|
|
//Mocker.GetMock<IRepository>()
|
|
|
|
Db.Insert(new RootDir { Path = @"C:\TV" });
|
|
|
|
// .Setup(f => f.All<RootDir>())
|
|
|
|
Db.Insert(new RootDir { Path = @"C:\TV2" });
|
|
|
|
// .Returns(sonicRepo.All<RootDir>);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
|
|
|
var result = Mocker.Resolve<RootDirProvider>().GetAll();
|
|
|
|
var result = Mocker.Resolve<RootDirProvider>().GetAll();
|
|
|
|
|
|
|
|
result.Should().HaveCount(2);
|
|
|
|
//Assert
|
|
|
|
|
|
|
|
Assert.AreEqual(result.Count, 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestCase("D:\\TV Shows\\")]
|
|
|
|
[TestCase("D:\\TV Shows\\")]
|
|
|
|
[TestCase("//server//folder")]
|
|
|
|
[TestCase("//server//folder")]
|
|
|
|
public void AddRootDir(string path)
|
|
|
|
public void should_be_able_to_add_root_dir(string path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
//Act
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
|
|
|
rootDirProvider.Add(new RootDir { Path = path });
|
|
|
|
rootDirProvider.Add(new RootDir { Path = path });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
//Assert
|
|
|
|
var rootDirs = rootDirProvider.GetAll();
|
|
|
|
var rootDirs = rootDirProvider.GetAll();
|
|
|
|
rootDirs.Should().NotBeEmpty();
|
|
|
|
|
|
|
|
rootDirs.Should().HaveCount(1);
|
|
|
|
rootDirs.Should().HaveCount(1);
|
|
|
|
path.Should().Be(rootDirs.First().Path);
|
|
|
|
rootDirs.First().Path.Should().Be(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void RemoveRootDir()
|
|
|
|
public void should_throw_if_folder_being_added_doesnt_exist()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
WithNoneExistingFolder();
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
|
|
|
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
|
|
|
|
Assert.Throws<DirectoryNotFoundException>(() => rootDirProvider.Add(new RootDir { Path = "C:\\TEST" }));
|
|
|
|
rootDirProvider.Remove(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
|
|
|
var rootDirs = rootDirProvider.GetAll();
|
|
|
|
|
|
|
|
rootDirs.Should().BeEmpty();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void GetRootDir()
|
|
|
|
public void should_be_able_to_remove_root_dir()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int id = 1;
|
|
|
|
|
|
|
|
const string path = @"C:\TV";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
//Act
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
|
|
|
var rootDirProvider = Mocker.Resolve<RootDirProvider>();
|
|
|
|
rootDirProvider.Add(new RootDir { Id = id, Path = path });
|
|
|
|
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
|
|
|
|
|
|
|
|
rootDirProvider.Add(new RootDir { Path = @"C:\TV2" });
|
|
|
|
|
|
|
|
rootDirProvider.Remove(1);
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
//Assert
|
|
|
|
var rootDir = rootDirProvider.GetRootDir(id);
|
|
|
|
var rootDirs = rootDirProvider.GetAll();
|
|
|
|
rootDir.Id.Should().Be(1);
|
|
|
|
rootDirs.Should().HaveCount(1);
|
|
|
|
rootDir.Path.Should().Be(path);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
public void None_existing_folder_returns_empty_list()
|
|
|
|
public void None_existing_folder_returns_empty_list()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const string path = "d:\\bad folder";
|
|
|
|
WithNoneExistingFolder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>(MockBehavior.Strict)
|
|
|
|
const string path = "d:\\bad folder";
|
|
|
|
.Setup(m => m.FolderExists(path)).Returns(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = Mocker.Resolve<RootDirProvider>().GetUnmappedFolders(path);
|
|
|
|
var result = Mocker.Resolve<RootDirProvider>().GetUnmappedFolders(path);
|
|
|
|
|
|
|
|
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
result.Should().BeEmpty();
|
|
|
|
result.Should().BeEmpty();
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectories(It.IsAny<String>()), Times.Never());
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
[ExpectedException(typeof(ArgumentException))]
|
|
|
|
public void GetUnmappedFolders_throw_on_empty_folders()
|
|
|
|
public void empty_folder_path_throws()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Assert.Throws<ArgumentException>(() => Mocker.Resolve<RootDirProvider>().GetUnmappedFolders(""));
|
|
|
|
Mocker.Resolve<RootDirProvider>().GetUnmappedFolders("");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestCase("")]
|
|
|
|
[TestCase("")]
|
|
|
|
[TestCase(null)]
|
|
|
|
[TestCase(null)]
|
|
|
|
[TestCase("BAD PATH")]
|
|
|
|
[TestCase("BAD PATH")]
|
|
|
|
[ExpectedException(typeof(ArgumentException))]
|
|
|
|
|
|
|
|
public void invalid_folder_path_throws_on_add(string path)
|
|
|
|
public void invalid_folder_path_throws_on_add(string path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Assert.Throws<ArgumentException>(() =>
|
|
|
|
Mocker.Resolve<RootDirProvider>().Add(new RootDir { Id = 0, Path = path });
|
|
|
|
Mocker.Resolve<RootDirProvider>().Add(new RootDir { Id = 0, Path = path })
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|