diff --git a/mRemoteNGDocumentation/user_interface/notifications.rst b/mRemoteNGDocumentation/user_interface/notifications.rst index 338fb3e1..b2105fe0 100644 --- a/mRemoteNGDocumentation/user_interface/notifications.rst +++ b/mRemoteNGDocumentation/user_interface/notifications.rst @@ -37,7 +37,7 @@ Popups settings .. figure:: /images/notifications_popup.png -When items are selected here you will recieve a popup on the error that occurrs +When items are selected here you will receive a popup on the error that occurs based on level chosen in settings here. This can be useful if you do not want to use the notification area and only get a popup if error occurs. (**default**: Errors enabled, Debug/Info/Warning disabled) diff --git a/mRemoteNGTests/Connection/ConnectionInitiatorTests.cs b/mRemoteNGTests/Connection/ConnectionInitiatorTests.cs index 1316921f..76eab3a4 100644 --- a/mRemoteNGTests/Connection/ConnectionInitiatorTests.cs +++ b/mRemoteNGTests/Connection/ConnectionInitiatorTests.cs @@ -1,8 +1,10 @@ +using System; using System.Linq; using mRemoteNG.App; using mRemoteNG.Connection; using mRemoteNG.Connection.Protocol; using mRemoteNG.Messages; +using mRemoteNG.Resources.Language; using NUnit.Framework; namespace mRemoteNGTests.Connection @@ -41,18 +43,10 @@ namespace mRemoteNGTests.Connection // Act _connectionInitiator.OpenConnection(connectionInfo); - // Give a moment for async operations - System.Threading.Thread.Sleep(100); - - // Assert - var errorMessages = _messageCollector.Messages - .Where(m => m.Class == MessageClass.ErrorMsg) - .ToList(); - - Assert.That(errorMessages, Is.Not.Empty, "Expected at least one error message"); - Assert.That(errorMessages.Any(m => m.Text.Contains("hostname")), - Is.True, - "Expected error message to mention 'hostname'"); + // Assert - poll for message with timeout + var foundMessage = WaitForMessage(MessageClass.ErrorMsg, timeoutMs: 1000); + Assert.That(foundMessage, Is.Not.Null, "Expected an error message to be added"); + Assert.That(foundMessage.Text, Is.EqualTo(Language.ConnectionOpenFailedNoHostname)); } [Test] @@ -69,18 +63,10 @@ namespace mRemoteNGTests.Connection // Act _connectionInitiator.OpenConnection(connectionInfo); - // Give a moment for async operations - System.Threading.Thread.Sleep(100); - - // Assert - var errorMessages = _messageCollector.Messages - .Where(m => m.Class == MessageClass.ErrorMsg) - .ToList(); - - Assert.That(errorMessages, Is.Not.Empty, "Expected at least one error message"); - Assert.That(errorMessages.Any(m => m.Text.Contains("hostname")), - Is.True, - "Expected error message to mention 'hostname'"); + // Assert - poll for message with timeout + var foundMessage = WaitForMessage(MessageClass.ErrorMsg, timeoutMs: 1000); + Assert.That(foundMessage, Is.Not.Null, "Expected an error message to be added"); + Assert.That(foundMessage.Text, Is.EqualTo(Language.ConnectionOpenFailedNoHostname)); } [Test] @@ -97,16 +83,35 @@ namespace mRemoteNGTests.Connection // Act _connectionInitiator.OpenConnection(connectionInfo); - // Give a moment for async operations - System.Threading.Thread.Sleep(100); + // Give a moment for any potential async operations + System.Threading.Thread.Sleep(200); // Assert var hostnameErrors = _messageCollector.Messages - .Where(m => m.Text.Contains("No hostname specified")) + .Where(m => m.Text == Language.ConnectionOpenFailedNoHostname) .ToList(); Assert.That(hostnameErrors, Is.Empty, "Should not have hostname error when hostname is provided"); } + + /// + /// Polls the message collector for a message of the specified class + /// + private IMessage WaitForMessage(MessageClass messageClass, int timeoutMs = 1000) + { + var startTime = DateTime.Now; + while ((DateTime.Now - startTime).TotalMilliseconds < timeoutMs) + { + var message = _messageCollector.Messages + .FirstOrDefault(m => m.Class == messageClass); + + if (message != null) + return message; + + System.Threading.Thread.Sleep(50); // Poll every 50ms + } + return null; + } } }