mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-28 01:02:37 +08:00
Add validation for topics before publishing.
This commit is contained in:
@@ -123,13 +123,12 @@ namespace MQTTnet.Tests
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
Assert.AreEqual(cts.Token, ex.CancellationToken);
|
||||
}
|
||||
|
||||
// Now set the event and verify that a future waiter gets the signal immediately.
|
||||
_aare.Set();
|
||||
waitTask = _aare.WaitOneAsync();
|
||||
Assert.AreEqual(TaskStatus.RanToCompletion, waitTask.Status);
|
||||
Assert.AreEqual(TaskStatus.WaitingForActivation, waitTask.Status);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Exceptions;
|
||||
using MQTTnet.Protocol;
|
||||
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttTopicValidator_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Valid_Topic()
|
||||
{
|
||||
MqttTopicValidator.ThrowIfInvalid("/a/b/c");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(MqttProtocolViolationException))]
|
||||
public void Invalid_Topic_Plus()
|
||||
{
|
||||
MqttTopicValidator.ThrowIfInvalid("/a/+/c");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(MqttProtocolViolationException))]
|
||||
public void Invalid_Topic_Hash()
|
||||
{
|
||||
MqttTopicValidator.ThrowIfInvalid("/a/#/c");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(MqttProtocolViolationException))]
|
||||
public void Invalid_Topic_Empty()
|
||||
{
|
||||
MqttTopicValidator.ThrowIfInvalid(string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user