diff --git a/NzbDrone.Core.Test/EpisodeStatusTest.cs b/NzbDrone.Core.Test/EpisodeStatusTest.cs index 62ae0d2b1..ec7996299 100644 --- a/NzbDrone.Core.Test/EpisodeStatusTest.cs +++ b/NzbDrone.Core.Test/EpisodeStatusTest.cs @@ -70,7 +70,7 @@ namespace NzbDrone.Core.Test .With(e => e.AirDate = DateTime.Now.AddDays(offsetDays)) .With(e => e.Ignored = ignored) .With(e => e.EpisodeFileId = 0) - .With(e => e.GrabDate = DateTime.Now.AddDays(-1)) + .With(e => e.GrabDate = DateTime.Now.AddHours(22)) .Build(); if (hasEpisodes) diff --git a/NzbDrone.Core.Test/FluentTest.cs b/NzbDrone.Core.Test/FluentTest.cs new file mode 100644 index 000000000..41df8fd38 --- /dev/null +++ b/NzbDrone.Core.Test/FluentTest.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using System.Net; +using System.ServiceModel.Syndication; +using AutoMoq; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Indexer; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class FluentTest : TestBase + { + [TestCase(null, "def", "def")] + [TestCase("", "def", "def")] + [TestCase("", 1, "1")] + [TestCase(null, "", "")] + [TestCase("actual", "def", "actual")] + public void WithDefault_success(string actual, object defaultValue, string result) + { + actual.WithDefault(defaultValue).Should().Be(result); + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void WithDefault_Fail() + { + "test".WithDefault(null); + } + + + } +} diff --git a/NzbDrone.Core.Test/Framework/MockLib.cs b/NzbDrone.Core.Test/Framework/MockLib.cs index 4ed4ea6c5..4ebf70d29 100644 --- a/NzbDrone.Core.Test/Framework/MockLib.cs +++ b/NzbDrone.Core.Test/Framework/MockLib.cs @@ -23,17 +23,6 @@ namespace NzbDrone.Core.Test.Framework get { return new[] { "c:\\tv\\the simpsons", "c:\\tv\\family guy", "c:\\tv\\southpark", "c:\\tv\\24" }; } } - public static ConfigProvider StandardConfig - { - get - { - var mock = new Mock(); - mock.SetupGet(c => c.SeriesRoot).Returns("C:\\"); - return mock.Object; - } - } - - public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "") { Console.WriteLine("Creating an empty PetaPoco database"); @@ -83,14 +72,5 @@ namespace NzbDrone.Core.Test.Framework .With(c => c.CleanTitle = Parser.NormalizeTitle(title)) .Build(); } - - public static IList GetFakeEpisodes(int seriesId) - { - var epNumber = new SequentialGenerator(); - return Builder.CreateListOfSize(10) - .WhereAll().Have(c => c.SeriesId = seriesId) - .WhereAll().Have(c => c.EpisodeNumber = epNumber.Generate()) - .Build(); - } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 2181f8ce7..fd96cd025 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -84,6 +84,7 @@ + diff --git a/NzbDrone.Core.Test/SeriesProviderTest.cs b/NzbDrone.Core.Test/SeriesProviderTest.cs index b1eb188ad..1597e4ad8 100644 --- a/NzbDrone.Core.Test/SeriesProviderTest.cs +++ b/NzbDrone.Core.Test/SeriesProviderTest.cs @@ -1,5 +1,4 @@ -// ReSharper disable RedundantUsingDirective -using System; +using System; using System.Linq; using AutoMoq; using FizzWare.NBuilder; @@ -15,11 +14,9 @@ using PetaPoco; using TvdbLib.Data; // ReSharper disable InconsistentNaming - namespace NzbDrone.Core.Test { [TestFixture] - // ReSharper disable InconsistentNaming public class SeriesProviderTest : TestBase { [Test] @@ -130,10 +127,12 @@ namespace NzbDrone.Core.Test var db = MockLib.GetEmptyDatabase(); mocker.SetConstant(db); - var fakeSeries = Builder.CreateNew().With(c => c.QualityProfileId = 1).Build(); + var fakeSeries = Builder.CreateNew() + .With(c => c.QualityProfileId = 1) + .Build(); var fakeQuality = Builder.CreateNew().Build(); - var id = db.Insert(fakeSeries); + db.Insert(fakeSeries); db.Insert(fakeQuality); //Act @@ -141,9 +140,10 @@ namespace NzbDrone.Core.Test var series = mocker.Resolve().GetSeries(1); //Assert - series.ShouldHave().AllPropertiesBut(s => s.QualityProfile, s => s.SeriesId); + series.ShouldHave().AllPropertiesBut(s => s.QualityProfile, s => s.SeriesId).EqualTo(fakeSeries); series.QualityProfile.Should().NotBeNull(); - series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.AllowedString); + series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.SonicAllowed).EqualTo(fakeQuality); + } [Test] @@ -239,8 +239,5 @@ namespace NzbDrone.Core.Test Assert.IsFalse(provider.IsMonitored(11)); Assert.IsFalse(provider.IsMonitored(1)); } - - - } } \ No newline at end of file diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index d1223a5ab..6fce01635 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.MainConnectionString, false)).WhenInjectedInto().InSingletonScope(); + _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto(); + _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto(); _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto().InSingletonScope(); _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto().InRequestScope(); } @@ -76,10 +77,10 @@ namespace NzbDrone.Core private static void BindIndexers() { - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); + _kernel.Bind().To(); + _kernel.Bind().To(); + _kernel.Bind().To(); + _kernel.Bind().To(); var indexers = _kernel.GetAll(); _kernel.Get().InitializeIndexers(indexers.ToList()); @@ -87,15 +88,15 @@ namespace NzbDrone.Core private static void BindJobs() { - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); - _kernel.Bind().To().InTransientScope(); + _kernel.Bind().To().InSingletonScope(); + _kernel.Bind().To().InSingletonScope(); + _kernel.Bind().To().InSingletonScope(); + _kernel.Bind().To().InSingletonScope(); + _kernel.Bind().To().InSingletonScope(); + _kernel.Bind().To().InSingletonScope(); + _kernel.Bind().To().InSingletonScope(); + _kernel.Bind().To().InSingletonScope(); + _kernel.Bind().To().InSingletonScope(); _kernel.Get().Initialize(); _kernel.Get().StartTimer(30); diff --git a/NzbDrone.Core/Datastore/Connection.cs b/NzbDrone.Core/Datastore/Connection.cs index a620e49ee..8749020f1 100644 --- a/NzbDrone.Core/Datastore/Connection.cs +++ b/NzbDrone.Core/Datastore/Connection.cs @@ -47,7 +47,7 @@ namespace NzbDrone.Core.Datastore DbConnection connection = new SQLiteConnection(connectionString); if (profiled) { - //connection = ProfiledDbConnection.Get(connection); + connection = ProfiledDbConnection.Get(connection); } var db = new Database(connection); diff --git a/NzbDrone.Core/Datastore/CustomeMapper.cs b/NzbDrone.Core/Datastore/CustomeMapper.cs index 4e3362aaa..e938aabdb 100644 --- a/NzbDrone.Core/Datastore/CustomeMapper.cs +++ b/NzbDrone.Core/Datastore/CustomeMapper.cs @@ -5,10 +5,10 @@ namespace NzbDrone.Core.Datastore { public class CustomeMapper : DefaultMapper { - public override Func GetFromDbConverter(DestinationInfo destinationInfo, Type SourceType) + public override Func GetFromDbConverter(DestinationInfo destinationInfo, Type sourceType) { - if ((SourceType == typeof(Int32) || SourceType == typeof(Int64)) && destinationInfo.Type.IsGenericType && destinationInfo.Type.GetGenericTypeDefinition() == typeof(Nullable<>)) + if ((sourceType == typeof(Int32) || sourceType == typeof(Int64)) && destinationInfo.Type.IsGenericType && destinationInfo.Type.GetGenericTypeDefinition() == typeof(Nullable<>)) { // If it is NULLABLE, then get the underlying type. eg if "Nullable" then this will return just "int" Type genericArgument = destinationInfo.Type.GetGenericArguments()[0]; @@ -18,31 +18,19 @@ namespace NzbDrone.Core.Datastore { int value; Int32.TryParse(s.ToString(), out value); - if (value == 0) - { - return null; - } - - return (Nullable)value; + return (DayOfWeek?)value; }; } - else - { - return delegate(object s) - { - int value; - Int32.TryParse(s.ToString(), out value); - if (value == 0) - { - return null; - } - return value; - }; - } + return delegate(object s) + { + int value; + Int32.TryParse(s.ToString(), out value); + return value; + }; } - return base.GetFromDbConverter(destinationInfo, SourceType); + return base.GetFromDbConverter(destinationInfo, sourceType); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Fluent.cs b/NzbDrone.Core/Fluent.cs new file mode 100644 index 000000000..ed165e77c --- /dev/null +++ b/NzbDrone.Core/Fluent.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core +{ + public static class Fluent + { + public static string WithDefault(this string actual, object defaultValue) + { + if (defaultValue == null) + throw new ArgumentNullException("defaultValue"); + if (String.IsNullOrWhiteSpace(actual)) + { + return defaultValue.ToString(); + } + + return actual; + } + } +} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index d5188af6d..afcb1b07e 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -165,6 +165,7 @@ + diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 66f2e342c..4be99ddc3 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using Ninject; using NLog; using NzbDrone.Core.Model; @@ -96,7 +97,7 @@ namespace NzbDrone.Core.Providers public virtual void RefreshEpisodeInfo(Series series) { - Logger.Info("Starting episode info refresh for series:{0}", series.SeriesId); + Logger.Info("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); int successCount = 0; int failCount = 0; var tvDbSeriesInfo = _tvDbProvider.GetSeries(series.SeriesId, true); @@ -151,7 +152,7 @@ namespace NzbDrone.Core.Providers catch (Exception e) { Logger.FatalException( - String.Format("An error has occurred while updating episode info for series {0}", series.SeriesId), e); + String.Format("An error has occurred while updating episode info for series {0}", tvDbSeriesInfo.SeriesName), e); failCount++; } } @@ -169,7 +170,7 @@ namespace NzbDrone.Core.Providers } - Logger.Debug("Finished episode refresh for series:{0}. Successful:{1} - Failed:{2} ", + Logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", tvDbSeriesInfo.SeriesName, successCount, failCount); } diff --git a/NzbDrone.Core/Providers/NotificationProvider.cs b/NzbDrone.Core/Providers/NotificationProvider.cs index 88f933d64..aebd6b114 100644 --- a/NzbDrone.Core/Providers/NotificationProvider.cs +++ b/NzbDrone.Core/Providers/NotificationProvider.cs @@ -7,12 +7,12 @@ namespace NzbDrone.Core.Providers { public class NotificationProvider { - private readonly Dictionary _basicNotifications = + private static readonly Dictionary _basicNotifications = new Dictionary(); - private readonly Object _lock = new object(); + private static readonly Object _lock = new object(); - private readonly Dictionary _progressNotification = + private static readonly Dictionary _progressNotification = new Dictionary(); public virtual List BasicNotifications diff --git a/NzbDrone.Web/Global.asax.cs b/NzbDrone.Web/Global.asax.cs index d282897a8..8bec6011c 100644 --- a/NzbDrone.Web/Global.asax.cs +++ b/NzbDrone.Web/Global.asax.cs @@ -41,7 +41,8 @@ namespace NzbDrone.Web //base.OnApplicationStarted(); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); - //RegisterRoutes(RouteTable.Routes); + + Logger.Debug("Fully initialized and ready."); } protected override IKernel CreateKernel() diff --git a/packages/Glimpse.0.81/lib/net40/Glimpse.Net.dll b/packages/Glimpse.0.81/lib/net40/Glimpse.Net.dll deleted file mode 100644 index 11e2e11e9..000000000 Binary files a/packages/Glimpse.0.81/lib/net40/Glimpse.Net.dll and /dev/null differ