From f4a765817bd7134fa3de15529a87e7b1c4088243 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Fri, 17 Jun 2011 19:51:53 -0700 Subject: [PATCH] Fixed some small issues, here and there. --- NzbDrone.Core.Test/ConfigProviderTest.cs | 24 ++++++++++++++++++- NzbDrone.Core.Test/ParserTest.cs | 1 + NzbDrone.Core/CentralDispatch.cs | 3 ++- NzbDrone.Core/Datastore/Connection.cs | 20 +++++++++------- NzbDrone.Core/Datastore/MigrationsHelper.cs | 8 ++++--- .../Providers/Core/ConfigProvider.cs | 2 +- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/NzbDrone.Core.Test/ConfigProviderTest.cs b/NzbDrone.Core.Test/ConfigProviderTest.cs index 342b3e00f..14c93ea98 100644 --- a/NzbDrone.Core.Test/ConfigProviderTest.cs +++ b/NzbDrone.Core.Test/ConfigProviderTest.cs @@ -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().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().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().SetValue(key, value); + mocker.Resolve().SetValue(key, value); + var result = mocker.Resolve().GetValue(key, ""); + + //Assert + result.Should().Be(value); + db.Fetch().Should().HaveCount(1); + } + } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 27e5a8309..0a3812f0a 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -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); diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index e2fa914a7..d1223a5ab 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -68,7 +68,8 @@ namespace NzbDrone.Core _kernel = new StandardKernel(); _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InRequestScope(); - _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto().InSingletonScope(); + _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto().InSingletonScope(); + _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto().InSingletonScope(); _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto().InRequestScope(); } } diff --git a/NzbDrone.Core/Datastore/Connection.cs b/NzbDrone.Core/Datastore/Connection.cs index 2ca526003..a620e49ee 100644 --- a/NzbDrone.Core/Datastore/Connection.cs +++ b/NzbDrone.Core/Datastore/Connection.cs @@ -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; } diff --git a/NzbDrone.Core/Datastore/MigrationsHelper.cs b/NzbDrone.Core/Datastore/MigrationsHelper.cs index cc21db325..ed0249417 100644 --- a/NzbDrone.Core/Datastore/MigrationsHelper.cs +++ b/NzbDrone.Core/Datastore/MigrationsHelper.cs @@ -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 _migrated = new Dictionary(); 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 diff --git a/NzbDrone.Core/Providers/Core/ConfigProvider.cs b/NzbDrone.Core/Providers/Core/ConfigProvider.cs index 6609b3ab1..298cb0738 100644 --- a/NzbDrone.Core/Providers/Core/ConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigProvider.cs @@ -278,7 +278,7 @@ namespace NzbDrone.Core.Providers.Core { string value; - var dbValue = _database.SingleOrDefault(key); + var dbValue = _database.SingleOrDefault("WHERE Key=@0", key); if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value)) return dbValue.Value;