2011-10-21 07:04:26 +02:00
|
|
|
|
using System.IO;
|
2011-11-03 06:04:14 +01:00
|
|
|
|
using AutoMoq;
|
2011-10-21 07:04:26 +02:00
|
|
|
|
using NUnit.Framework;
|
2011-11-03 06:04:14 +01:00
|
|
|
|
using Ninject;
|
|
|
|
|
using NzbDrone.Common;
|
2011-10-24 07:54:09 +02:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-05-19 05:55:35 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Framework
|
|
|
|
|
{
|
2011-11-03 06:04:14 +01:00
|
|
|
|
public class TestBase : LoggingTest
|
2011-05-22 18:53:21 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-19 05:55:35 +02:00
|
|
|
|
{
|
|
|
|
|
|
2011-11-03 06:04:14 +01:00
|
|
|
|
static TestBase()
|
|
|
|
|
{
|
|
|
|
|
InitLogging();
|
|
|
|
|
|
|
|
|
|
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
|
|
|
|
foreach (var file in oldDbFiles)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Delete(file);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MockLib.CreateDataBaseTemplate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected StandardKernel LiveKernel = null;
|
|
|
|
|
protected AutoMoqer Mocker = null;
|
|
|
|
|
|
|
|
|
|
protected string VirtualPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var virtualPath = Path.Combine(TempFolder, "VirtualNzbDrone");
|
|
|
|
|
if (!Directory.Exists(virtualPath)) Directory.CreateDirectory(virtualPath);
|
|
|
|
|
|
|
|
|
|
return virtualPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-19 05:55:35 +02:00
|
|
|
|
[SetUp]
|
2011-10-24 07:54:09 +02:00
|
|
|
|
public virtual void SetupBase()
|
2011-05-19 05:55:35 +02:00
|
|
|
|
{
|
|
|
|
|
ExceptionVerification.Reset();
|
2011-10-21 07:04:26 +02:00
|
|
|
|
if (Directory.Exists(TempFolder))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(TempFolder, true);
|
|
|
|
|
}
|
2011-10-24 07:54:09 +02:00
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(TempFolder);
|
2011-11-03 06:04:14 +01:00
|
|
|
|
|
|
|
|
|
LiveKernel = new StandardKernel();
|
|
|
|
|
Mocker = new AutoMoqer();
|
2011-05-19 05:55:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
2011-10-24 07:54:09 +02:00
|
|
|
|
public void TearDownBase()
|
2011-05-19 05:55:35 +02:00
|
|
|
|
{
|
2011-06-02 23:06:46 +02:00
|
|
|
|
ExceptionVerification.AssertNoUnexcpectedLogs();
|
2011-05-19 05:55:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-21 07:04:26 +02:00
|
|
|
|
|
2011-11-03 06:04:14 +01:00
|
|
|
|
protected void WithTempAsStartUpPath()
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<EnviromentProvider>()
|
|
|
|
|
.SetupGet(c => c.ApplicationPath)
|
|
|
|
|
.Returns(VirtualPath);
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<PathProvider>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-10-21 07:04:26 +02:00
|
|
|
|
protected string TempFolder
|
|
|
|
|
{
|
2011-10-24 07:54:09 +02:00
|
|
|
|
get { return Path.Combine(Directory.GetCurrentDirectory(), "temp"); }
|
2011-10-21 07:04:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string GetTestFilePath(string fileName)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(@".\Files\", fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string ReadTestFile(string fileName)
|
|
|
|
|
{
|
|
|
|
|
return File.ReadAllText(GetTestFilePath(fileName));
|
|
|
|
|
}
|
2011-05-19 05:55:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|