mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Added more tests for the containerinfo
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using mRemoteNG.Connection;
|
||||
using System.Linq;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Container;
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -231,5 +232,102 @@ namespace mRemoteNGTests.Container
|
||||
var targetsNewIndex = _containerInfo.Children.IndexOf(_con3);
|
||||
Assert.That(targetsNewIndex, Is.EqualTo(targetsIndexBeforeMove));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenChildAlreadyPresentAddChildAtDoesNothing()
|
||||
{
|
||||
_containerInfo.AddChild(_con1);
|
||||
_containerInfo.AddChild(_con2);
|
||||
_containerInfo.AddChild(_con3);
|
||||
var indexBeforeAttemptedMove = _containerInfo.Children.IndexOf(_con1);
|
||||
_containerInfo.AddChildAt(_con1, 2);
|
||||
var indexAfterAttemptedMove = _containerInfo.Children.IndexOf(_con1);
|
||||
Assert.That(indexAfterAttemptedMove, Is.EqualTo(indexBeforeAttemptedMove));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveChildDoesNothingIfChildNotInList()
|
||||
{
|
||||
_containerInfo.AddChild(_con1);
|
||||
var childListBeforeRemoval = _containerInfo.Children;
|
||||
_containerInfo.RemoveChild(_con2);
|
||||
var childListAfterRemoval = _containerInfo.Children;
|
||||
Assert.That(childListAfterRemoval, Is.EquivalentTo(childListBeforeRemoval));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClonedContainerHasNewConstantId()
|
||||
{
|
||||
var clone = _containerInfo.Clone();
|
||||
Assert.That(clone.ConstantID, Is.Not.EqualTo(_containerInfo.ConstantID));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClonedContainerContainsClonedChildren()
|
||||
{
|
||||
_containerInfo.AddChild(_con1);
|
||||
_containerInfo.AddChild(_con2);
|
||||
_containerInfo.AddChild(_con3);
|
||||
var clone = _containerInfo.Clone() as ContainerInfo;
|
||||
var clonedChildNames = clone?.Children.Select((node) => node.Name);
|
||||
var originalChildNames = _containerInfo?.Children.Select((node) => node.Name);
|
||||
Assert.That(clonedChildNames, Is.EquivalentTo(originalChildNames));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasChildrenReturnsFalseForNoChildren()
|
||||
{
|
||||
var hasChildren = _containerInfo.HasChildren();
|
||||
Assert.That(hasChildren, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasChildrenReturnsTrueWhenChildrenPresent()
|
||||
{
|
||||
_containerInfo.AddChild(_con1);
|
||||
var hasChildren = _containerInfo.HasChildren();
|
||||
Assert.That(hasChildren, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddChildAbovePutsNewChildInCorrectLocation()
|
||||
{
|
||||
_containerInfo.AddChild(_con1);
|
||||
var referenceChildIndexBeforeInsertion = _containerInfo.Children.IndexOf(_con1);
|
||||
_containerInfo.AddChildAbove(_con2, _con1);
|
||||
var newChildIndex = _containerInfo.Children.IndexOf(_con2);
|
||||
Assert.That(newChildIndex, Is.EqualTo(referenceChildIndexBeforeInsertion));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddChildAbovePutsNewChildAtEndOfListIfReferenceChildNotInList()
|
||||
{
|
||||
_containerInfo.AddChild(_con1);
|
||||
_containerInfo.AddChildAbove(_con2, _con3);
|
||||
var newChildIndex = _containerInfo.Children.IndexOf(_con2);
|
||||
var lastIndex = _containerInfo.Children.Count - 1;
|
||||
Assert.That(newChildIndex, Is.EqualTo(lastIndex));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddChildBelowPutsNewChildInCorrectLocation()
|
||||
{
|
||||
_containerInfo.AddChild(_con1);
|
||||
_containerInfo.AddChild(_con2);
|
||||
var referenceChildIndexBeforeInsertion = _containerInfo.Children.IndexOf(_con1);
|
||||
_containerInfo.AddChildBelow(_con3, _con1);
|
||||
var newChildIndex = _containerInfo.Children.IndexOf(_con3);
|
||||
Assert.That(newChildIndex, Is.EqualTo(referenceChildIndexBeforeInsertion + 1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddChildBelowPutsNewChildAtEndOfListIfReferenceChildNotInList()
|
||||
{
|
||||
_containerInfo.AddChild(_con1);
|
||||
_containerInfo.AddChildBelow(_con2, _con3);
|
||||
var newChildIndex = _containerInfo.Children.IndexOf(_con2);
|
||||
var lastIndex = _containerInfo.Children.Count - 1;
|
||||
Assert.That(newChildIndex, Is.EqualTo(lastIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace mRemoteNG.Container
|
||||
public class ContainerInfo : ConnectionInfo, INotifyCollectionChanged
|
||||
{
|
||||
[Browsable(false)]
|
||||
public List<ConnectionInfo> Children { get; set; } = new List<ConnectionInfo>();
|
||||
public List<ConnectionInfo> Children { get; } = new List<ConnectionInfo>();
|
||||
|
||||
[Category(""), Browsable(false), ReadOnly(false), Bindable(false), DefaultValue(""), DesignOnly(false)]
|
||||
public bool IsExpanded { get; set; }
|
||||
@@ -52,8 +52,8 @@ namespace mRemoteNG.Container
|
||||
public void AddChildBelow(ConnectionInfo newChildItem, ConnectionInfo reference)
|
||||
{
|
||||
var newChildIndex = Children.IndexOf(reference) + 1;
|
||||
if (newChildIndex > Children.Count)
|
||||
newChildIndex = 0;
|
||||
if (newChildIndex > Children.Count || newChildIndex < 1)
|
||||
newChildIndex = Children.Count;
|
||||
AddChildAt(newChildItem, newChildIndex);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user