[Ignore] // TODO #581 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).ConfigureAwait(false); s_clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); // Test Write API var args = new TransportAsyncCallbackArgs(); args.CompletedCallback = s_onWriteOperationComplete; args.SetBuffer(s_byteArray, 0, s_byteArray.Length); s_clientWebSocketTransport.WriteAsync(args); // Test Read API args.CompletedCallback = s_onReadOperationComplete; if (s_clientWebSocketTransport.ReadAsync(args)) { while (!s_isReadComplete) { Thread.Sleep(s_oneSecond); } } // Once Read operation is complete, close websocket transport // Test Close API await s_clientWebSocketTransport.CloseAsync(s_thirtySeconds).ConfigureAwait(false); }
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).ConfigureAwait(false); 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)).ConfigureAwait(false); }
[Ignore] //TODO #318 public async Task WriteAfterCloseTest() { 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).ConfigureAwait(false); using var clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); await clientWebSocketTransport.CloseAsync(s_thirtySeconds).ConfigureAwait(false); var args = new TransportAsyncCallbackArgs(); args.SetBuffer(s_byteArray, 0, s_byteArray.Length); args.CompletedCallback = (TransportAsyncCallbackArgs args) => { if (args.BytesTransfered != s_byteArray.Length) { throw new InvalidOperationException("All the bytes sent were not transferred"); } if (args.Exception != null) { throw args.Exception; } }; clientWebSocketTransport.WriteAsync(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, 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 void ClientWebSocketTransportWriteWithoutConnectTest() { var websocket = new ClientWebSocket(); var clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); var args = new TransportAsyncCallbackArgs(); args.SetBuffer(byteArray, 0, byteArray.Length); clientWebSocketTransport.WriteAsync(args); }
public void ClientWebSocketTransportWriteWithoutConnectTest() { var websocket = new ClientWebSocket(); var clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); var args = new TransportAsyncCallbackArgs(); args.SetBuffer(byteArray, 0, byteArray.Length); clientWebSocketTransport.WriteAsync(args); }
public async Task WriteAfterAbortTest() { 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).ConfigureAwait(false); clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); clientWebSocketTransport.Abort(); var args = new TransportAsyncCallbackArgs(); args.SetBuffer(byteArray, 0, byteArray.Length); clientWebSocketTransport.WriteAsync(args); }
public async Task WriteAfterCloseTest() { 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(); args.SetBuffer(byteArray, 0, byteArray.Length); args.CompletedCallback = onWriteOperationComplete; clientWebSocketTransport.WriteAsync(args); }
[Ignore] // TODO #581 public async Task WriteAfterCloseTest() { 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).ConfigureAwait(false); s_clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); await s_clientWebSocketTransport.CloseAsync(s_thirtySeconds).ConfigureAwait(false); var args = new TransportAsyncCallbackArgs(); args.SetBuffer(s_byteArray, 0, s_byteArray.Length); args.CompletedCallback = s_onWriteOperationComplete; s_clientWebSocketTransport.WriteAsync(args); }
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, 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 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 WriteAfterAbortTest() { 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(); args.SetBuffer(byteArray, 0, byteArray.Length); clientWebSocketTransport.WriteAsync(args); }
public async Task ReadWriteTest() { 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).ConfigureAwait(false); using var clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null); // Test Write API var args = new TransportAsyncCallbackArgs(); args.CompletedCallback = (TransportAsyncCallbackArgs args) => { if (args.BytesTransfered != s_byteArray.Length) { throw new InvalidOperationException("All the bytes sent were not transferred"); } if (args.Exception != null) { throw args.Exception; } }; args.SetBuffer(s_byteArray, 0, s_byteArray.Length); clientWebSocketTransport.WriteAsync(args); // Test Read API bool isReadComplete = false; args.CompletedCallback = (TransportAsyncCallbackArgs args) => { if (args.Exception != null) { throw args.Exception; } // Verify that data matches what was sent if (s_byteArray.Length != args.Count) { throw new InvalidOperationException("Expected " + s_byteArray.Length + " bytes in response"); } for (int i = 0; i < args.Count; i++) { if (s_byteArray[i] != args.Buffer[i]) { throw new InvalidOperationException("Response contents do not match what was sent"); } } isReadComplete = true; }; if (clientWebSocketTransport.ReadAsync(args)) { while (!isReadComplete) { await Task.Delay(s_oneSecond); } } // Once Read operation is complete, close websocket transport // Test Close API await clientWebSocketTransport.CloseAsync(s_thirtySeconds).ConfigureAwait(false); }