Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

75 lignes
2.1 KiB

  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using MQTTnet.Core.Packets;
  3. using MQTTnet.Core.Protocol;
  4. using MQTTnet.Core.Server;
  5. namespace MQTTnet.Core.Tests
  6. {
  7. [TestClass]
  8. public class MqttSubscriptionsManagerTests
  9. {
  10. [TestMethod]
  11. public void MqttSubscriptionsManager_SubscribeSingleSuccess()
  12. {
  13. var sm = new MqttClientSubscriptionsManager();
  14. var sp = new MqttSubscribePacket();
  15. sp.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.AtMostOnce));
  16. sm.Subscribe(sp);
  17. var pp = new MqttPublishPacket
  18. {
  19. Topic = "A/B/C",
  20. QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce
  21. };
  22. Assert.IsTrue(sm.IsSubscribed(pp));
  23. }
  24. [TestMethod]
  25. public void MqttSubscriptionsManager_SubscribeSingleNoSuccess()
  26. {
  27. var sm = new MqttClientSubscriptionsManager();
  28. var sp = new MqttSubscribePacket();
  29. sp.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.AtMostOnce));
  30. sm.Subscribe(sp);
  31. var pp = new MqttPublishPacket
  32. {
  33. Topic = "A/B/X",
  34. QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce
  35. };
  36. Assert.IsFalse(sm.IsSubscribed(pp));
  37. }
  38. [TestMethod]
  39. public void MqttSubscriptionsManager_SubscribeAndUnsubscribeSingle()
  40. {
  41. var sm = new MqttClientSubscriptionsManager();
  42. var sp = new MqttSubscribePacket();
  43. sp.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.AtMostOnce));
  44. sm.Subscribe(sp);
  45. var pp = new MqttPublishPacket
  46. {
  47. Topic = "A/B/C",
  48. QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce
  49. };
  50. Assert.IsTrue(sm.IsSubscribed(pp));
  51. var up = new MqttUnsubscribePacket();
  52. up.TopicFilters.Add("A/B/C");
  53. sm.Unsubscribe(up);
  54. Assert.IsFalse(sm.IsSubscribed(pp));
  55. }
  56. }
  57. }