mirror of
https://github.com/Radarr/Radarr
synced 2024-12-25 01:11:43 +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);
|
||||
|
||||
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 @@ public void Get_value_should_return_default_when_no_value()
|
|||
}
|
||||
|
||||
[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 @@ public void New_value_should_update_old_value()
|
|||
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("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 @@ public static void BindKernel()
|
|||
_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 @@ public static class Connection
|
|||
static Connection()
|
||||
{
|
||||
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);
|
||||
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();
|
||||
var db = new Database(profileConnection);
|
||||
|
||||
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 @@ public class MigrationsHelper
|
|||
{
|
||||
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 @@ public virtual string GetValue(string key, object defaultValue)
|
|||
{
|
||||
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…
Reference in a new issue