using System; using System.Collections.Generic; using System.IO; using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.RootFolderTests { [TestFixture] public class RootFolderServiceFixture : CoreTest { [SetUp] public void Setup() { Mocker.GetMock() .Setup(m => m.FolderExists(It.IsAny())) .Returns(true); Mocker.GetMock() .Setup(m => m.FolderWritable(It.IsAny())) .Returns(true); Mocker.GetMock() .Setup(s => s.All()) .Returns(new List()); } private void WithNonExistingFolder() { Mocker.GetMock() .Setup(m => m.FolderExists(It.IsAny())) .Returns(false); } [TestCase("D:\\Music\\")] [TestCase("//server//folder")] public void should_be_able_to_add_root_dir(string path) { var root = new RootFolder { Path = path.AsOsAgnostic() }; Subject.Add(root); Mocker.GetMock().Verify(c => c.Insert(root), Times.Once()); } [Test] public void should_throw_if_folder_being_added_doesnt_exist() { WithNonExistingFolder(); Assert.Throws(() => Subject.Add(new RootFolder { Path = "C:\\TEST".AsOsAgnostic() })); } [Test] public void should_be_able_to_remove_root_dir() { Subject.Remove(1); Mocker.GetMock().Verify(c => c.Delete(1), Times.Once()); } [TestCase("")] [TestCase(null)] [TestCase("BAD PATH")] public void invalid_folder_path_throws_on_add(string path) { Assert.Throws(() => Mocker.Resolve().Add(new RootFolder { Id = 0, Path = path })); } [Test] public void adding_duplicated_root_folder_should_throw() { Mocker.GetMock().Setup(c => c.All()).Returns(new List { new RootFolder { Path = "C:\\Music".AsOsAgnostic() } }); Assert.Throws(() => Subject.Add(new RootFolder { Path = @"C:\Music".AsOsAgnostic() })); } [Test] public void should_throw_when_adding_not_writable_folder() { Mocker.GetMock() .Setup(m => m.FolderWritable(It.IsAny())) .Returns(false); Assert.Throws(() => Subject.Add(new RootFolder { Path = @"C:\Music".AsOsAgnostic() })); } } }