2013-06-24 13:41:48 +02:00
|
|
|
|
/* 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 System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using XenAdmin.Commands;
|
|
|
|
|
using XenAdmin;
|
|
|
|
|
using NUnit.Framework;
|
2013-08-28 15:44:46 +02:00
|
|
|
|
|
|
|
|
|
using XenAdmin.Controls.MainWindowControls;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAPI;
|
|
|
|
|
using XenAdmin.Controls;
|
2013-07-01 17:59:42 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdminTests.CommandTests
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public struct CommandTestsDatabase
|
|
|
|
|
{
|
|
|
|
|
public const string George = "state1.xml";
|
|
|
|
|
public const string MidnightRide = "state4.xml";
|
|
|
|
|
public const string SingleHost = "single-host-krakout.xml";
|
|
|
|
|
public const string Boston = "boston-db.xml";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class CommandTest : MainWindowTester
|
|
|
|
|
{
|
|
|
|
|
internal Command Command { get; private set; }
|
|
|
|
|
|
|
|
|
|
internal abstract Command CreateCommand();
|
|
|
|
|
|
2013-08-28 15:44:46 +02:00
|
|
|
|
protected virtual NavigationPane.NavigationMode NativeMode
|
2013-07-01 17:59:42 +02:00
|
|
|
|
{
|
2013-08-28 15:44:46 +02:00
|
|
|
|
get { return NavigationPane.NavigationMode.Infrastructure; }
|
2013-07-01 17:59:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
internal IEnumerable<SelectedItemCollection> RunTest()
|
|
|
|
|
{
|
2013-08-28 15:44:46 +02:00
|
|
|
|
PutInNavigationMode(NativeMode);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return RunTest(GetSelections());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal IEnumerable<IXenObject> RunTest(Func<IXenObject> xenObject)
|
|
|
|
|
{
|
|
|
|
|
foreach (SelectedItemCollection selection in RunTest(GetSelections(xenObject)))
|
|
|
|
|
{
|
|
|
|
|
yield return selection.FirstAsXenObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal IEnumerable<IXenObject> RunTest(IEnumerable<IXenObject> xenObjects)
|
|
|
|
|
{
|
|
|
|
|
foreach (SelectedItemCollection selection in RunTest(GetSelections(xenObjects)))
|
|
|
|
|
{
|
|
|
|
|
yield return selection.FirstAsXenObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 15:44:46 +02:00
|
|
|
|
internal IEnumerable<SelectedItemCollection> RunTest( IEnumerable<SelectedItemCollection> selections)
|
|
|
|
|
{
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Command = CreateCommand();
|
|
|
|
|
|
2014-01-22 13:39:32 +01:00
|
|
|
|
((ICommand)Command).SetMainWindow(Program.MainWindow);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
bool noneExecuted = true;
|
|
|
|
|
|
|
|
|
|
foreach (SelectedItemCollection selection in selections)
|
|
|
|
|
{
|
|
|
|
|
((ICommand)Command).SetSelection(selection);
|
|
|
|
|
|
2013-08-28 15:44:46 +02:00
|
|
|
|
if (MW(() => Command.CanExecute()))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
noneExecuted = false;
|
|
|
|
|
SelectNodes(selection);
|
|
|
|
|
|
|
|
|
|
yield return selection;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(noneExecuted, "No tests were executed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<SelectedItemCollection> GetSelections(IEnumerable<IXenObject> xenObjects)
|
|
|
|
|
{
|
|
|
|
|
foreach (IXenObject x in xenObjects)
|
|
|
|
|
{
|
|
|
|
|
yield return new SelectedItemCollection(new[] { new SelectedItem(x) });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<SelectedItemCollection> GetSelections(Func<IXenObject> x)
|
|
|
|
|
{
|
|
|
|
|
yield return new SelectedItemCollection(new[] { new SelectedItem(x()) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<SelectedItemCollection> GetSelections()
|
|
|
|
|
{
|
|
|
|
|
List<object> output = new List<object>();
|
2013-10-08 11:17:57 +02:00
|
|
|
|
var rootNode = GetAllTreeNodes().Find(n => n.Parent == null);
|
2013-08-28 15:44:46 +02:00
|
|
|
|
foreach (VirtualTreeNode n in GetAllTreeNodes())
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-28 15:44:46 +02:00
|
|
|
|
if (!output.Contains(n.Tag))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-28 15:44:46 +02:00
|
|
|
|
output.Add(n.Tag);
|
|
|
|
|
|
|
|
|
|
GroupingTag gt = n.Tag as GroupingTag;
|
|
|
|
|
if (gt != null)
|
|
|
|
|
{
|
2013-10-08 11:17:57 +02:00
|
|
|
|
yield return new SelectedItemCollection(new[] { new SelectedItem(gt, rootNode) });
|
2013-08-28 15:44:46 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-28 15:44:46 +02:00
|
|
|
|
yield return new SelectedItemCollection(new[] { new SelectedItem(n.Tag as IXenObject) });
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectNodes(SelectedItemCollection selection)
|
|
|
|
|
{
|
|
|
|
|
List<object> objects = selection.AsObjects();
|
|
|
|
|
List<VirtualTreeNode> nodes = new List<VirtualTreeNode>(objects.ConvertAll(o => FindInTree(o)));
|
|
|
|
|
|
|
|
|
|
if (!nodes.Contains(null))
|
|
|
|
|
{
|
|
|
|
|
Assert.IsTrue(SelectInTree(objects.ToArray()), "Couldn't select node for selection.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-10-08 11:17:57 +02:00
|
|
|
|
PutInNavigationMode(NativeMode);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
nodes = new List<VirtualTreeNode>(objects.ConvertAll(o => FindInTree(o)));
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(nodes.Contains(null), "Couldn't find nodes for selection.");
|
|
|
|
|
Assert.IsTrue(SelectInTree(objects.ToArray()), "Couldn't select node for selection.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|