public async Task ForwardsTwinPatchOperationToTheCloudProxy() { var connMgr = Mock.Of <IConnectionManager>(); var identity = Mock.Of <IModuleIdentity>(m => m.DeviceId == "device1" && m.ModuleId == "module1" && m.Id == "device1/module1"); var cloudProxy = Mock.Of <ICloudProxy>(); IMessage receivedMessage = null; var edgeHub = new Mock <IEdgeHub>(); edgeHub.Setup(e => e.UpdateReportedPropertiesAsync(It.IsAny <IIdentity>(), It.IsAny <IMessage>())) .Callback <IIdentity, IMessage>((id, m) => receivedMessage = m) .Returns(Task.CompletedTask); Mock.Get(connMgr).Setup(c => c.GetCloudConnection(It.IsAny <string>())).Returns(Option.Some(cloudProxy)); var listener = new DeviceMessageHandler(identity, edgeHub.Object, connMgr); var underlyingDeviceProxy = new Mock <IDeviceProxy>(); bool updateSent = false; underlyingDeviceProxy.Setup(d => d.SendTwinUpdate(It.IsAny <IMessage>())) .Callback(() => updateSent = true) .Returns(Task.CompletedTask); listener.BindDeviceProxy(underlyingDeviceProxy.Object); IMessage message = new EdgeMessage.Builder(Encoding.UTF8.GetBytes("don't care")).Build(); await listener.UpdateReportedPropertiesAsync(message, Guid.NewGuid().ToString()); edgeHub.VerifyAll(); Assert.True(updateSent); Assert.NotNull(receivedMessage); Assert.Equal(Constants.TwinChangeNotificationMessageSchema, receivedMessage.SystemProperties[SystemProperties.MessageSchema]); Assert.Equal(Constants.TwinChangeNotificationMessageType, receivedMessage.SystemProperties[SystemProperties.MessageType]); Assert.Equal("device1", receivedMessage.SystemProperties[SystemProperties.ConnectionDeviceId]); Assert.Equal("module1", receivedMessage.SystemProperties[SystemProperties.ConnectionModuleId]); Assert.True(receivedMessage.SystemProperties.ContainsKey(SystemProperties.EnqueuedTime)); }