mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-17 01:33:03 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de647f650c |
@@ -21,6 +21,52 @@ namespace MQTTnet.Tests.Client
|
|||||||
[TestClass]
|
[TestClass]
|
||||||
public sealed class ManagedMqttClient_Tests : BaseTestClass
|
public sealed class ManagedMqttClient_Tests : BaseTestClass
|
||||||
{
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Subscribe_When_Offline_But_Existing_Session()
|
||||||
|
{
|
||||||
|
using (var testEnvironment = CreateTestEnvironment())
|
||||||
|
{
|
||||||
|
var server = await testEnvironment.StartServer(o => o.WithPersistentSessions());
|
||||||
|
|
||||||
|
// The connected client will crate a new session.
|
||||||
|
var mqttClient = await testEnvironment.ConnectClient();
|
||||||
|
mqttClient.Dispose();
|
||||||
|
|
||||||
|
mqttClient = testEnvironment.CreateClient();
|
||||||
|
var managedClient = testEnvironment.Factory.CreateManagedMqttClient(mqttClient);
|
||||||
|
|
||||||
|
// Subscribe before starting!
|
||||||
|
await managedClient.SubscribeAsync("a");
|
||||||
|
|
||||||
|
MqttApplicationMessage applicationMessage = null;
|
||||||
|
managedClient.ApplicationMessageReceivedAsync += e =>
|
||||||
|
{
|
||||||
|
applicationMessage = e.ApplicationMessage;
|
||||||
|
return CompletedTask.Instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Now the client must send the new subscription.
|
||||||
|
await managedClient.StartAsync(
|
||||||
|
new ManagedMqttClientOptions
|
||||||
|
{
|
||||||
|
ClientOptions = testEnvironment.Factory.CreateClientOptionsBuilder().WithCleanSession(false).WithTcpServer("127.0.0.1", testEnvironment.ServerPort).Build()
|
||||||
|
});
|
||||||
|
|
||||||
|
await LongTestDelay();
|
||||||
|
|
||||||
|
await server.InjectApplicationMessage(
|
||||||
|
new InjectedMqttApplicationMessage(
|
||||||
|
new MqttApplicationMessage
|
||||||
|
{
|
||||||
|
Topic = "a"
|
||||||
|
}));
|
||||||
|
|
||||||
|
await LongTestDelay();
|
||||||
|
|
||||||
|
Assert.IsNotNull(applicationMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task Connect_To_Invalid_Server()
|
public async Task Connect_To_Invalid_Server()
|
||||||
{
|
{
|
||||||
@@ -29,7 +75,6 @@ namespace MQTTnet.Tests.Client
|
|||||||
testEnvironment.IgnoreClientLogErrors = true;
|
testEnvironment.IgnoreClientLogErrors = true;
|
||||||
|
|
||||||
var mqttClient = testEnvironment.CreateClient();
|
var mqttClient = testEnvironment.CreateClient();
|
||||||
|
|
||||||
var managedClient = testEnvironment.Factory.CreateManagedMqttClient(mqttClient);
|
var managedClient = testEnvironment.Factory.CreateManagedMqttClient(mqttClient);
|
||||||
|
|
||||||
ConnectingFailedEventArgs connectingFailedEventArgs = null;
|
ConnectingFailedEventArgs connectingFailedEventArgs = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user