public async Task CapturesModuleIdentityFromTopic() { var publishInfo = new MqttPublishInfo("$edgehub/captured_device_id/captured_module_id/messages/events/prop1=val1&prop2=val2", new byte[0]); var(connectionRegistry, _) = GetHandlerDependencies(); var identityProvider = Mock.Of <IIdentityProvider>(); string passedDeviceId = null, passedModuleId = null; Mock.Get(identityProvider) .Setup(ip => ip.Create(It.IsAny <string>(), It.IsAny <string>())) .Returns((string device_id, string module_id) => { passedDeviceId = device_id; passedModuleId = module_id; return(new ModuleIdentity("host", device_id, module_id)); }); var sut = new TelemetryHandler(connectionRegistry, identityProvider); _ = await sut.HandleAsync(publishInfo); Assert.Equal("captured_device_id", passedDeviceId); Assert.Equal("captured_module_id", passedModuleId); }
public async Task InternalMessageCapturesProperties() { var deviceListenerCapture = new DeviceListenerCapture(); var publishInfo = new MqttPublishInfo("$edgehub/device_id/messages/events/prop1=val1&prop2=val2", new byte[] { 0x01, 0x02, 0x03 }); var(connectionRegistry, identityProvider) = GetHandlerDependencies(listenerCapture: deviceListenerCapture); var sut = new TelemetryHandler(connectionRegistry, identityProvider); var isHandled = await sut.HandleAsync(publishInfo); Assert.True(isHandled); Assert.NotNull(deviceListenerCapture.Captured); Assert.NotNull(deviceListenerCapture.Captured.LastCapturedMessage); var capturedMessage = deviceListenerCapture.Captured.LastCapturedMessage; var expectedProperties = new Dictionary <string, string>() { ["prop1"] = "val1", ["prop2"] = "val2", }; Assert.Equal(expectedProperties, capturedMessage.Properties); }
public async Task HandlesTelemetryTopics(string topic) { var publishInfo = new MqttPublishInfo(topic, new byte[0]); var(connectionRegistry, identityProvider) = GetHandlerDependencies(); var sut = new TelemetryHandler(connectionRegistry, identityProvider); var isHandled = await sut.HandleAsync(publishInfo); Assert.True(isHandled); }
public async Task DoesNotHandleUnknownClient() { var publishInfo = new MqttPublishInfo("$edgehub/device_id/messages/events/prop1=val1&prop2=val2", new byte[0]); var(connectionRegistry, identityProvider) = GetHandlerDependencies(shouldFindProxy: false); var sut = new TelemetryHandler(connectionRegistry, identityProvider); var isHandled = await sut.HandleAsync(publishInfo); Assert.False(isHandled); }
public async Task DoesNotHandleUnknownClient() { var publishInfo = new MqttPublishInfo("$edgehub/captured_device_id/captured_module_id/twin/get/?$rid=123", new byte[0]); var(connectionRegistry, identityProvider) = GetHandlerDependencies(shouldFindProxy: false); var sut = new TelemetryHandler(connectionRegistry, identityProvider); var isHandled = await sut.HandleAsync(publishInfo); Assert.False(isHandled); }
public async Task InternalMessageCapturesSystemProperties() { var deviceListenerCapture = new DeviceListenerCapture(); var publishInfo = new MqttPublishInfo("$edgehub/device_id/messages/events/%24.uid=userid&%24.cid=corrid", new byte[] { 0x01, 0x02, 0x03 }); var(connectionRegistry, _) = GetHandlerDependencies(listenerCapture: deviceListenerCapture); var identityProvider = Mock.Of <IIdentityProvider>(); string passedDeviceId = null; Mock.Get(identityProvider) .Setup(ip => ip.Create(It.IsAny <string>())) .Returns((string device_id) => { passedDeviceId = device_id; return(new DeviceIdentity("host", device_id)); }); var sut = new TelemetryHandler(connectionRegistry, identityProvider); var isHandled = await sut.HandleAsync(publishInfo); Assert.True(isHandled); Assert.NotNull(deviceListenerCapture.Captured); Assert.NotNull(deviceListenerCapture.Captured.LastCapturedMessage); var capturedMessage = deviceListenerCapture.Captured.LastCapturedMessage; var expectedProperties = new Dictionary <string, string>() { ["userId"] = "userid", ["cid"] = "corrid", ["connectionDeviceId"] = passedDeviceId }; Assert.Equal(expectedProperties, capturedMessage.SystemProperties); }