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.Data.SQLite;
using Marr.Data;
using NLog;
using NzbDrone.Common.Instrumentation;
@ -15,28 +14,26 @@ namespace NzbDrone.Core.Datastore
public class Database : IDatabase
{
private readonly string _connectionString;
private readonly Func<IDataMapper> _datamapperFactory;
private Logger logger = NzbDroneLogger.GetLogger();
public Database(string connectionString)
public Database(Func<IDataMapper> datamapperFactory)
{
_connectionString = connectionString;
_datamapperFactory = datamapperFactory;
}
public IDataMapper GetDataMapper()
{
return new DataMapper(SQLiteFactory.Instance, _connectionString)
{
SqlMode = SqlModes.Text,
};
return _datamapperFactory();
}
public Version Version
{
get
{
var version = GetDataMapper().ExecuteScalar("SELECT sqlite_version()").ToString();
var version = _datamapperFactory().ExecuteScalar("SELECT sqlite_version()").ToString();
return new Version(version);
}
}
@ -45,13 +42,13 @@ namespace NzbDrone.Core.Datastore
{
try
{
logger.Info("Vacuuming database " + _connectionString);
GetDataMapper().ExecuteNonQuery("Vacuum;");
logger.Info("Database Compressed " + _connectionString);
logger.Info("Vacuuming database");
_datamapperFactory().ExecuteNonQuery("Vacuum;");
logger.Info("Database Compressed");
}
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);
var db = new Database(connectionString);
var db = new Database(() =>
{
var dataMapper = new DataMapper(SQLiteFactory.Instance, connectionString)
{
SqlMode = SqlModes.Text,
};
return dataMapper;
});
db.Vacuum();
return db;
}
}