mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 14:07:46 +08:00
Address code review: fix typos, improve test robustness, use Language resources
Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
@@ -37,7 +37,7 @@ Popups settings
|
|||||||
|
|
||||||
.. figure:: /images/notifications_popup.png
|
.. 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.
|
based on level chosen in settings here.
|
||||||
This can be useful if you do not want to use the notification area
|
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)
|
and only get a popup if error occurs. (**default**: Errors enabled, Debug/Info/Warning disabled)
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using mRemoteNG.App;
|
using mRemoteNG.App;
|
||||||
using mRemoteNG.Connection;
|
using mRemoteNG.Connection;
|
||||||
using mRemoteNG.Connection.Protocol;
|
using mRemoteNG.Connection.Protocol;
|
||||||
using mRemoteNG.Messages;
|
using mRemoteNG.Messages;
|
||||||
|
using mRemoteNG.Resources.Language;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace mRemoteNGTests.Connection
|
namespace mRemoteNGTests.Connection
|
||||||
@@ -41,18 +43,10 @@ namespace mRemoteNGTests.Connection
|
|||||||
// Act
|
// Act
|
||||||
_connectionInitiator.OpenConnection(connectionInfo);
|
_connectionInitiator.OpenConnection(connectionInfo);
|
||||||
|
|
||||||
// Give a moment for async operations
|
// Assert - poll for message with timeout
|
||||||
System.Threading.Thread.Sleep(100);
|
var foundMessage = WaitForMessage(MessageClass.ErrorMsg, timeoutMs: 1000);
|
||||||
|
Assert.That(foundMessage, Is.Not.Null, "Expected an error message to be added");
|
||||||
// Assert
|
Assert.That(foundMessage.Text, Is.EqualTo(Language.ConnectionOpenFailedNoHostname));
|
||||||
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'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -69,18 +63,10 @@ namespace mRemoteNGTests.Connection
|
|||||||
// Act
|
// Act
|
||||||
_connectionInitiator.OpenConnection(connectionInfo);
|
_connectionInitiator.OpenConnection(connectionInfo);
|
||||||
|
|
||||||
// Give a moment for async operations
|
// Assert - poll for message with timeout
|
||||||
System.Threading.Thread.Sleep(100);
|
var foundMessage = WaitForMessage(MessageClass.ErrorMsg, timeoutMs: 1000);
|
||||||
|
Assert.That(foundMessage, Is.Not.Null, "Expected an error message to be added");
|
||||||
// Assert
|
Assert.That(foundMessage.Text, Is.EqualTo(Language.ConnectionOpenFailedNoHostname));
|
||||||
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'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -97,16 +83,35 @@ namespace mRemoteNGTests.Connection
|
|||||||
// Act
|
// Act
|
||||||
_connectionInitiator.OpenConnection(connectionInfo);
|
_connectionInitiator.OpenConnection(connectionInfo);
|
||||||
|
|
||||||
// Give a moment for async operations
|
// Give a moment for any potential async operations
|
||||||
System.Threading.Thread.Sleep(100);
|
System.Threading.Thread.Sleep(200);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var hostnameErrors = _messageCollector.Messages
|
var hostnameErrors = _messageCollector.Messages
|
||||||
.Where(m => m.Text.Contains("No hostname specified"))
|
.Where(m => m.Text == Language.ConnectionOpenFailedNoHostname)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
Assert.That(hostnameErrors, Is.Empty,
|
Assert.That(hostnameErrors, Is.Empty,
|
||||||
"Should not have hostname error when hostname is provided");
|
"Should not have hostname error when hostname is provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Polls the message collector for a message of the specified class
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user