コード例 #1
0
        public async Task TestCorruptedConnectPacket()
        {
            var writer     = new MqttBufferWriter(4096, 65535);
            var serializer = new MqttPacketFormatterAdapter(writer);
            var pipe       = new DuplexPipeMockup();
            var connection = new DefaultConnectionContext();

            connection.Transport = pipe;
            var ctx = new MqttConnectionContext(serializer, connection);

            await pipe.Receive.Writer.WriteAsync(writer.AddMqttHeader(MqttControlPacketType.Connect, new byte[0]));

            await Assert.ThrowsExceptionAsync <MqttProtocolViolationException>(() => ctx.ReceivePacketAsync(CancellationToken.None));

            // the first exception should complete the pipes so if someone tries to use the connection after that it should throw immidiatly
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => ctx.ReceivePacketAsync(CancellationToken.None));
        }