Added smoke test project.

pull/4/head
Keivan Beigi 11 years ago
parent 549b497770
commit d50f23da1c

@ -14,19 +14,19 @@ namespace NzbDrone.App.Test
[Test]
public void should_be_able_to_resolve_event_handlers()
{
ContainerBuilder.Instance.Resolve<IEnumerable<IHandle>>().Should().NotBeEmpty();
ContainerBuilder.BuildNzbDroneContainer().Resolve<IEnumerable<IHandle>>().Should().NotBeEmpty();
}
[Test]
public void should_be_able_to_resolve_indexers()
{
ContainerBuilder.Instance.Resolve<IEnumerable<IIndexerBase>>().Should().NotBeEmpty();
ContainerBuilder.BuildNzbDroneContainer().Resolve<IEnumerable<IIndexerBase>>().Should().NotBeEmpty();
}
[Test]
public void should_be_able_to_resolve_downlodclients()
{
ContainerBuilder.Instance.Resolve<IEnumerable<IDownloadClient>>().Should().NotBeEmpty();
ContainerBuilder.BuildNzbDroneContainer().Resolve<IEnumerable<IDownloadClient>>().Should().NotBeEmpty();
}
}
}

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NzbDrone.Smoke.Test</RootNamespace>
<AssemblyName>NzbDrone.Smoke.Test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Exceptron.Client">
<HintPath>..\packages\Exceptron.Client.1.0.20\lib\net20\Exceptron.Client.dll</HintPath>
</Reference>
<Reference Include="Exceptron.NLog">
<HintPath>..\packages\Exceptron.NLog.1.0.11\lib\net20\Exceptron.NLog.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions">
<HintPath>..\packages\FluentAssertions.2.0.1\lib\net40\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="Nancy.Hosting.Self">
<HintPath>..\packages\Nancy.Hosting.Self.0.16.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="RestSharp">
<HintPath>..\packages\RestSharp.104.1\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SmokeTestBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SmokeTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\NzbDrone.Test.Common\App.config">
<Link>App.config</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NzbDrone.Api\NzbDrone.Api.csproj">
<Project>{FD286DF8-2D3A-4394-8AD5-443FADE55FB2}</Project>
<Name>NzbDrone.Api</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
<Project>{f2be0fdf-6e47-4827-a420-dd4ef82407f8}</Project>
<Name>NzbDrone.Common</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
<Project>{ff5ee3b6-913b-47ce-9ceb-11c51b4e1205}</Project>
<Name>NzbDrone.Core</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone.Test.Common\NzbDrone.Test.Common.csproj">
<Project>{CADDFCE0-7509-4430-8364-2074E1EEFCA2}</Project>
<Name>NzbDrone.Test.Common</Name>
</ProjectReference>
<ProjectReference Include="..\NzbDrone\NzbDrone.csproj">
<Project>{d12f7f2f-8a3c-415f-88fa-6dd061a84869}</Project>
<Name>NzbDrone</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="..\Libraries\Sqlite\sqlite3.dll">
<Link>sqlite3.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NzbDrone.Smoke.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NzbDrone.Smoke.Test")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8a49cb1d-87ac-42f9-a582-607365a6bd79")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,27 @@
using System.Collections.Generic;
using NUnit.Framework;
using NzbDrone.Api.Series;
using RestSharp;
namespace NzbDrone.Smoke.Test
{
[TestFixture]
public class SmokeTest : SmokeTestBase
{
[Test]
public void start_application()
{
Get<List<SeriesResource>>(new RestRequest("series"));
}
[Test]
[Ignore]
public void add_series_without_required_fields_should_return_400()
{
var addSeriesRequest = new RestRequest("series") { RequestFormat = DataFormat.Json };
addSeriesRequest.AddBody(new SeriesResource());
Post<SeriesResource>(addSeriesRequest);
}
}
}

@ -0,0 +1,124 @@
using System;
using System.IO;
using System.Net;
using FluentAssertions;
using NLog;
using NLog.Config;
using NLog.Targets;
using NUnit.Framework;
using Nancy.Hosting.Self;
using NzbDrone.Api;
using NzbDrone.Common;
using RestSharp;
using TinyIoC;
namespace NzbDrone.Smoke.Test
{
[TestFixture]
public abstract class SmokeTestBase
{
private TinyNancyBootstrapper _bootstrapper;
private NancyHost _host;
protected RestClient RestClient { get; private set; }
private static readonly Logger RestLogger = LogManager.GetLogger("REST: ");
private static readonly Logger Logger = LogManager.GetLogger("TEST: ");
private EnvironmentProvider _environmentProvider;
protected TinyIoCContainer Container { get; private set; }
static SmokeTestBase()
{
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
{
LogManager.Configuration = new LoggingConfiguration();
var consoleTarget = new ConsoleTarget { Layout = "${message} ${exception}" };
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));
}
LogManager.ReconfigExistingLoggers();
}
[SetUp]
public void SmokeTestSetup()
{
_environmentProvider = new EnvironmentProvider();
if (Directory.Exists(_environmentProvider.GetAppDataPath()))
{
Directory.Delete(_environmentProvider.GetAppDataPath(), true);
}
Logger.Info("Working Folder: {0}", _environmentProvider.WorkingDirectory);
Logger.Info("Data Folder: {0}", _environmentProvider.GetAppDataPath());
Logger.Info("DB Path: {0}", _environmentProvider.GetNzbDroneDatabase());
Container = ContainerBuilder.BuildNzbDroneContainer();
_bootstrapper = new TinyNancyBootstrapper(Container);
const string url = "http://localhost:1313";
_host = new NancyHost(new Uri(url), _bootstrapper);
RestClient = new RestClient(url + "/api/");
_host.Start();
}
[TearDown]
public void SmokeTestTearDown()
{
_host.Stop();
}
protected T Get<T>(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.OK) where T : class,new()
{
RestLogger.Info("GET: {0}", RestClient.BuildUri(request));
var response = RestClient.Get<T>(request);
RestLogger.Info("Response: {0}", response.Content);
if (response.ErrorException != null)
{
throw response.ErrorException;
}
response.ErrorMessage.Should().BeBlank();
response.StatusCode.Should().Be(statusCode);
return response.Data;
}
protected T Post<T>(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.Created) where T : class,new()
{
RestLogger.Info("POST: {0}", RestClient.BuildUri(request));
var response = RestClient.Post<T>(request);
RestLogger.Info("Response: {0}", response.Content);
if (response.ErrorException != null)
{
throw response.ErrorException;
}
response.ErrorMessage.Should().BeBlank();
response.StatusCode.Should().Be(statusCode);
return response.Data;
}
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Exceptron.Client" version="1.0.20" targetFramework="net40" />
<package id="Exceptron.NLog" version="1.0.11" targetFramework="net40" />
<package id="FluentAssertions" version="2.0.1" targetFramework="net40" />
<package id="Nancy" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
<package id="NLog" version="2.0.1.2" targetFramework="net40" />
<package id="NUnit" version="2.6.2" targetFramework="net40" />
<package id="RestSharp" version="104.1" targetFramework="net40" />
</packages>

@ -31,9 +31,6 @@ namespace NzbDrone.Update
builder.RegisterAssemblyTypes(typeof(RestProvider).Assembly).SingleInstance();
_container = builder.Build();
ReportingService.RestProvider = _container.Resolve<RestProvider>();
logger.Info("Updating NzbDrone to version {0}", _container.Resolve<EnvironmentProvider>().Version);
_container.Resolve<Program>().Start(args);
}

@ -48,6 +48,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marr.Data", "Marr.Data\Marr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Libraries.Test", "NzbDrone.Libraries.Test\NzbDrone.Libraries.Test.csproj", "{CBF6B8B0-A015-413A-8C86-01238BB45770}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Smoke.Test", "NzbDrone.Smoke.Test\NzbDrone.Smoke.Test.csproj", "{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -258,6 +260,16 @@ Global
{CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|x86.ActiveCfg = Release|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|x86.ActiveCfg = Debug|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Any CPU.Build.0 = Release|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -270,6 +282,7 @@ Global
{BEC74619-DDBB-4FBA-B517-D3E20AFC9997} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{D18A5DEB-5102-4775-A1AF-B75DAAA8907B} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{CBF6B8B0-A015-413A-8C86-01238BB45770} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB} = {57A04B72-8088-4F75-A582-1158CF8291F7}
{FAFB5948-A222-4CF6-AD14-026BE7564802} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}
{CADDFCE0-7509-4430-8364-2074E1EEFCA2} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97}
{6BCE712F-846D-4846-9D1B-A66B858DA755} = {F9E67978-5CD6-4A5F-827B-4249711C0B02}

@ -41,7 +41,9 @@ namespace NzbDrone
return;
}
ContainerBuilder.Instance.Resolve<Router>().Route(args);
var container = ContainerBuilder.BuildNzbDroneContainer();
container.Resolve<Router>().Route(args);
}
catch (Exception e)
{

@ -21,18 +21,20 @@ namespace NzbDrone
public static class ContainerBuilder
{
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilder");
public static TinyIoCContainer Instance { get; private set; }
private static readonly List<Type> NzbDroneTypes;
static ContainerBuilder()
{
var container = new TinyIoCContainer();
NzbDroneTypes = new List<Type>();
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone").GetTypes());
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Common").GetTypes());
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Core").GetTypes());
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Api").GetTypes());
}
public static TinyIoCContainer BuildNzbDroneContainer()
{
var container = new TinyIoCContainer();
container.AutoRegisterInterfaces();
@ -48,7 +50,9 @@ namespace NzbDrone
container.InitDatabase();
Instance = container;
ReportingService.RestProvider = container.Resolve<RestProvider>();
return container;
}
private static void InitDatabase(this TinyIoCContainer container)
@ -58,7 +62,7 @@ namespace NzbDrone
//TODO: move this to factory
var environmentProvider = new EnvironmentProvider();
var appDataPath = environmentProvider.GetAppDataPath();
if (!Directory.Exists(appDataPath))
{
Directory.CreateDirectory(appDataPath);

@ -119,7 +119,6 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="ContainerBuilder.cs" />
<Compile Include="NzbDroneBootstrapper.cs" />
<Compile Include="ApplicationMode.cs" />
<Compile Include="AppMain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

@ -1,28 +0,0 @@
using NLog;
using NzbDrone.Common;
using TinyIoC;
using NzbDrone.Core;
using NzbDrone.Api;
namespace NzbDrone
{
public static class NzbDroneBootstrapper
{
private static readonly Logger logger = LogManager.GetLogger("NzbDroneBootstrapper");
static NzbDroneBootstrapper()
{
InitializeApp();
}
private static void InitializeApp()
{
var environmentProvider = ContainerBuilder.Instance.Resolve<EnvironmentProvider>();
ReportingService.RestProvider = ContainerBuilder.Instance.Resolve<RestProvider>();
logger.Info("Start-up Path:'{0}'", environmentProvider.WorkingDirectory);
}
}
}
Loading…
Cancel
Save