2011-05-22 19:53:21 +03:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-05-22 19:53:21 +03:00
|
|
|
using System;
|
2011-05-20 06:47:07 +03:00
|
|
|
using System.Linq;
|
2011-11-14 03:22:18 +03:00
|
|
|
|
2011-06-03 00:06:46 +03:00
|
|
|
using FluentAssertions;
|
2011-05-20 06:47:07 +03:00
|
|
|
using Moq;
|
2011-06-03 00:06:46 +03:00
|
|
|
using NUnit.Framework;
|
2011-11-13 07:07:06 +03:00
|
|
|
using NzbDrone.Common;
|
2011-04-10 00:35:13 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2011-05-20 06:47:07 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-10 00:35:13 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
2011-05-19 06:55:35 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-04-10 00:35:13 +03:00
|
|
|
|
2011-10-21 02:42:17 +03:00
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-04-10 00:35:13 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2011-05-19 06:55:35 +03:00
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 10:27:16 +03:00
|
|
|
public class RootDirProviderTest : CoreTest
|
2011-04-10 00:35:13 +03:00
|
|
|
{
|
2011-06-03 00:06:46 +03:00
|
|
|
|
2011-04-10 00:35:13 +03:00
|
|
|
[Test]
|
|
|
|
public void GetRootDirs()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
2011-11-23 08:58:26 +03:00
|
|
|
var emptyDatabase = TestDbHelper.GetEmptyDatabase();
|
2011-06-17 18:27:18 +03:00
|
|
|
mocker.SetConstant(emptyDatabase);
|
|
|
|
emptyDatabase.Insert(new RootDir { Path = @"C:\TV" });
|
|
|
|
emptyDatabase.Insert(new RootDir { Path = @"C:\TV2" });
|
|
|
|
|
|
|
|
//mocker.GetMock<IRepository>()
|
|
|
|
// .Setup(f => f.All<RootDir>())
|
|
|
|
// .Returns(sonicRepo.All<RootDir>);
|
2011-04-10 00:35:13 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<RootDirProvider>().GetAll();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.AreEqual(result.Count, 2);
|
|
|
|
}
|
|
|
|
|
2011-06-13 06:56:10 +03:00
|
|
|
[TestCase("D:\\TV Shows\\")]
|
|
|
|
[TestCase("//server//folder")]
|
|
|
|
public void AddRootDir(string path)
|
2011-04-10 00:35:13 +03:00
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var mocker = new AutoMoqer();
|
2011-11-23 08:58:26 +03:00
|
|
|
mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
|
2011-04-10 00:35:13 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var rootDirProvider = mocker.Resolve<RootDirProvider>();
|
2011-06-03 00:06:46 +03:00
|
|
|
rootDirProvider.Add(new RootDir { Path = path });
|
2011-04-10 00:35:13 +03:00
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
var rootDirs = rootDirProvider.GetAll();
|
2011-06-23 09:56:17 +03:00
|
|
|
rootDirs.Should().NotBeEmpty();
|
2011-06-03 00:06:46 +03:00
|
|
|
rootDirs.Should().HaveCount(1);
|
2011-06-23 09:56:17 +03:00
|
|
|
path.Should().Be(rootDirs.First().Path);
|
2011-04-10 00:35:13 +03:00
|
|
|
}
|
|
|
|
|
2011-06-13 06:56:10 +03:00
|
|
|
|
2011-04-10 00:35:13 +03:00
|
|
|
[Test]
|
|
|
|
public void RemoveRootDir()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var mocker = new AutoMoqer();
|
2011-11-23 08:58:26 +03:00
|
|
|
mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
|
2011-04-10 00:35:13 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var rootDirProvider = mocker.Resolve<RootDirProvider>();
|
2011-06-03 00:06:46 +03:00
|
|
|
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
|
2011-04-10 00:35:13 +03:00
|
|
|
rootDirProvider.Remove(1);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
var rootDirs = rootDirProvider.GetAll();
|
2011-06-03 00:06:46 +03:00
|
|
|
rootDirs.Should().BeEmpty();
|
2011-04-10 00:35:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetRootDir()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var mocker = new AutoMoqer();
|
2011-11-23 08:58:26 +03:00
|
|
|
mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
|
2011-04-10 00:35:13 +03:00
|
|
|
|
2011-05-19 06:55:35 +03:00
|
|
|
const int id = 1;
|
|
|
|
const string path = @"C:\TV";
|
2011-04-10 00:35:13 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var rootDirProvider = mocker.Resolve<RootDirProvider>();
|
2011-06-03 00:06:46 +03:00
|
|
|
rootDirProvider.Add(new RootDir { Id = id, Path = path });
|
2011-04-10 00:35:13 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
var rootDir = rootDirProvider.GetRootDir(id);
|
2011-06-23 09:56:17 +03:00
|
|
|
rootDir.Id.Should().Be(1);
|
|
|
|
rootDir.Path.Should().Be(path);
|
2011-04-10 00:35:13 +03:00
|
|
|
}
|
2011-05-20 06:47:07 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void None_existing_folder_returns_empty_list()
|
|
|
|
{
|
|
|
|
const string path = "d:\\bad folder";
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.GetMock<DiskProvider>(MockBehavior.Strict)
|
|
|
|
.Setup(m => m.FolderExists(path)).Returns(false);
|
|
|
|
|
|
|
|
var result = mocker.Resolve<RootDirProvider>().GetUnmappedFolders(path);
|
|
|
|
|
2011-06-23 09:56:17 +03:00
|
|
|
result.Should().NotBeNull();
|
|
|
|
result.Should().BeEmpty();
|
2011-05-20 06:47:07 +03:00
|
|
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[ExpectedException(typeof(ArgumentException))]
|
|
|
|
public void empty_folder_path_throws()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.Resolve<RootDirProvider>().GetUnmappedFolders("");
|
|
|
|
}
|
2011-06-13 06:56:10 +03:00
|
|
|
|
|
|
|
[TestCase("")]
|
|
|
|
[TestCase(null)]
|
|
|
|
[TestCase("BAD PATH")]
|
|
|
|
[ExpectedException(typeof(ArgumentException))]
|
|
|
|
public void invalid_folder_path_throws_on_add(string path)
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.Resolve<RootDirProvider>().Add(new RootDir { Id = 0, Path = path });
|
|
|
|
}
|
|
|
|
|
2011-04-10 00:35:13 +03:00
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|