You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Radarr/NzbDrone.Core.Test/Framework/TestBase.cs

112 lines
2.7 KiB

using System.IO;
using AutoMoq;
13 years ago
using Moq;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Test.Common;
using PetaPoco;
namespace NzbDrone.Core.Test.Framework
{
public class TestBase : LoggingTest
// ReSharper disable InconsistentNaming
{
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 IDatabase Db = null;
protected string VirtualPath
{
get
{
var virtualPath = Path.Combine(TempFolder, "VirtualNzbDrone");
if (!Directory.Exists(virtualPath)) Directory.CreateDirectory(virtualPath);
return virtualPath;
}
}
[SetUp]
public virtual void SetupBase()
{
ExceptionVerification.Reset();
if (Directory.Exists(TempFolder))
{
Directory.Delete(TempFolder, true);
}
Directory.CreateDirectory(TempFolder);
LiveKernel = new StandardKernel();
Mocker = new AutoMoqer();
}
13 years ago
protected void WithStrictMocker()
{
Mocker = new AutoMoqer(MockBehavior.Strict);
if (Db != null)
{
Mocker.SetConstant(Db);
}
}
protected void WithRealDb()
{
Db = MockLib.GetEmptyDatabase();
Mocker.SetConstant(Db);
13 years ago
}
[TearDown]
public void TearDownBase()
{
ExceptionVerification.AssertNoUnexcpectedLogs();
13 years ago
Mocker = new AutoMoqer(MockBehavior.Strict);
WebTimer.Stop();
}
protected void WithTempAsStartUpPath()
{
Mocker.GetMock<EnviromentProvider>()
.SetupGet(c => c.ApplicationPath)
.Returns(VirtualPath);
Mocker.Resolve<PathProvider>();
}
protected string TempFolder
{
get { return Path.Combine(Directory.GetCurrentDirectory(), "temp"); }
}
protected string GetTestFilePath(string fileName)
{
return Path.Combine(@".\Files\", fileName);
}
protected string ReadTestFile(string fileName)
{
return File.ReadAllText(GetTestFilePath(fileName));
}
}
}