1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Integration.Test/IntegrationTest.cs

102 lines
3.2 KiB
C#
Raw Normal View History

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