2013-08-13 05:08:37 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
using NUnit.Framework;
|
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-06-28 00:04:52 +00:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
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
|
|
|
|
|
{
|
|
|
|
|
protected RestClient RestClient { get; private set; }
|
|
|
|
|
|
|
|
|
|
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-13 05:08:37 +00:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SmokeTestSetup()
|
2013-04-22 03:18:08 +00:00
|
|
|
|
{
|
2013-08-13 05:08:37 +00:00
|
|
|
|
new StartupArguments();
|
|
|
|
|
|
|
|
|
|
KillNzbDrone();
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
InitRestClients();
|
|
|
|
|
|
|
|
|
|
PackageStart();
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
private static void KillNzbDrone()
|
|
|
|
|
{
|
|
|
|
|
foreach (var p in Process.GetProcessesByName("NzbDrone.Console"))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
p.Kill();
|
|
|
|
|
}
|
|
|
|
|
catch (Win32Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
private string AppDate;
|
|
|
|
|
|
|
|
|
|
private void PackageStart()
|
2013-04-22 03:18:08 +00:00
|
|
|
|
{
|
2013-08-13 05:08:37 +00:00
|
|
|
|
AppDate = Path.Combine(Directory.GetCurrentDirectory(), "_intg_" + DateTime.Now.Ticks);
|
|
|
|
|
|
|
|
|
|
Start("..\\..\\..\\..\\_output\\NzbDrone.Console.exe");
|
2013-08-05 22:24:54 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
while (RestClient.Get(new RestRequest("system/status")).ResponseStatus != ResponseStatus.Completed)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
private Process Start(string path)
|
|
|
|
|
{
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
var args = "-nobrowser -data=\"" + AppDate + "\"";
|
2013-05-24 21:28:13 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
var startInfo = new ProcessStartInfo(path, args)
|
|
|
|
|
{
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
RedirectStandardError = true,
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
};
|
2013-05-24 21:28:13 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
Console.WriteLine("Starting {0} {1}", path, args);
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
var process = new Process
|
|
|
|
|
{
|
|
|
|
|
StartInfo = startInfo
|
|
|
|
|
};
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
process.OutputDataReceived += (sender, eventArgs) =>
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(eventArgs.Data)) return;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
if (eventArgs.Data.Contains("Press enter to exit"))
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail("Process waiting for input");
|
|
|
|
|
}
|
2013-05-04 20:29:24 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
Console.WriteLine(eventArgs.Data);
|
|
|
|
|
};
|
2013-05-04 20:29:24 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
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();
|
2013-06-28 00:04:52 +00:00
|
|
|
|
|
2013-08-13 05:08:37 +00:00
|
|
|
|
return process;
|
2013-06-28 00:04:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitRestClients()
|
|
|
|
|
{
|
2013-08-13 05:08:37 +00:00
|
|
|
|
RestClient = new RestClient("http://localhost:8989/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-08-13 05:08:37 +00:00
|
|
|
|
KillNzbDrone();
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-27 02:03:34 +00:00
|
|
|
|
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|