mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-11-05 22:16:32 +08:00
Merge branch 'master' of https://github.com/chkr1011/MQTTnet into feature/Reason_Code_In_Subscription_Interceptor
# Conflicts: # Build/MQTTnet.nuspec # Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
This commit is contained in:
@@ -2,41 +2,46 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Client.Receiving;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Implementations;
|
||||
|
||||
namespace MQTTnet.Tests.Mockups
|
||||
{
|
||||
public sealed class TestApplicationMessageReceivedHandler : IMqttApplicationMessageReceivedHandler
|
||||
public sealed class TestApplicationMessageReceivedHandler
|
||||
{
|
||||
readonly List<MqttApplicationMessage> _messageReceivedEventArgs = new List<MqttApplicationMessage>();
|
||||
readonly List<MqttApplicationMessageReceivedEventArgs> _receivedEventArgs = new List<MqttApplicationMessageReceivedEventArgs>();
|
||||
|
||||
public Task HandleApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs eventArgs)
|
||||
public TestApplicationMessageReceivedHandler(IMqttClient mqttClient)
|
||||
{
|
||||
lock (_messageReceivedEventArgs)
|
||||
mqttClient.ApplicationMessageReceivedAsync += MqttClientOnApplicationMessageReceivedAsync;
|
||||
}
|
||||
|
||||
Task MqttClientOnApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs eventArgs)
|
||||
{
|
||||
lock (_receivedEventArgs)
|
||||
{
|
||||
_messageReceivedEventArgs.Add(eventArgs.ApplicationMessage);
|
||||
_receivedEventArgs.Add(eventArgs);
|
||||
}
|
||||
|
||||
return PlatformAbstractionLayer.CompletedTask;
|
||||
}
|
||||
|
||||
public List<MqttApplicationMessage> ReceivedApplicationMessages
|
||||
|
||||
public List<MqttApplicationMessageReceivedEventArgs> ReceivedEventArgs
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_messageReceivedEventArgs)
|
||||
lock (_receivedEventArgs)
|
||||
{
|
||||
return _messageReceivedEventArgs.ToList();
|
||||
return _receivedEventArgs.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AssertReceivedCountEquals(int expectedCount)
|
||||
{
|
||||
lock (_messageReceivedEventArgs)
|
||||
lock (_receivedEventArgs)
|
||||
{
|
||||
Assert.AreEqual(expectedCount, _messageReceivedEventArgs.Count);
|
||||
Assert.AreEqual(expectedCount, _receivedEventArgs.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Connecting;
|
||||
using MQTTnet.Client.Disconnecting;
|
||||
using MQTTnet.Client.ExtendedAuthenticationExchange;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Client.Publishing;
|
||||
using MQTTnet.Client.Receiving;
|
||||
using MQTTnet.Client.Subscribing;
|
||||
using MQTTnet.Client.Unsubscribing;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -53,13 +45,7 @@ namespace MQTTnet.Tests.Mockups
|
||||
add => Implementation.DisconnectedAsync += value;
|
||||
remove => Implementation.DisconnectedAsync -= value;
|
||||
}
|
||||
|
||||
public IMqttApplicationMessageReceivedHandler ApplicationMessageReceivedHandler
|
||||
{
|
||||
get => Implementation.ApplicationMessageReceivedHandler;
|
||||
set => Implementation.ApplicationMessageReceivedHandler = value;
|
||||
}
|
||||
|
||||
|
||||
public event Func<MqttApplicationMessageReceivedEventArgs, Task> ApplicationMessageReceivedAsync
|
||||
{
|
||||
add => Implementation.ApplicationMessageReceivedAsync += value;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Server;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,7 +7,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Diagnostics.Logger;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Extensions.Rpc;
|
||||
using MQTTnet.Extensions.Rpc.Options;
|
||||
using MQTTnet.Formatter;
|
||||
@@ -232,17 +231,7 @@ namespace MQTTnet.Tests.Mockups
|
||||
|
||||
public TestApplicationMessageReceivedHandler CreateApplicationMessageHandler(IMqttClient mqttClient)
|
||||
{
|
||||
if (mqttClient == null) throw new ArgumentNullException(nameof(mqttClient));
|
||||
|
||||
var handler = new TestApplicationMessageReceivedHandler();
|
||||
if (mqttClient.ApplicationMessageReceivedHandler != null)
|
||||
{
|
||||
throw new InvalidOperationException("ApplicationMessageReceivedHandler is already set.");
|
||||
}
|
||||
|
||||
mqttClient.ApplicationMessageReceivedHandler = handler;
|
||||
|
||||
return handler;
|
||||
return new TestApplicationMessageReceivedHandler(mqttClient);
|
||||
}
|
||||
|
||||
public void ThrowIfLogErrors()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using MQTTnet.Diagnostics.Logger;
|
||||
using MQTTnet.Diagnostics;
|
||||
|
||||
namespace MQTTnet.Tests.Mockups
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Diagnostics;
|
||||
|
||||
namespace MQTTnet.Tests.Mockups
|
||||
{
|
||||
@@ -12,7 +13,7 @@ namespace MQTTnet.Tests.Mockups
|
||||
_adapter = adapter;
|
||||
}
|
||||
|
||||
public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options)
|
||||
public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options, IMqttNetLogger logger)
|
||||
{
|
||||
return _adapter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user