Skip to content

Commit

Permalink
Created a Tests Common project that contains common code for unit and…
Browse files Browse the repository at this point in the history
… functional tests.

- Also began copying over necessary files from other projects such as
the functionaltests proj.
  • Loading branch information
NTaylorMullen committed Dec 15, 2012
1 parent 0c7723e commit 53498e2
Show file tree
Hide file tree
Showing 25 changed files with 987 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Microsoft.AspNet.SignalR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Owin.Hosting", "katana\src\Microsoft.Owin.Hosting\Microsoft.Owin.Hosting.csproj", "{C225EB2E-E7A7-463F-B058-1705F204978E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Owin.Samples", "samples\Microsoft.AspNet.Owin.Samples\Microsoft.AspNet.Owin.Samples.csproj", "{5D69B6BE-062B-408D-913E-5CD2F21D5D17}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.SignalR.Tests.Common", "tests\Microsoft.AspNet.SignalR.Tests.Common\Microsoft.AspNet.SignalR.Tests.Common.csproj", "{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}"
EndProject
Global
Expand Down Expand Up @@ -570,13 +571,17 @@ Global
{5D69B6BE-062B-408D-913E-5CD2F21D5D17}.Release|x86.ActiveCfg = Release|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Debug|ARM.ActiveCfg = Debug|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Debug|x64.ActiveCfg = Debug|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Debug|x86.ActiveCfg = Debug|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Release|Any CPU.Build.0 = Release|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Release|ARM.ActiveCfg = Release|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Release|x64.ActiveCfg = Release|Any CPU
{F18A8896-10BD-469E-9AA1-AEBACEF4D7B7}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Configuration;
using System.Web;
using System.Web.Routing;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;

[assembly: PreApplicationStartMethod(typeof(Microsoft.AspNet.SignalR.FunctionalTests.Infrastructure.IIS.RegisterHubs), "Start")]

namespace Microsoft.AspNet.SignalR.FunctionalTests.Infrastructure.IIS
{
public static class RegisterHubs
{
public static void Start()
{
string keepAliveRaw = ConfigurationManager.AppSettings["keepAlive"];
string connectionTimeoutRaw = ConfigurationManager.AppSettings["connectionTimeout"];
string disconnectTimeoutRaw = ConfigurationManager.AppSettings["disconnectTimeout"];
string heartbeatIntervalRaw = ConfigurationManager.AppSettings["heartbeatInterval"];
string enableRejoiningGroupsRaw = ConfigurationManager.AppSettings["enableRejoiningGroups"];

int keepAlive;
if (Int32.TryParse(keepAliveRaw, out keepAlive))
{
GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(keepAlive);
}
else
{
GlobalHost.Configuration.KeepAlive = null;
}

int connectionTimeout;
if (Int32.TryParse(connectionTimeoutRaw, out connectionTimeout))
{
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(connectionTimeout);
}

int disconnectTimeout;
if (Int32.TryParse(disconnectTimeoutRaw, out disconnectTimeout))
{
GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(disconnectTimeout);
}

int heartbeatInterval;
if (Int32.TryParse(heartbeatIntervalRaw, out heartbeatInterval))
{
GlobalHost.Configuration.HeartbeatInterval = TimeSpan.FromSeconds(heartbeatInterval);
}

bool enableRejoiningGroups;
if (Boolean.TryParse(enableRejoiningGroupsRaw, out enableRejoiningGroups) &&
enableRejoiningGroups)
{
GlobalHost.HubPipeline.EnableAutoRejoiningGroups();
}

// Register the default hubs route: ~/signalr/hubs
RouteTable.Routes.MapHubs();
RouteTable.Routes.MapConnection<MyBadConnection>("errors-are-fun", "ErrorsAreFun/{*operation}");
RouteTable.Routes.MapConnection<MyGroupEchoConnection>("group-echo", "group-echo/{*operation}");
RouteTable.Routes.MapConnection<MySendingConnection>("multisend", "multisend/{*operation}");
RouteTable.Routes.MapConnection<MyReconnect>("my-reconnect", "my-reconnect/{*operation}");
RouteTable.Routes.MapConnection<MyGroupConnection>("groups", "groups/{*operation}");
RouteTable.Routes.MapConnection<MyRejoinGroupsConnection>("rejoin-groups", "rejoin-groups/{*operation}");
RouteTable.Routes.MapConnection<FilteredConnection>("filter", "filter/{*operation}");
RouteTable.Routes.MapConnection<ConnectionThatUsesItems>("items", "items/{*operation}");
RouteTable.Routes.MapConnection<SyncErrorConnection>("sync-error", "sync-error/{*operation}");

// End point to hit to verify the webserver is up
RouteTable.Routes.Add("test-endpoint", new Route("ping", new TestEndPoint()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Web;
using System.Web.Routing;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class TestEndPoint : IRouteHandler, IHttpHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return this;
}

public bool IsReusable
{
get
{
return false;
}
}

public void ProcessRequest(HttpContext context)
{
context.Response.Write("Pong");
}
}
}
21 changes: 21 additions & 0 deletions tests/Microsoft.AspNet.SignalR.Tests.Common/Build/StartIISTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.AspNet.SignalR.FunctionalTests.Infrastructure;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.AspNet.SignalR.Tests.Common
{
public class StartIISTask : Task
{
[Required]
public ITaskItem[] HostLocation { get; set; }

public override bool Execute()
{
var myHost = new IISExpressTestHost(HostLocation[0].ToString());

myHost.Initialize(15, 120, 10, 1, false);

return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class ConnectionThatUsesItems : PersistentConnection
{
protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
return PrintEnvironment("OnConnectedAsync", request, connectionId);
}

protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
{
return PrintEnvironment("OnReceivedAsync", request, connectionId);
}

protected override Task OnDisconnectAsync(IRequest request, string connectionId)
{
return PrintEnvironment("OnDisconnectAsync", request, connectionId);
}

private Task PrintEnvironment(string method, IRequest request, string connectionId)
{
object owinEnv;
if (request.Items.TryGetValue("owin.environment", out owinEnv))
{
var env = (IDictionary<string, object>)owinEnv;
return Connection.Broadcast(new
{
method = method,
count = env.Count,
owinKeys = env.Keys,
keys = request.Items.Keys
});
}

return Connection.Broadcast(new
{
method = method,
count = 0,
keys = new string[0],
owinKeys = new string[0],
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class FilteredConnection : PersistentConnection
{
protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
{
return Connection.Broadcast(data, connectionId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Net;
using System.Threading.Tasks;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class MyBadConnection : PersistentConnection
{
protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
// Should throw 404
using (HttpWebRequest.Create("http://www.microsoft.com/mairyhadalittlelambbut_shelikedhertwinkling_littlestar_better").GetResponse()) { }

return base.OnConnectedAsync(request, connectionId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class MyGroupConnection : PersistentConnection
{
protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
{
JObject operation = JObject.Parse(data);
int type = operation.Value<int>("type");
string group = operation.Value<string>("group");

if (type == 1)
{
return Groups.Add(connectionId, group);
}
else if (type == 2)
{
return Groups.Remove(connectionId, group);
}
else if (type == 3)
{
return Groups.Send(group, operation.Value<string>("message"));
}

return base.OnReceivedAsync(request, connectionId, data);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class MyGroupEchoConnection : PersistentConnection
{
protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
return Groups.Send("test", "hey");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class MyReconnect : PersistentConnection
{
public int Reconnects { get; set; }

protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
return null;
}

protected override Task OnReconnectedAsync(IRequest request, string connectionId)
{
Reconnects++;
return base.OnReconnectedAsync(request, connectionId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class MyRejoinGroupsConnection : MyGroupConnection
{
protected override IEnumerable<string> OnRejoiningGroups(IRequest request, IEnumerable<string> groups, string connectionId)
{
return groups;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Threading.Tasks;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class MySendingConnection : PersistentConnection
{
protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
Connection.Send(connectionId, "OnConnectedAsync1");
Connection.Send(connectionId, "OnConnectedAsync2");

return base.OnConnectedAsync(request, connectionId);
}

protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
{
Connection.Send(connectionId, "OnReceivedAsync1");
Connection.Send(connectionId, "OnReceivedAsync2");

return base.OnReceivedAsync(request, connectionId, data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;

namespace Microsoft.AspNet.SignalR.FunctionalTests
{
public class SyncErrorConnection : PersistentConnection
{
protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
{
throw new InvalidOperationException("This is a bug!");
}
}
}
Loading

0 comments on commit 53498e2

Please sign in to comment.