Пример #1
0
        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, DefaultMessageAckTimeout);
            var messagingServiceClient = new 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);
            IMessage message = new EdgeMessage.Builder(new byte[] { 1, 2, 3 }).Build();
            await dp.SendC2DMessageAsync(message);

            Assert.NotNull(msg);
        }