2013-04-22 03:18:08 +00:00
|
|
|
|
using System;
|
2013-05-24 21:28:13 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
using System.IO;
|
2013-05-04 21:09:25 +00:00
|
|
|
|
using System.Linq;
|
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;
|
|
|
|
|
using NzbDrone.Common;
|
2013-05-10 23:53:50 +00:00
|
|
|
|
using NzbDrone.Common.Composition;
|
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-04-22 03:18:08 +00:00
|
|
|
|
using NzbDrone.Integration.Test.Client;
|
2013-05-04 21:09:25 +00:00
|
|
|
|
using NzbDrone.Owin;
|
|
|
|
|
using NzbDrone.Owin.MiddleWare;
|
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
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
Container.Register(c => c.Resolve<IDbFactory>().Create(dbPath));
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SmokeTestSetup()
|
|
|
|
|
{
|
|
|
|
|
Container = MainAppContainerBuilder.BuildContainer();
|
|
|
|
|
|
|
|
|
|
InitDatabase();
|
|
|
|
|
|
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-05-10 23:53:50 +00:00
|
|
|
|
var _hostConfig = new Mock<IConfigFileProvider>();
|
2013-05-04 20:29:24 +00:00
|
|
|
|
_hostConfig.SetupGet(c => c.Port).Returns(1313);
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-05-04 21:09:25 +00:00
|
|
|
|
_hostController = new OwinHostController(_hostConfig.Object, new[] { new NancyMiddleWare(_bootstrapper) }, Logger);
|
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
|
|
|
|
|
2013-05-04 20:29:24 +00:00
|
|
|
|
_hostController.StartServer();
|
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
|
|
|
|
}
|