sonarr-repo-only/NzbDrone.Core.Test/Framework/TestBase.cs

99 lines
2.4 KiB
C#
Raw Normal View History

using System.IO;
using AutoMoq;
2011-11-03 23:23:54 +00:00
using Moq;
using NUnit.Framework;
using Ninject;
using NzbDrone.Common;
2011-10-24 05:54:09 +00:00
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Framework
{
public class TestBase : LoggingTest
2011-05-22 16:53:21 +00:00
// 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 string VirtualPath
{
get
{
var virtualPath = Path.Combine(TempFolder, "VirtualNzbDrone");
if (!Directory.Exists(virtualPath)) Directory.CreateDirectory(virtualPath);
return virtualPath;
}
}
[SetUp]
2011-10-24 05:54:09 +00:00
public virtual void SetupBase()
{
ExceptionVerification.Reset();
if (Directory.Exists(TempFolder))
{
Directory.Delete(TempFolder, true);
}
2011-10-24 05:54:09 +00:00
Directory.CreateDirectory(TempFolder);
LiveKernel = new StandardKernel();
Mocker = new AutoMoqer();
}
2011-11-03 23:23:54 +00:00
protected void WithStrictMocker()
{
Mocker = new AutoMoqer(MockBehavior.Strict);
}
[TearDown]
2011-10-24 05:54:09 +00:00
public void TearDownBase()
{
2011-06-02 21:06:46 +00:00
ExceptionVerification.AssertNoUnexcpectedLogs();
2011-11-03 23:23:54 +00:00
Mocker = new AutoMoqer(MockBehavior.Strict);
}
protected void WithTempAsStartUpPath()
{
Mocker.GetMock<EnviromentProvider>()
.SetupGet(c => c.ApplicationPath)
.Returns(VirtualPath);
Mocker.Resolve<PathProvider>();
}
protected string TempFolder
{
2011-10-24 05:54:09 +00:00
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));
}
}
}