浏览代码

Merge branch 'master'

release/3.x.x
Volker Milbrandt 3 年前
父节点
当前提交
e342a51d50
共有 1 个文件被更改,包括 50 次插入0 次删除
  1. +50
    -0
      Tests/MQTTnet.Core.Tests/Server_Tests.cs

+ 50
- 0
Tests/MQTTnet.Core.Tests/Server_Tests.cs 查看文件

@@ -6,6 +6,7 @@ using MQTTnet.Client.Disconnecting;
using MQTTnet.Client.Options;
using MQTTnet.Client.Receiving;
using MQTTnet.Client.Subscribing;
using MQTTnet.Exceptions;
using MQTTnet.Protocol;
using MQTTnet.Server;
using MQTTnet.Tests.Mockups;
@@ -25,6 +26,55 @@ namespace MQTTnet.Tests
{
public TestContext TestContext { get; set; }

[TestMethod]
[DataRow("", null)]
[DataRow("", "")]
[DataRow(null, null)]
public async Task Use_Admissible_Credentials(string username, string password)
{
using (var testEnvironment = new TestEnvironment())
{
await testEnvironment.StartServerAsync();

var client = testEnvironment.CreateClient();

var clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("localhost", testEnvironment.ServerPort)
.WithCredentials(username, password)
.Build();

var connectResult = await client.ConnectAsync(clientOptions);

Assert.IsFalse(connectResult.IsSessionPresent);
Assert.IsTrue(client.IsConnected);
}
}

[TestMethod]
public async Task Use_Username_Null_Password_Empty()
{
string username = null;
string password = string.Empty;

using (var testEnvironment = new TestEnvironment())
{
testEnvironment.IgnoreClientLogErrors = true;

await testEnvironment.StartServerAsync();

var client = testEnvironment.CreateClient();

var clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("localhost", testEnvironment.ServerPort)
.WithCredentials(username, password)
.Build();

var ex = await Assert.ThrowsExceptionAsync<MqttCommunicationException>(async () => await client.ConnectAsync(clientOptions));
Assert.IsInstanceOfType(ex.InnerException, typeof(MqttProtocolViolationException));
Assert.AreEqual("If the User Name Flag is set to 0, the Password Flag MUST be set to 0 [MQTT-3.1.2-22].", ex.Message, false);
}
}

[TestMethod]
public async Task Use_Empty_Client_ID()
{


正在加载...
取消
保存