public async Task ClientWebSocketChannelWriteAfterCloseTest() { var websocket = new ClientWebSocket(); websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Mqtt); var uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix); await websocket.ConnectAsync(uri, CancellationToken.None); clientWebSocketChannel = new ClientWebSocketChannel(null, websocket); var threadLoop = new SingleThreadEventLoop("MQTTExecutionThread", TimeSpan.FromSeconds(1)); await threadLoop.RegisterAsync(clientWebSocketChannel); await clientWebSocketChannel.CloseAsync(); // Test Write API try { await clientWebSocketChannel.WriteAndFlushAsync(Unpooled.Buffer()); Assert.Fail("Should have thrown ClosedChannelException"); } catch (AggregateException e) { var innerException = e.InnerException as ClosedChannelException; Assert.IsNotNull(innerException); } done = true; }
public async Task ClientWebSocketChannelWriteWithoutConnectTest() { var websocket = new ClientWebSocket(); clientWebSocketChannel = new ClientWebSocketChannel(null, websocket); var threadLoop = new SingleThreadEventLoop("MQTTExecutionThread", TimeSpan.FromSeconds(1)); await threadLoop.RegisterAsync(clientWebSocketChannel); await clientWebSocketChannel.WriteAndFlushAsync(new ConnectPacket()); }