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.
 
 
 
 

34 lines
1.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using MQTTnet.Extensions;
  5. using MQTTnet.Packets;
  6. namespace MQTTnet.Tests
  7. {
  8. [TestClass]
  9. public class MqttApplicationMessage_Tests
  10. {
  11. [TestMethod]
  12. public void GetUserProperty_Test()
  13. {
  14. var message = new MqttApplicationMessage
  15. {
  16. UserProperties = new List<MqttUserProperty>
  17. {
  18. new MqttUserProperty("foo", "bar"),
  19. new MqttUserProperty("value", "1011"),
  20. new MqttUserProperty("CASE", "insensitive")
  21. }
  22. };
  23. Assert.AreEqual("bar", message.GetUserProperty("foo"));
  24. Assert.AreEqual(1011, message.GetUserProperty<int>("value"));
  25. Assert.AreEqual("insensitive", message.GetUserProperty("case"));
  26. Assert.AreEqual(null, message.GetUserProperty("nonExists"));
  27. Assert.AreEqual(null, message.GetUserProperty<int?>("nonExists"));
  28. Assert.ThrowsException<InvalidOperationException>(() => message.GetUserProperty<int>("nonExists"));
  29. }
  30. }
  31. }