Esempio n. 1
0
        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 #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 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 ClientWebSocketTransportReadTest()
        {
            var websocket = new ClientWebSocket();
            var clientWebSocketTransport    = new ClientWebSocketTransport(websocket, null, null);
            TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();

            byte[] byteArray = new byte[10];
            args.SetBuffer(byteArray, 0, 10);
            clientWebSocketTransport.ReadAsync(args);
        }
Esempio n. 5
0
        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).ConfigureAwait(false);

            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 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);
        }
Esempio n. 7
0
        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).ConfigureAwait(false);
        }
Esempio n. 8
0
        public async Task ClientWebSocketTransportReadWithoutConnectTest()
        {
            var  websocket = new ClientWebSocket();
            var  clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);
            var  args           = new TransportAsyncCallbackArgs();
            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;
            };
            var byteArray = new byte[10];

            args.SetBuffer(byteArray, 0, 10);
            if (clientWebSocketTransport.ReadAsync(args))
            {
                while (!isReadComplete)
                {
                    await Task.Delay(s_oneSecond);
                }
            }

            await websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None).ConfigureAwait(false);
        }
        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);
        }
        [Ignore] // TODO #581
        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).ConfigureAwait(false);

            s_clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);
            await s_clientWebSocketTransport.CloseAsync(s_thirtySeconds).ConfigureAwait(false);

            var args      = new TransportAsyncCallbackArgs();
            var byteArray = new byte[10];

            args.SetBuffer(byteArray, 0, 10);
            args.CompletedCallback = s_onReadOperationComplete;
            s_clientWebSocketTransport.ReadAsync(args);
        }
Esempio n. 11
0
        [Ignore] //TODO #318
        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).ConfigureAwait(false);

            using var clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);
            await clientWebSocketTransport.CloseAsync(s_thirtySeconds).ConfigureAwait(false);

            var args      = new TransportAsyncCallbackArgs();
            var byteArray = new byte[10];

            args.SetBuffer(byteArray, 0, 10);
            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");
                    }
                }
            };
            clientWebSocketTransport.ReadAsync(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 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);
        }
Esempio n. 16
0
        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);
        }