added signalR to Integration Test

This commit is contained in:
kayone 2013-11-13 12:08:37 -08:00
parent 47af488e4b
commit 5ab873150e
13 changed files with 136 additions and 54 deletions

View file

@ -1,4 +1,9 @@
using NLog;
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.AspNet.SignalR.Client;
using Microsoft.AspNet.SignalR.Client.Transports;
using NLog;
using NLog.Config;
using NLog.Targets;
using NUnit.Framework;
@ -7,7 +12,9 @@ using NzbDrone.Api.Config;
using NzbDrone.Api.History;
using NzbDrone.Api.RootFolders;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Serializer;
using NzbDrone.Integration.Test.Client;
using NzbDrone.SignalR;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.Categories;
using RestSharp;
@ -30,6 +37,16 @@ namespace NzbDrone.Integration.Test
protected ClientBase<NamingConfigResource> NamingConfig;
private NzbDroneRunner _runner;
private List<SignalRMessage> _signalRReceived;
private Connection _signalrConnection;
protected IEnumerable<SignalRMessage> SignalRMessages
{
get
{
return _signalRReceived;
}
}
public IntegrationTest()
{
@ -71,5 +88,48 @@ namespace NzbDrone.Integration.Test
{
_runner.KillAll();
}
[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());
}
});
while (_signalrConnection.State != ConnectionState.Connected)
{
Console.WriteLine("Connecting to signalR" + _signalrConnection.State);
Thread.Sleep(200);
}
_signalrConnection.Received += json => _signalRReceived.Add(Json.Deserialize<SignalRMessage>(json)); ;
}
}
}