示例#1
0
        public async Task DesiredUpdateCallForwarded()
        {
            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 desired = new EdgeMessage.Builder(new byte[0]).Build();

            Mock.Get(twinHandler)
            .Setup(h => h.SendDesiredPropertiesUpdate(It.Is <IMessage>(m => m == desired), It.Is <IIdentity>(i => i == identity)))
            .Returns(Task.CompletedTask);

            var sut = new DeviceProxy(identity, twinHandler, m2mHandler, c2dHandler, directMethodHandler);

            await sut.OnDesiredPropertyUpdates(desired);

            Mock.Get(directMethodHandler).VerifyAll();
        }
示例#2
0
        public void OnDesiredPropertyUpdatesSendsAMessageToTheProtocolGateway()
        {
            const string Update  = "{\"abc\": \"123\", \"$version\": 1}";
            var          message = new TestDesiredUpdateMessage(Update);

            var converter = new Mock <IMessageConverter <IProtocolGatewayMessage> >();

            converter.Setup(x => x.FromMessage(It.IsAny <IMessage>()))
            .Returns(() => message.PgMessage);

            var channel = new Mock <IMessagingChannel <IProtocolGatewayMessage> >();

            channel.Setup(x => x.Handle(It.IsAny <IProtocolGatewayMessage>()));

            var deviceProxy = new DeviceProxy(channel.Object, Mock.Of <IIdentity>(), converter.Object, ByteBufferConverter);

            deviceProxy.OnDesiredPropertyUpdates(message.CoreMessage);

            converter.Verify(x => x.FromMessage(It.Is <IMessage>(actualCore => message.CoreMessage.Equals(actualCore))));
            channel.Verify(x => x.Handle(It.Is <IProtocolGatewayMessage>(actualPg => message.PgMessage.Equals(actualPg))));
        }