fixed some tests, cleaned up root folders.

This commit is contained in:
kay.one 2013-02-16 20:33:56 -08:00
commit a0d0e4715e
18 changed files with 110 additions and 133 deletions

View file

@ -0,0 +1,109 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.RootFolderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class FreeSpaceOnDrivesFixture : CoreTest<RootFolderService>
{
[Test]
public void should_return_one_drive_when_only_one_root_dir_exists()
{
Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.All())
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" } });
Mocker.GetMock<DiskProvider>()
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(@"C:\"))
.Returns(123456);
var result = Subject.FreeSpaceOnDrives();
result.Should().HaveCount(1);
}
[Test]
public void should_return_one_drive_when_two_rootDirs_on_the_same_drive_exist()
{
Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.All())
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" },
new RootFolder { OID = 2, Path = @"C:\Test\TV2" }});
Mocker.GetMock<DiskProvider>()
.Setup(s => s.GetPathRoot(It.IsAny<String>()))
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(@"C:\"))
.Returns(123456);
var result = Subject.FreeSpaceOnDrives();
result.Should().HaveCount(1);
}
[Test]
public void should_return_two_drives_when_two_rootDirs_on_the_different_drive_exist()
{
Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.All())
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" },
new RootFolder { OID = 2, Path = @"D:\Test\TV" }});
Mocker.GetMock<DiskProvider>()
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.GetPathRoot(@"D:\Test\TV"))
.Returns(@"D:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
.Returns(123456);
var result = Subject.FreeSpaceOnDrives();
result.Should().HaveCount(2);
}
[Test]
public void should_skip_rootDir_if_not_found_on_disk()
{
Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.All())
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" } });
Mocker.GetMock<DiskProvider>()
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
.Throws(new DirectoryNotFoundException());
var result = Subject.FreeSpaceOnDrives();
result.Should().HaveCount(0);
ExceptionVerification.ExpectedWarns(1);
}
}
}

View file

@ -0,0 +1,104 @@
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.RootFolderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class RootFolderServiceFixture : CoreTest<RootFolderService>
{
[SetUp]
public void Setup()
{
Mocker.GetMock<DiskProvider>()
.Setup(m => m.FolderExists(It.IsAny<string>()))
.Returns(true);
Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.All())
.Returns(new List<RootFolder>());
}
private void WithNoneExistingFolder()
{
Mocker.GetMock<DiskProvider>()
.Setup(m => m.FolderExists(It.IsAny<string>()))
.Returns(false);
}
[TestCase("D:\\TV Shows\\")]
[TestCase("//server//folder")]
public void should_be_able_to_add_root_dir(string path)
{
var root = new RootFolder { Path = path };
Subject.Add(root);
Mocker.GetMock<IRootFolderRepository>().Verify(c => c.Add(root), Times.Once());
}
[Test]
public void should_throw_if_folder_being_added_doesnt_exist()
{
WithNoneExistingFolder();
Assert.Throws<DirectoryNotFoundException>(() => Subject.Add(new RootFolder { Path = "C:\\TEST" }));
}
[Test]
public void should_be_able_to_remove_root_dir()
{
Subject.Remove(1);
Mocker.GetMock<IRootFolderRepository>().Verify(c => c.Delete(1), Times.Once());
}
public void None_existing_folder_returns_empty_list()
{
WithNoneExistingFolder();
Mocker.GetMock<IRootFolderRepository>().Setup(c => c.All()).Returns(new List<RootFolder>());
const string path = "d:\\bad folder";
var result = Subject.GetUnmappedFolders(path);
result.Should().NotBeNull();
result.Should().BeEmpty();
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectories(It.IsAny<String>()), Times.Never());
}
[Test]
public void GetUnmappedFolders_throw_on_empty_folders()
{
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 { OID = 0, Path = path })
);
}
[Test]
public void adding_duplicated_root_folder_should_throw()
{
Mocker.GetMock<IRootFolderRepository>().Setup(c => c.All()).Returns(new List<RootFolder> { new RootFolder { Path = "C:\\TV" } });
Assert.Throws<InvalidOperationException>(() => Subject.Add(new RootFolder { Path = @"C:\TV" }));
}
}
}