Expose WithClientMessageQueueInterceptor

This commit is contained in:
Marc Sallin
2020-09-04 09:53:34 +02:00
committed by Sallin Marc, I212
parent b0c603082b
commit f1f9924bce
3 changed files with 80 additions and 0 deletions
+37
View File
@@ -1415,5 +1415,42 @@ namespace MQTTnet.Tests
Assert.AreEqual("a", undeliverd);
}
}
[TestMethod]
public async Task Intercept_ClientMessageQueue()
{
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync(new MqttServerOptionsBuilder()
.WithClientMessageQueueInterceptor(c => c.ApplicationMessage.Topic = "a"));
var topicAReceived = false;
var topicBReceived = false;
var client = await testEnvironment.ConnectClientAsync();
client.UseApplicationMessageReceivedHandler(c =>
{
if (c.ApplicationMessage.Topic == "a")
{
topicAReceived = true;
}
else if (c.ApplicationMessage.Topic == "b")
{
topicBReceived = true;
}
});
await client.SubscribeAsync("a");
await client.SubscribeAsync("b");
await client.PublishAsync("b");
await Task.Delay(500);
Assert.IsTrue(topicAReceived);
Assert.IsFalse(topicBReceived);
}
}
}
}