mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
cleaned up integration test project.
This commit is contained in:
parent
d50f23da1c
commit
9cabe7cf90
16 changed files with 270 additions and 161 deletions
78
NzbDrone.Integration.Test/Client/ClientBase.cs
Normal file
78
NzbDrone.Integration.Test/Client/ClientBase.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using FluentAssertions;
|
||||
using NLog;
|
||||
using RestSharp;
|
||||
|
||||
namespace NzbDrone.Integration.Test.Client
|
||||
{
|
||||
public abstract class ClientBase<TResource> where TResource : new()
|
||||
{
|
||||
private readonly IRestClient _restClient;
|
||||
private readonly string _resource;
|
||||
|
||||
private readonly Logger _logger;
|
||||
|
||||
protected ClientBase(IRestClient restClient, string resource)
|
||||
{
|
||||
_restClient = restClient;
|
||||
_resource = resource;
|
||||
_logger = LogManager.GetLogger("REST");
|
||||
}
|
||||
|
||||
public List<TResource> GetAll()
|
||||
{
|
||||
var request = BuildRequest();
|
||||
return Get<List<TResource>>(request);
|
||||
}
|
||||
|
||||
public TResource Post(TResource body)
|
||||
{
|
||||
var request = BuildRequest();
|
||||
request.AddBody(body);
|
||||
return Post<TResource>(request);
|
||||
}
|
||||
|
||||
protected RestRequest BuildRequest(string command = "")
|
||||
{
|
||||
return new RestRequest(_resource + "/" + command.Trim('/'))
|
||||
{
|
||||
RequestFormat = DataFormat.Json
|
||||
};
|
||||
}
|
||||
|
||||
protected T Get<T>(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.OK) where T : new()
|
||||
{
|
||||
request.Method = Method.GET;
|
||||
return Execute<T>(request, statusCode);
|
||||
}
|
||||
|
||||
public T Post<T>(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.Created) where T : new()
|
||||
{
|
||||
request.Method = Method.POST;
|
||||
return Execute<T>(request, statusCode);
|
||||
}
|
||||
|
||||
private T Execute<T>(IRestRequest request, HttpStatusCode statusCode) where T : new()
|
||||
{
|
||||
_logger.Info("{0}: {1}", request.Method, _restClient.BuildUri(request));
|
||||
|
||||
var response = _restClient.Execute<T>(request);
|
||||
|
||||
_logger.Info("Response: {0}", response.Content);
|
||||
|
||||
if (response.ErrorException != null)
|
||||
{
|
||||
throw response.ErrorException;
|
||||
}
|
||||
|
||||
response.ErrorMessage.Should().BeBlank();
|
||||
|
||||
|
||||
response.StatusCode.Should().Be(statusCode);
|
||||
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
22
NzbDrone.Integration.Test/Client/SeriesClient.cs
Normal file
22
NzbDrone.Integration.Test/Client/SeriesClient.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System.Collections.Generic;
|
||||
using NzbDrone.Api.Series;
|
||||
using RestSharp;
|
||||
|
||||
namespace NzbDrone.Integration.Test.Client
|
||||
{
|
||||
public class SeriesClient : ClientBase<SeriesResource>
|
||||
{
|
||||
public SeriesClient(IRestClient restClient)
|
||||
: base(restClient, "series")
|
||||
{
|
||||
}
|
||||
|
||||
public List<SeriesResource> Lookup(string term)
|
||||
{
|
||||
var request = BuildRequest("lookup?term={term}");
|
||||
request.AddUrlSegment("term", term);
|
||||
return Get<List<SeriesResource>>(request);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
118
NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj
Normal file
118
NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?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.Integration.Test</RootNamespace>
|
||||
<AssemblyName>NzbDrone.Integration.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="Client\ClientBase.cs" />
|
||||
<Compile Include="Client\SeriesClient.cs" />
|
||||
<Compile Include="SmokeTestBase.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SeriesTest.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>
|
36
NzbDrone.Integration.Test/Properties/AssemblyInfo.cs
Normal file
36
NzbDrone.Integration.Test/Properties/AssemblyInfo.cs
Normal file
|
@ -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")]
|
33
NzbDrone.Integration.Test/SeriesTest.cs
Normal file
33
NzbDrone.Integration.Test/SeriesTest.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Api.Series;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class SeriesTest : SmokeTestBase
|
||||
{
|
||||
[Test]
|
||||
public void should_have_no_series_on_start_application()
|
||||
{
|
||||
Series.GetAll().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void series_lookup_on_trakt()
|
||||
{
|
||||
var series = Series.Lookup("archer");
|
||||
|
||||
series.Should().NotBeEmpty();
|
||||
series.Should().Contain(c => c.Title == "Archer (2009)");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore]
|
||||
public void add_series_without_required_fields_should_return_400()
|
||||
{
|
||||
Series.Post(new SeriesResource());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
96
NzbDrone.Integration.Test/SmokeTestBase.cs
Normal file
96
NzbDrone.Integration.Test/SmokeTestBase.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using NUnit.Framework;
|
||||
using Nancy.Hosting.Self;
|
||||
using NzbDrone.Api;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Integration.Test.Client;
|
||||
using RestSharp;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public abstract class SmokeTestBase
|
||||
{
|
||||
private NancyBootstrapper _bootstrapper;
|
||||
private NancyHost _host;
|
||||
protected RestClient RestClient { get; private set; }
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetLogger("TEST");
|
||||
|
||||
protected TinyIoCContainer Container { get; private set; }
|
||||
|
||||
|
||||
protected SeriesClient Series;
|
||||
|
||||
static SmokeTestBase()
|
||||
{
|
||||
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
|
||||
{
|
||||
LogManager.Configuration = new LoggingConfiguration();
|
||||
var consoleTarget = new ConsoleTarget { Layout = "${logger} - ${message} ${exception}" };
|
||||
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));
|
||||
}
|
||||
|
||||
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
|
||||
private void InitDatabase()
|
||||
{
|
||||
Logger.Info("Registering Database...");
|
||||
|
||||
//TODO: move this to factory
|
||||
var environmentProvider = new EnvironmentProvider();
|
||||
var appDataPath = environmentProvider.GetAppDataPath();
|
||||
|
||||
if (!Directory.Exists(appDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(appDataPath);
|
||||
}
|
||||
|
||||
var dbPath = Path.Combine(environmentProvider.WorkingDirectory, DateTime.Now.Ticks + ".db");
|
||||
|
||||
|
||||
Logger.Info("Working Folder: {0}", environmentProvider.WorkingDirectory);
|
||||
Logger.Info("Data Folder: {0}", environmentProvider.GetAppDataPath());
|
||||
Logger.Info("DB Na: {0}", dbPath);
|
||||
|
||||
|
||||
Container.Register((c, p) => c.Resolve<IDbFactory>().Create(dbPath));
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SmokeTestSetup()
|
||||
{
|
||||
Container = ContainerBuilder.BuildNzbDroneContainer();
|
||||
|
||||
InitDatabase();
|
||||
|
||||
_bootstrapper = new NancyBootstrapper(Container);
|
||||
|
||||
const string url = "http://localhost:1313";
|
||||
|
||||
_host = new NancyHost(new Uri(url), _bootstrapper);
|
||||
|
||||
RestClient = new RestClient(url + "/api/");
|
||||
Series = new SeriesClient(RestClient);
|
||||
|
||||
_host.Start();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void SmokeTestTearDown()
|
||||
{
|
||||
_host.Stop();
|
||||
|
||||
_bootstrapper.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
11
NzbDrone.Integration.Test/packages.config
Normal file
11
NzbDrone.Integration.Test/packages.config
Normal file
|
@ -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>
|
Loading…
Add table
Add a link
Reference in a new issue