mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Merge pull request #3101 from mRemoteNG/copilot/fix-new-connection-error
Show error popup when connecting without hostname/IP
This commit is contained in:
@@ -465,4 +465,4 @@ namespace mRemoteNG.Connection
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace mRemoteNG.Properties {
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||
public bool PopupMessageWriterWriteErrorMsgs {
|
||||
get {
|
||||
return ((bool)(this["PopupMessageWriterWriteErrorMsgs"]));
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
<Setting Name="PopupMessageWriterWriteErrorMsgs" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
<Setting Name="LogToApplicationDirectory" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
|
||||
@@ -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**: all off)
|
||||
and only get a popup if error occurs. (**default**: Errors enabled, Debug/Info/Warning disabled)
|
||||
|
||||
117
mRemoteNGTests/Connection/ConnectionInitiatorTests.cs
Normal file
117
mRemoteNGTests/Connection/ConnectionInitiatorTests.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
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
|
||||
{
|
||||
[TestFixture]
|
||||
public class ConnectionInitiatorTests
|
||||
{
|
||||
private ConnectionInitiator _connectionInitiator;
|
||||
private MessageCollector _messageCollector;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_connectionInitiator = new ConnectionInitiator();
|
||||
_messageCollector = Runtime.MessageCollector;
|
||||
_messageCollector.ClearMessages();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Teardown()
|
||||
{
|
||||
_messageCollector?.ClearMessages();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OpenConnection_WithEmptyHostname_AddsErrorMessage()
|
||||
{
|
||||
// Arrange
|
||||
var connectionInfo = new ConnectionInfo
|
||||
{
|
||||
Name = "Test Connection",
|
||||
Hostname = "", // Empty hostname
|
||||
Protocol = ProtocolType.RDP // RDP doesn't support blank hostname
|
||||
};
|
||||
|
||||
// Act
|
||||
_connectionInitiator.OpenConnection(connectionInfo);
|
||||
|
||||
// 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]
|
||||
public void OpenConnection_WithNullHostname_AddsErrorMessage()
|
||||
{
|
||||
// Arrange
|
||||
var connectionInfo = new ConnectionInfo
|
||||
{
|
||||
Name = "Test Connection",
|
||||
Hostname = null, // Null hostname
|
||||
Protocol = ProtocolType.SSH2 // SSH doesn't support blank hostname
|
||||
};
|
||||
|
||||
// Act
|
||||
_connectionInitiator.OpenConnection(connectionInfo);
|
||||
|
||||
// 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]
|
||||
public void OpenConnection_WithValidHostname_DoesNotAddHostnameError()
|
||||
{
|
||||
// Arrange
|
||||
var connectionInfo = new ConnectionInfo
|
||||
{
|
||||
Name = "Test Connection",
|
||||
Hostname = "192.168.1.1", // Valid hostname
|
||||
Protocol = ProtocolType.RDP
|
||||
};
|
||||
|
||||
// Act
|
||||
_connectionInitiator.OpenConnection(connectionInfo);
|
||||
|
||||
// Give a moment for any potential async operations
|
||||
System.Threading.Thread.Sleep(200);
|
||||
|
||||
// Assert
|
||||
var hostnameErrors = _messageCollector.Messages
|
||||
.Where(m => m.Text == Language.ConnectionOpenFailedNoHostname)
|
||||
.ToList();
|
||||
|
||||
Assert.That(hostnameErrors, Is.Empty,
|
||||
"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