public void ClientWebSocketTransportReadTest() { var websocket = new ClientWebSocket(); var clientWebSocketTransport = new ClientWebSocketTransport(websocket, IotHubName, null, null); TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs(); byte[] byteArray = new byte[10]; args.SetBuffer(byteArray, 0, 10); clientWebSocketTransport.ReadAsync(args); }
public async Task ClientWebSocketTransportReadWithoutConnectTest() { var websocket = new ClientWebSocket(); var clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); var args = new TransportAsyncCallbackArgs(); var byteArray = new byte[10]; args.SetBuffer(byteArray, 0, 10); if (clientWebSocketTransport.ReadAsync(args)) { while (!readComplete) { Thread.Sleep(TimeSpan.FromSeconds(1)); } } await websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); }
public void ReadWriteTest() { var websocket = new ClientWebSocket(); // Set SubProtocol to AMQPWSB10 websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10); Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix); websocket.ConnectAsync(uri, CancellationToken.None).Wait(CancellationToken.None); clientWebSocketTransport = new ClientWebSocketTransport(websocket, IotHubName, null, null); // Test Write API TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs(); args.CompletedCallback = onWriteOperationComplete; args.SetBuffer(byteArray, 0, byteArray.Length); clientWebSocketTransport.WriteAsync(args); // Test Read API args.CompletedCallback = onReadOperationComplete; clientWebSocketTransport.ReadAsync(args); }
public void ReadWriteAfterAbortTest() { var websocket = new ClientWebSocket(); // Set SubProtocol to AMQPWSB10 websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10); Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix); websocket.ConnectAsync(uri, CancellationToken.None).Wait(CancellationToken.None); clientWebSocketTransport = new ClientWebSocketTransport(websocket, IotHubName, null, null); clientWebSocketTransport.Abort(); try { TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs(); args.SetBuffer(byteArray, 0, byteArray.Length); clientWebSocketTransport.WriteAsync(args); Assert.Fail("Did not throw object disposed exception"); } catch(ObjectDisposedException) { } try { TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs(); byte[] byteArray = new byte[10]; args.SetBuffer(byteArray, 0, 10); clientWebSocketTransport.ReadAsync(args); Assert.Fail("Did not throw object disposed exception"); } catch (ObjectDisposedException) { } }
public async Task ReadWriteTest() { var websocket = new ClientWebSocket(); // Set SubProtocol to AMQPWSB10 websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10); Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix); await websocket.ConnectAsync(uri, CancellationToken.None); clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); // Test Write API var args = new TransportAsyncCallbackArgs(); args.CompletedCallback = onWriteOperationComplete; args.SetBuffer(byteArray, 0, byteArray.Length); clientWebSocketTransport.WriteAsync(args); // Test Read API args.CompletedCallback = onReadOperationComplete; if (clientWebSocketTransport.ReadAsync(args)) { while (!readComplete) { Thread.Sleep(TimeSpan.FromSeconds(1)); } } // Once Read operation is complete, close websocket transport // Test Close API await clientWebSocketTransport.CloseAsync(TimeSpan.FromSeconds(30)); }
public async Task ReadAfterAbortTest() { var websocket = new ClientWebSocket(); // Set SubProtocol to AMQPWSB10 websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10); Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix); await websocket.ConnectAsync(uri, CancellationToken.None); clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); clientWebSocketTransport.Abort(); var args = new TransportAsyncCallbackArgs(); var byteArray = new byte[10]; args.SetBuffer(byteArray, 0, 10); clientWebSocketTransport.ReadAsync(args); }
public async Task ReadAfterCloseTest() { var websocket = new ClientWebSocket(); // Set SubProtocol to AMQPWSB10 websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10); var uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix); await websocket.ConnectAsync(uri, CancellationToken.None); clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); await clientWebSocketTransport.CloseAsync(TimeSpan.FromSeconds(30)); var args = new TransportAsyncCallbackArgs(); var byteArray = new byte[10]; args.SetBuffer(byteArray, 0, 10); args.CompletedCallback = onReadOperationComplete; clientWebSocketTransport.ReadAsync(args); }