diff --git a/NzbDrone.Api/ApiContainerExtensions.cs b/NzbDrone.Api/ApiContainerExtensions.cs new file mode 100644 index 000000000..01ca85966 --- /dev/null +++ b/NzbDrone.Api/ApiContainerExtensions.cs @@ -0,0 +1,16 @@ +using System.Linq; +using Autofac; +using Nancy.Bootstrapper; +using NzbDrone.Common; + +namespace NzbDrone.Api +{ + public static class ApiContainerExtensions + { + public static void RegisterApiServices(this ContainerBuilder containerBuilder) + { + containerBuilder.RegisterAssemblyTypes("NzbDrone.Api"); + containerBuilder.RegisterType().As(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/ContainerExtentions.cs b/NzbDrone.Api/ContainerExtentions.cs deleted file mode 100644 index f75c23271..000000000 --- a/NzbDrone.Api/ContainerExtentions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Linq; -using System.Reflection; -using Autofac; - -namespace NzbDrone.Api -{ - public static class ContainerExtensions - { - public static void RegisterApiServices(this ContainerBuilder containerBuilder) - { - var apiAssembly = Assembly.Load("NzbDrone.Api"); - - - containerBuilder.RegisterAssemblyTypes(apiAssembly) - .AsImplementedInterfaces() - .SingleInstance(); - - containerBuilder.RegisterAssemblyTypes(apiAssembly) - .AsSelf() - .SingleInstance(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 43ee52e58..91e91a67f 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -108,7 +108,7 @@ - + diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index 8f2d7723c..5af7bfb77 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -57,10 +57,6 @@ False ..\packages\Autofac.3.0.1\lib\net40\Autofac.dll - - False - ..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll - ..\packages\NBuilder.3.0.1.1\lib\FizzWare.NBuilder.dll @@ -82,9 +78,6 @@ - - - @@ -106,10 +99,6 @@ {CADDFCE0-7509-4430-8364-2074E1EEFCA2} NzbDrone.Test.Common - - {FAFB5948-A222-4CF6-AD14-026BE7564802} - NzbDrone.Test.Dummy - {D12F7F2F-8A3C-415F-88FA-6DD061A84869} NzbDrone diff --git a/NzbDrone.Common.Test/EnviromentProviderTest.cs b/NzbDrone.Common.Test/EnviromentProviderTest.cs index f6367e1d8..7b4eca09e 100644 --- a/NzbDrone.Common.Test/EnviromentProviderTest.cs +++ b/NzbDrone.Common.Test/EnviromentProviderTest.cs @@ -9,7 +9,7 @@ using NzbDrone.Test.Common; namespace NzbDrone.Common.Test { [TestFixture] - public class EnviromentProviderTest : TestBase + public class EnvironmentProviderTest : TestBase { readonly EnvironmentProvider environmentProvider = new EnvironmentProvider(); diff --git a/NzbDrone.Common/CommonContainerExtentions.cs b/NzbDrone.Common/CommonContainerExtentions.cs new file mode 100644 index 000000000..10e2cf192 --- /dev/null +++ b/NzbDrone.Common/CommonContainerExtentions.cs @@ -0,0 +1,33 @@ +using System; +using System.Linq; +using System.Reflection; +using Autofac; + +namespace NzbDrone.Common +{ + public static class CommonContainerExtensions + { + public static void RegisterCommonServices(this ContainerBuilder containerBuilder) + { + containerBuilder.RegisterAssemblyTypes("NzbDrone.Common"); + } + + public static void RegisterAssemblyTypes(this ContainerBuilder containerBuilder, string assemblyName) + { + var apiAssembly = Assembly.Load(assemblyName); + + if (apiAssembly == null) + { + throw new ApplicationException("Couldn't load assembly " + assemblyName); + } + + containerBuilder.RegisterAssemblyTypes(apiAssembly) + .AsImplementedInterfaces() + .SingleInstance(); + + containerBuilder.RegisterAssemblyTypes(apiAssembly) + .AsSelf() + .SingleInstance(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Common/EnvironmentProvider.cs b/NzbDrone.Common/EnvironmentProvider.cs index 90a6f32c5..f8c9da547 100644 --- a/NzbDrone.Common/EnvironmentProvider.cs +++ b/NzbDrone.Common/EnvironmentProvider.cs @@ -75,34 +75,7 @@ namespace NzbDrone.Common public virtual string ApplicationPath { - get - { - - if(IsMono) - { - return AppDomain.CurrentDomain.BaseDirectory; - } - - string applicationPath; - - applicationPath = CrawlToRoot(StartUpPath); - if (!string.IsNullOrWhiteSpace(applicationPath)) - return applicationPath; - - applicationPath = CrawlToRoot(Environment.CurrentDirectory); - if (!string.IsNullOrWhiteSpace(applicationPath)) - return applicationPath; - - applicationPath = CrawlToRoot(AppDomain.CurrentDomain.BaseDirectory); - if (!string.IsNullOrWhiteSpace(applicationPath)) - return applicationPath; - - applicationPath = CrawlToRoot(NzbDronePathFromEnvironment); - if (!string.IsNullOrWhiteSpace(applicationPath)) - return applicationPath; - - throw new ApplicationException("Can't finds IISExpress folder."); - } + get { return Directory.GetCurrentDirectory(); } } public string CrawlToRoot(string dir) diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index a534c94dc..db9143e3c 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -89,6 +89,7 @@ + diff --git a/NzbDrone.Common/SysTray/SysTrayApp.cs b/NzbDrone.Common/SysTray/SysTrayApp.cs index 0b0d844dc..eda39fa22 100644 --- a/NzbDrone.Common/SysTray/SysTrayApp.cs +++ b/NzbDrone.Common/SysTray/SysTrayApp.cs @@ -10,14 +10,14 @@ namespace NzbDrone.Common.SysTray { private readonly ConfigFileProvider _configFileProvider; private readonly ProcessProvider _processProvider; - private readonly HostController _hostController; + private readonly IHostController _hostController; private readonly EnvironmentProvider _environmentProvider; private readonly NotifyIcon _trayIcon = new NotifyIcon(); private readonly ContextMenu _trayMenu = new ContextMenu(); public SysTrayApp(ConfigFileProvider configFileProvider, ProcessProvider processProvider, - HostController hostController, EnvironmentProvider environmentProvider) + IHostController hostController, EnvironmentProvider environmentProvider) { _configFileProvider = configFileProvider; _processProvider = processProvider; diff --git a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs index 7362c71d3..3613d3147 100644 --- a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; - using FizzWare.NBuilder; using FluentAssertions; using Moq; @@ -13,12 +12,11 @@ using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; -using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test.JobTests { [TestFixture] - public class BacklogSearchJobTest : CoreTest + public class BacklogSearchJobTest : CoreTest { private void WithEnableBacklogSearching() { @@ -40,7 +38,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act - Mocker.Resolve().Start(notification, null); + Subject.Start(notification, null); //Assert Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), @@ -75,7 +73,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") == 1))); //Act - Mocker.Resolve().Start(notification, null); + Subject.Start(notification, null); //Assert Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), @@ -104,7 +102,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act - Mocker.Resolve().Start(notification, null); + Subject.Start(notification, null); //Assert Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), @@ -137,7 +135,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); //Act - Mocker.Resolve().Start(notification, null); + Subject.Start(notification, null); //Assert Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), @@ -171,10 +169,10 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList()); //Act - Mocker.Resolve().Start(notification, null); + Subject.Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0 && + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0 && d.GetPropertyValue("SeasonNumber") >= 0)), Times.Once()); } @@ -213,7 +211,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5 }); //Act - Mocker.Resolve().Start(notification, null); + Subject.Start(notification, null); //Assert Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0 && @@ -251,7 +249,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act - var result = Mocker.Resolve().GetMissingForEnabledSeries(); + var result = Subject.GetMissingForEnabledSeries(); //Assert result.Should().NotBeEmpty(); @@ -290,7 +288,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act - var result = Mocker.Resolve().GetMissingForEnabledSeries(); + var result = Subject.GetMissingForEnabledSeries(); //Assert result.Should().NotBeEmpty(); @@ -330,7 +328,7 @@ namespace NzbDrone.Core.Test.JobTests .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); //Act - var result = Mocker.Resolve().GetMissingForEnabledSeries(); + var result = Subject.GetMissingForEnabledSeries(); //Assert result.Should().NotBeEmpty(); diff --git a/NzbDrone.Core/ContainerExtentions.cs b/NzbDrone.Core/ContainerExtentions.cs index e04950fe4..133c2b4da 100644 --- a/NzbDrone.Core/ContainerExtentions.cs +++ b/NzbDrone.Core/ContainerExtentions.cs @@ -22,11 +22,7 @@ namespace NzbDrone.Core public static void RegisterCoreServices(this ContainerBuilder containerBuilder) { - var core = Assembly.Load("NzbDrone.Core"); - var common = Assembly.Load("NzbDrone.Common"); - - containerBuilder.RegisterAssembly(core); - containerBuilder.RegisterAssembly(common); + containerBuilder.RegisterAssembly("NzbDrone.Core"); containerBuilder.InitDatabase(); @@ -34,17 +30,12 @@ namespace NzbDrone.Core } - private static void RegisterAssembly(this ContainerBuilder container, Assembly assembly) + private static void RegisterAssembly(this ContainerBuilder container, string assemblyName) { - logger.Info("Registering Services from {0}", assembly.FullName); - container.RegisterAssemblyTypes(assembly) - .AsSelf() - .SingleInstance(); + container.RegisterAssemblyTypes(assemblyName); - container.RegisterAssemblyTypes(assembly) - .AsImplementedInterfaces() - .SingleInstance(); + var assembly = Assembly.Load(assemblyName); container.RegisterAssemblyTypes(assembly) .Where(t => t.IsSubclassOf(typeof(IndexerBase))) diff --git a/NzbDrone.Core/Lifecycle/AppRestartJob.cs b/NzbDrone.Core/Lifecycle/AppRestartJob.cs index 954946b9c..33643e5ae 100644 --- a/NzbDrone.Core/Lifecycle/AppRestartJob.cs +++ b/NzbDrone.Core/Lifecycle/AppRestartJob.cs @@ -9,11 +9,11 @@ namespace NzbDrone.Core.Lifecycle { public class AppRestartJob : IJob { - private readonly HostController _hostController; + private readonly IHostController _hostController; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public AppRestartJob(HostController hostController) + public AppRestartJob(IHostController hostController) { _hostController = hostController; } diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index da7192230..580f34014 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -75,8 +75,13 @@ namespace NzbDrone.Test.Common } + [Obsolete("Use Mock.Verify() instead")] protected void WithStrictMocker() { + return; + + //TODO: Remove dependency on restrict mocks! + if (_mocker != null) throw new InvalidOperationException("Can not switch to a strict container after container has been used. make sure this is the first call in your test."); diff --git a/NzbDrone.Update.Test/UpdateProviderStartFixture.cs b/NzbDrone.Update.Test/UpdateProviderStartFixture.cs index d32b3c0e1..4ed2fe116 100644 --- a/NzbDrone.Update.Test/UpdateProviderStartFixture.cs +++ b/NzbDrone.Update.Test/UpdateProviderStartFixture.cs @@ -125,7 +125,7 @@ namespace NzbDrone.Update.Test Mocker.Resolve().Start(TARGET_FOLDER); //Assert - Mocker.GetMock().Verify(c => c.StopServer(), Times.Once()); + Mocker.GetMock().Verify(c => c.StopServer(), Times.Once()); } [Test] diff --git a/NzbDrone.Update/Providers/UpdateProvider.cs b/NzbDrone.Update/Providers/UpdateProvider.cs index 7ff6ff3e1..ef13ebc01 100644 --- a/NzbDrone.Update/Providers/UpdateProvider.cs +++ b/NzbDrone.Update/Providers/UpdateProvider.cs @@ -12,11 +12,11 @@ namespace NzbDrone.Update.Providers private readonly ServiceProvider _serviceProvider; private readonly ProcessProvider _processProvider; private readonly EnvironmentProvider _environmentProvider; - private readonly HostController _hostController; + private readonly IHostController _hostController; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public UpdateProvider(DiskProvider diskProvider, ServiceProvider serviceProvider, - ProcessProvider processProvider, EnvironmentProvider environmentProvider, HostController hostController) + ProcessProvider processProvider, EnvironmentProvider environmentProvider, IHostController hostController) { _diskProvider = diskProvider; _serviceProvider = serviceProvider; diff --git a/NzbDrone/ApplicationServer.cs b/NzbDrone/ApplicationServer.cs index a7dd39d57..5c9c4044b 100644 --- a/NzbDrone/ApplicationServer.cs +++ b/NzbDrone/ApplicationServer.cs @@ -15,13 +15,13 @@ namespace NzbDrone private readonly ConfigFileProvider _configFileProvider; private readonly EnvironmentProvider _environmentProvider; - private readonly HostController _hostController; + private readonly IHostController _hostController; private readonly ProcessProvider _processProvider; private readonly MonitoringProvider _monitoringProvider; private readonly SecurityProvider _securityProvider; private readonly DiskProvider _diskProvider; - public ApplicationServer(ConfigFileProvider configFileProvider, HostController hostController, + public ApplicationServer(ConfigFileProvider configFileProvider, IHostController hostController, EnvironmentProvider environmentProvider, ProcessProvider processProvider, MonitoringProvider monitoringProvider, SecurityProvider securityProvider, DiskProvider diskProvider) diff --git a/NzbDrone/CentralDispatch.cs b/NzbDrone/CentralDispatch.cs index 32bca4775..d70984b83 100644 --- a/NzbDrone/CentralDispatch.cs +++ b/NzbDrone/CentralDispatch.cs @@ -1,23 +1,21 @@ using Autofac; using NLog; -using Nancy.Bootstrapper; using NzbDrone.Api; using NzbDrone.Common; using NzbDrone.Core.Instrumentation; -using NzbDrone.Providers; namespace NzbDrone { public static class CentralDispatch { - private static IContainer _container; - private static readonly Logger Logger = LogManager.GetLogger("Host.CentralDispatch"); + private static readonly IContainer container; + private static readonly Logger logger = LogManager.GetLogger("Host.CentralDispatch"); static CentralDispatch() { var builder = new ContainerBuilder(); BindKernel(builder); - _container = builder.Build(); + container = builder.Build(); InitilizeApp(); } @@ -25,35 +23,24 @@ namespace NzbDrone { get { - return _container; + return container; } } private static void BindKernel(ContainerBuilder builder) { - builder.RegisterAssemblyTypes(typeof(DiskProvider).Assembly).SingleInstance(); - builder.RegisterType(); - builder.RegisterModule(); - - builder.RegisterType().As().SingleInstance(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().SingleInstance(); + builder.RegisterCommonServices(); + builder.RegisterApiServices(); + builder.RegisterAssemblyTypes("NzbDrone"); } private static void InitilizeApp() { - var environmentProvider = _container.Resolve(); - - ReportingService.RestProvider = _container.Resolve(); + var environmentProvider = container.Resolve(); + + ReportingService.RestProvider = container.Resolve(); ReportingService.SetupExceptronDriver(); LogConfiguration.RegisterRollingFileLogger(environmentProvider.GetLogFileName(), LogLevel.Info); @@ -61,7 +48,7 @@ namespace NzbDrone LogConfiguration.RegisterUdpLogger(); LogConfiguration.RegisterRemote(); LogConfiguration.Reload(); - Logger.Info("Start-up Path:'{0}'", environmentProvider.ApplicationPath); + logger.Info("Start-up Path:'{0}'", environmentProvider.ApplicationPath); } } } diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 21b7fbe94..935b5f5d3 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -68,16 +68,6 @@ False ..\packages\Autofac.3.0.1\lib\net40\Autofac.dll - - False - ..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll - - - True - - - True - ..\packages\Nancy.0.16.1\lib\net40\Nancy.dll diff --git a/NzbDrone/Providers/MonitoringProvider.cs b/NzbDrone/Providers/MonitoringProvider.cs index ddb289231..e7e06a5da 100644 --- a/NzbDrone/Providers/MonitoringProvider.cs +++ b/NzbDrone/Providers/MonitoringProvider.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Providers { private static readonly Logger logger = LogManager.GetLogger("Host.MonitoringProvider"); - private readonly HostController _hostController; + private readonly IHostController _hostController; private readonly ProcessProvider _processProvider; private readonly HttpProvider _httpProvider; private readonly ConfigFileProvider _configFileProvider; @@ -21,7 +21,7 @@ namespace NzbDrone.Providers private Timer _pingTimer; private Timer _processPriorityCheckTimer; - public MonitoringProvider(ProcessProvider processProvider, HostController hostController, + public MonitoringProvider(ProcessProvider processProvider, IHostController hostController, HttpProvider httpProvider, ConfigFileProvider configFileProvider) { _processProvider = processProvider;