|
|
@ -1,20 +1,12 @@
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System;
|
|
|
|
using Moq;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using NLog;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using NLog.Config;
|
|
|
|
using System.IO;
|
|
|
|
using NLog.Targets;
|
|
|
|
using System.Threading;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Api;
|
|
|
|
|
|
|
|
using NzbDrone.Api.Commands;
|
|
|
|
using NzbDrone.Api.Commands;
|
|
|
|
using NzbDrone.Api.RootFolders;
|
|
|
|
using NzbDrone.Api.RootFolders;
|
|
|
|
using NzbDrone.Common.Composition;
|
|
|
|
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
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;
|
|
|
|
using NzbDrone.Integration.Test.Client;
|
|
|
|
using NzbDrone.Test.Common.Categories;
|
|
|
|
using NzbDrone.Test.Common.Categories;
|
|
|
|
using RestSharp;
|
|
|
|
using RestSharp;
|
|
|
@ -25,64 +17,110 @@ namespace NzbDrone.Integration.Test
|
|
|
|
[IntegrationTest]
|
|
|
|
[IntegrationTest]
|
|
|
|
public abstract class IntegrationTest
|
|
|
|
public abstract class IntegrationTest
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private NancyBootstrapper _bootstrapper;
|
|
|
|
|
|
|
|
private IHostController _hostController;
|
|
|
|
|
|
|
|
protected RestClient RestClient { get; private set; }
|
|
|
|
protected RestClient RestClient { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetLogger("TEST");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected IContainer Container { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected SeriesClient Series;
|
|
|
|
protected SeriesClient Series;
|
|
|
|
protected ClientBase<RootFolderResource> RootFolders;
|
|
|
|
protected ClientBase<RootFolderResource> RootFolders;
|
|
|
|
protected ClientBase<CommandResource> Commands;
|
|
|
|
protected ClientBase<CommandResource> Commands;
|
|
|
|
protected ReleaseClient Releases;
|
|
|
|
protected ReleaseClient Releases;
|
|
|
|
protected IndexerClient Indexers;
|
|
|
|
protected IndexerClient Indexers;
|
|
|
|
|
|
|
|
|
|
|
|
private static void ResetLogger()
|
|
|
|
[SetUp]
|
|
|
|
|
|
|
|
public void SmokeTestSetup()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LogManager.Configuration = new LoggingConfiguration();
|
|
|
|
new StartupArguments();
|
|
|
|
var consoleTarget = new ConsoleTarget { Layout = "${time} - ${logger} - ${message} ${exception}" };
|
|
|
|
|
|
|
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
|
|
|
KillNzbDrone();
|
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LogManager.ReconfigExistingLoggers();
|
|
|
|
InitRestClients();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PackageStart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void KillNzbDrone()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var p in Process.GetProcessesByName("NzbDrone.Console"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
p.Kill();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Win32Exception)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
private string AppDate;
|
|
|
|
public void SmokeTestSetup()
|
|
|
|
|
|
|
|
|
|
|
|
private void PackageStart()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ResetLogger();
|
|
|
|
AppDate = Path.Combine(Directory.GetCurrentDirectory(), "_intg_" + DateTime.Now.Ticks);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Start("..\\..\\..\\..\\_output\\NzbDrone.Console.exe");
|
|
|
|
|
|
|
|
|
|
|
|
Container = MainAppContainerBuilder.BuildContainer(new string[0]);
|
|
|
|
while (RestClient.Get(new RestRequest("system/status")).ResponseStatus != ResponseStatus.Completed)
|
|
|
|
Container.Register(typeof(IAppFolderInfo), new IntegrationTestFolderInfo());
|
|
|
|
{
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DbFactory.RegisterDatabase(Container);
|
|
|
|
private Process Start(string path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var taskManagerMock = new Mock<ITaskManager>();
|
|
|
|
var args = "-nobrowser -data=\"" + AppDate + "\"";
|
|
|
|
taskManagerMock.Setup(c => c.GetPending()).Returns(new List<ScheduledTask>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Container.TinyContainer.Register(taskManagerMock.Object);
|
|
|
|
var startInfo = new ProcessStartInfo(path, args)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
|
|
|
RedirectStandardError = true,
|
|
|
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_bootstrapper = new NancyBootstrapper(Container.TinyContainer);
|
|
|
|
Console.WriteLine("Starting {0} {1}", path, args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var process = new Process
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
StartInfo = startInfo
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var hostConfig = new Mock<IConfigFileProvider>();
|
|
|
|
process.OutputDataReceived += (sender, eventArgs) =>
|
|
|
|
hostConfig.SetupGet(c => c.Port).Returns(1313);
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(eventArgs.Data)) return;
|
|
|
|
|
|
|
|
|
|
|
|
_hostController = new OwinHostController(hostConfig.Object, new[] { new NancyMiddleWare(_bootstrapper) }, Logger);
|
|
|
|
if (eventArgs.Data.Contains("Press enter to exit"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Assert.Fail("Process waiting for input");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(eventArgs.Data);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
InitRestClients();
|
|
|
|
process.ErrorDataReceived += (sender, eventArgs) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(eventArgs.Data)) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (eventArgs.Data.Contains("Press enter to exit"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Assert.Fail("Process waiting for input");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(eventArgs.Data);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process.Start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process.BeginErrorReadLine();
|
|
|
|
|
|
|
|
process.BeginOutputReadLine();
|
|
|
|
|
|
|
|
|
|
|
|
_hostController.StartServer();
|
|
|
|
return process;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InitRestClients()
|
|
|
|
private void InitRestClients()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RestClient = new RestClient(_hostController.AppUrl + "/api/");
|
|
|
|
RestClient = new RestClient("http://localhost:8989/api");
|
|
|
|
Series = new SeriesClient(RestClient);
|
|
|
|
Series = new SeriesClient(RestClient);
|
|
|
|
Releases = new ReleaseClient(RestClient);
|
|
|
|
Releases = new ReleaseClient(RestClient);
|
|
|
|
RootFolders = new ClientBase<RootFolderResource>(RestClient);
|
|
|
|
RootFolders = new ClientBase<RootFolderResource>(RestClient);
|
|
|
@ -93,8 +131,7 @@ namespace NzbDrone.Integration.Test
|
|
|
|
[TearDown]
|
|
|
|
[TearDown]
|
|
|
|
public void SmokeTestTearDown()
|
|
|
|
public void SmokeTestTearDown()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_hostController.StopServer();
|
|
|
|
KillNzbDrone();
|
|
|
|
_bootstrapper.Shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|