2011-05-22 18:53:21 +02:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-21 01:42:17 +02:00
|
|
|
|
|
2011-05-22 18:53:21 +02:00
|
|
|
|
using System;
|
2013-02-04 05:18:59 +01:00
|
|
|
|
using System.Collections.Generic;
|
2012-01-19 04:57:27 +01:00
|
|
|
|
using System.IO;
|
2011-05-20 05:47:07 +02:00
|
|
|
|
using System.Linq;
|
2011-06-02 23:06:46 +02:00
|
|
|
|
using FluentAssertions;
|
2011-05-20 05:47:07 +02:00
|
|
|
|
using Moq;
|
2011-06-02 23:06:46 +02:00
|
|
|
|
using NUnit.Framework;
|
2011-11-13 05:07:06 +01:00
|
|
|
|
using NzbDrone.Common;
|
2013-02-17 06:09:35 +01:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-02-04 05:18:59 +01:00
|
|
|
|
using NzbDrone.Core.RootFolders;
|
2011-05-19 05:55:35 +02:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-04-09 23:35:13 +02:00
|
|
|
|
|
2013-02-17 05:33:56 +01:00
|
|
|
|
namespace NzbDrone.Core.Test.RootFolderTests
|
2011-04-09 23:35:13 +02:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-05-19 05:55:35 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-05 05:07:07 +01:00
|
|
|
|
public class RootFolderServiceFixture : CoreTest<RootFolderService>
|
2011-04-09 23:35:13 +02:00
|
|
|
|
{
|
2012-01-19 04:57:27 +01:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2013-02-05 05:07:07 +01:00
|
|
|
|
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
2013-02-17 06:09:35 +01:00
|
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
2013-02-05 05:07:07 +01:00
|
|
|
|
.Setup(s => s.All())
|
|
|
|
|
.Returns(new List<RootFolder>());
|
2012-01-19 04:57:27 +01:00
|
|
|
|
}
|
2011-06-02 23:06:46 +02:00
|
|
|
|
|
2012-01-19 04:57:27 +01:00
|
|
|
|
private void WithNoneExistingFolder()
|
2011-04-09 23:35:13 +02:00
|
|
|
|
{
|
2012-01-19 04:57:27 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
|
.Setup(m => m.FolderExists(It.IsAny<string>()))
|
|
|
|
|
.Returns(false);
|
|
|
|
|
}
|
2011-04-09 23:35:13 +02:00
|
|
|
|
|
2011-06-13 05:56:10 +02:00
|
|
|
|
[TestCase("D:\\TV Shows\\")]
|
|
|
|
|
[TestCase("//server//folder")]
|
2012-01-19 04:57:27 +01:00
|
|
|
|
public void should_be_able_to_add_root_dir(string path)
|
2011-04-09 23:35:13 +02:00
|
|
|
|
{
|
2013-02-05 05:07:07 +01:00
|
|
|
|
var root = new RootFolder { Path = path };
|
|
|
|
|
|
2013-02-04 05:18:59 +01:00
|
|
|
|
Subject.Add(root);
|
2011-04-09 23:35:13 +02:00
|
|
|
|
|
2013-02-17 06:09:35 +01:00
|
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>().Verify(c => c.Add(root), Times.Once());
|
2011-04-09 23:35:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-19 04:57:27 +01:00
|
|
|
|
public void should_throw_if_folder_being_added_doesnt_exist()
|
2011-04-09 23:35:13 +02:00
|
|
|
|
{
|
2012-01-19 04:57:27 +01:00
|
|
|
|
WithNoneExistingFolder();
|
2011-04-09 23:35:13 +02:00
|
|
|
|
|
2013-02-05 05:07:07 +01:00
|
|
|
|
Assert.Throws<DirectoryNotFoundException>(() => Subject.Add(new RootFolder { Path = "C:\\TEST" }));
|
2011-04-09 23:35:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-19 04:57:27 +01:00
|
|
|
|
public void should_be_able_to_remove_root_dir()
|
2011-04-09 23:35:13 +02:00
|
|
|
|
{
|
2013-02-04 05:18:59 +01:00
|
|
|
|
Subject.Remove(1);
|
2013-02-17 06:09:35 +01:00
|
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>().Verify(c => c.Delete(1), Times.Once());
|
2011-04-09 23:35:13 +02:00
|
|
|
|
}
|
2011-05-20 05:47:07 +02:00
|
|
|
|
|
|
|
|
|
public void None_existing_folder_returns_empty_list()
|
|
|
|
|
{
|
2012-01-19 04:57:27 +01:00
|
|
|
|
WithNoneExistingFolder();
|
2011-05-20 05:47:07 +02:00
|
|
|
|
|
2013-02-17 06:09:35 +01:00
|
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>().Setup(c => c.All()).Returns(new List<RootFolder>());
|
2013-02-04 05:18:59 +01:00
|
|
|
|
|
2012-01-19 04:57:27 +01:00
|
|
|
|
const string path = "d:\\bad folder";
|
2011-05-20 05:47:07 +02:00
|
|
|
|
|
2013-02-04 05:18:59 +01:00
|
|
|
|
var result = Subject.GetUnmappedFolders(path);
|
2011-05-20 05:47:07 +02:00
|
|
|
|
|
2011-06-23 08:56:17 +02:00
|
|
|
|
result.Should().NotBeNull();
|
|
|
|
|
result.Should().BeEmpty();
|
2012-01-19 04:57:27 +01:00
|
|
|
|
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectories(It.IsAny<String>()), Times.Never());
|
2011-05-20 05:47:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-19 04:57:27 +01:00
|
|
|
|
public void GetUnmappedFolders_throw_on_empty_folders()
|
2011-05-20 05:47:07 +02:00
|
|
|
|
{
|
2013-02-04 05:18:59 +01:00
|
|
|
|
Assert.Throws<ArgumentException>(() => Mocker.Resolve<RootFolderService>().GetUnmappedFolders(""));
|
2011-05-20 05:47:07 +02:00
|
|
|
|
}
|
2011-06-13 05:56:10 +02:00
|
|
|
|
|
|
|
|
|
[TestCase("")]
|
|
|
|
|
[TestCase(null)]
|
|
|
|
|
[TestCase("BAD PATH")]
|
|
|
|
|
public void invalid_folder_path_throws_on_add(string path)
|
|
|
|
|
{
|
2012-01-19 04:57:27 +01:00
|
|
|
|
Assert.Throws<ArgumentException>(() =>
|
2013-02-17 02:52:40 +01:00
|
|
|
|
Mocker.Resolve<RootFolderService>().Add(new RootFolder { OID = 0, Path = path })
|
2012-01-19 04:57:27 +01:00
|
|
|
|
);
|
2011-06-13 05:56:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 06:04:55 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void adding_duplicated_root_folder_should_throw()
|
|
|
|
|
{
|
2013-02-17 06:09:35 +01:00
|
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>().Setup(c => c.All()).Returns(new List<RootFolder> { new RootFolder { Path = "C:\\TV" } });
|
2012-01-19 06:04:55 +01:00
|
|
|
|
|
2013-02-05 05:07:07 +01:00
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Subject.Add(new RootFolder { Path = @"C:\TV" }));
|
2012-01-19 06:04:55 +01:00
|
|
|
|
}
|
2011-04-09 23:35:13 +02:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|