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