2011-11-26 02:06:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2012-02-12 00:01:52 +00:00
|
|
|
|
using NUnit.Framework;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Common;
|
2011-11-18 04:36:37 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2012-02-12 00:01:52 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-11-13 07:27:16 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
using PetaPoco;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.Framework
|
|
|
|
|
{
|
|
|
|
|
public class CoreTest : TestBase
|
|
|
|
|
{
|
|
|
|
|
static CoreTest()
|
|
|
|
|
{
|
2011-11-14 00:22:18 +00:00
|
|
|
|
//Delete old db files
|
2011-11-13 07:27:16 +00:00
|
|
|
|
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
|
|
|
|
foreach (var file in oldDbFiles)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Delete(file);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 00:22:18 +00:00
|
|
|
|
//Delete App_data folder
|
2012-03-07 02:59:43 +00:00
|
|
|
|
var appData = new EnvironmentProvider().GetAppDataPath();
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
|
|
|
|
if (Directory.Exists(appData))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(appData, true);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-23 05:58:26 +00:00
|
|
|
|
TestDbHelper.CreateDataBaseTemplate();
|
2011-11-13 07:27:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-05 06:34:36 +00:00
|
|
|
|
|
2011-11-26 02:06:40 +00:00
|
|
|
|
private IDatabase _db;
|
|
|
|
|
protected IDatabase Db
|
2011-11-13 07:27:16 +00:00
|
|
|
|
{
|
2011-11-26 02:06:40 +00:00
|
|
|
|
get
|
2011-11-13 07:27:16 +00:00
|
|
|
|
{
|
2011-11-26 02:06:40 +00:00
|
|
|
|
if (_db == null)
|
|
|
|
|
throw new InvalidOperationException("Test db doesn't exists. Make sure you call WithRealDb() if you intend to use an actual database.");
|
|
|
|
|
|
|
|
|
|
return _db;
|
2011-11-13 07:27:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void WithRealDb()
|
|
|
|
|
{
|
2011-12-02 01:33:17 +00:00
|
|
|
|
_db = TestDbHelper.GetEmptyDatabase();
|
2011-11-13 07:27:16 +00:00
|
|
|
|
Mocker.SetConstant(Db);
|
|
|
|
|
}
|
2011-11-18 04:36:37 +00:00
|
|
|
|
|
|
|
|
|
|
2011-12-02 01:33:17 +00:00
|
|
|
|
protected static ProgressNotification MockNotification
|
2011-11-18 04:36:37 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new ProgressNotification("Mock notification");
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-12 00:01:52 +00:00
|
|
|
|
|
2012-04-30 01:24:24 +00:00
|
|
|
|
protected static void ThrowException()
|
|
|
|
|
{
|
|
|
|
|
throw new ApplicationException("This is a message for test exception");
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-12 00:01:52 +00:00
|
|
|
|
[TearDown]
|
|
|
|
|
public void CoreTestTearDown()
|
|
|
|
|
{
|
|
|
|
|
ConfigProvider.ClearCache();
|
|
|
|
|
}
|
2011-11-13 07:27:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|