fixed broken tests

This commit is contained in:
kayone 2013-11-27 23:52:22 -08:00 committed by Mark McDowall
parent a0b0f586c8
commit 3f899f2130
2 changed files with 20 additions and 14 deletions

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Data.SQLite;
using Marr.Data; using Marr.Data;
using NLog; using NLog;
using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Instrumentation;
@ -15,28 +14,26 @@ namespace NzbDrone.Core.Datastore
public class Database : IDatabase public class Database : IDatabase
{ {
private readonly string _connectionString; private readonly Func<IDataMapper> _datamapperFactory;
private Logger logger = NzbDroneLogger.GetLogger(); private Logger logger = NzbDroneLogger.GetLogger();
public Database(string connectionString) public Database(Func<IDataMapper> datamapperFactory)
{ {
_connectionString = connectionString; _datamapperFactory = datamapperFactory;
} }
public IDataMapper GetDataMapper() public IDataMapper GetDataMapper()
{ {
return new DataMapper(SQLiteFactory.Instance, _connectionString) return _datamapperFactory();
{
SqlMode = SqlModes.Text,
};
} }
public Version Version public Version Version
{ {
get get
{ {
var version = GetDataMapper().ExecuteScalar("SELECT sqlite_version()").ToString(); var version = _datamapperFactory().ExecuteScalar("SELECT sqlite_version()").ToString();
return new Version(version); return new Version(version);
} }
} }
@ -45,13 +42,13 @@ namespace NzbDrone.Core.Datastore
{ {
try try
{ {
logger.Info("Vacuuming database " + _connectionString); logger.Info("Vacuuming database");
GetDataMapper().ExecuteNonQuery("Vacuum;"); _datamapperFactory().ExecuteNonQuery("Vacuum;");
logger.Info("Database Compressed " + _connectionString); logger.Info("Database Compressed");
} }
catch (Exception e) catch (Exception e)
{ {
logger.Error("An Error occurred while vacuuming database. " + _connectionString, e); logger.Error("An Error occurred while vacuuming database.", e);
} }
} }
} }

View File

@ -73,10 +73,19 @@ namespace NzbDrone.Core.Datastore
_migrationController.MigrateToLatest(connectionString, migrationType); _migrationController.MigrateToLatest(connectionString, migrationType);
var db = new Database(connectionString); var db = new Database(() =>
{
var dataMapper = new DataMapper(SQLiteFactory.Instance, connectionString)
{
SqlMode = SqlModes.Text,
};
return dataMapper;
});
db.Vacuum(); db.Vacuum();
return db; return db;
} }
} }