diff --git a/mRemoteNGTests/Connection/ConnectionInfoTests.cs b/mRemoteNGTests/Connection/ConnectionInfoTests.cs index b3f80c680..6db4eed9e 100644 --- a/mRemoteNGTests/Connection/ConnectionInfoTests.cs +++ b/mRemoteNGTests/Connection/ConnectionInfoTests.cs @@ -1,4 +1,5 @@ using mRemoteNG.Connection; +using mRemoteNG.Connection.Protocol.SSH; using mRemoteNG.Container; using NUnit.Framework; @@ -53,5 +54,23 @@ namespace mRemoteNGTests.Connection _connectionInfo.CopyFrom(secondConnection); Assert.That(_connectionInfo.Domain, Is.EqualTo(secondConnection.Domain)); } + + [Test] + public void PropertyChangedEventRaisedWhenOpenConnectionsChanges() + { + var eventWasCalled = false; + _connectionInfo.PropertyChanged += (sender, args) => eventWasCalled = true; + _connectionInfo.OpenConnections.Add(new ProtocolSSH2()); + Assert.That(eventWasCalled); + } + + [Test] + public void PropertyChangedEventArgsAreCorrectWhenOpenConnectionsChanges() + { + var nameOfModifiedProperty = ""; + _connectionInfo.PropertyChanged += (sender, args) => nameOfModifiedProperty = args.PropertyName; + _connectionInfo.OpenConnections.Add(new ProtocolSSH2()); + Assert.That(nameOfModifiedProperty, Is.EqualTo("OpenConnections")); + } } } \ No newline at end of file diff --git a/mRemoteV1/Connection/ConnectionInfo.cs b/mRemoteV1/Connection/ConnectionInfo.cs index 4d7118769..75b4d331d 100644 --- a/mRemoteV1/Connection/ConnectionInfo.cs +++ b/mRemoteV1/Connection/ConnectionInfo.cs @@ -30,7 +30,7 @@ namespace mRemoteNG.Connection public ConnectionInfoInheritance Inheritance { get; set; } [Browsable(false)] - public ProtocolList OpenConnections { get; set; } + public ProtocolList OpenConnections { get; protected set; } [Browsable(false)] public bool IsContainer { get; set; } @@ -83,14 +83,13 @@ namespace mRemoteNG.Connection newConnectionInfo.CopyFrom(this); newConnectionInfo.ConstantID = MiscTools.CreateConstantID(); newConnectionInfo.SetParent(Parent); - newConnectionInfo.OpenConnections = new ProtocolList(); newConnectionInfo.Inheritance = Inheritance.Clone(); return newConnectionInfo; } - public void CopyFrom(ConnectionInfo sourceConnectionInfo) + public void CopyFrom(AbstractConnectionInfoData sourceConnectionInfo) { - var properties = typeof(ConnectionInfo).GetProperties(); + var properties = typeof(AbstractConnectionInfoData).GetProperties(); foreach (var property in properties) { var remotePropertyValue = property.GetValue(sourceConnectionInfo, null); @@ -319,9 +318,15 @@ namespace mRemoteNG.Connection private void SetNonBrowsablePropertiesDefaults() { Inheritance = new ConnectionInfoInheritance(this); - OpenConnections = new ProtocolList(); + SetNewOpenConnectionList(); PositionID = 0; } + + protected void SetNewOpenConnectionList() + { + OpenConnections = new ProtocolList(); + OpenConnections.CollectionChanged += (sender, args) => RaisePropertyChangedEvent(this, new PropertyChangedEventArgs("OpenConnections")); + } #endregion - } + } } \ No newline at end of file