public async Task RequestDelegate_WhenContextMatchesTopicInUse_ProcessesMqttMessage( MqttApplicationBuilder mqttApplicationBuilder ) { var mqttRequestContext = new TestMqttRequestContext { Topic = "test/topic" }; mqttApplicationBuilder.Use(MqttRequestDelegateHelper.Create(ctx => ctx.Topic.Equals("test/topic"))); var mqttApplication = mqttApplicationBuilder.Build(); var result = await mqttApplication.RequestDelegate.Invoke(mqttRequestContext); Assert.True(result); }
public async Task RequestDelegate_WithMultipleMappedParameterizedHandlers_BehavesAsExpected( MqttApplicationBuilder mqttApplicationBuilder ) { var mqttRequestContext1 = new TestMqttRequestContext <TestTopicParameters> { Topic = "test/1/one" }; var mqttRequestContext2 = new TestMqttRequestContext <TestTopicParameters> { Topic = "test/2/two" }; var mqttRequestContext3 = new TestMqttRequestContext <TestTopicParameters> { Topic = "test/3/three" }; var mqttRequestContext4 = new TestMqttRequestContext <TestTopicParameters> { Topic = "test/4/four" }; mqttApplicationBuilder.Map( "test/1/+StringProperty", MqttRequestDelegateHelper.Create <TestTopicParameters>( ctx => { Assert.Equal("one", ctx.TopicParameters.StringProperty); return(true); })); mqttApplicationBuilder.Map( "test/2/+StringProperty", MqttRequestDelegateHelper.Create <TestTopicParameters>( ctx => { Assert.Equal("two", ctx.TopicParameters.StringProperty); return(true); })); mqttApplicationBuilder.Map( "test/3/+StringProperty", MqttRequestDelegateHelper.Create <TestTopicParameters>( ctx => { Assert.Equal("three", ctx.TopicParameters.StringProperty); return(true); })); mqttApplicationBuilder.Use(MqttRequestDelegateHelper.DoesNotHandleRequest()); var mqttApplication = mqttApplicationBuilder.Build(); var result1 = await mqttApplication.RequestDelegate.Invoke(mqttRequestContext1); var result2 = await mqttApplication.RequestDelegate.Invoke(mqttRequestContext2); var result3 = await mqttApplication.RequestDelegate.Invoke(mqttRequestContext3); var result4 = await mqttApplication.RequestDelegate.Invoke(mqttRequestContext4); Assert.True(result1); Assert.True(result2); Assert.True(result3); Assert.False(result4); }