1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

fixed some broken tests.

This commit is contained in:
Keivan Beigi 2013-02-18 17:57:08 -08:00
parent acaa05c9c0
commit 324b5e3b80
19 changed files with 95 additions and 135 deletions

View File

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

View File

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

View File

@ -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" />

View File

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

View File

@ -9,7 +9,7 @@
namespace NzbDrone.Common.Test
{
[TestFixture]
public class EnviromentProviderTest : TestBase
public class EnvironmentProviderTest : TestBase
{
readonly EnvironmentProvider environmentProvider = new EnvironmentProvider();

View File

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

View File

@ -75,34 +75,7 @@ public virtual bool IsUserInteractive
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)

View File

@ -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" />

View File

@ -10,14 +10,14 @@ public class SysTrayApp : Form
{
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;

View File

@ -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.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 @@ public void no_missing_epsiodes_should_not_trigger_any_search()
.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 @@ public void individual_missing_episode()
.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 @@ public void individual_missing_episodes_only()
.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 @@ public void series_season_missing_episodes_only_mismatch_count()
.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 @@ public void series_season_missing_episodes_only()
.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 @@ public void multiple_missing_episodes()
.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 @@ public void GetMissingForEnabledSeries_should_only_return_episodes_for_monitored
.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 @@ public void GetMissingForEnabledSeries_should_only_return_explicity_enabled_seri
.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 @@ public void GetMissingForEnabledSeries_should_return_explicity_enabled_and_inher
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
//Act
var result = Mocker.Resolve<BacklogSearchJob>().GetMissingForEnabledSeries();
var result = Subject.GetMissingForEnabledSeries();
//Assert
result.Should().NotBeEmpty();

View File

@ -22,11 +22,7 @@ public static class ContainerExtentions
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 @@ public static void RegisterCoreServices(this ContainerBuilder containerBuilder)
}
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)))

View File

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

View File

@ -75,8 +75,13 @@ public void TestBaseTearDown()
}
[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.");

View File

@ -125,7 +125,7 @@ public void should_stop_orphan_iisexpress_instances()
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]

View File

@ -12,11 +12,11 @@ public class UpdateProvider
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;

View File

@ -15,13 +15,13 @@ public class ApplicationServer : ServiceBase
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)

View File

@ -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 @@ public static IContainer Container
{
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 @@ private static void InitilizeApp()
LogConfiguration.RegisterUdpLogger();
LogConfiguration.RegisterRemote();
LogConfiguration.Reload();
Logger.Info("Start-up Path:'{0}'", environmentProvider.ApplicationPath);
logger.Info("Start-up Path:'{0}'", environmentProvider.ApplicationPath);
}
}
}

View File

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

View File

@ -12,7 +12,7 @@ public class MonitoringProvider
{
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 @@ public class MonitoringProvider
private Timer _pingTimer;
private Timer _processPriorityCheckTimer;
public MonitoringProvider(ProcessProvider processProvider, HostController hostController,
public MonitoringProvider(ProcessProvider processProvider, IHostController hostController,
HttpProvider httpProvider, ConfigFileProvider configFileProvider)
{
_processProvider = processProvider;