Skip to content

Commit

Permalink
Added tests for headers
Browse files Browse the repository at this point in the history
  • Loading branch information
abnanda1 committed Jul 3, 2013
1 parent 4438a95 commit f9f2b97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,32 @@ public void RequestHeadersSetCorrectly(HostType hostType, TransportType transpor
[Theory]
[InlineData(HostType.IISExpress, TransportType.LongPolling)]
[InlineData(HostType.IISExpress, TransportType.ServerSentEvents)]
[InlineData(HostType.IISExpress, TransportType.Websockets)]
[InlineData(HostType.HttpListener, TransportType.LongPolling)]
[InlineData(HostType.HttpListener, TransportType.ServerSentEvents)]
[InlineData(HostType.HttpListener, TransportType.Websockets)]
public void RequestHeadersCannotBeSetOnceConnected(HostType hostType, TransportType transportType)
public void RequestHeadersCanBeSetOnceConnected(HostType hostType, TransportType transportType)
{
using (var host = CreateHost(hostType, transportType))
{
// Arrange
host.Initialize();
var connection = CreateConnection(host, "/examine-request");
var mre = new ManualResetEventSlim();

using (connection)
connection.Received += (arg) =>
{
connection.Start(host.Transport).Wait();
JObject headers = JsonConvert.DeserializeObject<JObject>(arg);
Assert.Equal("test-header", (string)headers["testHeader"]);
var ex = Assert.Throws<InvalidOperationException>(() => connection.Headers.Add("test-header", "test-header"));
Assert.Equal("Request headers cannot be set after the connection has started.", ex.Message);
}
mre.Set();
};

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

connection.Headers.Add("test-header", "test-header");
connection.Send("message");

// Assert
Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public void RequestHeadersSetCorrectly(HostType hostType, TransportType transpor
}

hubConnection.Start(host.Transport).Wait();
proxy.Invoke("Send", "Hello");
proxy.Invoke("Send");

Assert.True(tcs.Task.Wait(TimeSpan.FromSeconds(10)));
}
Expand All @@ -453,27 +453,32 @@ public void RequestHeadersSetCorrectly(HostType hostType, TransportType transpor
[InlineData(HostType.Memory, TransportType.LongPolling, MessageBusType.FakeMultiStream)]
[InlineData(HostType.IISExpress, TransportType.LongPolling, MessageBusType.Default)]
[InlineData(HostType.IISExpress, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData(HostType.IISExpress, TransportType.Websockets, MessageBusType.Default)]
[InlineData(HostType.HttpListener, TransportType.LongPolling, MessageBusType.Default)]
[InlineData(HostType.HttpListener, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData(HostType.HttpListener, TransportType.Websockets, MessageBusType.Default)]
public void RequestHeadersCannotBeSetOnceConnected(HostType hostType, TransportType transportType, MessageBusType messageBusType)
public void RequestHeadersCanBeSetOnceConnected(HostType hostType, TransportType transportType, MessageBusType messageBusType)
{
using (var host = CreateHost(hostType, transportType))
{
// Arrange
host.Initialize(messageBusType: messageBusType);
HubConnection hubConnection = CreateHubConnection(host);

var mre = new ManualResetEventSlim();

using (hubConnection)
{
IHubProxy proxy = hubConnection.CreateHubProxy("ExamineHeadersHub");

proxy.On("sendHeader", (headers) =>
{
Assert.Equal<string>("test-header", (string)headers.testHeader);

This comment has been minimized.

Copy link
@davidfowl

davidfowl Jul 3, 2013

Member

You don't need the <string>

mre.Set();
});

hubConnection.Start(host.Transport).Wait();

var ex = Assert.Throws<InvalidOperationException>(() => hubConnection.Headers.Add("test-header", "test-header"));
Assert.Equal("Request headers cannot be set after the connection has started.", ex.Message);
hubConnection.Headers.Add("test-header", "test-header");
proxy.Invoke("Send");

This comment has been minimized.

Copy link
@davidfowl

davidfowl Jul 3, 2013

Member

Why aren't you calling InvokeWithTimeout?

This comment has been minimized.

Copy link
@davidfowl

davidfowl Jul 3, 2013

Member

Actually that only really matters for websockets.

Assert.True(mre.Wait(TimeSpan.FromSeconds(5)));
}
}
}
Expand Down

0 comments on commit f9f2b97

Please sign in to comment.