Lidarr/NzbDrone.Core.Test/ProviderTests/RootDirProviderTest.cs

139 lines
3.8 KiB
C#
Raw Normal View History

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