xenadmin/XenAdminTests/TreeTests/FlickerFreeTreeViewTests.cs
Konstantina Chremmou f7391e991b
CA-156873, CP-31105 (partial): Apply common branding and versioning to assemblies; branding refactoring
Added brand management files and refactored the following brand variables:
* BRANDING_XENSERVER_UPDATE_URL
* BRANDING_PERF_ALERT_MAIL_LANGUAGE_DEFAULT
* BRANDING_SEARCH
* BRANDING_UPDATE
* BRANDING_BACKUP
* BRANDING_LEGACY_PRODUCT_BRAND
* ISO
* BRANDING_VERSION_5_6
* BRANDING_VERSION_6_2
* BRANDING_VERSION_6_0
* BRANDING_VERSION_6_5
* BRANDING_VERSION_7_0
* BRANDING_VERSION_7_1_2
* BRANDING_VERSION_8_0
* BRANDING_VERSION_8_1
* BRANDIND_COPYRIGHT
* BRANDING_COPYRIGHT_2

Also: Try passing the timestamp server as parameter
2020-01-22 14:47:39 +00:00

225 lines
9.3 KiB
C#

/* Copyright (c) Citrix Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
using NUnit.Framework;
using XenAdmin.Controls;
using XenAdmin.Model;
using XenAdmin;
using XenAdmin.Core;
using XenAdmin.Network;
namespace XenAdminTests.TreeTests
{
[TestFixture, Category(TestCategories.Unit)]
public class FlickerFreeTreeViewTests
{
private FlickerFreeTreeView _tv;
[SetUp]
public void Setup()
{
_tv = new FlickerFreeTreeView();
// ensure handle is created. Some tests fail if you don't do this.
Assert.NotNull(_tv.Handle);
}
[TearDown]
public void TearDown()
{
if (_tv != null)
_tv.Dispose();
}
[Test]
[Description("Tests that the parent node of the selected nodes get selected when the selected nodes' tags disappear.")]
public void TestParentNodeSelectedWhenSelectedNodeTagsChange()
{
// populate the tree-view with some folders
Folder foldersTag = new Folder(null, "Folders");
_tv.Nodes.Add(new VirtualTreeNode(BrandManager.BRAND_CONSOLE));
VirtualTreeNode folders = new VirtualTreeNode("Folders") { Tag = foldersTag };
_tv.Nodes[0].Nodes.Add(folders);
folders.Nodes.Add(new VirtualTreeNode("folder1") { Tag = new Folder(null, "folder1") });
folders.Nodes.Add(new VirtualTreeNode("folder2") { Tag = new Folder(null, "folder2") });
// set the 2 folders to be the selected nodes.
_tv.SelectedNodes.SetContents(new [] { folders.Nodes[0], folders.Nodes[1] });
// now build up a new nodes tree
VirtualTreeNode newRootNode = new VirtualTreeNode(BrandManager.BRAND_CONSOLE);
VirtualTreeNode newFolders = new VirtualTreeNode("Folders") { Tag = foldersTag };
newRootNode.Nodes.Add(newFolders);
newFolders.Nodes.Add(new VirtualTreeNode("folder1a") { Tag = new Folder(null, "folder1a") });
newFolders.Nodes.Add(new VirtualTreeNode("folder2a") { Tag = new Folder(null, "folder2a") });
int count = 0;
EventHandler handler = delegate
{
count++;
Assert.AreEqual(1, _tv.SelectedNodes.Count, "There should only be one node selected.");
Assert.AreEqual("Folders", _tv.SelectedNodes[0].Text, "The Folders node should be selected.");
};
_tv.SelectionsChanged += handler;
try
{
// merge the new node tree in.
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { newRootNode });
_tv.EndUpdate();
Assert.GreaterOrEqual(count, 1, "SelectionsChanged should fire.");
}
finally
{
_tv.SelectionsChanged -= handler;
}
}
[Test]
public void TestNodeStaysSelected()
{
VirtualTreeNode root = new VirtualTreeNode("root");
root.Nodes.Add(new VirtualTreeNode("1") { Tag = new Folder(null, "1") });
root.Nodes.Add(new VirtualTreeNode("2") { Tag = new Folder(null, "2") });
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { root });
_tv.EndUpdate();
_tv.SelectedNode = _tv.Nodes[0].Nodes[0];
root = new VirtualTreeNode("root");
root.Nodes.Add(new VirtualTreeNode("1") { Tag = new Folder(null, "1") });
root.Nodes.Add(new VirtualTreeNode("2") { Tag = new Folder(null, "2") });
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { root });
_tv.EndUpdate();
Assert.AreEqual("1", _tv.SelectedNode.Text);
}
[Test]
public void TestNodeStaysSelectedAsItMoves()
{
VirtualTreeNode root = new VirtualTreeNode("root");
root.Nodes.Add(new VirtualTreeNode("1") { Tag = new Folder(null, "1") });
root.Nodes.Add(new VirtualTreeNode("2") { Tag = new Folder(null, "2") });
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { root });
_tv.EndUpdate();
_tv.SelectedNode = _tv.Nodes[0].Nodes[0];
root = new VirtualTreeNode("root");
root.Nodes.Add(new VirtualTreeNode("2") { Tag = new Folder(null, "2") });
root.Nodes.Add(new VirtualTreeNode("1") { Tag = new Folder(null, "1") });
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { root });
_tv.EndUpdate();
Assert.AreEqual(1, _tv.SelectedNodes.Count, "Node didn't stay selected");
Assert.AreEqual("1", _tv.SelectedNode.Text, "Node didn't stay selected");
Assert.AreEqual(new Folder(null, "1"), _tv.SelectedNode.Tag, "Node didn't stay selected");
}
[Test]
public void TestMultipleNodesStaySelectedAsTheyMove()
{
VirtualTreeNode root = new VirtualTreeNode("root");
root.Nodes.Add(new VirtualTreeNode("1") { Tag = new Folder(null, "1") });
root.Nodes.Add(new VirtualTreeNode("2") { Tag = new Folder(null, "2") });
root.Nodes.Add(new VirtualTreeNode("3") { Tag = new Folder(null, "3") });
root.Nodes.Add(new VirtualTreeNode("4") { Tag = new Folder(null, "4") });
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { root });
_tv.EndUpdate();
_tv.SelectedNodes.SetContents(new [] { root.Nodes[0], root.Nodes[1] });
root = new VirtualTreeNode("root");
root.Nodes.Add(new VirtualTreeNode("4") { Tag = new Folder(null, "4") });
root.Nodes.Add(new VirtualTreeNode("3") { Tag = new Folder(null, "3") });
root.Nodes.Add(new VirtualTreeNode("2") { Tag = new Folder(null, "2") });
root.Nodes.Add(new VirtualTreeNode("1") { Tag = new Folder(null, "1") });
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { root });
_tv.EndUpdate();
Assert.AreEqual(2, _tv.SelectedNodes.Count, "Nodes didn't stay selected");
Assert.AreEqual("1", _tv.SelectedNodes[0].Text, "Nodes didn't stay selected");
Assert.AreEqual("2", _tv.SelectedNodes[1].Text, "Nodes didn't stay selected");
Assert.AreEqual(new Folder(null, "1"), _tv.SelectedNodes[0].Tag, "Nodes didn't stay selected");
Assert.AreEqual(new Folder(null, "2"), _tv.SelectedNodes[1].Tag, "Nodes didn't stay selected");
}
[Test]
public void TestSingleParentNodeGetsSelectedWhenMultipleNodesDisappear()
{
IXenConnection con1 = new XenConnection();
IXenConnection con2 = new XenConnection();
IXenConnection con3 = new XenConnection();
VirtualTreeNode root = new VirtualTreeNode("root");
root.Nodes.Add(new VirtualTreeNode("1") { Tag = new Folder(null, "1") { Connection = con1 } });
root.Nodes.Add(new VirtualTreeNode("2") { Tag = new Folder(null, "2") { Connection = con2 } });
root.Nodes.Add(new VirtualTreeNode("3") { Tag = new Folder(null, "3") { Connection = con3 } });
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { root });
_tv.EndUpdate();
_tv.SelectedNodes.SetContents(new [] { root.Nodes[0], root.Nodes[1] });
root = new VirtualTreeNode("root");
root.Nodes.Add(new VirtualTreeNode("3") { Tag = new Folder(null, "3") { Connection = con3 } });
_tv.BeginUpdate();
_tv.UpdateRootNodes(new [] { root });
_tv.EndUpdate();
Assert.AreEqual(1, _tv.SelectedNodes.Count, "Nodes didn't stay selected");
Assert.AreEqual("root", _tv.SelectedNode.Text, "Nodes didn't stay selected");
}
}
}