2013-11-13 20:08:37 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Microsoft.AspNet.SignalR.Client;
|
|
|
|
|
using Microsoft.AspNet.SignalR.Client.Transports;
|
|
|
|
|
using NLog;
|
2013-08-14 05:02:25 +00:00
|
|
|
|
using NLog.Config;
|
|
|
|
|
using NLog.Targets;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
using NUnit.Framework;
|
2013-04-27 02:03:34 +00:00
|
|
|
|
using NzbDrone.Api.Commands;
|
2013-08-28 00:16:24 +00:00
|
|
|
|
using NzbDrone.Api.Config;
|
2013-09-10 05:39:18 +00:00
|
|
|
|
using NzbDrone.Api.History;
|
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-11-13 20:08:37 +00:00
|
|
|
|
using NzbDrone.Common.Serializer;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
using NzbDrone.Integration.Test.Client;
|
2013-11-13 20:08:37 +00:00
|
|
|
|
using NzbDrone.SignalR;
|
2013-11-12 03:25:54 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
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-09-10 05:39:18 +00:00
|
|
|
|
protected ClientBase<HistoryResource> History;
|
2013-05-03 05:24:52 +00:00
|
|
|
|
protected IndexerClient Indexers;
|
2013-08-27 03:20:03 +00:00
|
|
|
|
protected EpisodeClient Episodes;
|
2013-08-28 00:16:24 +00:00
|
|
|
|
protected ClientBase<NamingConfigResource> NamingConfig;
|
2013-12-19 08:38:28 +00:00
|
|
|
|
protected NotificationClient Notifications;
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-14 03:22:28 +00:00
|
|
|
|
private NzbDroneRunner _runner;
|
2013-11-13 20:08:37 +00:00
|
|
|
|
private List<SignalRMessage> _signalRReceived;
|
|
|
|
|
private Connection _signalrConnection;
|
|
|
|
|
|
2014-09-02 04:02:55 +00:00
|
|
|
|
|
|
|
|
|
protected static readonly string RootUrl = "http://localhost:8989/";
|
|
|
|
|
|
2013-11-13 20:08:37 +00:00
|
|
|
|
protected IEnumerable<SignalRMessage> SignalRMessages
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _signalRReceived;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-14 03:22:28 +00:00
|
|
|
|
|
2013-08-14 05:02:25 +00:00
|
|
|
|
public IntegrationTest()
|
|
|
|
|
{
|
2013-11-26 06:53:36 +00:00
|
|
|
|
new StartupContext();
|
2013-08-14 05:02:25 +00:00
|
|
|
|
|
|
|
|
|
LogManager.Configuration = new LoggingConfiguration();
|
|
|
|
|
var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" };
|
|
|
|
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
|
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 06:18:57 +00:00
|
|
|
|
[TestFixtureSetUp]
|
|
|
|
|
//[SetUp]
|
2013-08-13 05:08:37 +00:00
|
|
|
|
public void SmokeTestSetup()
|
2013-04-22 03:18:08 +00:00
|
|
|
|
{
|
2013-08-14 03:22:28 +00:00
|
|
|
|
_runner = new NzbDroneRunner();
|
|
|
|
|
_runner.KillAll();
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-08-14 03:22:28 +00:00
|
|
|
|
_runner.Start();
|
2013-09-21 02:07:42 +00:00
|
|
|
|
InitRestClients();
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
|
|
// Add Wombles
|
|
|
|
|
var wombles = Indexers.Post(new Api.Indexers.IndexerResource
|
|
|
|
|
{
|
2014-08-18 02:25:00 +00:00
|
|
|
|
EnableRss = true,
|
2014-04-19 15:09:22 +00:00
|
|
|
|
ConfigContract = "NullConfig",
|
|
|
|
|
Implementation = "Wombles",
|
|
|
|
|
Name = "Wombles",
|
|
|
|
|
Protocol = Core.Indexers.DownloadProtocol.Usenet,
|
|
|
|
|
Fields = new List<Api.ClientSchema.Field>()
|
|
|
|
|
});
|
2013-08-13 05:08:37 +00:00
|
|
|
|
}
|
2013-04-22 03:18:08 +00:00
|
|
|
|
|
2013-06-28 00:04:52 +00:00
|
|
|
|
private void InitRestClients()
|
|
|
|
|
{
|
2014-09-02 04:02:55 +00:00
|
|
|
|
RestClient = new RestClient(RootUrl + "api/");
|
2013-09-21 02:07:42 +00:00
|
|
|
|
Series = new SeriesClient(RestClient, _runner.ApiKey);
|
|
|
|
|
Releases = new ReleaseClient(RestClient, _runner.ApiKey);
|
|
|
|
|
RootFolders = new ClientBase<RootFolderResource>(RestClient, _runner.ApiKey);
|
|
|
|
|
Commands = new ClientBase<CommandResource>(RestClient, _runner.ApiKey);
|
|
|
|
|
History = new ClientBase<HistoryResource>(RestClient, _runner.ApiKey);
|
|
|
|
|
Indexers = new IndexerClient(RestClient, _runner.ApiKey);
|
|
|
|
|
Episodes = new EpisodeClient(RestClient, _runner.ApiKey);
|
|
|
|
|
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, _runner.ApiKey, "config/naming");
|
2013-12-19 08:38:28 +00:00
|
|
|
|
Notifications = new NotificationClient(RestClient, _runner.ApiKey);
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 06:18:57 +00:00
|
|
|
|
[TestFixtureTearDown]
|
|
|
|
|
//[TearDown]
|
2013-04-22 03:18:08 +00:00
|
|
|
|
public void SmokeTestTearDown()
|
|
|
|
|
{
|
2013-08-14 03:22:28 +00:00
|
|
|
|
_runner.KillAll();
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|
2013-11-13 20:08:37 +00:00
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void IntegrationSetup()
|
|
|
|
|
{
|
|
|
|
|
if (_signalrConnection != null)
|
|
|
|
|
{
|
|
|
|
|
switch (_signalrConnection.State)
|
|
|
|
|
{
|
|
|
|
|
case ConnectionState.Connected:
|
|
|
|
|
case ConnectionState.Connecting:
|
|
|
|
|
{
|
|
|
|
|
_signalrConnection.Stop();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_signalrConnection = null;
|
|
|
|
|
_signalRReceived = new List<SignalRMessage>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void ConnectSignalR()
|
|
|
|
|
{
|
|
|
|
|
_signalRReceived = new List<SignalRMessage>();
|
|
|
|
|
_signalrConnection = new Connection("http://localhost:8989/signalr");
|
|
|
|
|
_signalrConnection.Start(new LongPollingTransport()).ContinueWith(task =>
|
|
|
|
|
{
|
|
|
|
|
if (task.IsFaulted)
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail("SignalrConnection failed. {0}", task.Exception.GetBaseException());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-11-13 20:27:27 +00:00
|
|
|
|
var retryCount = 0;
|
2013-11-13 20:08:37 +00:00
|
|
|
|
|
|
|
|
|
while (_signalrConnection.State != ConnectionState.Connected)
|
|
|
|
|
{
|
2013-11-13 20:27:27 +00:00
|
|
|
|
if (retryCount > 25)
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail("Couldn't establish signalr connection. State: {0}", _signalrConnection.State);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retryCount++;
|
|
|
|
|
Console.WriteLine("Connecting to signalR" + _signalrConnection.State);
|
2013-11-13 20:08:37 +00:00
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_signalrConnection.Received += json => _signalRReceived.Add(Json.Deserialize<SignalRMessage>(json)); ;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 03:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|