2013-06-28 03:03:04 +02:00
|
|
|
|
using System.Collections.Generic;
|
2013-05-04 22:29:24 +02:00
|
|
|
|
using Moq;
|
2013-04-22 05:18:08 +02:00
|
|
|
|
using NLog;
|
|
|
|
|
using NLog.Config;
|
|
|
|
|
using NLog.Targets;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Api;
|
2013-04-27 04:03:34 +02:00
|
|
|
|
using NzbDrone.Api.Commands;
|
2013-04-22 05:18:08 +02:00
|
|
|
|
using NzbDrone.Api.RootFolders;
|
2013-05-11 01:53:50 +02:00
|
|
|
|
using NzbDrone.Common.Composition;
|
2013-06-28 02:04:52 +02:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-05-23 07:12:01 +02:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-04-22 05:18:08 +02:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-05-24 23:28:13 +02:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2013-08-07 07:32:22 +02:00
|
|
|
|
using NzbDrone.Host;
|
|
|
|
|
using NzbDrone.Host.Owin;
|
|
|
|
|
using NzbDrone.Host.Owin.MiddleWare;
|
2013-04-22 05:18:08 +02:00
|
|
|
|
using NzbDrone.Integration.Test.Client;
|
2013-05-22 07:32:25 +02:00
|
|
|
|
using NzbDrone.Test.Common.Categories;
|
2013-04-22 05:18:08 +02:00
|
|
|
|
using RestSharp;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Integration.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-05-22 07:32:25 +02:00
|
|
|
|
[IntegrationTest]
|
2013-04-22 05:18:08 +02:00
|
|
|
|
public abstract class IntegrationTest
|
|
|
|
|
{
|
|
|
|
|
private NancyBootstrapper _bootstrapper;
|
2013-05-04 22:29:24 +02:00
|
|
|
|
private IHostController _hostController;
|
2013-04-22 05:18:08 +02:00
|
|
|
|
protected RestClient RestClient { get; private set; }
|
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetLogger("TEST");
|
|
|
|
|
|
2013-05-11 01:53:50 +02:00
|
|
|
|
protected IContainer Container { get; private set; }
|
2013-04-22 05:18:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected SeriesClient Series;
|
|
|
|
|
protected ClientBase<RootFolderResource> RootFolders;
|
2013-04-27 04:03:34 +02:00
|
|
|
|
protected ClientBase<CommandResource> Commands;
|
2013-04-28 21:46:13 +02:00
|
|
|
|
protected ReleaseClient Releases;
|
2013-05-03 07:24:52 +02:00
|
|
|
|
protected IndexerClient Indexers;
|
2013-04-22 05:18:08 +02:00
|
|
|
|
|
2013-08-06 00:24:54 +02:00
|
|
|
|
private static void ResetLogger()
|
2013-04-22 05:18:08 +02:00
|
|
|
|
{
|
2013-07-12 21:13:16 +02:00
|
|
|
|
LogManager.Configuration = new LoggingConfiguration();
|
|
|
|
|
var consoleTarget = new ConsoleTarget { Layout = "${time} - ${logger} - ${message} ${exception}" };
|
|
|
|
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
|
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
2013-04-22 05:18:08 +02:00
|
|
|
|
|
|
|
|
|
LogManager.ReconfigExistingLoggers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SmokeTestSetup()
|
|
|
|
|
{
|
2013-08-06 00:24:54 +02:00
|
|
|
|
ResetLogger();
|
|
|
|
|
|
2013-07-09 02:47:09 +02:00
|
|
|
|
Container = MainAppContainerBuilder.BuildContainer(new string[0]);
|
2013-07-05 06:43:28 +02:00
|
|
|
|
Container.Register(typeof(IAppFolderInfo), new IntegrationTestFolderInfo());
|
2013-04-22 05:18:08 +02:00
|
|
|
|
|
2013-06-28 03:03:04 +02:00
|
|
|
|
DbFactory.RegisterDatabase(Container);
|
2013-04-22 05:18:08 +02:00
|
|
|
|
|
2013-05-24 23:28:13 +02:00
|
|
|
|
var taskManagerMock = new Mock<ITaskManager>();
|
|
|
|
|
taskManagerMock.Setup(c => c.GetPending()).Returns(new List<ScheduledTask>());
|
|
|
|
|
|
|
|
|
|
Container.TinyContainer.Register(taskManagerMock.Object);
|
|
|
|
|
|
2013-05-11 01:53:50 +02:00
|
|
|
|
_bootstrapper = new NancyBootstrapper(Container.TinyContainer);
|
2013-04-22 05:18:08 +02:00
|
|
|
|
|
|
|
|
|
|
2013-06-28 02:04:52 +02:00
|
|
|
|
var hostConfig = new Mock<IConfigFileProvider>();
|
|
|
|
|
hostConfig.SetupGet(c => c.Port).Returns(1313);
|
2013-04-22 05:18:08 +02:00
|
|
|
|
|
2013-06-28 02:04:52 +02:00
|
|
|
|
_hostController = new OwinHostController(hostConfig.Object, new[] { new NancyMiddleWare(_bootstrapper) }, Logger);
|
2013-05-04 22:29:24 +02:00
|
|
|
|
|
|
|
|
|
|
2013-06-28 02:04:52 +02:00
|
|
|
|
InitRestClients();
|
|
|
|
|
|
|
|
|
|
_hostController.StartServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitRestClients()
|
|
|
|
|
{
|
2013-05-04 22:29:24 +02:00
|
|
|
|
RestClient = new RestClient(_hostController.AppUrl + "/api/");
|
2013-04-22 05:18:08 +02:00
|
|
|
|
Series = new SeriesClient(RestClient);
|
2013-04-28 21:46:13 +02:00
|
|
|
|
Releases = new ReleaseClient(RestClient);
|
2013-04-22 05:18:08 +02:00
|
|
|
|
RootFolders = new ClientBase<RootFolderResource>(RestClient);
|
2013-04-27 04:03:34 +02:00
|
|
|
|
Commands = new ClientBase<CommandResource>(RestClient);
|
2013-05-03 07:24:52 +02:00
|
|
|
|
Indexers = new IndexerClient(RestClient);
|
2013-04-22 05:18:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void SmokeTestTearDown()
|
|
|
|
|
{
|
2013-05-04 22:29:24 +02:00
|
|
|
|
_hostController.StopServer();
|
2013-04-22 05:18:08 +02:00
|
|
|
|
_bootstrapper.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-27 04:03:34 +02:00
|
|
|
|
|
2013-04-22 05:18:08 +02:00
|
|
|
|
}
|