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.
 
 
 
 

33 lines
1.1 KiB

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