1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-23 02:05:27 +02:00
Sonarr/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs

103 lines
3.2 KiB
C#
Raw Normal View History

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