1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 18:28:19 +00:00
Sonarr/NzbDrone.Core.Test/RootDirProviderTest.cs

167 lines
4.9 KiB
C#
Raw Normal View History

2011-05-22 16:53:21 +00:00
// ReSharper disable RedundantUsingDirective
using System;
using System.Linq;
2011-04-09 21:35:13 +00:00
using AutoMoq;
2011-06-02 21:06:46 +00:00
using FluentAssertions;
using Moq;
2011-06-02 21:06:46 +00:00
using NUnit.Framework;
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;
2011-04-09 21:35:13 +00:00
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class RootDirProviderTest : TestBase
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
var mocker = new AutoMoqer();
var emptyDatabase = MockLib.GetEmptyDatabase();
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-09 21:35:13 +00:00
//Act
var result = mocker.Resolve<RootDirProvider>().GetAll();
//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
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyDatabase());
2011-04-09 21:35:13 +00:00
//Act
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();
Assert.IsNotEmpty(rootDirs);
2011-06-02 21:06:46 +00:00
rootDirs.Should().HaveCount(1);
2011-04-09 21:35:13 +00:00
Assert.AreEqual(path, rootDirs.First().Path);
}
[TestCase("D:\\TV Shows\\")]
[TestCase("//server//folder")]
public void UpdateRootDir(string newPath)
2011-04-09 21:35:13 +00:00
{
//Setup
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyDatabase());
2011-04-09 21:35:13 +00:00
//Act
var rootDirProvider = mocker.Resolve<RootDirProvider>();
2011-06-02 21:06:46 +00:00
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
rootDirProvider.Update(new RootDir { Id = 1, Path = newPath });
2011-04-09 21:35:13 +00:00
//Assert
var rootDirs = rootDirProvider.GetAll();
Assert.IsNotEmpty(rootDirs);
2011-06-02 21:06:46 +00:00
rootDirs.Should().HaveCount(1);
Assert.AreEqual(newPath, rootDirs.First().Path);
2011-04-09 21:35:13 +00:00
}
[Test]
public void RemoveRootDir()
{
//Setup
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyDatabase());
2011-04-09 21:35:13 +00:00
//Act
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
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.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
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);
Assert.AreEqual(1, rootDir.Id);
Assert.AreEqual(path, rootDir.Path);
}
[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);
Assert.IsNotNull(result);
Assert.IsEmpty(result);
mocker.VerifyAllMocks();
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void empty_folder_path_throws()
{
var mocker = new AutoMoqer();
mocker.Resolve<RootDirProvider>().GetUnmappedFolders("");
}
[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 });
}
[TestCase("")]
[TestCase(null)]
[TestCase("BAD PATH")]
[ExpectedException(typeof(ArgumentException))]
public void invalid_folder_path_throws_on_update(string path)
{
var mocker = new AutoMoqer();
mocker.Resolve<RootDirProvider>().Update(new RootDir { Id = 2, Path = path });
}
2011-04-09 21:35:13 +00:00
}
2011-04-10 02:44:01 +00:00
}