Пример #1
0
        public void TopicFilters_WithMultipleMappedHandlersAndNoDefaultMapping_ContainsExpectedFilters(
            MqttApplicationBuilder mqttApplicationBuilder
            )
        {
            mqttApplicationBuilder.Map("test/1", MqttRequestDelegateHelper.Throws(new Exception("1")));
            mqttApplicationBuilder.Map("test/2", MqttRequestDelegateHelper.Throws(new Exception("2")));
            mqttApplicationBuilder.Map("test/3", MqttRequestDelegateHelper.Throws(new Exception("3")));

            var mqttApplication = mqttApplicationBuilder.Build();

            Assert.Collection(
                mqttApplication.TopicFilters,
                f1 => Assert.Equal("test/1", f1.Topic),
                f2 => Assert.Equal("test/2", f2.Topic),
                f3 => Assert.Equal("test/3", f3.Topic));
        }
Пример #2
0
        public async Task RequestDelegate_WithMultipleMappedHandlers_BehavesAsExpected(
            MqttApplicationBuilder mqttApplicationBuilder
            )
        {
            var mqttRequestContext1 = new TestMqttRequestContext {
                Topic = "test/1"
            };
            var mqttRequestContext2 = new TestMqttRequestContext {
                Topic = "test/2"
            };
            var mqttRequestContext3 = new TestMqttRequestContext {
                Topic = "test/3"
            };
            var mqttRequestContext4 = new TestMqttRequestContext {
                Topic = "test/4"
            };

            mqttApplicationBuilder.Map("test/1", MqttRequestDelegateHelper.Throws(new Exception("1")));
            mqttApplicationBuilder.Map("test/2", MqttRequestDelegateHelper.Throws(new Exception("2")));
            mqttApplicationBuilder.Map("test/3", MqttRequestDelegateHelper.Throws(new Exception("3")));
            mqttApplicationBuilder.Use(MqttRequestDelegateHelper.HandlesRequest());

            var mqttApplication = mqttApplicationBuilder.Build();

            Assert.Collection(
                mqttApplication.TopicFilters,
                f1 => Assert.Equal("test/1", f1.Topic),
                f2 => Assert.Equal("test/2", f2.Topic),
                f3 => Assert.Equal("test/3", f3.Topic),
                f4 => Assert.Equal("#", f4.Topic));

            var exception1 = await Assert.ThrowsAsync <Exception>(() => mqttApplication.RequestDelegate.Invoke(mqttRequestContext1));

            var exception2 = await Assert.ThrowsAsync <Exception>(() => mqttApplication.RequestDelegate.Invoke(mqttRequestContext2));

            var exception3 = await Assert.ThrowsAsync <Exception>(() => mqttApplication.RequestDelegate.Invoke(mqttRequestContext3));

            var result4 = await mqttApplication.RequestDelegate.Invoke(mqttRequestContext4);

            Assert.Equal("1", exception1.Message);
            Assert.Equal("2", exception2.Message);
            Assert.Equal("3", exception3.Message);

            Assert.True(result4);
        }