Преглед изворни кода

Add topic filter tests from MQTT spec

release/3.x.x
Christian пре 6 година
родитељ
комит
74a5522965
2 измењених фајлова са 28 додато и 2 уклоњено
  1. +1
    -1
      Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs
  2. +27
    -1
      Tests/MQTTnet.Core.Tests/TopicFilterComparerTests.cs

+ 1
- 1
Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs Прегледај датотеку

@@ -129,7 +129,7 @@ namespace MQTTnet.Adapter
{
return null;
}
if (header.BodyLength == 0)
{
return new ReceivedMqttPacket(header, new MemoryStream(new byte[0], false));


+ 27
- 1
Tests/MQTTnet.Core.Tests/TopicFilterComparerTests.cs Прегледај датотеку

@@ -60,7 +60,33 @@ namespace MQTTnet.Core.Tests
CompareAndAssert("A/B/C/D", "#", true);
}

private void CompareAndAssert(string topic, string filter, bool expectedResult)
[TestMethod]
public void TopicFilterComparer_MultiLevel_Sport()
{
// Tests from official MQTT spec (4.7.1.2 Multi-level wildcard)
CompareAndAssert("sport/tennis/player1", "sport/tennis/player1/#", true);
CompareAndAssert("sport/tennis/player1/ranking", "sport/tennis/player1/#", true);
CompareAndAssert("sport/tennis/player1/score/wimbledon", "sport/tennis/player1/#", true);

CompareAndAssert("sport/tennis/player1", "sport/tennis/+", true);
CompareAndAssert("sport/tennis/player2", "sport/tennis/+", true);
CompareAndAssert("sport/tennis/player1/ranking", "sport/tennis/+", false);

CompareAndAssert("sport", "sport/#", true);
CompareAndAssert("sport", "sport/+", false);
CompareAndAssert("sport/", "sport/+", true);
}

[TestMethod]
public void TopicFilterComparer_SingleLevel_Finance()
{
// Tests from official MQTT spec (4.7.1.3 Single level wildcard)
CompareAndAssert("/finance", "+/+", true);
CompareAndAssert("/finance", "/+", true);
CompareAndAssert("/finance", "+", false);
}

private static void CompareAndAssert(string topic, string filter, bool expectedResult)
{
Assert.AreEqual(expectedResult, MqttTopicFilterComparer.IsMatch(topic, filter));
}


Loading…
Откажи
Сачувај