mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Updated restmodule, moved series, root folder to the new restmodule.
This commit is contained in:
parent
4878556e14
commit
a2e84a8f83
16 changed files with 321 additions and 219 deletions
|
@ -1,29 +1,32 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using FluentAssertions;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Api.REST;
|
||||
using RestSharp;
|
||||
|
||||
namespace NzbDrone.Integration.Test.Client
|
||||
{
|
||||
public abstract class ClientBase<TResource> where TResource : new()
|
||||
public class ClientBase<TResource> where TResource : RestResource, new()
|
||||
{
|
||||
private readonly IRestClient _restClient;
|
||||
private readonly string _resource;
|
||||
|
||||
private readonly Logger _logger;
|
||||
|
||||
protected ClientBase(IRestClient restClient, string resource)
|
||||
public ClientBase(IRestClient restClient, string resource = null)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
resource = new TResource().ResourceName;
|
||||
}
|
||||
|
||||
_restClient = restClient;
|
||||
_resource = resource;
|
||||
_logger = LogManager.GetLogger("REST");
|
||||
}
|
||||
|
||||
public List<TResource> GetAll()
|
||||
public List<TResource> All()
|
||||
{
|
||||
var request = BuildRequest();
|
||||
return Get<List<TResource>>(request);
|
||||
|
@ -36,6 +39,12 @@ namespace NzbDrone.Integration.Test.Client
|
|||
return Post<TResource>(request);
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
var request = BuildRequest(id.ToString());
|
||||
Delete(request);
|
||||
}
|
||||
|
||||
public List<string> InvalidPost(TResource body)
|
||||
{
|
||||
var request = BuildRequest();
|
||||
|
@ -63,6 +72,12 @@ namespace NzbDrone.Integration.Test.Client
|
|||
return Execute<T>(request, statusCode);
|
||||
}
|
||||
|
||||
public void Delete(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.OK)
|
||||
{
|
||||
request.Method = Method.DELETE;
|
||||
Execute<object>(request, statusCode);
|
||||
}
|
||||
|
||||
private T Execute<T>(IRestRequest request, HttpStatusCode statusCode) where T : new()
|
||||
{
|
||||
_logger.Info("{0}: {1}", request.Method, _restClient.BuildUri(request));
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace NzbDrone.Integration.Test.Client
|
|||
public class SeriesClient : ClientBase<SeriesResource>
|
||||
{
|
||||
public SeriesClient(IRestClient restClient)
|
||||
: base(restClient, "series")
|
||||
: base(restClient)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -19,4 +19,4 @@ namespace NzbDrone.Integration.Test.Client
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,96 +1,99 @@
|
|||
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 = MainAppContainerBuilder.BuildContainer();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
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.Api.RootFolders;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Integration.Test.Client;
|
||||
using RestSharp;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public abstract class IntegrationTest
|
||||
{
|
||||
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;
|
||||
protected ClientBase<RootFolderResource> RootFolders;
|
||||
|
||||
static IntegrationTest()
|
||||
{
|
||||
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.Info, 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 = MainAppContainerBuilder.BuildContainer();
|
||||
|
||||
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);
|
||||
RootFolders = new ClientBase<RootFolderResource>(RestClient);
|
||||
|
||||
_host.Start();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void SmokeTestTearDown()
|
||||
{
|
||||
_host.Stop();
|
||||
|
||||
_bootstrapper.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -76,9 +76,10 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Client\ClientBase.cs" />
|
||||
<Compile Include="Client\SeriesClient.cs" />
|
||||
<Compile Include="SmokeTestBase.cs" />
|
||||
<Compile Include="IntegrationTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SeriesTest.cs" />
|
||||
<Compile Include="RootFolderIntegrationTest.cs" />
|
||||
<Compile Include="SeriesIntegrationTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\NzbDrone.Test.Common\App.config">
|
||||
|
|
37
NzbDrone.Integration.Test/RootFolderIntegrationTest.cs
Normal file
37
NzbDrone.Integration.Test/RootFolderIntegrationTest.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Api.RootFolders;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class RootFolderIntegrationTest : IntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public void should_have_no_root_folder_initially()
|
||||
{
|
||||
RootFolders.All().Should().BeEmpty();
|
||||
|
||||
var rootFolder = new RootFolderResource
|
||||
{
|
||||
Path = Directory.GetCurrentDirectory()
|
||||
};
|
||||
|
||||
var postResponse = RootFolders.Post(rootFolder);
|
||||
|
||||
postResponse.Id.Should().NotBe(0);
|
||||
postResponse.FreeSpace.Should().NotBe(0);
|
||||
|
||||
RootFolders.All().Should().OnlyContain(c => c.Id == postResponse.Id);
|
||||
|
||||
|
||||
RootFolders.Delete(postResponse.Id);
|
||||
|
||||
RootFolders.All().Should().BeEmpty();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -2,16 +2,17 @@
|
|||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Api.Series;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class SeriesTest : SmokeTestBase
|
||||
public class SeriesIntegrationTest : IntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public void should_have_no_series_on_start_application()
|
||||
{
|
||||
Series.GetAll().Should().BeEmpty();
|
||||
Series.All().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -30,5 +31,14 @@ namespace NzbDrone.Integration.Test
|
|||
errors.Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_add_series()
|
||||
{
|
||||
var series = Series.Lookup("archer").First();
|
||||
|
||||
Series.Post(series);
|
||||
|
||||
Series.All().Should().HaveCount(1);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue