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

Application will automatically restart on db error.

Added SyncProvider Tests
This commit is contained in:
kay.one 2011-04-09 19:28:54 -07:00
parent fcf51978f9
commit 8cade435d1
5 changed files with 65 additions and 5 deletions

View File

@ -93,6 +93,7 @@
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs"> <Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="SyncProviderTest.cs" />
<Compile Include="RootDirProviderTest.cs" /> <Compile Include="RootDirProviderTest.cs" />
<Compile Include="RssProviderTest.cs" /> <Compile Include="RssProviderTest.cs" />
<Compile Include="HistoryProviderTest.cs" /> <Compile Include="HistoryProviderTest.cs" />

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using AutoMoq;
using Gallio.Framework;
using MbUnit.Framework;
using MbUnit.Framework.ContractVerifiers;
using Moq;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SyncProviderTest
{
[Test]
public void None_existing_folder_returns_empty_list()
{
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<SyncProvider>().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<SyncProvider>().GetUnmappedFolders("");
}
}
}

View File

@ -30,6 +30,11 @@ public MediaFileProvider(IRepository repository, ConfigProvider configProvider,
_episodeProvider = episodeProvider; _episodeProvider = episodeProvider;
} }
public MediaFileProvider()
{
}
/// <summary> /// <summary>
/// Scans the specified series folder for media files /// Scans the specified series folder for media files
/// </summary> /// </summary>

View File

@ -41,15 +41,17 @@ public List<String> GetUnmappedFolders(string path)
{ {
Logger.Debug("Generating list of unmapped folders"); Logger.Debug("Generating list of unmapped folders");
if (String.IsNullOrEmpty(path)) if (String.IsNullOrEmpty(path))
throw new InvalidOperationException("Invalid path provided"); throw new ArgumentException("Invalid path provided", "path");
var results = new List<String>();
if (!_diskProvider.FolderExists(path)) if (!_diskProvider.FolderExists(path))
{ {
Logger.Debug("Path supplied does not exist: {0}", path); Logger.Debug("Path supplied does not exist: {0}", path);
return null; return results;
} }
var results = new List<String>();
foreach (string seriesFolder in _diskProvider.GetDirectories(path)) foreach (string seriesFolder in _diskProvider.GetDirectories(path))
{ {
var cleanPath = Parser.NormalizePath(new DirectoryInfo(seriesFolder).FullName); var cleanPath = Parser.NormalizePath(new DirectoryInfo(seriesFolder).FullName);

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Data.SQLite;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
@ -74,11 +75,17 @@ protected void Application_Error(object sender, EventArgs e)
{ {
Response.Redirect(Request.ApplicationPath); Response.Redirect(Request.ApplicationPath);
} }
return;
} }
else
Logger.FatalException(lastError.Message, lastError);
if (lastError is SQLiteException)
{ {
Logger.FatalException(lastError.Message, lastError); Logger.Warn("Restarting application");
HttpRuntime.UnloadAppDomain();
} }
} }
protected void Application_BeginRequest() protected void Application_BeginRequest()