public async Task when_writing_packet_then_inner_channel_is_notified(string packetPath, Type packetType) { MqttConfiguration configuration = new MqttConfiguration { WaitTimeoutSecs = 1 }; packetPath = Path.Combine(Environment.CurrentDirectory, packetPath); byte[] bytes = Packet.ReadAllBytes(packetPath); Subject <byte[]> receiver = new Subject <byte[]>(); Mock <IMqttChannel <byte[]> > innerChannel = new Mock <IMqttChannel <byte[]> >(); innerChannel.Setup(x => x.ReceiverStream).Returns(receiver); innerChannel.Setup(x => x.SendAsync(It.IsAny <byte[]>())) .Returns(Task.Delay(0)); IPacket packet = Activator.CreateInstance(packetType) as IPacket; Mock <IPacketManager> manager = new Mock <IPacketManager>(); manager.Setup(x => x.GetBytesAsync(It.IsAny <IPacket>())) .Returns(Task.FromResult(bytes)); PacketChannel channel = new PacketChannel(innerChannel.Object, manager.Object, configuration); await channel.SendAsync(packet); innerChannel.Verify(x => x.SendAsync(It.Is <byte[]>(b => b.ToList().SequenceEqual(bytes)))); manager.Verify(x => x.GetBytesAsync(It.Is <IPacket>(p => Convert.ChangeType(p, packetType) == packet))); }
public async Task when_writing_packet_from_source_then_inner_channel_is_notified(string packetPath, string jsonPath, Type packetType) { var configuration = new MqttConfiguration { WaitTimeoutSecs = 1 }; packetPath = Path.Combine(Environment.CurrentDirectory, packetPath); var bytes = Packet.ReadAllBytes(packetPath); var receiver = new Subject <byte[]> (); var innerChannel = new Mock <IMqttChannel <byte[]> >(); innerChannel.Setup(x => x.ReceiverStream).Returns(receiver); innerChannel.Setup(x => x.SendAsync(It.IsAny <byte[]> ())) .Returns(Task.Delay(0)); jsonPath = Path.Combine(Environment.CurrentDirectory, jsonPath); var packet = Packet.ReadPacket(jsonPath, packetType) as IPacket; var manager = new Mock <IPacketManager> (); manager.Setup(x => x.GetBytesAsync(It.IsAny <IPacket>())) .Returns(Task.FromResult(bytes)); var channel = new PacketChannel(innerChannel.Object, manager.Object, configuration); await channel.SendAsync(packet) .ConfigureAwait(continueOnCapturedContext: false); innerChannel.Verify(x => x.SendAsync(It.Is <byte[]> (b => b.ToList().SequenceEqual(bytes)))); manager.Verify(x => x.GetBytesAsync(It.Is <IPacket> (p => Convert.ChangeType(p, packetType) == packet))); }