mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Added collection management functions to ContainerInfo (Add, AddRange, Remove, RemoveRange). Added unit tests
This commit is contained in:
84
mRemoteNGTests/Container/ContainerInfoTests.cs
Normal file
84
mRemoteNGTests/Container/ContainerInfoTests.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Container;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
namespace mRemoteNGTests.Container
|
||||
{
|
||||
public class ContainerInfoTests
|
||||
{
|
||||
private ContainerInfo _containerInfo;
|
||||
private ConnectionInfo _connectionInfo;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_containerInfo = new ContainerInfo();
|
||||
_connectionInfo = new ConnectionInfo();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Teardown()
|
||||
{
|
||||
_containerInfo = null;
|
||||
_connectionInfo = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddSetsParentPropertyOnTheChild()
|
||||
{
|
||||
_containerInfo.Add(_connectionInfo);
|
||||
Assert.That(_connectionInfo.Parent, Is.EqualTo(_containerInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddAddsChildToChildrenList()
|
||||
{
|
||||
_containerInfo.Add(_connectionInfo);
|
||||
Assert.That(_containerInfo.Children, Does.Contain(_connectionInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddRangeAddsAllItems()
|
||||
{
|
||||
var collection = new[] {new ConnectionInfo(),new ConnectionInfo(), new ContainerInfo()};
|
||||
_containerInfo.AddRange(collection);
|
||||
Assert.That(_containerInfo.Children, Is.EquivalentTo(collection));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveUnsetsParentPropertyOnChild()
|
||||
{
|
||||
_containerInfo.Add(_connectionInfo);
|
||||
_containerInfo.Remove(_connectionInfo);
|
||||
Assert.That(_connectionInfo.Parent, Is.Not.EqualTo(_containerInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveRemovesChildFromChildrenList()
|
||||
{
|
||||
_containerInfo.Add(_connectionInfo);
|
||||
_containerInfo.Remove(_connectionInfo);
|
||||
Assert.That(_containerInfo.Children, Does.Not.Contains(_connectionInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveRangeRemovesAllIndicatedItems()
|
||||
{
|
||||
var collection = new[] { new ConnectionInfo(), new ConnectionInfo(), new ContainerInfo() };
|
||||
_containerInfo.AddRange(collection);
|
||||
_containerInfo.RemoveRange(collection);
|
||||
Assert.That(_containerInfo.Children, Does.Not.Contains(collection[0]).And.Not.Contains(collection[1]).And.Not.Contains(collection[2]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveRangeDoesNotRemoveUntargetedMembers()
|
||||
{
|
||||
var collection = new[] { new ConnectionInfo(), new ConnectionInfo(), new ContainerInfo() };
|
||||
_containerInfo.AddRange(collection);
|
||||
_containerInfo.Add(_connectionInfo);
|
||||
_containerInfo.RemoveRange(collection);
|
||||
Assert.That(_containerInfo.Children, Does.Contain(_connectionInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,7 @@
|
||||
<Compile Include="Connection\ConnectionInfoInheritanceTests.cs" />
|
||||
<Compile Include="Connection\DefaultConnectionInfoTests.cs" />
|
||||
<Compile Include="Connection\DefaultConnectionInheritanceTests.cs" />
|
||||
<Compile Include="Container\ContainerInfoTests.cs" />
|
||||
<Compile Include="ListViewTester.cs" />
|
||||
<Compile Include="Config\Connections\SqlConnectionUpdateCheckerTests.cs" />
|
||||
<Compile Include="Config\Connections\SqlUpdateQueryBuilderTest.cs" />
|
||||
|
||||
@@ -19,12 +19,40 @@ namespace mRemoteNG.Container
|
||||
IsContainer = true;
|
||||
}
|
||||
|
||||
public void Add(ConnectionInfo newChildItem)
|
||||
{
|
||||
newChildItem.Parent = this;
|
||||
Children.Add(newChildItem);
|
||||
}
|
||||
|
||||
public void AddRange(IEnumerable<ConnectionInfo> newChildren)
|
||||
{
|
||||
foreach (var child in newChildren)
|
||||
{
|
||||
Add(child);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(ConnectionInfo removalTarget)
|
||||
{
|
||||
removalTarget.Parent = null;
|
||||
Children.Remove(removalTarget);
|
||||
}
|
||||
|
||||
public void RemoveRange(IEnumerable<ConnectionInfo> removalTargets)
|
||||
{
|
||||
foreach (var child in removalTargets)
|
||||
{
|
||||
Remove(child);
|
||||
}
|
||||
}
|
||||
|
||||
public new ContainerInfo Copy()
|
||||
{
|
||||
return (ContainerInfo)MemberwiseClone();
|
||||
}
|
||||
|
||||
public void SetDefaults()
|
||||
private void SetDefaults()
|
||||
{
|
||||
IsExpanded = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user