コード例 #1
0
        public async Task LegacyWebSocketWriteAfterAbortTest()
        {
            var websocket = new IotHubClientWebSocket(WebSocketConstants.SubProtocols.Amqpwsb10);
            await websocket.ConnectAsync(IotHubName, Port, "ws://", TimeSpan.FromMinutes(1));
            legacyClientWebSocketTransport = new LegacyClientWebSocketTransport(websocket, TimeSpan.FromMinutes(1), null, null);
            legacyClientWebSocketTransport.Abort();

            var args = new TransportAsyncCallbackArgs();
            args.SetBuffer(byteArray, 0, byteArray.Length);
            legacyClientWebSocketTransport.WriteAsync(args);
            Assert.Fail("Did not throw object disposed exception");
        }
コード例 #2
0
 public async Task LegacyWebSocketWriteAfterCloseTest()
 {
     var websocket = new IotHubClientWebSocket(WebSocketConstants.SubProtocols.Amqpwsb10);
     await websocket.ConnectAsync(IotHubName, Port, "ws://", TimeSpan.FromMinutes(1));
     legacyClientWebSocketTransport = new LegacyClientWebSocketTransport(websocket, TimeSpan.FromMinutes(1), null, null);
     await legacyClientWebSocketTransport.CloseAsync(TimeSpan.FromSeconds(30));
     var args = new TransportAsyncCallbackArgs();
     args.SetBuffer(byteArray, 0, byteArray.Length);
     legacyClientWebSocketTransport.WriteAsync(args);
 }
コード例 #3
0
        public async Task LegacyClientWebSocketTransportReadWithoutConnectTest()
        {
            var websocket = new IotHubClientWebSocket(WebSocketConstants.SubProtocols.Amqpwsb10);
            var clientWebSocketTransport = new LegacyClientWebSocketTransport(websocket, TimeSpan.FromSeconds(60), 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();
        }
コード例 #4
0
        public async Task LegacyWebSocketReadWriteTest()
        {
            var websocket = new IotHubClientWebSocket(WebSocketConstants.SubProtocols.Amqpwsb10);
            await websocket.ConnectAsync(IotHubName, Port, "ws://", TimeSpan.FromMinutes(1));

            legacyClientWebSocketTransport = new LegacyClientWebSocketTransport(websocket, TimeSpan.FromSeconds(60), null, null);

            // Test Write API
            TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
            args.CompletedCallback = onWriteOperationComplete;
            args.SetBuffer(byteArray, 0, byteArray.Length);
            legacyClientWebSocketTransport.WriteAsync(args);

            // Test Read API
            args.CompletedCallback = onReadOperationComplete;
            if (legacyClientWebSocketTransport.ReadAsync(args))
            {
                while (!readComplete)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }

            // Once Read operation is complete, close websocket transport
            legacyClientWebSocketTransport.CloseAsync(TimeSpan.FromSeconds(30)).Wait(CancellationToken.None);
        }
コード例 #5
0
 public void LegacyClientWebSocketTransportWriteWithoutConnectTest()
 {
     var websocket = new IotHubClientWebSocket(WebSocketConstants.SubProtocols.Amqpwsb10);
     var clientWebSocketTransport = new LegacyClientWebSocketTransport(websocket, TimeSpan.FromSeconds(60), null, null);
     var args = new TransportAsyncCallbackArgs();
     args.SetBuffer(byteArray, 0, byteArray.Length);
     clientWebSocketTransport.WriteAsync(args);
 }