mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
Rename tests.
This commit is contained in:
+2
-2
@@ -8,11 +8,11 @@ namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
// Inspired from the vs-threading tests (https://github.com/Microsoft/vs-threading/blob/master/src/Microsoft.VisualStudio.Threading.Tests/AsyncAutoResetEventTests.cs)
|
||||
public class AsyncAutoResetEventTests
|
||||
public class AsyncAutoResetEvent_Tests
|
||||
{
|
||||
private readonly AsyncAutoResetEvent _aare;
|
||||
|
||||
public AsyncAutoResetEventTests()
|
||||
public AsyncAutoResetEvent_Tests()
|
||||
{
|
||||
_aare = new AsyncAutoResetEvent();
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ using MQTTnet.Internal;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class AsyncLockTests
|
||||
public class AsyncLock_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void AsyncLock()
|
||||
+1
-1
@@ -6,7 +6,7 @@ using MQTTnet.Internal;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class BlockingQueueTests
|
||||
public class BlockingQueue_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Preserve_Order()
|
||||
+12
-6
@@ -9,26 +9,31 @@ using MQTTnet.Internal;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class ExtensionTests
|
||||
public class Extension_Tests
|
||||
{
|
||||
[ExpectedException(typeof(MqttCommunicationTimedOutException))]
|
||||
[TestMethod]
|
||||
public async Task TimeoutAfter()
|
||||
{
|
||||
await MqttTaskTimeout.WaitAsync(ct => Task.Delay(TimeSpan.FromMilliseconds(500), ct), TimeSpan.FromMilliseconds(100), CancellationToken.None);
|
||||
await MqttTaskTimeout.WaitAsync(ct => Task.Delay(TimeSpan.FromMilliseconds(500), ct),
|
||||
TimeSpan.FromMilliseconds(100), CancellationToken.None);
|
||||
}
|
||||
|
||||
[ExpectedException(typeof(MqttCommunicationTimedOutException))]
|
||||
[TestMethod]
|
||||
public async Task TimeoutAfterWithResult()
|
||||
{
|
||||
await MqttTaskTimeout.WaitAsync(ct => Task.Delay(TimeSpan.FromMilliseconds(500), ct).ContinueWith(t => 5, ct), TimeSpan.FromMilliseconds(100), CancellationToken.None);
|
||||
await MqttTaskTimeout.WaitAsync(
|
||||
ct => Task.Delay(TimeSpan.FromMilliseconds(500), ct).ContinueWith(t => 5, ct),
|
||||
TimeSpan.FromMilliseconds(100), CancellationToken.None);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TimeoutAfterCompleteInTime()
|
||||
{
|
||||
var result = await MqttTaskTimeout.WaitAsync(ct => Task.Delay(TimeSpan.FromMilliseconds(100), ct).ContinueWith(t => 5, ct), TimeSpan.FromMilliseconds(500), CancellationToken.None);
|
||||
var result = await MqttTaskTimeout.WaitAsync(
|
||||
ct => Task.Delay(TimeSpan.FromMilliseconds(100), ct).ContinueWith(t => 5, ct),
|
||||
TimeSpan.FromMilliseconds(500), CancellationToken.None);
|
||||
Assert.AreEqual(5, result);
|
||||
}
|
||||
|
||||
@@ -77,7 +82,8 @@ namespace MQTTnet.Tests
|
||||
var tasks = Enumerable.Range(0, 100000)
|
||||
.Select(i =>
|
||||
{
|
||||
return MqttTaskTimeout.WaitAsync(ct => Task.Delay(TimeSpan.FromMilliseconds(1), ct), TimeSpan.FromMinutes(1), CancellationToken.None);
|
||||
return MqttTaskTimeout.WaitAsync(ct => Task.Delay(TimeSpan.FromMilliseconds(1), ct),
|
||||
TimeSpan.FromMinutes(1), CancellationToken.None);
|
||||
});
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
@@ -92,4 +98,4 @@ namespace MQTTnet.Tests
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@ using MQTTnet.Tests.Mockups;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class ManagedMqttClientTests
|
||||
public class ManagedMqttClient_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task Drop_New_Messages_On_Full_Queue()
|
||||
+1
-1
@@ -7,7 +7,7 @@ using MQTTnet.Protocol;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttApplicationMessageBuilderTests
|
||||
public class MqttApplicationMessageBuilder_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void CreateApplicationMessage_TopicOnly()
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttFactoryTests
|
||||
public class MqttFactory_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task Create_Managed_Client_With_Logger()
|
||||
+1
-2
@@ -5,14 +5,13 @@ using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Packets;
|
||||
using MQTTnet.Server;
|
||||
using MQTTnet.Server.Status;
|
||||
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttKeepAliveMonitorTests
|
||||
public class MqttKeepAliveMonitor_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void KeepAlive_Timeout()
|
||||
+1
-1
@@ -4,7 +4,7 @@ using MQTTnet.Client;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttPacketIdentifierProviderTests
|
||||
public class MqttPacketIdentifierProvider_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Reset()
|
||||
+1
-1
@@ -8,7 +8,7 @@ using MQTTnet.Internal;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttPacketReaderTests
|
||||
public class MqttPacketReader_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task MqttPacketReader_EmptyStream()
|
||||
+1
-1
@@ -14,7 +14,7 @@ using MQTTnet.Protocol;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttPacketSerializerTests
|
||||
public class MqttPacketSerializer_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void SerializeV310_MqttConnectPacket()
|
||||
+1
-1
@@ -4,7 +4,7 @@ using MQTTnet.Formatter;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttPacketWriterTests
|
||||
public class MqttPacketWriter_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WritePacket()
|
||||
+1
-1
@@ -6,7 +6,7 @@ using MQTTnet.Server;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttSubscriptionsManagerTests
|
||||
public class MqttSubscriptionsManager_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void MqttSubscriptionsManager_SubscribeSingleSuccess()
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Implementations;
|
||||
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttTcpChannel_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task Dispose_Channel_While_Used()
|
||||
{
|
||||
var ct = new CancellationTokenSource();
|
||||
|
||||
try
|
||||
{
|
||||
var serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
serverSocket.Bind(new IPEndPoint(IPAddress.Any, 50000));
|
||||
serverSocket.Listen(0);
|
||||
|
||||
#pragma warning disable 4014
|
||||
Task.Run(async () =>
|
||||
#pragma warning restore 4014
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
var client = await serverSocket.AcceptAsync();
|
||||
var data = new byte[] { 128 };
|
||||
await client.SendAsync(new ArraySegment<byte>(data), SocketFlags.None);
|
||||
}
|
||||
}, ct.Token);
|
||||
|
||||
var clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
await clientSocket.ConnectAsync(IPAddress.Loopback, 50000);
|
||||
|
||||
await Task.Delay(100, ct.Token);
|
||||
|
||||
var tcpChannel = new MqttTcpChannel(new NetworkStream(clientSocket, true));
|
||||
|
||||
var buffer = new byte[1];
|
||||
await tcpChannel.ReadAsync(buffer, 0, 1, ct.Token);
|
||||
|
||||
Assert.AreEqual(128, buffer[0]);
|
||||
|
||||
// This block should fail after dispose.
|
||||
#pragma warning disable 4014
|
||||
Task.Run(() =>
|
||||
#pragma warning restore 4014
|
||||
{
|
||||
Task.Delay(200, ct.Token);
|
||||
tcpChannel.Dispose();
|
||||
}, ct.Token);
|
||||
|
||||
try
|
||||
{
|
||||
await tcpChannel.ReadAsync(buffer, 0, 1, CancellationToken.None);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Assert.IsInstanceOfType(exception, typeof(SocketException));
|
||||
Assert.AreEqual(SocketError.OperationAborted, ((SocketException)exception).SocketErrorCode);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ct.Cancel(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ using MQTTnet.Server;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class RoundtripTimeTests
|
||||
public class RoundtripTime_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task Round_Trip_Time()
|
||||
+1
-1
@@ -4,7 +4,7 @@ using MQTTnet.Server;
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class TopicFilterComparerTests
|
||||
public class TopicFilterComparer_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void TopicFilterComparer_DirectMatch()
|
||||
Reference in New Issue
Block a user