1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Missing root dir won't stop app

Fixed: Missing root dir won't prevent UI from loading
This commit is contained in:
Mark McDowall 2012-12-25 23:20:31 -08:00
parent 861b2ec1e3
commit cd98fbb4fa
5 changed files with 131 additions and 12 deletions

View File

@ -193,8 +193,8 @@ public virtual void InheritFolderPermissions(string filename)
public virtual ulong FreeDiskSpace(DirectoryInfo directoryInfo)
{
if (!directoryInfo.Exists)
throw new DirectoryNotFoundException();
if(!directoryInfo.Exists)
throw new DirectoryNotFoundException(directoryInfo.FullName);
ulong freeBytesAvailable;
ulong totalNumberOfBytes;

View File

@ -142,6 +142,7 @@
<Compile Include="HelperTests\XElementHelperTests\ConvertToTFixture.cs" />
<Compile Include="IndexerTests\NzbxFixture.cs" />
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />
<Compile Include="ProviderTests\RootDirProviderTests\FreeSpaceOnDrivesFixture.cs" />
<Compile Include="ProviderTests\SearchProviderTests\GetSeriesTitleFixture.cs" />
<Compile Include="ProviderTests\TvRageMappingProviderTests\FindMatchingTvRageSeriesFixture.cs" />
<Compile Include="ProviderTests\TvRageMappingProviderTests\ProcessResultsFixture.cs" />
@ -237,7 +238,7 @@
<Compile Include="ProviderTests\DecisionEngineTests\AllowedDownloadSpecificationFixture.cs" />
<Compile Include="ProviderTests\JobProviderTests\JobProviderFixture.cs" />
<Compile Include="QualityTest.cs" />
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
<Compile Include="ProviderTests\RootDirProviderTests\RootDirProviderFixture.cs" />
<Compile Include="ProviderTests\IndexerProviderTest.cs" />
<Compile Include="ProviderTests\HistoryProviderTest.cs" />
<Compile Include="ProviderTests\MediaFileProviderTest.cs" />

View File

@ -0,0 +1,114 @@
// 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.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
using PetaPoco;
namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class FreeSpaceOnDrivesFixture : CoreTest
{
[Test]
public void should_return_one_drive_when_only_one_root_dir_exists()
{
Mocker.GetMock<IDatabase>()
.Setup(s => s.Fetch<RootDir>())
.Returns(new List<RootDir> { new RootDir { Id = 1, Path = @"C:\Test\TV" } });
Mocker.GetMock<DiskProvider>()
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(@"C:\")))
.Returns(123456);
var result = Mocker.Resolve<RootDirProvider>().FreeSpaceOnDrives();
result.Should().HaveCount(1);
}
[Test]
public void should_return_one_drive_when_two_rootDirs_on_the_same_drive_exist()
{
Mocker.GetMock<IDatabase>()
.Setup(s => s.Fetch<RootDir>())
.Returns(new List<RootDir> { new RootDir { Id = 1, Path = @"C:\Test\TV" },
new RootDir { Id = 2, Path = @"C:\Test\TV2" }});
Mocker.GetMock<DiskProvider>()
.Setup(s => s.GetPathRoot(It.IsAny<String>()))
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(@"C:\")))
.Returns(123456);
var result = Mocker.Resolve<RootDirProvider>().FreeSpaceOnDrives();
result.Should().HaveCount(1);
}
[Test]
public void should_return_two_drives_when_two_rootDirs_on_the_different_drive_exist()
{
Mocker.GetMock<IDatabase>()
.Setup(s => s.Fetch<RootDir>())
.Returns(new List<RootDir> { new RootDir { Id = 1, Path = @"C:\Test\TV" },
new RootDir { Id = 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<DirectoryInfo>()))
.Returns(123456);
var result = Mocker.Resolve<RootDirProvider>().FreeSpaceOnDrives();
result.Should().HaveCount(2);
}
[Test]
public void should_skip_rootDir_if_not_found_on_disk()
{
Mocker.GetMock<IDatabase>()
.Setup(s => s.Fetch<RootDir>())
.Returns(new List<RootDir> { new RootDir { Id = 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<DirectoryInfo>()))
.Throws(new DirectoryNotFoundException());
var result = Mocker.Resolve<RootDirProvider>().FreeSpaceOnDrives();
result.Should().HaveCount(0);
ExceptionVerification.ExpectedWarns(1);
}
}
}

View File

@ -14,11 +14,11 @@
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class RootDirProviderTest : CoreTest
public class RootDirProviderFixture : CoreTest
{
[SetUp]
public void Setup()
@ -35,7 +35,6 @@ private void WithNoneExistingFolder()
.Returns(false);
}
[Test]
public void GetRootDir_should_return_all_existing_roots()
{
@ -48,7 +47,6 @@ public void GetRootDir_should_return_all_existing_roots()
result.Should().HaveCount(2);
}
[TestCase("D:\\TV Shows\\")]
[TestCase("//server//folder")]
public void should_be_able_to_add_root_dir(string path)
@ -74,7 +72,6 @@ public void should_throw_if_folder_being_added_doesnt_exist()
Assert.Throws<DirectoryNotFoundException>(() => rootDirProvider.Add(new RootDir { Path = "C:\\TEST" }));
}
[Test]
public void should_be_able_to_remove_root_dir()
{
@ -91,7 +88,6 @@ public void should_be_able_to_remove_root_dir()
rootDirs.Should().HaveCount(1);
}
[Test]
public void None_existing_folder_returns_empty_list()
{
@ -132,6 +128,5 @@ public void adding_duplicated_root_folder_should_throw()
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
Assert.Throws<InvalidOperationException>(() => rootDirProvider.Add(new RootDir { Path = @"C:\TV" }));
}
}
}

View File

@ -98,8 +98,17 @@ public virtual Dictionary<string, ulong> FreeSpaceOnDrives()
{
var pathRoot = _diskProvider.GetPathRoot(rootDir.Path);
if (!freeSpace.ContainsKey(pathRoot))
freeSpace.Add(pathRoot, _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path)));
if(!freeSpace.ContainsKey(pathRoot))
{
try
{
freeSpace.Add(pathRoot, _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path)));
}
catch(Exception ex)
{
Logger.WarnException("Error getting fromm space for: " + pathRoot, ex);
}
}
}
return freeSpace;