Skip to content

Commit

Permalink
Fixed previous fixes to Issue #598
Browse files Browse the repository at this point in the history
Fixed bug in JS and .NET clients where StateChanged events would be passed a
copy of the new state in lieu of the old state.
  • Loading branch information
halter73 committed Oct 16, 2012
1 parent b0b2e81 commit 5d1e1ab
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 13 deletions.
Expand Up @@ -74,7 +74,7 @@
changeState = function (connection, expectedState, newState) {
if (expectedState === connection.state) {
connection.state = newState;
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: newState }]);
$(connection).trigger(events.onStateChanged, [{ oldState: expectedState, newState: newState }]);
return true;
}

Expand Down Expand Up @@ -1184,6 +1184,9 @@
url = transportLogic.getUrl(connection, this.name);
url += "&frameId=" + frameId;

// Set body prior to setting URL to avoid caching issues.
$("body").append(frame);

frame.prop("src", url);
transportLogic.foreverFrame.connections[frameId] = connection;

Expand All @@ -1203,8 +1206,6 @@
connection.onSuccess = onSuccess;
}

$("body").append(frame);

// After connecting, if after the specified timeout there's no response stop the connection
// and raise on failed
// REVIEW: Why is connectTimeOut set here and never used again?
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -74,7 +74,7 @@
changeState = function (connection, expectedState, newState) {
if (expectedState === connection.state) {
connection.state = newState;
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: newState }]);
$(connection).trigger(events.onStateChanged, [{ oldState: expectedState, newState: newState }]);
return true;
}

Expand Down Expand Up @@ -1184,6 +1184,9 @@
url = transportLogic.getUrl(connection, this.name);
url += "&frameId=" + frameId;

// Set body prior to setting URL to avoid caching issues.
$("body").append(frame);

frame.prop("src", url);
transportLogic.foreverFrame.connections[frameId] = connection;

Expand All @@ -1203,8 +1206,6 @@
connection.onSuccess = onSuccess;
}

$("body").append(frame);

// After connecting, if after the specified timeout there's no response stop the connection
// and raise on failed
// REVIEW: Why is connectTimeOut set here and never used again?
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -73,7 +73,7 @@
changeState = function (connection, expectedState, newState) {
if (expectedState === connection.state) {
connection.state = newState;
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: newState }]);
$(connection).trigger(events.onStateChanged, [{ oldState: expectedState, newState: newState }]);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNet.SignalR.Client/Connection.cs
Expand Up @@ -162,10 +162,11 @@ private set
{
if (_state != value)
{
var stateChange = new StateChange(oldState: _state, newState: value);
_state = value;
if (StateChanged != null)
{
StateChanged(new StateChange(_state, value));
StateChanged(stateChange);
}
}
}
Expand Down
Expand Up @@ -15,6 +15,13 @@ test("Changing State", function () {
equal(con.changeState(con.fn, con.connectionState.disconnected, con.connectionState.connecting), true, "Changes state from disconnected to connecting.");
equal(con.changeState(con.fn, con.connectionState.connected, con.connectionState.reconnecting), false, "Changing state from connected to connecting when state is connecting.");

con.fn.stateChanged(function (change) {
equal(change.oldState, con.connectionState.connecting, "Verifies that the proper old state is passed to the stateChanged event handler.");
equal(change.newState, con.connectionState.connected, "Verifies that the proper new state is passed to the stateChanged event handler.");
$(this).unbind(con.events.onStateChanged);
});
con.changeState(con.fn, con.connectionState.connecting, con.connectionState.connected);

// Reset the connection state back to disconnected
con.changeState(con.fn, con.connectionState.connecting, con.connectionState.disconnected);
con.changeState(con.fn, con.connectionState.connected, con.connectionState.disconnected);
});
29 changes: 29 additions & 0 deletions tests/Microsoft.AspNet.SignalR.Tests/Client/ConnectionFacts.cs
@@ -0,0 +1,29 @@
using System;
using Microsoft.AspNet.SignalR.Client;
using Xunit;

namespace Microsoft.AspNet.SignalR.Tests
{
public class ConnectionFacts : IDisposable
{
[Fact]
public void ConnectionStateChangedEventIsCalledWithAppropriateArguments()
{
var connection = new Client.Connection("http://test");

connection.StateChanged += stateChange =>
{
Assert.Equal(ConnectionState.Disconnected, stateChange.OldState);
Assert.Equal(ConnectionState.Connecting, stateChange.NewState);
};

Assert.True(((Client.IConnection)connection).ChangeState(ConnectionState.Disconnected, ConnectionState.Connecting));
}

public void Dispose()
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -82,6 +82,7 @@
<Link>Hubs\DemoHub.cs</Link>
</Compile>
<Compile Include="ChunkBufferFacts.cs" />
<Compile Include="Client\ConnectionFacts.cs" />
<Compile Include="Infrastructure\CountDownRange.cs" />
<Compile Include="Server\AckHandlerFacts.cs" />
<Compile Include="Server\Hubs\HubAuthFacts.cs" />
Expand Down Expand Up @@ -133,4 +134,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

0 comments on commit 5d1e1ab

Please sign in to comment.