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