コード例 #1
0
        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;
        }
コード例 #2
0
 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());
 }
コード例 #3
0
        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());
        }
コード例 #4
0
        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;
        }