Skip to content

Commit

Permalink
Add more unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Dec 4, 2024
1 parent 4bfd77d commit 9d9dd44
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 1 addition & 3 deletions MQTTnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet", "Source\MQTTnet\M
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B3F60ECB-45BA-4C66-8903-8BB89CA67998}"
ProjectSection(SolutionItems) = preProject
.github\workflows\ci.yml = .github\workflows\ci.yml
CODE-OF-CONDUCT.md = CODE-OF-CONDUCT.md
LICENSE = LICENSE
README.md = README.md
Source\ReleaseNotes.md = Source\ReleaseNotes.md
.github\workflows\ci.yml = .github\workflows\ci.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.AspNetCore", "Source\MQTTnet.AspnetCore\MQTTnet.AspNetCore.csproj", "{F10C4060-F7EE-4A83-919F-FF723E72F94A}"
Expand Down Expand Up @@ -85,6 +85,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {07536672-5CBC-4BE3-ACE0-708A431A7894}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task InvokeAsync(ConnectionDelegate next, ConnectionContext connect
}
}

private static bool IsMqttRequest(ReadOnlySequence<byte> buffer)
public static bool IsMqttRequest(ReadOnlySequence<byte> buffer)
{
if (!buffer.IsEmpty)
{
Expand Down
24 changes: 24 additions & 0 deletions Source/MQTTnet.Tests/ASP/MqttConnectionMiddlewareTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.AspNetCore;
using System;
using System.Buffers;

namespace MQTTnet.Tests.ASP
{
[TestClass]
public class MqttConnectionMiddlewareTest
{
[TestMethod]
public void IsMqttRequestTest()
{
var mqttv31Request = Convert.FromHexString("102800044d51545404c0003c0008636c69656e7469640008757365726e616d650008706173736f777264");
var mqttv50Request = Convert.FromHexString("102900044d51545405c0003c000008636c69656e7469640008757365726e616d650008706173736f777264");

var isMqttv31 = MqttConnectionMiddleware.IsMqttRequest(new ReadOnlySequence<byte>(mqttv31Request));
var isMqttv50 = MqttConnectionMiddleware.IsMqttRequest(new ReadOnlySequence<byte>(mqttv50Request));

Assert.IsTrue(isMqttv31);
Assert.IsTrue(isMqttv50);
}
}
}

0 comments on commit 9d9dd44

Please sign in to comment.