Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RavioliCompositionOverSpaghettiInheritance - refactoring usage of Web…
…SocketHandler on the client WebSocketHandler class is used on the server and on the client. While on the server we just instantiate this type on the client the WebSocketTransport derives from it. This blocks creating a base class for client transport which would contain a common functionality (e.g. parsing the response). After this change WebSocketTransport no longer derives from the WebSocketHandler but instantiates it and uses it internally.
- Loading branch information
moozzyk
committed
May 31, 2014
1 parent
a7c438f
commit 8b3b450
Showing
6 changed files
with
133 additions
and
15 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
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
46 changes: 46 additions & 0 deletions
46
src/Microsoft.AspNet.SignalR.Client45/Transports/WebSockets/ClientWebSocketHandler.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,46 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information. | ||
|
||
using System.Diagnostics; | ||
using Microsoft.AspNet.SignalR.WebSockets; | ||
|
||
namespace Microsoft.AspNet.SignalR.Client.Transports.WebSockets | ||
{ | ||
internal class ClientWebSocketHandler : WebSocketHandler | ||
{ | ||
private readonly WebSocketTransport _webSocketTransport; | ||
|
||
public ClientWebSocketHandler(WebSocketTransport webSocketTransport) | ||
: base(maxIncomingMessageSize: null) | ||
{ | ||
Debug.Assert(webSocketTransport != null, "webSocketTransport is null"); | ||
|
||
_webSocketTransport = webSocketTransport; | ||
} | ||
|
||
// for mocking | ||
internal ClientWebSocketHandler() | ||
: base(maxIncomingMessageSize: null) | ||
{ | ||
} | ||
|
||
public override void OnMessage(string message) | ||
{ | ||
_webSocketTransport.OnMessage(message); | ||
} | ||
|
||
public override void OnOpen() | ||
{ | ||
_webSocketTransport.OnOpen(); | ||
} | ||
|
||
public override void OnClose() | ||
{ | ||
_webSocketTransport.OnClose(); | ||
} | ||
|
||
public override void OnError() | ||
{ | ||
_webSocketTransport.OnError(Error); | ||
} | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
...t.AspNet.SignalR.Client.Tests/Client/Transports/WebSockets/ClientWebSocketHandlerFacts.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,57 @@ | ||
| ||
using System; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNet.SignalR.Client.Transports.WebSockets | ||
{ | ||
public class ClientWebSocketHandlerFacts | ||
{ | ||
[Fact] | ||
public void OnOpenCallsIntoWebSocketTransportOnMessage() | ||
{ | ||
var mockWebSocketTransport = new Mock<WebSocketTransport>(); | ||
|
||
var webSocketHandler = new ClientWebSocketHandler(mockWebSocketTransport.Object); | ||
webSocketHandler.OnOpen(); | ||
|
||
mockWebSocketTransport.Verify(p => p.OnOpen(), Times.Once()); | ||
} | ||
|
||
[Fact] | ||
public void OnMessageCallsIntoWebSocketTransportOnMessage() | ||
{ | ||
var mockWebSocketTransport = new Mock<WebSocketTransport>(); | ||
|
||
var webSocketHandler = new ClientWebSocketHandler(mockWebSocketTransport.Object); | ||
webSocketHandler.OnMessage("msg"); | ||
|
||
mockWebSocketTransport.Verify(p => p.OnMessage("msg"), Times.Once()); | ||
} | ||
|
||
[Fact] | ||
public void OnCloseCallsIntoWebSocketTransportOnClose() | ||
{ | ||
var mockWebSocketTransport = new Mock<WebSocketTransport>(); | ||
|
||
var webSocketHandler = new ClientWebSocketHandler(mockWebSocketTransport.Object); | ||
webSocketHandler.OnClose(); | ||
|
||
mockWebSocketTransport.Verify(p => p.OnClose(), Times.Once()); | ||
} | ||
|
||
[Fact] | ||
public void OnErrorCallsIntoWebSocketTransportOnErrorAndPassesException() | ||
{ | ||
var exception = new Exception(); | ||
var mockWebSocketTransport = new Mock<WebSocketTransport>(); | ||
|
||
var webSocketHandler = | ||
new ClientWebSocketHandler(mockWebSocketTransport.Object) { Error = exception }; | ||
|
||
webSocketHandler.OnError(); | ||
|
||
mockWebSocketTransport.Verify(p => p.OnError(exception), Times.Once()); | ||
} | ||
} | ||
} |
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