1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 07:52:37 +01:00
Sonarr/NzbDrone.Core.Test/Framework/CoreTest.cs

78 lines
1.9 KiB
C#
Raw Normal View History

2011-11-26 03:06:40 +01:00
using System;
using System.IO;
using NUnit.Framework;
using NzbDrone.Common;
2011-11-18 05:36:37 +01:00
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core;
2011-11-13 08:27:16 +01:00
using NzbDrone.Test.Common;
using PetaPoco;
namespace NzbDrone.Core.Test.Framework
{
public class CoreTest : TestBase
{
static CoreTest()
{
//Delete old db files
2011-11-13 08:27:16 +01:00
var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
foreach (var file in oldDbFiles)
{
try
{
File.Delete(file);
}
catch { }
}
//Delete App_data folder
var appData = new EnvironmentProvider().GetAppDataPath();
if (Directory.Exists(appData))
{
Directory.Delete(appData, true);
}
TestDbHelper.CreateDataBaseTemplate();
2011-11-13 08:27:16 +01:00
}
2011-11-26 03:06:40 +01:00
private IDatabase _db;
protected IDatabase Db
2011-11-13 08:27:16 +01:00
{
2011-11-26 03:06:40 +01:00
get
2011-11-13 08:27:16 +01:00
{
2011-11-26 03:06:40 +01: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 08:27:16 +01:00
}
}
protected void WithRealDb()
{
2011-12-02 02:33:17 +01:00
_db = TestDbHelper.GetEmptyDatabase();
2011-11-13 08:27:16 +01:00
Mocker.SetConstant(Db);
}
2011-11-18 05:36:37 +01:00
2011-12-02 02:33:17 +01:00
protected static ProgressNotification MockNotification
2011-11-18 05:36:37 +01:00
{
get
{
return new ProgressNotification("Mock notification");
}
}
2012-04-30 03:24:24 +02:00
protected static void ThrowException()
{
throw new ApplicationException("This is a message for test exception");
}
[TearDown]
public void CoreTestTearDown()
{
ConfigProvider.ClearCache();
}
2011-11-13 08:27:16 +01:00
}
}