You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
1.6 KiB

  1. using System.Threading.Tasks;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using MQTTnet.Client;
  4. using MQTTnet.Formatter;
  5. namespace MQTTnet.Tests.Server
  6. {
  7. [TestClass]
  8. public sealed class No_Local_Tests : BaseTestClass
  9. {
  10. [TestMethod]
  11. public Task Subscribe_With_No_Local()
  12. {
  13. return ExecuteTest(true, 0);
  14. }
  15. [TestMethod]
  16. public Task Subscribe_Without_No_Local()
  17. {
  18. return ExecuteTest(false, 1);
  19. }
  20. async Task ExecuteTest(
  21. bool noLocal,
  22. int expectedCountAfterPublish)
  23. {
  24. using (var testEnvironment = CreateTestEnvironment(MqttProtocolVersion.V500))
  25. {
  26. await testEnvironment.StartServer();
  27. var client1 = await testEnvironment.ConnectClient();
  28. var applicationMessageHandler = testEnvironment.CreateApplicationMessageHandler(client1);
  29. var topicFilter = testEnvironment.Factory.CreateTopicFilterBuilder().WithTopic("Topic").WithNoLocal(noLocal).Build();
  30. await client1.SubscribeAsync(topicFilter);
  31. await LongTestDelay();
  32. applicationMessageHandler.AssertReceivedCountEquals(0);
  33. // The client will publish a message where it is itself subscribing to.
  34. await client1.PublishAsync("Topic", "Payload", true);
  35. await LongTestDelay();
  36. applicationMessageHandler.AssertReceivedCountEquals(expectedCountAfterPublish);
  37. }
  38. }
  39. }
  40. }