Rename tests.

This commit is contained in:
Christian Kratky
2019-04-03 23:44:48 +02:00
parent 2267770a72
commit a8db0dd3d6
17 changed files with 101 additions and 22 deletions
@@ -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();
}
@@ -6,7 +6,7 @@ using MQTTnet.Internal;
namespace MQTTnet.Tests
{
[TestClass]
public class AsyncLockTests
public class AsyncLock_Tests
{
[TestMethod]
public void AsyncLock()
@@ -6,7 +6,7 @@ using MQTTnet.Internal;
namespace MQTTnet.Tests
{
[TestClass]
public class BlockingQueueTests
public class BlockingQueue_Tests
{
[TestMethod]
public void Preserve_Order()
@@ -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
}
}
}
}
}
@@ -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()
@@ -7,7 +7,7 @@ using MQTTnet.Protocol;
namespace MQTTnet.Tests
{
[TestClass]
public class MqttApplicationMessageBuilderTests
public class MqttApplicationMessageBuilder_Tests
{
[TestMethod]
public void CreateApplicationMessage_TopicOnly()
@@ -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()
@@ -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()
@@ -4,7 +4,7 @@ using MQTTnet.Client;
namespace MQTTnet.Tests
{
[TestClass]
public class MqttPacketIdentifierProviderTests
public class MqttPacketIdentifierProvider_Tests
{
[TestMethod]
public void Reset()
@@ -8,7 +8,7 @@ using MQTTnet.Internal;
namespace MQTTnet.Tests
{
[TestClass]
public class MqttPacketReaderTests
public class MqttPacketReader_Tests
{
[TestMethod]
public async Task MqttPacketReader_EmptyStream()
@@ -14,7 +14,7 @@ using MQTTnet.Protocol;
namespace MQTTnet.Tests
{
[TestClass]
public class MqttPacketSerializerTests
public class MqttPacketSerializer_Tests
{
[TestMethod]
public void SerializeV310_MqttConnectPacket()
@@ -4,7 +4,7 @@ using MQTTnet.Formatter;
namespace MQTTnet.Tests
{
[TestClass]
public class MqttPacketWriterTests
public class MqttPacketWriter_Tests
{
[TestMethod]
public void WritePacket()
@@ -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);
}
}
}
}
@@ -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()
@@ -4,7 +4,7 @@ using MQTTnet.Server;
namespace MQTTnet.Tests
{
[TestClass]
public class TopicFilterComparerTests
public class TopicFilterComparer_Tests
{
[TestMethod]
public void TopicFilterComparer_DirectMatch()