Fixed some small issues, here and there.

pull/4/head
kay.one 13 years ago
parent 45a51497b6
commit f4a765817b

@ -39,6 +39,7 @@ namespace NzbDrone.Core.Test
mocker.SetConstant(db);
db.Insert(new Config { Key = key, Value = value });
db.Insert(new Config { Key = "Other Key", Value = "OtherValue" });
//Act
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
@ -67,7 +68,7 @@ namespace NzbDrone.Core.Test
}
[Test]
public void New_value_should_update_old_value()
public void New_value_should_update_old_value_new_value()
{
const string key = "MY_KEY";
const string originalValue = "OLD_VALUE";
@ -88,5 +89,26 @@ namespace NzbDrone.Core.Test
db.Fetch<Config>().Should().HaveCount(1);
}
[Test]
public void New_value_should_update_old_value_same_value()
{
const string key = "MY_KEY";
const string value = "OLD_VALUE";
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
//Act
mocker.Resolve<ConfigProvider>().SetValue(key, value);
mocker.Resolve<ConfigProvider>().SetValue(key, value);
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
//Assert
result.Should().Be(value);
db.Fetch<Config>().Should().HaveCount(1);
}
}
}

@ -152,6 +152,7 @@ namespace NzbDrone.Core.Test
[TestCase("The Daily Show - 2011-04-12 - Gov. Deval Patrick", "The.Daily.Show", 2011, 04, 12)]
[TestCase("2011.01.10 - Denis Leary - HD TV.mkv", "", 2011, 1, 10)]
[TestCase("2011.03.13 - Denis Leary - HD TV.mkv", "", 2011, 3, 13)]
[TestCase("The Tonight Show with Jay Leno - 2011-06-16 - Larry David, \"Bachelorette\" Ashley Hebert, Pitbull with Ne-Yo", "The Tonight Show with Jay Leno", 2011, 3, 13)]
public void episode_daily_parse(string postTitle, string title, int year, int month, int day)
{
var result = Parser.ParseEpisodeInfo(postTitle);

@ -68,7 +68,8 @@ namespace NzbDrone.Core
_kernel = new StandardKernel();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InRequestScope();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto<SubsonicTarget>().InSingletonScope();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto<IJob>().InSingletonScope();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto<SubsonicTarget>().InSingletonScope();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto<LogProvider>().InRequestScope();
}
}

@ -1,5 +1,6 @@
using System;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
using System.IO;
using MvcMiniProfiler.Data;
@ -14,6 +15,7 @@ namespace NzbDrone.Core.Datastore
static Connection()
{
if (!AppDataPath.Exists) AppDataPath.Create();
Database.Mapper = new CustomeMapper();
}
@ -38,18 +40,20 @@ namespace NzbDrone.Core.Datastore
}
}
public static IDatabase GetPetaPocoDb(string connectionString)
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
{
MigrationsHelper.Run(connectionString, true);
DbConnection connection = new SQLiteConnection(connectionString);
if (profiled)
{
//connection = ProfiledDbConnection.Get(connection);
}
var profileConnection = ProfiledDbConnection.Get(new SQLiteConnection(connectionString));
Database.Mapper = new CustomeMapper();
var db = new Database(profileConnection);
var db = new Database(connection);
if (profileConnection.State != ConnectionState.Open)
profileConnection.Open();
if (connection.State != ConnectionState.Open)
connection.Open();
return db;
}

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using NLog;
@ -8,12 +9,13 @@ namespace NzbDrone.Core.Datastore
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static bool IsMigrated { get; private set; }
public static readonly Dictionary<String, String> _migrated = new Dictionary<string, string>();
public static void Run(string connetionString, bool trace)
{
if (IsMigrated) return;
IsMigrated = true;
if (_migrated.ContainsKey(connetionString)) return;
_migrated.Add(connetionString, string.Empty);
Logger.Info("Preparing run database migration");
try

@ -278,7 +278,7 @@ namespace NzbDrone.Core.Providers.Core
{
string value;
var dbValue = _database.SingleOrDefault<Config>(key);
var dbValue = _database.SingleOrDefault<Config>("WHERE Key=@0", key);
if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value))
return dbValue.Value;

Loading…
Cancel
Save