#141 ConnectionInfo now listens to collection changed events from the ProtocolList and raises a PropertyChanged event for OpenConnections when the list contents changes.

This commit is contained in:
David Sparer
2016-10-05 12:37:05 -06:00
parent e2e010c418
commit c471f621b2
2 changed files with 30 additions and 6 deletions

View File

@@ -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"));
}
}
}

View File

@@ -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
}
}
}