public async Task TestReceiveMessagingChannelAbandon() { IProtocolGatewayMessage msg = null; IMessageConverter <IProtocolGatewayMessage> messageConverter = ProtocolGatewayMessageConverter.Value; var dp = new DeviceProxy(Channel.Object, MockIdentity, messageConverter, ByteBufferConverter); var cloudProxy = new Mock <ICloudProxy>(); cloudProxy.Setup(d => d.SendFeedbackMessageAsync(It.IsAny <string>(), It.IsAny <FeedbackStatus>())).Callback <string, FeedbackStatus>( (mid, status) => { Assert.Equal(FeedbackStatus.Abandon, status); }); var connectionManager = new Mock <IConnectionManager>(); connectionManager.Setup(c => c.GetCloudConnection(It.IsAny <string>())) .Returns(Task.FromResult(Option.Some(cloudProxy.Object))); var deviceListner = new DeviceMessageHandler(MockIdentity, EdgeHub.Object, connectionManager.Object, DefaultMessageAckTimeout); var messagingServiceClient = new MessagingServiceClient(deviceListner, messageConverter, ByteBufferConverter); Channel.Setup(r => r.Handle(It.IsAny <IProtocolGatewayMessage>())) .Callback <IProtocolGatewayMessage>( m => { msg = m; messagingServiceClient.AbandonAsync(msg.Id); }); messagingServiceClient.BindMessagingChannel(Channel.Object); IMessage message = new EdgeMessage.Builder(new byte[] { 1, 2, 3 }).Build(); await dp.SendC2DMessageAsync(message); Assert.NotNull(msg); }
public async Task TestReceiveMessagingChannelDispose() { IProtocolGatewayMessage msg = null; IMessageConverter <IProtocolGatewayMessage> messageConverter = ProtocolGatewayMessageConverter.Value; var dp = new DeviceProxy(Channel.Object, MockIdentity, messageConverter, ByteBufferConverter); var cloudProxy = new Mock <ICloudProxy>(); cloudProxy.Setup(d => d.CloseAsync()).Callback( () => { }); var connectionManager = new Mock <IConnectionManager>(); connectionManager.Setup(c => c.GetCloudConnection(It.IsAny <string>())) .Returns(Task.FromResult(Option.Some(cloudProxy.Object))); var deviceListner = new DeviceMessageHandler(MockIdentity, EdgeHub.Object, connectionManager.Object); var messagingServiceClient = new Mqtt.MessagingServiceClient(deviceListner, messageConverter, ByteBufferConverter); Channel.Setup(r => r.Handle(It.IsAny <IProtocolGatewayMessage>())) .Callback <IProtocolGatewayMessage>( m => { msg = m; messagingServiceClient.DisposeAsync(new Exception("Some issue")); }); messagingServiceClient.BindMessagingChannel(Channel.Object); Core.IMessage message = new EdgeMessage.Builder(new byte[] { 1, 2, 3 }).Build(); await dp.SendC2DMessageAsync(message); Assert.NotNull(msg); }
public async Task Cloud2DeviceMessagesForwarded() { var twinHandler = Mock.Of <ITwinHandler>(); var m2mHandler = Mock.Of <IModuleToModuleMessageHandler>(); var c2dHandler = Mock.Of <ICloud2DeviceMessageHandler>(); var directMethodHandler = Mock.Of <IDirectMethodHandler>(); var identity = new DeviceIdentity("hub", "device_id"); var message = new EdgeMessage.Builder(new byte[0]).Build(); Mock.Get(c2dHandler) .Setup(h => h.SendC2DMessageAsync(It.Is <IMessage>(m => m == message), It.Is <IIdentity>(i => i == identity))) .Returns(Task.CompletedTask); var sut = new DeviceProxy(identity, twinHandler, m2mHandler, c2dHandler, directMethodHandler); await sut.SendC2DMessageAsync(message); Mock.Get(directMethodHandler).VerifyAll(); }