T RecodePacket <T>(T packet, bool useServer, bool explodeForDecode) where T : Packet { var output = new List <object>(); MqttEncoder.DoEncode(Allocator, packet, output); T observedPacket = null; this.contextMock.Setup(x => x.FireChannelRead(It.IsAny <T>())) .Callback((object message) => observedPacket = Assert.IsAssignableFrom <T>(message)) .Returns(this.contextMock.Object); foreach (IByteBuffer message in output) { MqttDecoder mqttDecoder = (useServer ? this.serverDecoder : this.clientDecoder); if (explodeForDecode) { while (message.IsReadable()) { IByteBuffer finalBuffer = message.ReadBytes(1); mqttDecoder.ChannelRead(this.contextMock.Object, finalBuffer); } } else { mqttDecoder.ChannelRead(this.contextMock.Object, message); } } return(observedPacket); }
public MqttCodecTests() { this.serverDecoder = new MqttDecoder(true, 256 * 1024); this.clientDecoder = new MqttDecoder(false, 256 * 1024); this.contextMock = new Mock <IChannelHandlerContext>(MockBehavior.Strict); this.contextMock.Setup(x => x.Removed).Returns(false); this.contextMock.Setup(x => x.Allocator).Returns(UnpooledByteBufferAllocator.Default); }