mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-18 21:35:51 -04:00
removed sqlce
This commit is contained in:
@@ -1,146 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Model.Notification;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Test.Common;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core.Test.Framework
|
||||
{
|
||||
public abstract class SqlCeTest : CoreTest
|
||||
{
|
||||
private string _dbTemplateName;
|
||||
|
||||
[SetUp]
|
||||
public void CoreTestSetup()
|
||||
{
|
||||
if (EnvironmentProvider.IsMono)
|
||||
{
|
||||
throw new IgnoreException("SqlCe is not supported in mono.");
|
||||
}
|
||||
|
||||
if (NCrunch.Framework.NCrunchEnvironment.NCrunchIsResident())
|
||||
{
|
||||
_dbTemplateName = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()) + ".sdf";
|
||||
}
|
||||
else
|
||||
{
|
||||
_dbTemplateName = "db_template.sdf";
|
||||
}
|
||||
|
||||
CreateDataBaseTemplate();
|
||||
}
|
||||
|
||||
private IDatabase GetEmptyDatabase(string fileName = "")
|
||||
{
|
||||
Console.WriteLine("====================DataBase====================");
|
||||
Console.WriteLine("Cloning database from template.");
|
||||
|
||||
if (String.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
fileName = Guid.NewGuid() + ".sdf";
|
||||
}
|
||||
|
||||
File.Copy(_dbTemplateName, fileName);
|
||||
|
||||
var connectionString = ConnectionFactory.GetConnectionString(fileName);
|
||||
var database = ConnectionFactory.GetPetaPocoDb(connectionString);
|
||||
|
||||
Console.WriteLine("====================DataBase====================");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
private void CreateDataBaseTemplate()
|
||||
{
|
||||
Console.WriteLine("Creating an empty PetaPoco database");
|
||||
var connectionString = ConnectionFactory.GetConnectionString(_dbTemplateName);
|
||||
var database = ConnectionFactory.GetPetaPocoDb(connectionString);
|
||||
database.Dispose();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private IDatabase _db;
|
||||
protected IDatabase Db
|
||||
{
|
||||
get
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void WithRealDb()
|
||||
{
|
||||
if (EnvironmentProvider.IsMono)
|
||||
{
|
||||
throw new IgnoreException("SqlCe is not supported in mono.");
|
||||
}
|
||||
|
||||
_db = GetEmptyDatabase();
|
||||
Mocker.SetConstant(Db);
|
||||
}
|
||||
|
||||
|
||||
[TearDown]
|
||||
public void CoreTestTearDown()
|
||||
{
|
||||
ConfigService.ClearCache();
|
||||
|
||||
if (EnvironmentProvider.IsMono)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_db != null && _db.Connection != null && File.Exists(_db.Connection.Database))
|
||||
{
|
||||
var file = _db.Connection.Database;
|
||||
_db.Dispose();
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
|
||||
}
|
||||
catch (IOException) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SqlCeTest<TSubject> : SqlCeTest where TSubject : class
|
||||
{
|
||||
|
||||
private TSubject _subject;
|
||||
|
||||
|
||||
protected TSubject Subject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_subject == null)
|
||||
{
|
||||
_subject = Mocker.Resolve<TSubject>();
|
||||
}
|
||||
|
||||
return _subject;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void InitiateSubject()
|
||||
{
|
||||
_subject = Mocker.Resolve<TSubject>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using PetaPoco;
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Test.Framework
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user