fixed some broken tests.

pull/4/head
Keivan Beigi 12 years ago
parent acaa05c9c0
commit 324b5e3b80

@ -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<NancyBootstrapper>().As<INancyBootstrapper>();
}
}
}

@ -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();
}
}
}

@ -108,7 +108,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AutomapperBootstraper.cs" />
<Compile Include="ContainerExtentions.cs" />
<Compile Include="ApiContainerExtensions.cs" />
<Compile Include="Directories\DirectoryModule.cs" />
<Compile Include="Extentions\NancyJsonSerializer.cs" />
<Compile Include="Extentions\Serializer.cs" />

@ -57,10 +57,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.dll</HintPath>
</Reference>
<Reference Include="Autofac.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="FizzWare.NBuilder, Version=3.0.1.0, Culture=neutral, PublicKeyToken=5651b03e12e42c12, processorArchitecture=MSIL">
<HintPath>..\packages\NBuilder.3.0.1.1\lib\FizzWare.NBuilder.dll</HintPath>
</Reference>
@ -82,9 +78,6 @@
<Reference Include="System.Core" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
@ -106,10 +99,6 @@
<Project>{CADDFCE0-7509-4430-8364-2074E1EEFCA2}</Project>
<Name>NzbDrone.Test.Common</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj">
<Project>{FAFB5948-A222-4CF6-AD14-026BE7564802}</Project>
<Name>NzbDrone.Test.Dummy</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone\NzbDrone.csproj">
<Project>{D12F7F2F-8A3C-415F-88FA-6DD061A84869}</Project>
<Name>NzbDrone</Name>

@ -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();

@ -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();
}
}
}

@ -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)

@ -89,6 +89,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="CommonContainerExtentions.cs" />
<Compile Include="EnsureThat\Ensure.cs" />
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" />
<Compile Include="EnsureThat\EnsureCollectionExtensions.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;

@ -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<BacklogSearchJob>
{
private void WithEnableBacklogSearching()
{
@ -40,7 +38,7 @@ namespace NzbDrone.Core.Test.JobTests
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
//Act
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
Subject.Start(notification, null);
//Assert
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = It.IsAny<int>() }),
@ -75,7 +73,7 @@ namespace NzbDrone.Core.Test.JobTests
.Setup(s => s.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") == 1)));
//Act
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
Subject.Start(notification, null);
//Assert
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") >= 0)),
@ -104,7 +102,7 @@ namespace NzbDrone.Core.Test.JobTests
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
//Act
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
Subject.Start(notification, null);
//Assert
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") >= 0)),
@ -137,7 +135,7 @@ namespace NzbDrone.Core.Test.JobTests
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
//Act
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
Subject.Start(notification, null);
//Assert
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("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<BacklogSearchJob>().Start(notification, null);
Subject.Start(notification, null);
//Assert
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") >= 0 &&
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") >= 0 &&
d.GetPropertyValue<int>("SeasonNumber") >= 0)),
Times.Once());
}
@ -213,7 +211,7 @@ namespace NzbDrone.Core.Test.JobTests
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5 });
//Act
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
Subject.Start(notification, null);
//Assert
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") >= 0 &&
@ -251,7 +249,7 @@ namespace NzbDrone.Core.Test.JobTests
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
//Act
var result = Mocker.Resolve<BacklogSearchJob>().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<BacklogSearchJob>().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<BacklogSearchJob>().GetMissingForEnabledSeries();
var result = Subject.GetMissingForEnabledSeries();
//Assert
result.Should().NotBeEmpty();

@ -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)))

@ -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;
}

@ -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.");

@ -125,7 +125,7 @@ namespace NzbDrone.Update.Test
Mocker.Resolve<UpdateProvider>().Start(TARGET_FOLDER);
//Assert
Mocker.GetMock<HostController>().Verify(c => c.StopServer(), Times.Once());
Mocker.GetMock<IHostController>().Verify(c => c.StopServer(), Times.Once());
}
[Test]

@ -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;

@ -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)

@ -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<Router>();
builder.RegisterModule<LogInjectionModule>();
builder.RegisterType<NancyBootstrapper>().As<INancyBootstrapper>().SingleInstance();
builder.RegisterType<ApplicationServer>().SingleInstance();
builder.RegisterType<ConfigFileProvider>().SingleInstance();
builder.RegisterType<ConsoleProvider>().SingleInstance();
builder.RegisterType<EnvironmentProvider>().SingleInstance();
builder.RegisterType<HostController>().SingleInstance();
builder.RegisterType<MonitoringProvider>().SingleInstance();
builder.RegisterType<ProcessProvider>().SingleInstance();
builder.RegisterType<ServiceProvider>().SingleInstance();
builder.RegisterType<HttpProvider>().SingleInstance();
builder.RegisterCommonServices();
builder.RegisterApiServices();
builder.RegisterAssemblyTypes("NzbDrone");
}
private static void InitilizeApp()
{
var environmentProvider = _container.Resolve<EnvironmentProvider>();
ReportingService.RestProvider = _container.Resolve<RestProvider>();
var environmentProvider = container.Resolve<EnvironmentProvider>();
ReportingService.RestProvider = container.Resolve<RestProvider>();
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);
}
}
}

@ -68,16 +68,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.dll</HintPath>
</Reference>
<Reference Include="Autofac.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference>

@ -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;

Loading…
Cancel
Save