public void BrokenCustomConfigCreatorThrowsException() { // Arrange var mqttTriggerAttribute = new MqttTriggerAttribute(typeof(BrokenTestMqttConfigProvider)); var attributeToConfigConverter = new AttributeToConfigConverter(mqttTriggerAttribute, _resolver, _mockLogger.Object); // Act & Assert var ex = Assert.Throws <InvalidCustomConfigCreatorException>(() => attributeToConfigConverter.GetMqttConfiguration()); }
public void NoServernameProvidedResultsInException() { // Arrange var mqttTriggerAttribute = new MqttTriggerAttribute(new[] { "testTopic" }) { ConnectionString = "Server=;Port=1883;Username=UserName;Password=Password;ClientId=" }; var attributeToConfigConverter = new AttributeToConfigConverter(mqttTriggerAttribute, _resolver, _mockLogger.Object); // Act & Assert var ex = Assert.Throws <Exception>(() => attributeToConfigConverter.GetMqttConfiguration()); }
public void InvalidPortThrowsException() { // Arrange var mqttTriggerAttribute = new MqttTriggerAttribute("testTopic") { ConnectionString = "Server=ServerName;Port=ByeWorld;Username=UserName;Password=Password" }; var attributeToConfigConverter = new AttributeToConfigConverter(mqttTriggerAttribute, _resolver, _mockLogger.Object); // Act & Assert var ex = Assert.Throws <FormatException>(() => attributeToConfigConverter.GetMqttConfiguration()); }
public MqttConnection GetMqttConnection(IRquireMqttConnection attribute) { var attributeToConfigConverter = new AttributeToConfigConverter(attribute, _nameResolver, _logger); var mqttConfiguration = attributeToConfigConverter.GetMqttConfiguration(); if (mqttConnections.ContainsKey(mqttConfiguration.Name) && attribute is MqttTriggerAttribute) { throw new Exception($"Error setting up listener for this attribute. Connectionstring '{mqttConfiguration.Name}' is already used by another Trigger. Connections can only be reused for output bindings. Each trigger needs it own connectionstring"); } var connection = mqttConnections.GetOrAdd(mqttConfiguration.Name, (c) => new MqttConnection(_mqttFactory, mqttConfiguration, _logger)); return(connection); }
public void CustomConfigProviderIsInvoked() { // Arrange var mqttTriggerAttribute = new MqttTriggerAttribute(typeof(TestMqttConfigProvider)); var attributeToConfigConverter = new AttributeToConfigConverter(mqttTriggerAttribute, _resolver, _mockLogger.Object); // Act var result = attributeToConfigConverter.GetMqttConfiguration(); // Assert Assert.NotNull(result); //Assert.Contains(result.Topics.Select(x => x.Topic), (x) => x == "Test"); }
public void NoClientIdGuidBasedClientIdIsGenerated() { // Arrange var mqttTriggerAttribute = new MqttTriggerAttribute(new[] { "testTopic" }) { ConnectionString = "Server=ServerName;Port=1883;Username=UserName;Password=Password;ClientId=" }; var attributeToConfigConverter = new AttributeToConfigConverter(mqttTriggerAttribute, _resolver, _mockLogger.Object); // Act var result = attributeToConfigConverter.GetMqttConfiguration(); // Assert Assert.NotNull(result.Options.ClientOptions.ClientId); Assert.True(Guid.TryParse(result.Options.ClientOptions.ClientId, out var guid)); }
public void ValidConfigurationIsMappedCorrect() { // Arrange var mqttTriggerAttribute = new MqttTriggerAttribute("testTopic") { ConnectionString = "Server=ServerName;Port=1883;Username=UserName;Password=Password;ClientId=TestClientId" }; var attributeToConfigConverter = new AttributeToConfigConverter(mqttTriggerAttribute, _resolver, _mockLogger.Object); // Act var result = attributeToConfigConverter.GetMqttConfiguration(); // Assert //Assert.Equal(mqttTriggerAttribute.Topics, result.Topics.Select(x => x.Topic)); Assert.Equal("TestClientId", result.Options.ClientOptions.ClientId); }