25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MqttSubscriptionsManagerTests.cs 2.3 KiB

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