Ejemplo n.º 1
0
 public SendContext(WebSocketHandler webSocketHandler, ArraySegment<byte> message, WebSocketMessageType messageType, bool endOfMessage)
 {
     Handler = webSocketHandler;
     Message = message;
     MessageType = messageType;
     EndOfMessage = endOfMessage;
 }
Ejemplo n.º 2
0
 public CloseContext(WebSocketHandler webSocketHandler)
 {
     Handler = webSocketHandler;
 }
Ejemplo n.º 3
0
 public CloseContext(WebSocketHandler webSocketHandler)
 {
     Handler = webSocketHandler;
 }
Ejemplo n.º 4
0
        public async Task WebSocketHandlerClosesIfWebSocketStateIsCloseSentAfterClosing()
        {
            var messageIndex = 0;
            var webSocketMessages = new[] { new WebSocketReceiveResult(0, WebSocketMessageType.Text, endOfMessage: false),
                                            new WebSocketReceiveResult(0, WebSocketMessageType.Text, endOfMessage: false),
                                            new WebSocketReceiveResult(0, WebSocketMessageType.Close, endOfMessage: true)};

            var webSocket = new Mock<WebSocket>(MockBehavior.Strict);

            webSocket.Setup(w => w.ReceiveAsync(It.IsAny<ArraySegment<byte>>(), CancellationToken.None))
                     .Returns(() => TaskAsyncHelper.FromResult(webSocketMessages[messageIndex++]));

            WebSocketState state = WebSocketState.Open;
            webSocket.Setup(w => w.State).Returns(() => state);
            webSocket.Setup(w => w.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None))
                .Returns(() =>
                {
                    state = WebSocketState.CloseSent;
                    return TaskAsyncHelper.Empty;
                });

            webSocket.Setup(w => w.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None))
                .Returns(() =>
                {
                    state = WebSocketState.Closed;
                    return TaskAsyncHelper.Empty;
                });

            var webSocketHandler = new WebSocketHandler(64 * 1024);
            await webSocketHandler.ProcessWebSocketRequestAsync(webSocket.Object, CancellationToken.None);

            webSocket.VerifyAll();
        }
Ejemplo n.º 5
0
        public async Task SendNoopsIfNotOpen(WebSocketState state)
        {
            var webSocket = new Mock<WebSocket>();
            var webSocketHandler = new WebSocketHandler(64 * 1024);

            webSocket.Setup(m => m.State).Returns(state);
            webSocketHandler.WebSocket = webSocket.Object;

            await webSocketHandler.SendAsync("Hello");

            webSocket.Verify(m => m.SendAsync(It.IsAny<ArraySegment<byte>>(), WebSocketMessageType.Text, true, CancellationToken.None), Times.Never());
        }
Ejemplo n.º 6
0
        public async Task CloseNoopsIfInTerminalState(WebSocketState state)
        {
            var webSocket = new Mock<WebSocket>();
            var webSocketHandler = new WebSocketHandler(64 * 1024);

            webSocket.Setup(m => m.State).Returns(state);
            webSocketHandler.WebSocket = webSocket.Object;

            await webSocketHandler.CloseAsync();

            webSocket.Verify(m => m.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None), Times.Never());
        }