Improve unit tests.

This commit is contained in:
Christian Kratky
2020-04-18 16:55:37 +02:00
parent e9724c0202
commit cf7e59a774
3 changed files with 11 additions and 4 deletions
@@ -10,6 +10,8 @@ namespace MQTTnet.Implementations
{
readonly Socket _socket;
NetworkStream _networkStream;
public CrossPlatformSocket(AddressFamily addressFamily)
{
_socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);
@@ -137,6 +139,8 @@ namespace MQTTnet.Implementations
try
{
_networkStream?.Dispose();
// Workaround for: workaround for https://github.com/dotnet/corefx/issues/24430
using (cancellationToken.Register(() => _socket.Dispose()))
{
@@ -148,6 +152,8 @@ namespace MQTTnet.Implementations
await _socket.ConnectAsync(host, port).ConfigureAwait(false);
#endif
}
_networkStream = new NetworkStream(_socket, true);
}
catch (ObjectDisposedException)
{
@@ -190,11 +196,12 @@ namespace MQTTnet.Implementations
public NetworkStream GetStream()
{
return new NetworkStream(_socket, true);
return _networkStream;
}
public void Dispose()
{
_networkStream?.Dispose();
_socket?.Dispose();
}