Skip to content

Commit

Permalink
Test sending preserialized json from a PersistentConnection
Browse files Browse the repository at this point in the history
Removed unnecessary/invalid newlines from the request body in MemoryHost

#1546
  • Loading branch information
halter73 committed Jun 11, 2013
1 parent 4bcda59 commit f8f8eae
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Microsoft.AspNet.SignalR.Hosting.Memory/MemoryHost.cs
Expand Up @@ -230,7 +230,6 @@ private static Stream GetRequestBody(IDictionary<string, string> postData)
writer.Write(item.Key);
writer.Write("=");
writer.Write(UrlEncoder.UrlEncode(item.Value));
writer.WriteLine();
first = false;
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNet.SignalR.Tests.Common;
using Microsoft.AspNet.SignalR.Tests.Common.Infrastructure;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Owin;
using Xunit;
using Xunit.Extensions;
Expand Down Expand Up @@ -553,6 +554,46 @@ public void SendWithSyncErrorThrows(HostType hostType, TransportType transportTy
}
}

public class ReceiveFacts : HostedTest
{
[Theory]
[InlineData(HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData(HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Fake)]
[InlineData(HostType.Memory, TransportType.ServerSentEvents, MessageBusType.FakeMultiStream)]
[InlineData(HostType.Memory, TransportType.LongPolling, MessageBusType.Default)]
[InlineData(HostType.Memory, TransportType.LongPolling, MessageBusType.Fake)]
[InlineData(HostType.Memory, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
[InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
[InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
public void ReceivePreserializedJson(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
using (var host = CreateHost(hostType, transportType))
{
host.Initialize(messageBusType: messageBusType);

var connection = CreateConnection(host, "/preserialize");
var tcs = new TaskCompletionSource<string>();

connection.Received += json =>
{
tcs.TrySetResult(json);
};

using (connection)
{
connection.Start(host.Transport).Wait();

connection.SendWithTimeout(new { preserialized = true });

Assert.True(tcs.Task.Wait(TimeSpan.FromSeconds(5)));
var json = JObject.Parse(tcs.Task.Result);
Assert.True((bool)json["preserialized"]);
}
}
}
}

public class Owin : HostedTest
{
[Theory]
Expand Down
Expand Up @@ -116,6 +116,7 @@ public static void ConfigureRoutes(IAppBuilder app, IDependencyResolver resolver
app.MapConnection<AddGroupOnConnectedConnection>("add-group", config);
app.MapConnection<UnusableProtectedConnection>("protected", config);
app.MapConnection<FallbackToLongPollingConnection>("/fall-back", config);
app.MapConnection<PreserializedJsonConnection>("preserialize", config);

// This subpipeline is protected by basic auth
app.MapPath("/basicauth", subApp =>
Expand Down
@@ -0,0 +1,15 @@
using System;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.AspNet.SignalR.Tests.Common.Connections
{
public class PreserializedJsonConnection : PersistentConnection
{
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
var jsonBytes = new ArraySegment<byte>(Encoding.UTF8.GetBytes(data));
return Connection.Send(connectionId, jsonBytes);
}
}
}
Expand Up @@ -124,6 +124,7 @@
<Compile Include="Connections\AuthenticatedEchoConnection.cs" />
<Compile Include="Connections\ExamineHeadersConnection.cs" />
<Compile Include="Connections\ExamineReconnectPath.cs" />
<Compile Include="Connections\PreserializedJsonConnection.cs" />
<Compile Include="Handlers\GCHandler.cs" />
<Compile Include="Handlers\PingHandler.cs" />
<Compile Include="Build\StartIISTask.cs" />
Expand Down

0 comments on commit f8f8eae

Please sign in to comment.