mirror of
https://github.com/Radarr/Radarr
synced 2024-12-25 17:27:59 +00:00
Fixed some small issues, here and there.
This commit is contained in:
parent
45a51497b6
commit
f4a765817b
6 changed files with 44 additions and 14 deletions
|
@ -39,6 +39,7 @@ public void Get_value_from_database()
|
||||||
mocker.SetConstant(db);
|
mocker.SetConstant(db);
|
||||||
|
|
||||||
db.Insert(new Config { Key = key, Value = value });
|
db.Insert(new Config { Key = key, Value = value });
|
||||||
|
db.Insert(new Config { Key = "Other Key", Value = "OtherValue" });
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
|
var result = mocker.Resolve<ConfigProvider>().GetValue(key, "");
|
||||||
|
@ -67,7 +68,7 @@ public void Get_value_should_return_default_when_no_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
[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 key = "MY_KEY";
|
||||||
const string originalValue = "OLD_VALUE";
|
const string originalValue = "OLD_VALUE";
|
||||||
|
@ -88,5 +89,26 @@ public void New_value_should_update_old_value()
|
||||||
db.Fetch<Config>().Should().HaveCount(1);
|
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 @@ public void episode_multipart_parse(string postTitle, string title, int season,
|
||||||
[TestCase("The Daily Show - 2011-04-12 - Gov. Deval Patrick", "The.Daily.Show", 2011, 04, 12)]
|
[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.01.10 - Denis Leary - HD TV.mkv", "", 2011, 1, 10)]
|
||||||
[TestCase("2011.03.13 - Denis Leary - HD TV.mkv", "", 2011, 3, 13)]
|
[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)
|
public void episode_daily_parse(string postTitle, string title, int year, int month, int day)
|
||||||
{
|
{
|
||||||
var result = Parser.ParseEpisodeInfo(postTitle);
|
var result = Parser.ParseEpisodeInfo(postTitle);
|
||||||
|
|
|
@ -68,7 +68,8 @@ public static void BindKernel()
|
||||||
_kernel = new StandardKernel();
|
_kernel = new StandardKernel();
|
||||||
|
|
||||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InRequestScope();
|
_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();
|
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto<LogProvider>().InRequestScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using MvcMiniProfiler.Data;
|
using MvcMiniProfiler.Data;
|
||||||
|
@ -14,6 +15,7 @@ public static class Connection
|
||||||
static Connection()
|
static Connection()
|
||||||
{
|
{
|
||||||
if (!AppDataPath.Exists) AppDataPath.Create();
|
if (!AppDataPath.Exists) AppDataPath.Create();
|
||||||
|
Database.Mapper = new CustomeMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,17 +41,19 @@ public static String LogConnectionString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static IDatabase GetPetaPocoDb(string connectionString)
|
public static IDatabase GetPetaPocoDb(string connectionString, Boolean profiled = true)
|
||||||
{
|
{
|
||||||
MigrationsHelper.Run(connectionString, true);
|
MigrationsHelper.Run(connectionString, true);
|
||||||
|
DbConnection connection = new SQLiteConnection(connectionString);
|
||||||
|
if (profiled)
|
||||||
|
{
|
||||||
|
//connection = ProfiledDbConnection.Get(connection);
|
||||||
|
}
|
||||||
|
|
||||||
var profileConnection = ProfiledDbConnection.Get(new SQLiteConnection(connectionString));
|
var db = new Database(connection);
|
||||||
|
|
||||||
Database.Mapper = new CustomeMapper();
|
if (connection.State != ConnectionState.Open)
|
||||||
var db = new Database(profileConnection);
|
connection.Open();
|
||||||
|
|
||||||
if (profileConnection.State != ConnectionState.Open)
|
|
||||||
profileConnection.Open();
|
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
|
@ -8,12 +9,13 @@ public class MigrationsHelper
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
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)
|
public static void Run(string connetionString, bool trace)
|
||||||
{
|
{
|
||||||
if (IsMigrated) return;
|
if (_migrated.ContainsKey(connetionString)) return;
|
||||||
IsMigrated = true;
|
_migrated.Add(connetionString, string.Empty);
|
||||||
|
|
||||||
Logger.Info("Preparing run database migration");
|
Logger.Info("Preparing run database migration");
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -278,7 +278,7 @@ public virtual string GetValue(string key, object defaultValue)
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
|
|
||||||
var dbValue = _database.SingleOrDefault<Config>(key);
|
var dbValue = _database.SingleOrDefault<Config>("WHERE Key=@0", key);
|
||||||
|
|
||||||
if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value))
|
if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value))
|
||||||
return dbValue.Value;
|
return dbValue.Value;
|
||||||
|
|
Loading…
Reference in a new issue