1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-29 11:25:26 +00:00
Radarr/NzbDrone.Integration.Test/IntegrationTest.cs

139 lines
3.7 KiB
C#
Raw Normal View History

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Threading;
using NUnit.Framework;
using NzbDrone.Api.Commands;
using NzbDrone.Api.RootFolders;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Integration.Test.Client;
2013-05-22 05:32:25 +00:00
using NzbDrone.Test.Common.Categories;
using RestSharp;
namespace NzbDrone.Integration.Test
{
[TestFixture]
2013-05-22 05:32:25 +00:00
[IntegrationTest]
public abstract class IntegrationTest
{
protected RestClient RestClient { get; private set; }
protected SeriesClient Series;
protected ClientBase<RootFolderResource> RootFolders;
protected ClientBase<CommandResource> Commands;
protected ReleaseClient Releases;
2013-05-03 05:24:52 +00:00
protected IndexerClient Indexers;
[SetUp]
public void SmokeTestSetup()
{
new StartupArguments();
KillNzbDrone();
InitRestClients();
PackageStart();
}
private static void KillNzbDrone()
{
foreach (var p in Process.GetProcessesByName("NzbDrone.Console"))
{
try
{
p.Kill();
}
catch (Win32Exception)
{
}
}
}
private string AppDate;
private void PackageStart()
{
AppDate = Path.Combine(Directory.GetCurrentDirectory(), "_intg_" + DateTime.Now.Ticks);
Start("..\\..\\..\\..\\_output\\NzbDrone.Console.exe");
2013-08-05 22:24:54 +00:00
while (RestClient.Get(new RestRequest("system/status")).ResponseStatus != ResponseStatus.Completed)
{
Thread.Sleep(1000);
}
}
private Process Start(string path)
{
var args = "-nobrowser -data=\"" + AppDate + "\"";
var startInfo = new ProcessStartInfo(path, args)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
};
Console.WriteLine("Starting {0} {1}", path, args);
var process = new Process
{
StartInfo = startInfo
};
process.OutputDataReceived += (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.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();
return process;
}
private void InitRestClients()
{
RestClient = new RestClient("http://localhost:8989/api");
Series = new SeriesClient(RestClient);
Releases = new ReleaseClient(RestClient);
RootFolders = new ClientBase<RootFolderResource>(RestClient);
Commands = new ClientBase<CommandResource>(RestClient);
2013-05-03 05:24:52 +00:00
Indexers = new IndexerClient(RestClient);
}
[TearDown]
public void SmokeTestTearDown()
{
KillNzbDrone();
}
}
}