2013-04-22 03:18:08 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NLog.Config;
|
|
|
|
|
using NLog.Targets;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Nancy.Hosting.Self;
|
|
|
|
|
using NzbDrone.Api;
|
2013-04-27 02:03:34 +00:00
|
|
|
|
using NzbDrone.Api.Commands;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
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;
|
2013-04-27 02:03:34 +00:00
|
|
|
|
protected ClientBase<CommandResource> Commands;
|
2013-04-28 19:46:13 +00:00
|
|
|
|
protected ReleaseClient Releases;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
|
|
|
|
static IntegrationTest()
|
|
|
|
|
{
|
|
|
|
|
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
|
|
|
|
|
{
|
|
|
|
|
LogManager.Configuration = new LoggingConfiguration();
|
2013-04-28 19:46:13 +00:00
|
|
|
|
var consoleTarget = new ConsoleTarget { Layout = "${time} - ${logger} - ${message} ${exception}" };
|
2013-04-22 03:18:08 +00:00
|
|
|
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
2013-04-28 19:46:13 +00:00
|
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2013-04-28 19:46:13 +00:00
|
|
|
|
Releases = new ReleaseClient(RestClient);
|
2013-04-22 03:18:08 +00:00
|
|
|
|
RootFolders = new ClientBase<RootFolderResource>(RestClient);
|
2013-04-27 02:03:34 +00:00
|
|
|
|
Commands = new ClientBase<CommandResource>(RestClient);
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
|
|
|
|
_host.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void SmokeTestTearDown()
|
|
|
|
|
{
|
|
|
|
|
_host.Stop();
|
|
|
|
|
|
|
|
|
|
_bootstrapper.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-27 02:03:34 +00:00
|
|
|
|
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|