Merge branch 'master' into feature/low_level_client

This commit is contained in:
Christian Kratky
2020-04-03 22:53:22 +02:00
7 changed files with 139 additions and 15 deletions
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Extensions;
using MQTTnet.Packets;
namespace MQTTnet.Tests
{
[TestClass]
public class MqttApplicationMessage_Tests
{
[TestMethod]
public void GetUserProperty_Test()
{
var message = new MqttApplicationMessage
{
UserProperties = new List<MqttUserProperty>
{
new MqttUserProperty("foo", "bar"),
new MqttUserProperty("value", "1011"),
new MqttUserProperty("CASE", "insensitive")
}
};
Assert.AreEqual("bar", message.GetUserProperty("foo"));
Assert.AreEqual(1011, message.GetUserProperty<int>("value"));
Assert.AreEqual("insensitive", message.GetUserProperty("case"));
Assert.AreEqual(null, message.GetUserProperty("nonExists"));
Assert.AreEqual(null, message.GetUserProperty<int?>("nonExists"));
Assert.ThrowsException<InvalidOperationException>(() => message.GetUserProperty<int>("nonExists"));
}
}
}
@@ -0,0 +1,22 @@
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Client.Options;
using MQTTnet.Extensions;
namespace MQTTnet.Tests
{
[TestClass]
public class MqttClientOptionsBuilder_Tests
{
[TestMethod]
public void WithConnectionUri_Credential_Test()
{
var options = new MqttClientOptionsBuilder()
.WithConnectionUri("mqtt://user:password@127.0.0.1")
.Build();
Assert.AreEqual("user", options.Credentials.Username);
Assert.IsTrue(Encoding.UTF8.GetBytes("password").SequenceEqual(options.Credentials.Password));
}
}
}