diff --git a/mRemoteNGTests/Tree/NodeSearcherTests.cs b/mRemoteNGTests/Tree/NodeSearcherTests.cs
new file mode 100644
index 000000000..dbf6cf4b6
--- /dev/null
+++ b/mRemoteNGTests/Tree/NodeSearcherTests.cs
@@ -0,0 +1,94 @@
+using System.Linq;
+using mRemoteNG.Connection;
+using mRemoteNG.Container;
+using mRemoteNG.Tree;
+using mRemoteNG.Tree.Root;
+using NUnit.Framework;
+
+
+namespace mRemoteNGTests.Tree
+{
+ public class NodeSearcherTests
+ {
+ private NodeSearcher _nodeSearcher;
+ private ContainerInfo _folder1;
+ private ContainerInfo _folder2;
+ private ConnectionInfo _con1;
+ private ConnectionInfo _con2;
+ private ConnectionInfo _con3;
+ private ConnectionInfo _con4;
+ private ConnectionInfo _con5;
+
+ [OneTimeSetUp]
+ public void OnetimeSetup()
+ {
+ var connectionTreeModel = SetupConnectionTreeModel();
+ _nodeSearcher = new NodeSearcher(connectionTreeModel);
+ }
+
+ [Test]
+ public void SearchByNameReturnsAllExpectedMatches()
+ {
+ var matches = _nodeSearcher.SearchByName("folder");
+ Assert.That(matches.ToList(), Is.EquivalentTo(new[] {_folder1, _folder2}));
+ }
+
+ [Test]
+ public void NextMatchAdvancesTheIterator()
+ {
+ _nodeSearcher.SearchByName("folder");
+ var match1 = _nodeSearcher.CurrentMatch;
+ var match2 = _nodeSearcher.NextMatch();
+ Assert.That(match1, Is.Not.EqualTo(match2));
+ }
+
+ [Test]
+ public void PreviousMatchRollsBackTheIterator()
+ {
+ _nodeSearcher.SearchByName("con");
+ var match1 = _nodeSearcher.CurrentMatch;
+ _nodeSearcher.NextMatch();
+ var match2 = _nodeSearcher.PreviousMatch();
+ Assert.That(match1, Is.EqualTo(match2));
+ }
+
+ [Test]
+ public void SearchingWithEmptyStringReturnsNoMatches()
+ {
+ var matches = _nodeSearcher.SearchByName("");
+ Assert.That(matches.Count(), Is.EqualTo(0));
+ }
+
+ private ConnectionTreeModel SetupConnectionTreeModel()
+ {
+ /*
+ * Tree:
+ * Root
+ * |--- folder1
+ * | |--- con1
+ * | L--- con2
+ * |--- folder2
+ * | |--- con3
+ * | L--- con4
+ * L--- con5
+ *
+ */
+ var connectionTreeModel = new ConnectionTreeModel();
+ var root = new RootNodeInfo(RootNodeType.Connection);
+ _folder1 = new ContainerInfo { Name = "folder1"};
+ _con1 = new ConnectionInfo { Name = "con1"};
+ _con2 = new ConnectionInfo { Name = "con2"};
+ _folder2 = new ContainerInfo { Name = "folder2" };
+ _con3 = new ConnectionInfo { Name = "con3" };
+ _con4 = new ConnectionInfo { Name = "con4" };
+ _con5 = new ConnectionInfo { Name = "con5" };
+
+ connectionTreeModel.AddRootNode(root);
+ root.AddChildRange(new [] { _folder1, _folder2, _con5 });
+ _folder1.AddChildRange(new [] { _con1, _con2 });
+ _folder2.AddChildRange(new[] { _con3, _con4 });
+
+ return connectionTreeModel;
+ }
+ }
+}
\ No newline at end of file
diff --git a/mRemoteNGTests/mRemoteNGTests.csproj b/mRemoteNGTests/mRemoteNGTests.csproj
index 3ee05503e..8e037e4a1 100644
--- a/mRemoteNGTests/mRemoteNGTests.csproj
+++ b/mRemoteNGTests/mRemoteNGTests.csproj
@@ -139,6 +139,7 @@
+
Form
diff --git a/mRemoteV1/Tree/NodeSearcher.cs b/mRemoteV1/Tree/NodeSearcher.cs
index 359585794..40cd4aa7e 100644
--- a/mRemoteV1/Tree/NodeSearcher.cs
+++ b/mRemoteV1/Tree/NodeSearcher.cs
@@ -5,7 +5,7 @@ using mRemoteNG.Connection;
namespace mRemoteNG.Tree
{
- internal class NodeSearcher
+ public class NodeSearcher
{
private readonly ConnectionTreeModel _connectionTreeModel;
@@ -18,7 +18,7 @@ namespace mRemoteNG.Tree
_connectionTreeModel = connectionTreeModel;
}
- internal IEnumerable SearchByName(string searchText)
+ public IEnumerable SearchByName(string searchText)
{
ResetMatches();
if (searchText == "") return Matches;
@@ -33,22 +33,34 @@ namespace mRemoteNG.Tree
return Matches;
}
- internal ConnectionInfo NextMatch()
+ public ConnectionInfo NextMatch()
{
var currentMatchIndex = Matches.IndexOf(CurrentMatch);
- if (currentMatchIndex < Matches.Count-1)
+ if (!CurrentMatchIsTheLastMatchInTheList())
CurrentMatch = Matches[currentMatchIndex + 1];
return CurrentMatch;
}
- internal ConnectionInfo PreviousMatch()
+ private bool CurrentMatchIsTheLastMatchInTheList()
{
var currentMatchIndex = Matches.IndexOf(CurrentMatch);
- if (currentMatchIndex > 0)
+ return currentMatchIndex >= Matches.Count - 1;
+ }
+
+ public ConnectionInfo PreviousMatch()
+ {
+ var currentMatchIndex = Matches.IndexOf(CurrentMatch);
+ if (!CurrentMatchIsTheFirstMatchInTheList())
CurrentMatch = Matches[currentMatchIndex - 1];
return CurrentMatch;
}
+ private bool CurrentMatchIsTheFirstMatchInTheList()
+ {
+ var currentMatchIndex = Matches.IndexOf(CurrentMatch);
+ return currentMatchIndex <= 0;
+ }
+
private void ResetMatches()
{
Matches = new List();