mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 11:03:07 +08:00
Add session to subscribe interceptor.
This commit is contained in:
@@ -10,15 +10,12 @@ using MQTTnet.Exceptions;
|
||||
using MQTTnet.LowLevelClient;
|
||||
using MQTTnet.Packets;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Tests.Mockups;
|
||||
|
||||
namespace MQTTnet.Tests.Client
|
||||
{
|
||||
[TestClass]
|
||||
public class LowLevelMqttClient_Tests
|
||||
public sealed class LowLevelMqttClient_Tests : BaseTestClass
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(MqttCommunicationException))]
|
||||
public async Task Connect_To_Not_Existing_Server()
|
||||
@@ -34,7 +31,7 @@ namespace MQTTnet.Tests.Client
|
||||
[TestMethod]
|
||||
public async Task Connect_And_Disconnect()
|
||||
{
|
||||
using (var testEnvironment = new TestEnvironment(TestContext))
|
||||
using (var testEnvironment = CreateTestEnvironment())
|
||||
{
|
||||
await testEnvironment.StartServer();
|
||||
|
||||
@@ -50,7 +47,7 @@ namespace MQTTnet.Tests.Client
|
||||
[TestMethod]
|
||||
public async Task Authenticate()
|
||||
{
|
||||
using (var testEnvironment = new TestEnvironment(TestContext))
|
||||
using (var testEnvironment = CreateTestEnvironment())
|
||||
{
|
||||
await testEnvironment.StartServer();
|
||||
|
||||
@@ -71,7 +68,7 @@ namespace MQTTnet.Tests.Client
|
||||
[TestMethod]
|
||||
public async Task Subscribe()
|
||||
{
|
||||
using (var testEnvironment = new TestEnvironment(TestContext))
|
||||
using (var testEnvironment = CreateTestEnvironment())
|
||||
{
|
||||
await testEnvironment.StartServer();
|
||||
|
||||
@@ -94,21 +91,23 @@ namespace MQTTnet.Tests.Client
|
||||
[TestMethod]
|
||||
public async Task Loose_Connection()
|
||||
{
|
||||
using (var testEnvironment = new TestEnvironment(TestContext))
|
||||
using (var testEnvironment = CreateTestEnvironment())
|
||||
{
|
||||
testEnvironment.ServerPort = 8364;
|
||||
var server = await testEnvironment.StartServer();
|
||||
|
||||
var client = await testEnvironment.ConnectLowLevelClient(o => o.WithCommunicationTimeout(TimeSpan.Zero));
|
||||
|
||||
await Authenticate(client).ConfigureAwait(false);
|
||||
|
||||
await server.StopAsync();
|
||||
|
||||
await Task.Delay(1000);
|
||||
await Task.Delay(2000);
|
||||
|
||||
try
|
||||
{
|
||||
await client.SendAsync(MqttPingReqPacket.Instance, CancellationToken.None).ConfigureAwait(false);
|
||||
await Task.Delay(1000);
|
||||
await client.SendAsync(MqttPingReqPacket.Instance, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
catch (MqttCommunicationException exception)
|
||||
|
||||
@@ -878,7 +878,7 @@ namespace MQTTnet.Tests.Server
|
||||
// This should lead to no subscriptions for "n" at all. So also no sending of retained messages.
|
||||
if (c.TopicFilter.Topic == "n")
|
||||
{
|
||||
c.AcceptSubscription = false;
|
||||
c.ReasonCode = MqttSubscribeReasonCode.UnspecifiedError;
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using MQTTnet.Tests.Mockups;
|
||||
namespace MQTTnet.Tests.Server
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttSubscriptionsManager_Tests
|
||||
public class MqttSubscriptionsManager_Tests : BaseTestClass
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task MqttSubscriptionsManager_SubscribeSingleSuccess()
|
||||
@@ -102,12 +102,18 @@ namespace MQTTnet.Tests.Server
|
||||
|
||||
MqttClientSession CreateSession()
|
||||
{
|
||||
var logger = new TestLogger();
|
||||
var options = new MqttServerOptions();
|
||||
var retainedMessagesManager = new MqttRetainedMessagesManager();
|
||||
var eventDispatcher = new MqttServerEventDispatcher(logger);
|
||||
|
||||
return new MqttClientSession(
|
||||
"",
|
||||
new ConcurrentDictionary<object, object>(),
|
||||
new MqttServerEventDispatcher(new TestLogger()),
|
||||
new MqttServerOptions(),
|
||||
new MqttRetainedMessagesManager());
|
||||
eventDispatcher,
|
||||
options,
|
||||
retainedMessagesManager,
|
||||
new MqttClientSessionsManager(options, retainedMessagesManager, eventDispatcher, logger));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,12 +73,12 @@ namespace MQTTnet.TestApp.NetCore
|
||||
{
|
||||
if (context.TopicFilter.Topic.StartsWith("admin/foo/bar") && context.ClientId != "theAdmin")
|
||||
{
|
||||
context.AcceptSubscription = false;
|
||||
context.ReasonCode = MqttSubscribeReasonCode.ImplementationSpecificError;
|
||||
}
|
||||
|
||||
if (context.TopicFilter.Topic.StartsWith("the/secret/stuff") && context.ClientId != "Imperator")
|
||||
{
|
||||
context.AcceptSubscription = false;
|
||||
context.ReasonCode = MqttSubscribeReasonCode.ImplementationSpecificError;
|
||||
context.CloseConnection = true;
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user