forked from SignalR/SignalR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a Tests Common project that contains common code for unit and…
… functional tests. - Also began copying over necessary files from other projects such as the functionaltests proj.
- Loading branch information
1 parent
0c7723e
commit 53498e2
Showing
25 changed files
with
987 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/Microsoft.AspNet.SignalR.Tests.Common/App_Start/RegisterHubs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Microsoft.AspNet.SignalR.Tests.Common/App_Start/TestEndPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
tests/Microsoft.AspNet.SignalR.Tests.Common/Build/StartIISTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/ConnectionThatUsesItems.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
}); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/FilteredConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/MyBadConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/MyGroupConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/MyGroupEchoConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/MyReconnect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/MyRejoinGroupsConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/MySendingConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/Microsoft.AspNet.SignalR.Tests.Common/Connections/SyncErrorConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
} |
Oops, something went wrong.