Index: Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs =================================================================== diff -u -ref35125104cc8b0201f9c961049cc6c8a30fb74d -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs (.../FileImportActivity.cs) (revision ef35125104cc8b0201f9c961049cc6c8a30fb74d) +++ Core/Common/src/Core.Common.Base/Service/FileImportActivity.cs (.../FileImportActivity.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -66,6 +66,13 @@ fileImporter.Cancel(); } - protected override void OnFinish() {} + protected override void OnFinish() + { + var observableTarget = target as IObservable; + if (observableTarget != null) + { + observableTarget.NotifyObservers(); + } + } } } \ No newline at end of file Index: Core/Common/src/Core.Common.Controls.TreeView/Core.Common.Controls.TreeView.csproj =================================================================== diff -u -r905cfbd0916a140115717f06eb3755d49420ef21 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Controls.TreeView/Core.Common.Controls.TreeView.csproj (.../Core.Common.Controls.TreeView.csproj) (revision 905cfbd0916a140115717f06eb3755d49420ef21) +++ Core/Common/src/Core.Common.Controls.TreeView/Core.Common.Controls.TreeView.csproj (.../Core.Common.Controls.TreeView.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -45,7 +45,6 @@ Properties\GlobalAssembly.cs - @@ -54,15 +53,13 @@ True Resources.resx - - Component - + Index: Core/Common/src/Core.Common.Controls.TreeView/DragOperations.cs =================================================================== diff -u -r8cae5d69ac2d4cf678486ac2b457c0dfe97089d5 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Controls.TreeView/DragOperations.cs (.../DragOperations.cs) (revision 8cae5d69ac2d4cf678486ac2b457c0dfe97089d5) +++ Core/Common/src/Core.Common.Controls.TreeView/DragOperations.cs (.../DragOperations.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,7 +1,7 @@ namespace Core.Common.Controls.TreeView { /// - /// Enum that specifies dragoperations. + /// Enum that specifies drag operations. /// public enum DragOperations { Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Controls.TreeView/ITreeNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/src/Core.Common.Controls.TreeView/PlaceholderLocation.cs =================================================================== diff -u -r8cae5d69ac2d4cf678486ac2b457c0dfe97089d5 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Controls.TreeView/PlaceholderLocation.cs (.../PlaceholderLocation.cs) (revision 8cae5d69ac2d4cf678486ac2b457c0dfe97089d5) +++ Core/Common/src/Core.Common.Controls.TreeView/PlaceholderLocation.cs (.../PlaceholderLocation.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,7 +1,7 @@ namespace Core.Common.Controls.TreeView { /// - /// Enum to specify whether the mouse is above or below a treenode. + /// Enum to specify whether or not the mouse is above or below a tree node. /// public enum PlaceholderLocation { Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Controls.TreeView/TreeNode.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/src/Core.Common.Controls.TreeView/TreeNodeDataDeletedEventArgs.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Controls.TreeView/TreeNodeDataDeletedEventArgs.cs (revision 0) +++ Core/Common/src/Core.Common.Controls.TreeView/TreeNodeDataDeletedEventArgs.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,24 @@ +using System; + +namespace Core.Common.Controls.TreeView +{ + /// + /// Event arguments to be used in the event that node data has been deleted from a . + /// + public class TreeNodeDataDeletedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// The deleted data instance. + public TreeNodeDataDeletedEventArgs(object deletedDataInstance) + { + DeletedDataInstance = deletedDataInstance; + } + + /// + /// Gets the data instance deleted from the . + /// + public object DeletedDataInstance { get; private set; } + } +} \ No newline at end of file Index: Core/Common/src/Core.Common.Controls.TreeView/TreeNodeExpandCollapseState.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Controls.TreeView/TreeNodeExpandCollapseState.cs (.../TreeNodeExpandCollapseState.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Core/Common/src/Core.Common.Controls.TreeView/TreeNodeExpandCollapseState.cs (.../TreeNodeExpandCollapseState.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; - +using System.Windows.Forms; using Core.Common.Controls.TreeView.Properties; namespace Core.Common.Controls.TreeView @@ -37,7 +37,7 @@ throw new ArgumentException(Resources.TreeNodeExpandCollapseState_Node_tag_cannot_be_null_for_record_to_work); } wasExpanded = nodeToBeRecorded.IsExpanded; - childStates = nodeToBeRecorded.Nodes.Where(n => n.Nodes.Any()).ToDictionary(n => n.Tag, n => new TreeNodeExpandCollapseState(n)); + childStates = nodeToBeRecorded.Nodes.OfType().Where(n => n.Nodes.Count > 0).ToDictionary(n => n.Tag, n => new TreeNodeExpandCollapseState(n)); } /// @@ -70,7 +70,7 @@ } } - foreach (var treeNode in targetNode.Nodes.Where(n => n.Nodes.Any() && childStates.ContainsKey(n.Tag))) + foreach (var treeNode in targetNode.Nodes.OfType().Where(n => n.Nodes.Count > 0 && childStates.ContainsKey(n.Tag))) { childStates[treeNode.Tag].Restore(treeNode); } Index: Core/Common/src/Core.Common.Controls.TreeView/TreeNodeGraphicExtensions.cs =================================================================== diff -u -rcc608d648b3fe89d6f748f5245c532014186d578 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Controls.TreeView/TreeNodeGraphicExtensions.cs (.../TreeNodeGraphicExtensions.cs) (revision cc608d648b3fe89d6f748f5245c532014186d578) +++ Core/Common/src/Core.Common.Controls.TreeView/TreeNodeGraphicExtensions.cs (.../TreeNodeGraphicExtensions.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -13,36 +13,12 @@ private const int spaceBetweenNodeParts = 2; /// - /// Checks if the is on the expand button of the node - /// - /// Node to check for - /// Point to search for - public static bool IsOnExpandButton(this TreeNode node, Point point) - { - if (node == null || !node.HasChildren) - { - return false; - } - - var yBoundsMiddle = node.Bounds.Top + node.Bounds.Height/2; - var graphics = node.TreeView.CreateGraphics(); - var buttonSize = GetExpandButtonSize(graphics); - var rectangle = new Rectangle(GetTreeLineLeft(node) - buttonSize/2, yBoundsMiddle - buttonSize/2, buttonSize, buttonSize); - return rectangle.Contains(point); - } - - /// /// Checks if the is on the checkbox of the node /// /// Node to check for /// Point to search for public static bool IsOnCheckBox(this TreeNode node, Point point) { - if (node == null || !node.ShowCheckBox) - { - return false; - } - var topOffset = (node.Bounds.Height - defaultImageHeight)/2; var rectangle = new Rectangle(GetCheckBoxLeft(node), node.Bounds.Top + topOffset, defaultImageWidth, defaultImageHeight); return rectangle.Contains(point); @@ -52,19 +28,28 @@ /// Draws a tree node using the boundaries of the node /// /// Node to draw + /// The to use while drawing the node. /// Graphic to draw on /// Is node in selected state - public static void DrawNode(this TreeNode node, Graphics graphics, bool selected) + public static void DrawNode(this TreeNode node, TreeNodeInfo treeNodeInfo, Graphics graphics, bool selected) { - if (node.Bounds.Height == 0) //nothing to draw + if (node.Bounds.Height == 0) // Nothing to draw { return; } - DrawText(graphics, node, selected); + DrawText(graphics, node, treeNodeInfo, selected); DrawTreeLines(graphics, node); - DrawCheckbox(graphics, node); - DrawImage(graphics, node); + + if (treeNodeInfo.CanCheck != null && treeNodeInfo.CanCheck(node.Tag)) + { + DrawCheckbox(graphics, node); + } + + if (treeNodeInfo.Image != null) + { + DrawImage(graphics, node, treeNodeInfo); + } } /// @@ -145,9 +130,9 @@ if (node.Parent != null) { - graphics.DrawLine(pen, xLine, bounds.Top, xLine, (hasNextNodeOnSameLevel) ? bounds.Bottom : yBoundsMiddle); // Vertical line + graphics.DrawLine(pen, xLine, bounds.Top, xLine, hasNextNodeOnSameLevel ? bounds.Bottom : yBoundsMiddle); // Vertical line } - if (node.Parent != null || node.HasChildren) + if (node.Parent != null || node.Nodes.Count > 0) { graphics.DrawLine(pen, xLine + 1, yBoundsMiddle, GetCheckBoxLeft(node) - spaceBetweenNodeParts, yBoundsMiddle); // Horizontal line } @@ -172,14 +157,14 @@ private static void DrawExpandGraphic(Graphics graphics, TreeNode node, int yBoundsMiddle) { - if (!node.HasChildren) + if (node.Nodes.Count == 0) { return; } if (Application.RenderWithVisualStyles) { - var image = (node.IsExpanded) + var image = node.IsExpanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed; @@ -210,7 +195,7 @@ } } - private static void DrawText(Graphics graphics, TreeNode node, bool selected) + private static void DrawText(Graphics graphics, TreeNode node, TreeNodeInfo treeNodeInfo, bool selected) { if (node.IsEditing && node.IsSelected) { @@ -219,23 +204,23 @@ var bounds = node.Bounds; var treeView = node.TreeView; - var foreColor = (selected && treeView.Focused) + var foreColor = selected && treeView.Focused ? SystemColors.HighlightText - : (node.ForeColor != Color.Empty) ? node.ForeColor : treeView.ForeColor; + : node.ForeColor != Color.Empty ? node.ForeColor : treeView.ForeColor; - var backgroundColor = (selected) + var backgroundColor = selected ? treeView.Focused ? SystemColors.Highlight : Color.FromArgb(255, 232, 232, 232) - : (node.BackColor != Color.Empty) + : node.BackColor != Color.Empty ? node.BackColor : treeView.BackColor; var font = new Font(node.NodeFont ?? treeView.Font, FontStyle.Regular); var topOffset = (node.Bounds.Height - TextRenderer.MeasureText(node.Text, font).Height)/2; - var startPoint = new Point(GetTextLeft(node), bounds.Top + topOffset); + var startPoint = new Point(GetTextLeft(node, treeNodeInfo), bounds.Top + topOffset); var drawingBounds = treeView.FullRowSelect ? new Rectangle(0, bounds.Top, treeView.Width, bounds.Height) - : new Rectangle(GetTextLeft(node), bounds.Top, bounds.Width, bounds.Height); + : new Rectangle(GetTextLeft(node, treeNodeInfo), bounds.Top, bounds.Width, bounds.Height); graphics.FillRectangle(new SolidBrush(backgroundColor), drawingBounds); @@ -249,11 +234,6 @@ private static void DrawCheckbox(Graphics graphics, TreeNode node) { - if (!node.ShowCheckBox) - { - return; - } - var topOffset = (node.Bounds.Height - defaultImageHeight)/2; var imgRect = new Rectangle(GetCheckBoxLeft(node), node.Bounds.Top + topOffset, defaultImageWidth, defaultImageHeight); @@ -279,18 +259,14 @@ return Convert.ToInt32(20*(72/graphics.DpiX)); } - private static void DrawImage(Graphics graphics, TreeNode node) + private static void DrawImage(Graphics graphics, TreeNode node, TreeNodeInfo treeNodeInfo) { - if (node.Image == null) - { - return; - } - + var image = treeNodeInfo.Image(node.Tag); var graphicsUnit = GraphicsUnit.Pixel; var topOffset = (node.Bounds.Height - defaultImageHeight)/2; - var imgRect = new Rectangle(GetImageLeft(node), node.Bounds.Top + topOffset, defaultImageWidth, defaultImageHeight); + var imgRect = new Rectangle(GetImageLeft(node, treeNodeInfo), node.Bounds.Top + topOffset, defaultImageWidth, defaultImageHeight); - graphics.DrawImage(node.Image, imgRect, node.Image.GetBounds(ref graphicsUnit), graphicsUnit); + graphics.DrawImage(image, imgRect, image.GetBounds(ref graphicsUnit), graphicsUnit); } private static int GetTreeLineLeft(TreeNode node) @@ -303,16 +279,22 @@ return node.Bounds.Left - (defaultImageWidth + spaceBetweenNodeParts); } - private static int GetImageLeft(TreeNode node) + private static int GetImageLeft(TreeNode node, TreeNodeInfo treeNodeInfo) { var xCheckBox = GetCheckBoxLeft(node); - return node.ShowCheckBox ? xCheckBox + defaultImageWidth + spaceBetweenNodeParts : xCheckBox; + + return treeNodeInfo.CanCheck != null && treeNodeInfo.CanCheck(node.Tag) + ? xCheckBox + defaultImageWidth + spaceBetweenNodeParts + : xCheckBox; } - private static int GetTextLeft(TreeNode node) + private static int GetTextLeft(TreeNode node, TreeNodeInfo treeNodeInfo) { - var xImage = GetImageLeft(node); - return node.Image != null ? xImage + defaultImageWidth + spaceBetweenNodeParts : xImage; + var xImage = GetImageLeft(node, treeNodeInfo); + + return treeNodeInfo.Image != null && treeNodeInfo.Image(node.Tag) != null + ? xImage + defaultImageWidth + spaceBetweenNodeParts + : xImage; } private static TreeNode GetNextNodeSameLevel(TreeNode node) Index: Core/Common/src/Core.Common.Controls.TreeView/TreeNodeInfo.cs =================================================================== diff -u -r778cb6e89f676cb60f95da71d7aed9d5b355ed2e -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Controls.TreeView/TreeNodeInfo.cs (.../TreeNodeInfo.cs) (revision 778cb6e89f676cb60f95da71d7aed9d5b355ed2e) +++ Core/Common/src/Core.Common.Controls.TreeView/TreeNodeInfo.cs (.../TreeNodeInfo.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -29,10 +29,10 @@ public Func Text { get; set; } /// - /// Gets or sets a function for obtaining the tree node foreground color. + /// Gets or sets a function for obtaining the tree node fore color. /// The object parameter represents the wrapped data of the tree node. /// - public Func ForegroundColor { get; set; } + public Func ForeColor { get; set; } /// /// Gets or sets a function for obtaining the tree node image. @@ -44,8 +44,9 @@ /// Gets or sets a function for obtaining the tree node context menu. /// The object parameter represents the wrapped data of the tree node. /// The parameter represents the tree node. + /// The parameter represents the current tree node information object. /// - public Func ContextMenu { get; set; } + public Func ContextMenuStrip { get; set; } /// /// Gets or sets a function for obtaining child node objects. @@ -81,13 +82,24 @@ public Action OnNodeRemoved { get; set; } /// - /// Gets or sets an action for obtaining the logic to perform after checking or unchecking the tree node. + /// Gets or sets a function for checking whether or not the tree node can be checked. /// The object parameter represents the wrapped data of the tree node. - /// The bool parameter represents the new checked state of the tree node. /// - public Action OnNodeChecked { get; set; } + public Func CanCheck { get; set; } /// + /// Gets or sets a function for checking whether or not the tree node should be checked. + /// The object parameter represents the wrapped data of the tree node. + /// + public Func IsChecked { get; set; } + + /// + /// Gets or sets an action for obtaining the logic to perform after checking or unchecking the tree node. + /// The parameter represents the tree node which is checked. + /// + public Action OnNodeChecked { get; set; } + + /// /// Gets or sets a function for checking whether or not the tree node can be dragged to another location. /// The object parameter represents the wrapped data of the tree node. /// The parameter represents the tree node which is dragged. @@ -96,33 +108,30 @@ /// /// Gets or sets a function for checking whether or not the tree node can be dropped to another location. - /// The object parameter represents the wrapped data of the tree node. /// The first parameter represents the tree node which is dragged. /// The second parameter represents the tree node being considered as drop target. /// The parameter represents the supported drop operations for the tree node which is dragged. /// The return value indicates what operation is valid when the tree node is dropped onto the drop target. /// /// When dragging a node, the function of the of the drop target should be called. - public Func CanDrop { get; set; } + public Func CanDrop { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be inserted into the drop target at a specific index. - /// The object parameter represents the wrapped data of the tree node. /// The first parameter represents the tree node which is dragged. /// The second parameter represents the tree node being considered as drop target. /// - public Func CanInsert { get; set; } + public Func CanInsert { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after dropping a tree node. - /// The object parameter represents the wrapped data of the tree node. /// The first parameter represents the tree node which is dragged. /// The second parameter represents the tree node being considered as drop target. /// The parameter represents the type of drag operation that was performed. /// The parameter represents the drop target index which the tree node was inserted at. /// /// When dragging a node, the function of the of the drop target should be called. - public Action OnDrop { get; set; } + public Action OnDrop { get; set; } } /// @@ -157,10 +166,10 @@ public Func Text { get; set; } /// - /// Gets or sets a function for obtaining the tree node foreground color. + /// Gets or sets a function for obtaining the tree node color. /// The parameter represents the wrapped data of the tree node. /// - public Func ForegroundColor { get; set; } + public Func ForeColor { get; set; } /// /// Gets or sets a function for obtaining the tree node image. @@ -172,8 +181,9 @@ /// Gets or sets a function for obtaining the tree node context menu. /// The parameter represents the wrapped data of the tree node. /// The parameter represents the tree node. + /// The parameter represents the current tree node information object. /// - public Func ContextMenu { get; set; } + public Func ContextMenuStrip { get; set; } /// /// Gets or sets a function for obtaining child node objects. @@ -209,13 +219,24 @@ public Action OnNodeRemoved { get; set; } /// - /// Gets or sets an action for obtaining the logic to perform after checking or unchecking the tree node. + /// Gets or sets a function for checking whether or not the tree node can be checked. /// The parameter represents the wrapped data of the tree node. - /// The bool parameter represents the new checked state of the tree node. /// - public Action OnNodeChecked { get; set; } + public Func CanCheck { get; set; } /// + /// Gets or sets a function for checking whether or not the tree node should be checked. + /// The parameter represents the wrapped data of the tree node. + /// + public Func IsChecked { get; set; } + + /// + /// Gets or sets an action for obtaining the logic to perform after checking or unchecking the tree node. + /// The parameter represents the tree node which is checked. + /// + public Action OnNodeChecked { get; set; } + + /// /// Gets or sets a function for checking whether or not the tree node can be dragged to another location. /// The parameter represents the wrapped data of the tree node. /// The parameter represents the tree node which is dragged. @@ -224,33 +245,30 @@ /// /// Gets or sets a function for checking whether or not the tree node can be dropped to another location. - /// The parameter represents the wrapped data of the tree node. /// The first parameter represents the tree node which is dragged. /// The second parameter represents the tree node being considered as drop target. /// The parameter represents the supported drop operations for the tree node which is dragged. /// The return value indicates what operation is valid when the tree node is dropped onto the drop target. /// /// When dragging a node, the function of the of the drop target should be called. - public Func CanDrop { get; set; } + public Func CanDrop { get; set; } /// /// Gets or sets a function for checking whether or not the tree node can be inserted into the drop target at a specific index. - /// The parameter represents the wrapped data of the tree node. /// The first parameter represents the tree node which is dragged. /// The second parameter represents the tree node being considered as drop target. /// - public Func CanInsert { get; set; } + public Func CanInsert { get; set; } /// /// Gets or sets an action for obtaining the logic to perform after dropping a tree node. - /// The parameter represents the wrapped data of the tree node. /// The first parameter represents the tree node which is dragged. /// The second parameter represents the tree node being considered as drop target. /// The parameter represents the type of drag operation that was performed. /// The parameter represents the drop target index which the tree node was inserted at. /// /// When dragging a node, the function of the of the drop target should be called. - public Action OnDrop { get; set; } + public Action OnDrop { get; set; } /// /// This operator converts a into a . @@ -262,20 +280,54 @@ return new TreeNodeInfo { TagType = treeNodeInfo.TagType, - Text = tag => treeNodeInfo.Text((TData) tag), - ForegroundColor = tag => treeNodeInfo.ForegroundColor((TData) tag), - Image = tag => treeNodeInfo.Image((TData) tag), - ContextMenu = (tag, sourceNode) => treeNodeInfo.ContextMenu((TData) tag, sourceNode), - ChildNodeObjects = tag => treeNodeInfo.ChildNodeObjects((TData) tag), - CanRename = sourceNode => treeNodeInfo.CanRename(sourceNode), - OnNodeRenamed = (tag, name) => treeNodeInfo.OnNodeRenamed((TData) tag, name), - CanRemove = (tag, parentTag) => treeNodeInfo.CanRemove((TData) tag, parentTag), - OnNodeRemoved = (tag, parentTag) => treeNodeInfo.OnNodeRemoved((TData) tag, parentTag), - OnNodeChecked = (tag, checkedState) => treeNodeInfo.OnNodeChecked((TData) tag, checkedState), - CanDrag = (tag, sourceNode) => treeNodeInfo.CanDrag((TData) tag, sourceNode), - CanDrop = (tag, sourceNode, targetNode, dragOperations) => treeNodeInfo.CanDrop((TData) tag, sourceNode, targetNode, dragOperations), - CanInsert = (tag, sourceNode, targetNode) => treeNodeInfo.CanInsert((TData) tag, sourceNode, targetNode), - OnDrop = (tag, sourceNode, targetNode, dragOperations, index) => treeNodeInfo.OnDrop((TData) tag, sourceNode, targetNode, dragOperations, index), + Text = treeNodeInfo.Text != null + ? tag => treeNodeInfo.Text((TData) tag) + : (Func) null, + ForeColor = treeNodeInfo.ForeColor != null + ? tag => treeNodeInfo.ForeColor((TData) tag) + : (Func) null, + Image = treeNodeInfo.Image != null + ? tag => treeNodeInfo.Image((TData) tag) + : (Func) null, + ContextMenuStrip = treeNodeInfo.ContextMenuStrip != null + ? (tag, sourceNode, info) => treeNodeInfo.ContextMenuStrip((TData) tag, sourceNode, info) + : (Func) null, + ChildNodeObjects = treeNodeInfo.ChildNodeObjects != null + ? tag => treeNodeInfo.ChildNodeObjects((TData) tag) + : (Func) null, + CanRename = treeNodeInfo.CanRename != null + ? sourceNode => treeNodeInfo.CanRename(sourceNode) + : (Func) null, + OnNodeRenamed = treeNodeInfo.OnNodeRenamed != null + ? (tag, name) => treeNodeInfo.OnNodeRenamed((TData) tag, name) + : (Action) null, + CanRemove = treeNodeInfo.CanRemove != null + ? (tag, parentTag) => treeNodeInfo.CanRemove((TData) tag, parentTag) + : (Func) null, + OnNodeRemoved = treeNodeInfo.OnNodeRemoved != null + ? (tag, parentTag) => treeNodeInfo.OnNodeRemoved((TData) tag, parentTag) + : (Action) null, + CanCheck = treeNodeInfo.CanCheck != null + ? tag => treeNodeInfo.CanCheck((TData) tag) + : (Func) null, + IsChecked = treeNodeInfo.IsChecked != null + ? tag => treeNodeInfo.IsChecked((TData) tag) + : (Func) null, + OnNodeChecked = treeNodeInfo.OnNodeChecked != null + ? sourceNode => treeNodeInfo.OnNodeChecked(sourceNode) + : (Action) null, + CanDrag = treeNodeInfo.CanDrag != null + ? (tag, sourceNode) => treeNodeInfo.CanDrag((TData) tag, sourceNode) + : (Func) null, + CanDrop = treeNodeInfo.CanDrop != null + ? (sourceNode, targetNode, dragOperations) => treeNodeInfo.CanDrop(sourceNode, targetNode, dragOperations) + : (Func) null, + CanInsert = treeNodeInfo.CanInsert != null + ? (sourceNode, targetNode) => treeNodeInfo.CanInsert(sourceNode, targetNode) + : (Func) null, + OnDrop = treeNodeInfo.OnDrop != null + ? (sourceNode, targetNode, dragOperations, index) => treeNodeInfo.OnDrop(sourceNode, targetNode, dragOperations, index) + : (Action) null, }; } } Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Controls.TreeView/TreeNodeList.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/src/Core.Common.Controls.TreeView/TreeView.cs =================================================================== diff -u -r0d17d6adbe5df05db51e20685df0a47944fa6a30 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Controls.TreeView/TreeView.cs (.../TreeView.cs) (revision 0d17d6adbe5df05db51e20685df0a47944fa6a30) +++ Core/Common/src/Core.Common.Controls.TreeView/TreeView.cs (.../TreeView.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,1075 +1,145 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; using System.Drawing; -using System.Linq; -using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; -using Core.Common.Controls.TreeView.Properties; -using log4net; - using BaseResources = Core.Common.Base.Properties.Resources; namespace Core.Common.Controls.TreeView { - /// - /// Summary description for Tree. - /// public class TreeView : System.Windows.Forms.TreeView { - public event EventHandler SelectedNodeChanged; - public event EventHandler OnUpdate; - - /// - /// Occurs when a node with data has been deleted from the tree view. - /// - public event EventHandler DataDeleted; - - private const int TV_FIRST = 0x1100; - private const int TVM_SETBKCOLOR = TV_FIRST + 29; - private const int TVM_SETEXTENDEDSTYLE = TV_FIRST + 44; - - private const int TVS_EX_DOUBLEBUFFER = 0x0004; - private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private readonly TreeNodeList nodes; - private readonly TreeViewController controller; - private int dropAtLocation; - private Point lastDragOverPoint; - private PlaceholderLocation lastPlaceholderLocation; - private TreeNode nodeDropTarget; - private TreeNode lastPlaceholderNode; - private Graphics placeHolderGraphics; - private bool bufferedNodeExpanded; - /// - /// TreeView based on system windows forms component. - /// public TreeView() { controller = new TreeViewController(this); - ImageList = new ImageList - { - ColorDepth = ColorDepth.Depth32Bit - }; - nodes = new TreeNodeList(base.Nodes); + DrawMode = TreeViewDrawMode.OwnerDrawAll; LabelEdit = true; HideSelection = false; - BeforeLabelEdit += TreeViewBeforeLabelEdit; - AfterCheck += TreeViewAfterCheck; - - DragDrop += TreeViewDragDrop; - DragOver += TreeViewDragOver; - ItemDrag += TreeViewItemDrag; - DragLeave += TreeViewDragLeave; - - MouseDown += TreeViewMouseDown; - MouseClick += TreeViewClick; - - // http://dev.nomad-net.info/articles/double-buffered-tree-and-list-views // Enable default double buffering processing - SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true); + SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); - //SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); // Disable default CommCtrl painting on non-Vista systems if (!NativeInterop.IsWinVista) { SetStyle(ControlStyles.UserPaint, true); } } - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public Func OnProcessCmdKey { get; set; } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public new TreeNode SelectedNode + public TreeViewController TreeViewController { get { - return (TreeNode) base.SelectedNode; + return controller; } - set - { - base.SelectedNode = value; - - if (SelectedNodeChanged != null) - { - SelectedNodeChanged(this, new EventArgs()); - } - } } - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public object Data - { - get - { - return controller.Data; - } - set - { - controller.Data = value; - } - } + # region Logic for preventing expand/collapse on double click - /// - /// The nodepresenters handle building logic for dataobjects added to the tree. - /// - public IEnumerable NodePresenters + protected override void DefWndProc(ref Message m) { - get - { - return controller.NodePresenters; - } - } + const int wmLbuttondblclk = 515; + const int wmErasebkgnd = 0x0014; - /// - /// List of all nodes that belong to the tree. - /// - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public new IList Nodes - { - get + if (m.Msg == wmLbuttondblclk) { - return nodes; + return; // Don't handle double click } - } - public new void CollapseAll() - { - foreach (var node in Nodes) + if (m.Msg == wmErasebkgnd) { - CollapseAll(node); + return; // Don't clear background as this only causes flicker } - } - public void CollapseAll(TreeNode node) - { - node.Collapse(); - - foreach (var childNode in node.Nodes) - { - CollapseAll(childNode); - } + base.DefWndProc(ref m); } - public new void ExpandAll() - { - foreach (var node in Nodes) - { - ExpandAll(node); - } - } + # endregion - public void ExpandAll(TreeNode node) - { - node.Expand(); + # region Double buffered tree view related logic (see http://dev.nomad-net.info/articles/double-buffered-tree-and-list-views) - foreach (var childNode in node.Nodes) - { - ExpandAll(childNode); - } - } + private const int tvFirst = 0x1100; + private const int tvmSetbkcolor = tvFirst + 29; + private const int tvmSetextendedstyle = tvFirst + 44; + private const int tvsExDoublebuffer = 0x0004; - public void StartLabelEdit(TreeNode node) + private void UpdateExtendedStyles() { - if (!controller.CanRenameNode(node)) - { - return; - } + var style = 0; - node.BeginEdit(); - } - - public void RegisterNodePresenter(ITreeNodePresenter presenter) - { - controller.RegisterNodePresenter(presenter); - } - - public ITreeNodePresenter GetTreeViewNodePresenter(object nodeData) - { - if (nodeData == null) + if (DoubleBuffered) { - throw new ArgumentNullException("nodeData", Resources.TreeView_Error_Unable_to_resolve_node_presenter_for_null_data); + style |= tvsExDoublebuffer; } - return controller.ResolveNodePresenterForData(nodeData); - } - /// - /// Create a new Node for this tree with default properties - /// - /// - public TreeNode NewNode() - { - return new TreeNode(this); - } - - /// - /// Search all the nodes in the treeView, for a node with a matching tag. - /// - /// - /// if a node is not loaded, don't do so - /// - public TreeNode GetNodeByTag(object nodeData, bool skipUnLoadedNodes = true) - { - if (Nodes.Count > 0) + if (style != 0) { - return GetNodeByTag(Nodes[0], nodeData, skipUnLoadedNodes); + NativeInterop.SendMessage(Handle, tvmSetextendedstyle, (IntPtr) tvsExDoublebuffer, (IntPtr) style); } - - return null; } - public void UpdateNode(TreeNode treeNode) + protected override void OnHandleCreated(EventArgs e) { - controller.UpdateNode(treeNode, treeNode.Tag); - FireOnUpdateEvent(treeNode); - } + base.OnHandleCreated(e); - /// - /// Fires the event with the given . - /// - /// The to fire an update event for. - private void FireOnUpdateEvent(TreeNode treeNode) - { - if (OnUpdate != null) - { - OnUpdate(treeNode, EventArgs.Empty); - } - } + UpdateExtendedStyles(); - public void TryDeleteNodeData(TreeNode treeNode) - { - if (!controller.CanDeleteNode(treeNode)) + if (!NativeInterop.IsWinXp) { - MessageBox.Show(Resources.TreeView_DeleteNodeData_The_selected_item_cannot_be_removed, BaseResources.Confirm, MessageBoxButtons.OK); - return; + NativeInterop.SendMessage(Handle, tvmSetbkcolor, IntPtr.Zero, (IntPtr) ColorTranslator.ToWin32(BackColor)); } - - var message = string.Format(Resources.TreeView_DeleteNodeData_Are_you_sure_you_want_to_delete_the_following_item_0_, treeNode.Text); - if (MessageBox.Show(message, BaseResources.Confirm, MessageBoxButtons.OKCancel) != DialogResult.OK) - { - return; - } - - DeleteNodeData(treeNode); } - public void TryDeleteSelectedNodeData() - { - TryDeleteNodeData(SelectedNode); - } - - private void DeleteNodeData(TreeNode node) - { - var presenter = GetTreeViewNodePresenter(node.Tag); - presenter.RemoveNodeData(node.Parent.Tag, node.Tag); - - SelectedNode = SelectedNode ?? Nodes.FirstOrDefault(); - if (DataDeleted != null) - { - DataDeleted(this, new TreeViewDataDeletedEventArgs(node.Tag)); - } - } - - public override void Refresh() - { - if (Nodes.Count == 0) - { - return; - } - - BeginUpdate(); - try - { - var selectedNodePath = SelectedNode == null ? string.Empty : SelectedNode.FullPath; - - //don't use allNodes since update of childnodes is done by parent. - foreach (TreeNode node in Nodes) - { - controller.UpdateNode(node); - } - - if (!string.IsNullOrEmpty(selectedNodePath)) - { - var nodeToSelect = - Nodes.SelectMany(GetAllLoadedNodes).FirstOrDefault(n => n.FullPath == selectedNodePath); - - if (nodeToSelect != null) - { - base.SelectedNode = nodeToSelect; - } - } - - // expand root node if children were added - if (Nodes.Count > 0 && Nodes[0].Nodes.Count > 0) - { - Nodes[0].Expand(); - } - - Sort(); - } - finally - { - EndUpdate(); - } - } - - private IEnumerable GetAllLoadedNodes(TreeNode currentNode) - { - var allChildNodes = new[] - { - currentNode - }; - - return allChildNodes.Concat(currentNode.Nodes.SelectMany(GetAllLoadedNodes)); - } - protected override void OnPaint(PaintEventArgs e) { if (GetStyle(ControlStyles.UserPaint)) { - Message m = new Message + var m = new Message { HWnd = Handle, - Msg = NativeInterop.WM_PRINTCLIENT, + Msg = NativeInterop.WmPrintclient, WParam = e.Graphics.GetHdc(), - LParam = (IntPtr) NativeInterop.PRF_CLIENT + LParam = (IntPtr) NativeInterop.PrfClient }; DefWndProc(ref m); + e.Graphics.ReleaseHdc(m.WParam); } base.OnPaint(e); } - protected override void OnHandleCreated(EventArgs e) - { - base.OnHandleCreated(e); - UpdateExtendedStyles(); - if (!NativeInterop.IsWinXP || !Application.RenderWithVisualStyles) - { - NativeInterop.SendMessage(Handle, TVM_SETBKCOLOR, IntPtr.Zero, (IntPtr) ColorTranslator.ToWin32(BackColor)); - } - controller.OnTreeViewHandleCreated(); - } - - /// - /// Custom drawing. - /// - /// - protected override void OnDrawNode(DrawTreeNodeEventArgs e) - { - e.DrawDefault = false; - - var selected = (e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected; - - ((TreeNode) e.Node).DrawNode(e.Graphics, selected); - } - - protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e) - { - BeginUpdate(); - - try - { - var treeNode = e.Node as TreeNode; - - if (treeNode != null) - { - //check e.Label for null, this indicates node edit was cancelled. - if (treeNode.IsUpdating || treeNode.Tag == null || e.Label == null) - { - return; - } - - var nodePresenter = GetTreeViewNodePresenter(treeNode.Tag); - if (nodePresenter == null) - { - return; - } - - if (nodePresenter.CanRenameNodeTo(treeNode, e.Label)) - { - // First set text to prevent eventHandlers from working with a node that - // is not yet updated (with the previous text) - // Setting the node text is done after this method is completed (and e.cancel is false). - treeNode.Text = e.Label; - nodePresenter.OnNodeRenamed(treeNode.Tag, e.Label); - } - else - { - e.CancelEdit = true; - return; - } - } - - base.OnAfterLabelEdit(e); - BeginInvoke(new Action(Sort)); - } - finally - { - EndUpdate(); - } - } - - /// - /// Do not expand/collapse on doubleclick - /// - /// - protected override void DefWndProc(ref Message m) - { - const int WM_LBUTTONDBLCLK = 515; - const int WM_ERASEBKGND = 0x0014; - - if (m.Msg == WM_LBUTTONDBLCLK) - { - //dont handle doubleclick in base class - } - else if (m.Msg == WM_ERASEBKGND) - { - return; //don't clear background (only causes flicker) - } - else - { - //log.DebugFormat(m.ToString()); - base.DefWndProc(ref m); - } - } - - protected override bool ProcessCmdKey(ref Message msg, Keys keyData) - { - if (Nodes.Count == 0) - { - if (OnProcessCmdKey != null) - { - return OnProcessCmdKey(keyData); - } - - return base.ProcessCmdKey(ref msg, keyData); - } - - if (SelectedNode == null) - { - SelectedNode = Nodes[0]; - } - - if (SelectedNode.IsEditing) - { - return base.ProcessCmdKey(ref msg, keyData); - } - - switch (keyData) - { - case Keys.F2: - //start editing the label - StartLabelEdit(SelectedNode); - return true; - - case Keys.Apps: - if (SelectedNode != null && ContextMenu != null && SelectedNode.ContextMenuStrip != null) - { - Point location = SelectedNode.Bounds.Location; - location.Offset(0, SelectedNode.Bounds.Height); - SelectedNode.ContextMenuStrip.Show(location); - } - return true; - - // TODO: Customize completely within OnProcessCmdKey - case Keys.Delete: - if (OnProcessCmdKey == null && SelectedNode != null && SelectedNode.Tag != null) - { - TryDeleteSelectedNodeData(); - return true; - } - break; - - case Keys.F5: - - //refresh treeview - Refresh(); - return true; - - case Keys.Space: - var node = SelectedNode; - if (node != null && node.ShowCheckBox) - { - //Toggle checked state - node.Checked = !node.Checked; - } - return true; - case Keys.Up: - { - //hack: we manually handle this because ms doesnot fire selectednodechanged - // Select the previous node - var treeNode = SelectedNode.PrevVisibleNode as TreeNode; - if (treeNode != null) - { - SelectedNode = treeNode; - } - } - return true; - case Keys.Down: - { - //hack: we manually handle this because ms doesnot fire selectednodechanged - // Select the next node - var treeNode = SelectedNode.NextVisibleNode as TreeNode; - if (treeNode != null) - { - SelectedNode = treeNode; - } - } - return true; - case Keys.Right: - { - //hack: we manually handle this because ms doesnot fire selectednodechanged - - if (SelectedNode.Nodes.Count > 0) - { - if (!SelectedNode.IsExpanded) - { - SelectedNode.Expand(); - } - else - { - SelectedNode = SelectedNode.Nodes[0]; - } - } - } - return true; - case Keys.Left: - { - //hack: we manually handle this because ms doesnot fire selectednodechanged - - if (SelectedNode.IsExpanded) - { - SelectedNode.Collapse(); - } - else - { - if (SelectedNode.Parent != null) - { - SelectedNode = SelectedNode.Parent; - } - } - } - return true; - case Keys.Home: - { - //hack: we manually handle this because ms doesnot fire selectednodechanged - - SelectedNode = Nodes.First(); - } - return true; - case Keys.End: - { - //hack: we manually handle this because ms doesnot fire selectednodechanged - - SelectedNode = GetLastNode(Nodes.Last()); - } - return true; - } - - if (keyData == (Keys.Control | Keys.Shift | Keys.Right)) - { - ExpandAll(SelectedNode); - SelectedNode.EnsureVisible(); - return true; - } - - if (keyData == (Keys.Control | Keys.Shift | Keys.Left)) - { - CollapseAll(SelectedNode); - SelectedNode.EnsureVisible(); - return true; - } - - if (OnProcessCmdKey != null) - { - if (OnProcessCmdKey(keyData)) - { - return true; - } - } - - return base.ProcessCmdKey(ref msg, keyData); - } - - private void UpdateExtendedStyles() - { - int Style = 0; - - if (DoubleBuffered) - { - Style |= TVS_EX_DOUBLEBUFFER; - } - - if (Style != 0) - { - NativeInterop.SendMessage(Handle, TVM_SETEXTENDEDSTYLE, (IntPtr) TVS_EX_DOUBLEBUFFER, (IntPtr) Style); - } - } - - private new void Sort() - { - if (TreeViewNodeSorter == null) - { - return; - } - - var oldSelectedNode = SelectedNode; - - SuspendLayout(); - base.Sort(); - ResumeLayout(); - - SelectedNode = oldSelectedNode; - } - - private TreeNode GetLastNode(TreeNode treeNode) - { - if (treeNode.Nodes.Count > 0) - { - return GetLastNode(treeNode.Nodes.Last()); - } - - return treeNode; - } - - private void TreeViewMouseDown(object sender, MouseEventArgs e) - { - var treeView = sender as TreeView; - if (treeView == null) - { - return; - } - - var treeNode = (TreeNode) GetNodeAt(e.X, e.Y); - if (treeNode == null) - { - return; - } - - // buffer expanded state for use in TreeViewClick - bufferedNodeExpanded = treeNode.IsExpanded; - } - - private void TreeViewClick(object sender, MouseEventArgs e) - { - var point = PointToClient(MousePosition); - var node = (TreeNode) GetNodeAt(point); - if (node == null) - { - return; - } - - SelectedNode = node; - - if (node.IsOnCheckBox(point)) - { - node.Checked = !node.Checked; - } - - if (node.IsOnExpandButton(point)) - { - // Use buffered expanded state because it gets changed just - // before Click event is handled - if (bufferedNodeExpanded) - { - node.Collapse(true); - } - else - { - node.Expand(); - } - } - } - - private void TreeViewAfterCheck(object sender, TreeViewEventArgs e) - { - controller.OnNodeChecked((TreeNode) e.Node); - } - - /// - /// Check if node label can be edited - /// - /// - /// - private void TreeViewBeforeLabelEdit(object sender, NodeLabelEditEventArgs e) - { - if (!controller.CanRenameNode(e.Node as TreeNode)) - { - e.CancelEdit = true; - } - } - - private static TreeNode GetNodeByTag(TreeNode rootNode, object tag, bool skipUnLoadedNodes) - { - if (Equals(rootNode.Tag, tag)) - { - return rootNode; - } - - return rootNode.Nodes.Select(n => GetNodeByTag(n, tag, skipUnLoadedNodes)).FirstOrDefault(node => node != null); - } - - /// - /// Use Nodepresenter to see wether the current node can be dragged - /// set the allowed effects based on the possible dragoperation. - /// - /// - /// - private void TreeViewItemDrag(object sender, ItemDragEventArgs e) - { - // gather allowed effects for the current item. - var sourceNode = (TreeNode) e.Item; - ITreeNodePresenter presenter = GetTreeViewNodePresenter(sourceNode.Tag); - - if (presenter == null) - { - return; - } - - DragOperations dragOperation = presenter.CanDrag(sourceNode.Tag); - - DragDropEffects effects = ToDragDropEffects(dragOperation); - - if (effects == DragDropEffects.None) - { - return; - } - - // store both treenode and tag of treenode in dataobject - // to be dragged. - IDataObject dataObject = new DataObject(); - dataObject.SetData(typeof(TreeNode), sourceNode); - - if (sourceNode.Tag != null) - { - dataObject.SetData(sourceNode.Tag.GetType(), sourceNode.Tag); - } - - DoDragDrop(dataObject, effects); - } - - /// - /// Update the UI of the treeview for the current action - /// - /// - /// - private void TreeViewDragOver(object sender, DragEventArgs e) - { - if (lastDragOverPoint.X == e.X && lastDragOverPoint.Y == e.Y) - { - return; - } - - lastDragOverPoint = new Point(e.X, e.Y); - var point = PointToClient(lastDragOverPoint); - - var nodeOver = GetNodeAt(point) as TreeNode; - var nodeDragging = e.Data.GetData(typeof(TreeNode)) as TreeNode; - - if (nodeOver == null || nodeDragging == null || nodeOver == nodeDragging || nodeOver.IsChildOf(nodeDragging)) - { - ClearPlaceHolders(); - return; - } - - ScrollIntoView(point, nodeOver, sender); - PlaceholderLocation placeholderLocation = GetPlaceHoldersLocation(nodeDragging, nodeOver, e); - - if (null == nodeDropTarget) - { - return; - } - - ITreeNodePresenter presenter = GetTreeViewNodePresenter(nodeDropTarget.Tag); - DragOperations allowedOperations = presenter.CanDrop(nodeDragging.Tag, nodeDragging, nodeDropTarget, ToDragOperation(e.AllowedEffect)); - e.Effect = ToDragDropEffects(allowedOperations); - - if (PlaceholderLocation.None == placeholderLocation) - { - return; - } - - // determine if the node can be dropped based on the allowed operations. - // A node can also be a valid drop traget if it is the root item! (nodeDragging.Parent == null) - // This applies in any case to the MapLegendView - if (DragOperations.None != presenter.CanDrop(nodeDragging.Tag, nodeDragging, nodeDropTarget, allowedOperations)) - { - DrawPlaceholder(nodeOver, placeholderLocation); - } - else - { - ClearPlaceHolders(); - e.Effect = DragDropEffects.None; - } - } - - private PlaceholderLocation GetPlaceHoldersLocation(TreeNode nodeDragging, TreeNode nodeOver, DragEventArgs e) - { - PlaceholderLocation loc = PlaceholderLocation.None; - int offsetY = PointToClient(Cursor.Position).Y - nodeOver.Bounds.Top; - - if (offsetY < (nodeOver.Bounds.Height/3) && nodeDragging.NextNode != nodeOver) - { - if (nodeOver.Parent != null) - { - ITreeNodePresenter parentNodePresenter = GetTreeViewNodePresenter(nodeOver.Parent.Tag); - if (parentNodePresenter.CanInsert(nodeDragging.Tag, nodeDragging, nodeOver)) - { - nodeDropTarget = nodeOver.Parent; - dropAtLocation = nodeOver.Parent == null ? 0 : nodeOver.Parent.Nodes.IndexOf(nodeOver); - loc = PlaceholderLocation.Top; - } - else - { - nodeDropTarget = nodeOver; - dropAtLocation = 0; - loc = PlaceholderLocation.Middle; - } - } - else - { - nodeDropTarget = nodeOver; - dropAtLocation = 0; - loc = PlaceholderLocation.Middle; - } - } - else if ((nodeOver.Parent != null) && (offsetY > nodeOver.Bounds.Height - nodeOver.Bounds.Height / 3) && - nodeDragging.PrevNode != nodeOver) - { - ITreeNodePresenter nodePresenter = GetTreeViewNodePresenter(nodeOver.Parent.Tag); - if (nodePresenter.CanInsert(nodeDragging.Tag, nodeDragging, nodeOver)) - { - nodeDropTarget = nodeOver.Parent; - dropAtLocation = nodeOver.Parent == null - ? 0 - : nodeOver.Parent.Nodes.IndexOf(nodeOver) + 1; - loc = PlaceholderLocation.Bottom; - } - else - { - nodeDropTarget = nodeOver; - dropAtLocation = 0; - loc = PlaceholderLocation.Middle; - } - } - else if (nodeDragging != nodeOver && offsetY < (nodeOver.Bounds.Height - (nodeOver.Bounds.Height/4)) - && offsetY > (nodeOver.Bounds.Height/4)) - { - nodeDropTarget = nodeOver; - dropAtLocation = 0; - loc = PlaceholderLocation.Middle; - } - - if (loc == PlaceholderLocation.None || - (loc == PlaceholderLocation.Middle && nodeDropTarget == nodeDragging.Parent)) - { - ClearPlaceHolders(); - e.Effect = DragDropEffects.None; - } - return loc; - } - - /// - /// handle scrolling - /// http://www.syncfusion.com/FAQ/windowsforms/faq_c91c.aspx - /// - /// - /// - /// - private static void ScrollIntoView(Point point, TreeNode nodeOver, object sender) - { - var treeView = sender as TreeView; - if (treeView == null) - { - return; - } - int delta = treeView.Height - point.Y; - if ((delta < treeView.Height/2) && (delta > 0)) - { - var nextVisibleNode = nodeOver.NextVisibleNode as TreeNode; - if (nextVisibleNode != null) - { - nextVisibleNode.ScrollTo(); - } - } - if ((delta > treeView.Height/2) && (delta < treeView.Height)) - { - var previousVisibleNode = nodeOver.PrevVisibleNode as TreeNode; - if (previousVisibleNode != null) - { - previousVisibleNode.ScrollTo(); - } - } - } - - /// - /// Event handler for drag drop. Inserts Node at droplocation when node is being moved - /// When node is being copied from other location Dropped should be handled externally - /// Triggers afterdrop event. - /// - /// - /// - private void TreeViewDragDrop(object sender, DragEventArgs e) - { - ClearPlaceHolders(); - Point point = PointToClient(new Point(e.X, e.Y)); - var nodeOver = GetNodeAt(point) as TreeNode; - - var nodeDragging = e.Data.GetData(typeof(TreeNode)) as TreeNode; - - if (nodeOver == null || nodeDragging == null) - { - //this handler only deals with nodes. - ClearPlaceHolders(); - - if (nodeOver != null) - { - e.Effect = DragDropEffects.All; - } - - return; - } - - if (e.Effect.Equals(DragDropEffects.Move) && nodeDragging.Parent == nodeDropTarget && - nodeOver.Index > nodeDragging.Index) - { - // src item higher up in the tree is removed. This means all indices shift by one. - if (dropAtLocation > 0) - { - dropAtLocation--; - } - } - - //dropAtLocation should never be < 0 - if (dropAtLocation < 0) - { - dropAtLocation = 0; - } - - var parentNode = nodeDragging.Parent; - - //ensure droptarget is loaded. - Trace.Assert(nodeDropTarget.Nodes != null); - - try - { - controller.OnDragDrop(nodeDragging, parentNode, nodeDropTarget, ToDragOperation(e.Effect), dropAtLocation); - } - catch (Exception ex) - { - log.Error(string.Format(Resources.TreeView_TreeViewDragDrop_Error_during_drag_drop_0_, ex.Message)); - } - } - - private void TreeViewDragLeave(object sender, EventArgs e) - { - ClearPlaceHolders(); - } - - /// - /// Indicate the dragged node can be inserted either above or below - /// another node - /// - private void DrawPlaceholder(TreeNode node, PlaceholderLocation location) - { - if (lastPlaceholderNode == node && lastPlaceholderLocation == location) - { - return; - } - - ClearPlaceHolders(); - - lastPlaceholderNode = node; - lastPlaceholderLocation = location; - - placeHolderGraphics = CreateGraphics(); - node.DrawPlaceHolder(location, CreateGraphics()); - } - - /// - /// If placeholders were drawn before, refresh the tree - /// - private void ClearPlaceHolders() - { - if (placeHolderGraphics != null) - { - lastPlaceholderNode = null; - - base.Refresh(); - placeHolderGraphics.Dispose(); - placeHolderGraphics = null; - } - } - private static class NativeInterop { - public const int WM_PRINTCLIENT = 0x0318; - public const int PRF_CLIENT = 0x00000004; + public const int WmPrintclient = 0x0318; + public const int PrfClient = 0x00000004; - public static bool IsWinXP + public static bool IsWinXp { get { - OperatingSystem OS = Environment.OSVersion; - return (OS.Platform == PlatformID.Win32NT) && - ((OS.Version.Major > 5) || ((OS.Version.Major == 5) && (OS.Version.Minor == 1))); + OperatingSystem os = Environment.OSVersion; + return (os.Platform == PlatformID.Win32NT) && + ((os.Version.Major > 5) || ((os.Version.Major == 5) && (os.Version.Minor == 1))); } } public static bool IsWinVista { get { - OperatingSystem OS = Environment.OSVersion; - return (OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6); + OperatingSystem os = Environment.OSVersion; + return (os.Platform == PlatformID.Win32NT) && (os.Version.Major >= 6); } } [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); } - private DragDropEffects ToDragDropEffects(DragOperations operation) - { - return (DragDropEffects)Enum.Parse(typeof(DragDropEffects), operation.ToString()); - } - - private DragOperations ToDragOperation(DragDropEffects dragDropEffects) - { - return (DragOperations)Enum.Parse(typeof(DragOperations), dragDropEffects.ToString()); - } - - /// - /// Event arguments to be used in the event that data has been deleted from a . - /// - public class TreeViewDataDeletedEventArgs : EventArgs - { - /// - /// Initializes a new instance of the class. - /// - /// The deleted data instance. - public TreeViewDataDeletedEventArgs(object deletedDataInstance) - { - DeletedDataInstance = deletedDataInstance; - } - - /// - /// Gets the data instance deleted from the . - /// - public object DeletedDataInstance { get; private set; } - } + # endregion } } \ No newline at end of file Index: Core/Common/src/Core.Common.Controls.TreeView/TreeViewController.cs =================================================================== diff -u -rfc0a61c81da4dcf9f436c8b8bd9c51c6b4d65ef8 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Controls.TreeView/TreeViewController.cs (.../TreeViewController.cs) (revision fc0a61c81da4dcf9f436c8b8bd9c51c6b4d65ef8) +++ Core/Common/src/Core.Common.Controls.TreeView/TreeViewController.cs (.../TreeViewController.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,28 +1,36 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Controls.TreeView.Properties; -using Core.Common.Utils.Extensions; - using log4net; +using BaseResources = Core.Common.Base.Properties.Resources; namespace Core.Common.Controls.TreeView { - public class TreeViewController + public class TreeViewController : IDisposable { - private static readonly ILog Log = LogManager.GetLogger(typeof(TreeViewController)); - private readonly TreeView treeView; - private readonly ICollection nodePresenters = new HashSet(); - - private readonly Dictionary nodeTagTypePresenters = new Dictionary(); + private readonly ICollection treeNodeInfos = new HashSet(); + private readonly Dictionary tagTypeTreeNodeInfoLookup = new Dictionary(); + private readonly int maximumTextLength = 259; + private readonly Dictionary treeNodeObserverLookup = new Dictionary(); private object data; + private int dropAtLocation; + private Point lastDragOverPoint; + private PlaceholderLocation lastPlaceholderLocation; + private TreeNode nodeDropTarget; + private TreeNode lastPlaceholderNode; + private Graphics placeHolderGraphics; - private bool updatingExpandedState; // prevents recursive entries - private TreeNode expandedStateRootNode; - private string[] expandedNodePaths; + private static readonly ILog Log = LogManager.GetLogger(typeof(TreeViewController)); + public event EventHandler TreeNodeDoubleClick; + public event EventHandler NodeUpdated; // TODO; Way to explicit! + public event EventHandler NodeDataDeleted; // TODO; Way to explicit! + public TreeViewController(TreeView treeView) { if (treeView == null) @@ -31,21 +39,28 @@ } this.treeView = treeView; - } - /// - /// List of registered node presenters - /// - public IEnumerable NodePresenters - { - get + // Ensure tree nodes are correctly aligned + treeView.ImageList = new ImageList { - return nodePresenters; - } + ColorDepth = ColorDepth.Depth32Bit + }; + + treeView.BeforeLabelEdit += TreeViewBeforeLabelEdit; + treeView.AfterLabelEdit += TreeViewAfterLabelEdit; + treeView.AfterCheck += TreeViewAfterCheck; + treeView.KeyDown += TreeViewKeyDown; + treeView.MouseClick += TreeViewMouseClick; + treeView.DoubleClick += TreeViewDoubleClick; + treeView.DragDrop += TreeViewDragDrop; + treeView.DragOver += TreeViewDragOver; + treeView.ItemDrag += TreeViewItemDrag; + treeView.DragLeave += TreeViewDragLeave; + treeView.DrawNode += TreeViewDrawNode; } /// - /// Data to render in the tree view + /// Gets or sets the data to render in the tree view. /// public object Data { @@ -55,370 +70,792 @@ } set { - treeView.Nodes.Clear(); + RemoveAllNodes(); + data = value; if (data == null) { return; } - CreateRootNode(); + AddRootNode(); treeView.SelectedNode = treeView.Nodes.Count > 0 ? treeView.Nodes[0] : null; } } - /// - /// Registers the node presenter. - /// - /// The presenter. - public void RegisterNodePresenter(ITreeNodePresenter presenter) + public IEnumerable TreeNodeInfos { - nodePresenters.Add(presenter); - presenter.TreeView = treeView; + get + { + return treeNodeInfos; + } } /// - /// Gets the most specific node presenter for a piece of data. Does so by walking up the class hierarchy and trying to find an exact match - /// It is in the helper to allow heavy testing since this is complex logic. + /// This method registers the provided . /// - /// Object to search a node presenter for - public ITreeNodePresenter ResolveNodePresenterForData(object item) + /// The to register. + public void RegisterTreeNodeInfo(TreeNodeInfo treeNodeInfo) { - //try to find a match on the exact type - if (item == null) + treeNodeInfos.Add(treeNodeInfo); + tagTypeTreeNodeInfoLookup[treeNodeInfo.TagType] = treeNodeInfo; + } + + public void DeleteNode(TreeNode selectedNode, TreeNodeInfo treeNodeInfo) + { + var message = string.Format(Resources.TreeView_DeleteNodeData_Are_you_sure_you_want_to_delete_the_following_item_0_, selectedNode.Text); + if (MessageBox.Show(message, BaseResources.Confirm, MessageBoxButtons.OKCancel) != DialogResult.OK) { - return null; + return; } - ITreeNodePresenter presenter; + if (treeNodeInfo.OnNodeRemoved != null) + { + treeNodeInfo.OnNodeRemoved(selectedNode.Tag, selectedNode.Parent != null ? selectedNode.Parent.Tag : null); + } - // try to get presenter from the cache - var type = item.GetType(); - nodeTagTypePresenters.TryGetValue(type, out presenter); + OnNodeDataDeleted(selectedNode); + } - // resolve presenter for type - if (presenter == null) + public void CollapseAll(TreeNode node) + { + node.Collapse(); + + foreach (var childNode in node.Nodes.OfType()) { - presenter = GetNodePresenterForType(type) ?? - nodePresenters.FirstOrDefault(np => np.NodeTagType.IsInstanceOfType(item)); + CollapseAll(childNode); + } + } - nodeTagTypePresenters[type] = presenter; + public void ExpandAll(TreeNode node) + { + node.Expand(); + + foreach (var childNode in node.Nodes.OfType()) + { + ExpandAll(childNode); } + } - return presenter; + /// + /// This method searches all nodes in the for a node with a matching tag. + /// + /// The node data to search the corresponding for. + /// The corresponding the provided node data or null if not found. + public TreeNode GetNodeByTag(object nodeData) + { + return treeView.Nodes.Count > 0 ? GetNodeByTag(treeView.Nodes[0], nodeData) : null; } + private static TreeNode GetNodeByTag(TreeNode rootNode, object tag) + { + if (Equals(rootNode.Tag, tag)) + { + return rootNode; + } + + return rootNode.Nodes + .OfType() + .Select(n => GetNodeByTag(n, tag)) + .FirstOrDefault(node => node != null); + } + /// - /// Action to perform when the node is checked/unchecked + /// This method updates the provided . /// - /// Node that is checked/unchecked - public void OnNodeChecked(TreeNode node) + /// The to update. + /// Thrown when no corresponding can be found for the provided . + private void UpdateNode(TreeNode treeNode) { - if (node.IsUpdating) + var treeNodeInfo = GetTreeNodeInfoForData(treeNode.Tag); + if (treeNodeInfo == null) { - return; + throw new InvalidOperationException("No tree node info registered"); } - if (node.Tag == null) + // First of all refresh the child nodes as the other logic below might depend on the presence of child nodes + RefreshChildNodes(treeNode, treeNodeInfo); + + if (treeNodeInfo.Text != null) { - throw new InvalidOperationException(Resources.TreeView_Error_Unable_to_resolve_node_presenter_for_null_data); + var text = treeNodeInfo.Text(treeNode.Tag); + + // Having very big strings causes rendering problems in the tree view + treeNode.Text = text.Length > maximumTextLength + ? text.Substring(0, maximumTextLength) + : text; } + else + { + treeNode.Text = ""; + } - node.Presenter.OnNodeChecked(node); + treeNode.ForeColor = treeNodeInfo.ForeColor != null + ? treeNodeInfo.ForeColor(treeNode.Tag) + : Color.FromKnownColor(KnownColor.ControlText); + + if (treeNodeInfo.CanCheck != null && treeNodeInfo.CanCheck(treeNode.Tag) + && treeNodeInfo.IsChecked != null && treeNode.Checked != treeNodeInfo.IsChecked(treeNode.Tag)) + { + treeView.AfterCheck -= TreeViewAfterCheck; + treeNode.Checked = !treeNode.Checked; + treeView.AfterCheck += TreeViewAfterCheck; + } + + OnNodeUpdated(treeNode); } - public void UpdateNode(TreeNode treeNode) + private void AddRootNode() { - UpdateNode(treeNode, treeNode.Tag); + var rootNode = new TreeNode + { + Tag = data + }; + + UpdateNode(rootNode); + + if (rootNode.Nodes.Count > 0) + { + rootNode.Expand(); + } + + treeView.Nodes.Add(rootNode); + + treeNodeObserverLookup.Add(rootNode, new TreeNodeObserver(rootNode, this)); } - /// - /// Updates the node and if loaded the sub nodes - /// - /// Node to update - /// the object bound to this node - public void UpdateNode(TreeNode treeNode, object tag) + private void AddNode(TreeNode parentNode, object nodeData, int insertionIndex = -1) { - var treeViewControl = treeView as Control; - if (treeViewControl != null && treeViewControl.InvokeRequired) + var newNode = new TreeNode { - UpdateNodeInvokeDelegate updateNode = UpdateNode; - treeViewControl.Invoke(updateNode, treeNode, tag); + Tag = nodeData + }; + + if (treeView.CheckBoxes) + { + newNode.Checked = parentNode.Checked; } + + UpdateNode(newNode); + + if (insertionIndex != -1) + { + parentNode.Nodes.Insert(insertionIndex, newNode); + } else { - treeView.BeginUpdate(); - try - { - var nodePresenter = treeNode.Presenter; + parentNode.Nodes.Add(newNode); + } - if (nodePresenter == null) - { - Log.Debug(string.Format(Resources.TreeViewController_UpdateNode_Can_t_find_INodePresenter_for_0_make_sure_you_added_it_to_Presenters_collection_of_a_TreeView, tag)); - return; - } + treeNodeObserverLookup.Add(newNode, new TreeNodeObserver(newNode, this)); + } - if (!ReferenceEquals(treeNode.Tag, tag)) - { - treeNode.Tag = tag; - treeNode.Presenter = ResolveNodePresenterForData(tag); - nodePresenter = treeNode.Presenter; - } + private void RemoveAllNodes() + { + foreach (var treeNode in treeNodeObserverLookup.Keys) + { + treeNodeObserverLookup[treeNode].Dispose(); + } - nodePresenter.UpdateNode(treeNode.Parent, treeNode, treeNode.Tag); + treeNodeObserverLookup.Clear(); + treeView.Nodes.Clear(); + } - var childNodeObjects = GetChildNodeObjects(treeNode).ToArray(); - var count = childNodeObjects.Length; + private void RemoveTreeNodeFromLookupRecursively(TreeNode treeNode) + { + treeNodeObserverLookup[treeNode].Dispose(); + treeNodeObserverLookup.Remove(treeNode); - treeNode.HasChildren = count > 0; - - if (treeNode.Nodes.Count != count) - { - RefreshChildNodes(treeNode); - } - else - { - //update existing nodes - for (var i = 0; i < treeNode.Nodes.Count; i++) - { - UpdateNode(treeNode.Nodes[i], childNodeObjects[i]); - } - } - } - finally - { - treeView.EndUpdate(); - } + foreach (var childNode in treeNode.Nodes.OfType()) + { + RemoveTreeNodeFromLookupRecursively(childNode); } } /// - /// Refreshes the sub nodes of the treeNode + /// This method tries to return a object corresponding to the provided data. /// - /// Node for which to refresh the children - /// If the tree node is loaded - public void RefreshChildNodes(TreeNode treeNode) + /// The data to find the corresponding for. + /// The for the provided data or null if no corresponding was found. + private TreeNodeInfo GetTreeNodeInfoForData(object item) { - RememberExpandedState(treeNode); - - try + if (item == null) { - treeNode.Nodes.Clear(); + return null; + } - var nodePresenter = treeNode.Presenter; - if (nodePresenter == null) - { - return; - } + TreeNodeInfo treeNodeInfo; - var childNodeObjects = nodePresenter.GetChildNodeObjects(treeNode.Tag); - if (childNodeObjects == null) + // Try to find an exact match + tagTypeTreeNodeInfoLookup.TryGetValue(item.GetType(), out treeNodeInfo); + + // Try to match based on class hierarchy + return treeNodeInfo ?? tagTypeTreeNodeInfoLookup.FirstOrDefault(kvp => kvp.Key.IsInstanceOfType(item)).Value; + } + + private void RefreshChildNodes(TreeNode treeNode, TreeNodeInfo treeNodeInfo) + { + var currentTreeNodes = treeNode.Nodes.OfType().ToList(); + var currentTreeNodesPerTag = currentTreeNodes.ToDictionary(ctn => ctn.Tag, ctn => ctn); + var newChildNodeObjects = treeNodeInfo.ChildNodeObjects != null + ? treeNodeInfo.ChildNodeObjects(treeNode.Tag) + : new object[0]; + + treeNode.Nodes.Clear(); + + foreach (var newChildNodeObject in newChildNodeObjects) + { + // Try to recycle any exiting node + if (currentTreeNodesPerTag.ContainsKey(newChildNodeObject)) { - return; - } + var existingNode = currentTreeNodesPerTag[newChildNodeObject]; - foreach (object o in childNodeObjects) + treeNode.Nodes.Add(existingNode); + currentTreeNodes.Remove(existingNode); + } + else { - AddNewNode(treeNode, o); + // Create a new one otherwise + AddNode(treeNode, newChildNodeObject); } } - finally + + foreach (var removedNode in currentTreeNodes) { - RestoreExpandedState(treeNode); + RemoveTreeNodeFromLookupRecursively(removedNode); } } - private void AddNewNode(TreeNode parentNode, object nodeData, int insertionIndex = -1) - { - var newNode = treeView.NewNode(); + # region TreeView event handling - if (treeView.CheckBoxes) + private void TreeViewBeforeLabelEdit(object sender, NodeLabelEditEventArgs e) + { + var treeNodeInfo = GetTreeNodeInfoForData(e.Node.Tag); + if (treeNodeInfo.CanRename == null || !treeNodeInfo.CanRename(e.Node)) { - newNode.Checked = parentNode.Checked; + e.CancelEdit = true; } + } - UpdateNode(parentNode, newNode, nodeData); - - if (insertionIndex != -1) + private void TreeViewAfterLabelEdit(object sender, NodeLabelEditEventArgs e) + { + // Check Label for null as this indicates the node edit was cancelled + if (e.Label == null) { - parentNode.Nodes.Insert(insertionIndex, newNode); + return; } - else + + var treeNodeInfo = GetTreeNodeInfoForData(e.Node.Tag); + if (treeNodeInfo.OnNodeRenamed != null) { - parentNode.Nodes.Add(newNode); + treeNodeInfo.OnNodeRenamed(e.Node.Tag, e.Label); } - - newNode.HasChildren = HasChildren(newNode); } - /// - /// Checks if the label of the treeNode can be changed - /// - /// Node to check for - public bool CanRenameNode(TreeNode node) + private void TreeViewAfterCheck(object sender, TreeViewEventArgs e) { - return AskNodePresenter(node, np => np.CanRenameNode(node), false); + var treeNodeInfo = GetTreeNodeInfoForData(e.Node.Tag); + if (treeNodeInfo.OnNodeChecked != null) + { + treeNodeInfo.OnNodeChecked(e.Node); + } } - /// - /// Checks if the provided node can be deleted - /// - /// Node to check - public bool CanDeleteNode(TreeNode node) + private void TreeViewKeyDown(object sender, KeyEventArgs keyEventArgs) { - return AskNodePresenter(node, np => + var selectedNode = treeView.SelectedNode; + if (selectedNode == null) { - var parentNodeData = node.Parent != null ? node.Parent.Tag : null; - return np.CanRemove(parentNodeData, node.Tag); - }, false); + return; + } + + switch (keyEventArgs.KeyData) + { + case Keys.F5: // Refresh the selected node in the tree view + { + if (treeView.SelectedNode != null) + { + UpdateNode(treeView.SelectedNode); + } + break; + } + case Keys.F2: // Start editing the label of the selected node + { + selectedNode.BeginEdit(); + break; + } + case Keys.Apps: // If implemented, show the context menu of the selected node + { + var treeNodeInfo = GetTreeNodeInfoForData(selectedNode.Tag); + + // Update the context menu (relevant in case of keyboard navigation in the tree view) + selectedNode.ContextMenuStrip = treeNodeInfo.ContextMenuStrip != null + ? treeNodeInfo.ContextMenuStrip(selectedNode.Tag, selectedNode, treeNodeInfo) + : null; + + if (treeView.ContextMenu != null && selectedNode.ContextMenuStrip != null) + { + var location = selectedNode.Bounds.Location; + location.Offset(0, selectedNode.Bounds.Height); + + selectedNode.ContextMenuStrip.Show(location); + } + break; + } + case Keys.Enter: // Perform the same action as on double click + { + OnTreeNodeDoubleClick(); + + break; + } + case Keys.Delete: // If allowed, delete the selected node + { + var treeNodeInfo = GetTreeNodeInfoForData(selectedNode.Tag); + + if (treeNodeInfo.CanRemove == null || !treeNodeInfo.CanRemove(selectedNode.Tag, selectedNode.Parent != null ? selectedNode.Parent.Tag : null)) + { + MessageBox.Show(Resources.TreeView_DeleteNodeData_The_selected_item_cannot_be_removed, BaseResources.Confirm, MessageBoxButtons.OK); + break; + } + + DeleteNode(selectedNode, treeNodeInfo); + + break; + } + case Keys.Space: // If applicable, change the checked state of the selected node + { + var treeNodeInfo = GetTreeNodeInfoForData(selectedNode.Tag); + if (treeNodeInfo.CanCheck != null && treeNodeInfo.CanCheck(selectedNode.Tag)) + { + selectedNode.Checked = !selectedNode.Checked; + } + + break; + } + } + + if (keyEventArgs.KeyData == (Keys.Control | Keys.Shift | Keys.Right)) // Expand all tree nodes + { + ExpandAll(selectedNode); + selectedNode.EnsureVisible(); + } + + if (keyEventArgs.KeyData == (Keys.Control | Keys.Shift | Keys.Left)) // Collapse all tree nodes + { + CollapseAll(selectedNode); + selectedNode.EnsureVisible(); + } } - public void OnDragDrop(TreeNode nodeDragging, TreeNode parentNode, TreeNode nodeDropTarget, DragOperations dragOperation, int dropAtLocation) + private void TreeViewMouseClick(object sender, MouseEventArgs e) { - var nodePresenter = nodeDropTarget.Presenter; - if (nodePresenter == null) + var point = treeView.PointToClient(Cursor.Position); + var clickedNode = treeView.GetNodeAt(point); + if (clickedNode == null) { return; } - nodePresenter.OnDragDrop(nodeDragging.Tag, parentNode.Tag, nodeDropTarget.Tag, dragOperation, dropAtLocation); + treeView.SelectedNode = clickedNode; + + var treeNodeInfo = GetTreeNodeInfoForData(clickedNode.Tag); + + // Update the context menu + clickedNode.ContextMenuStrip = treeNodeInfo.ContextMenuStrip != null + ? treeNodeInfo.ContextMenuStrip(clickedNode.Tag, clickedNode, treeNodeInfo) + : null; + + if (treeNodeInfo.CanCheck != null && treeNodeInfo.CanCheck(clickedNode.Tag) && clickedNode.IsOnCheckBox(point)) + { + clickedNode.Checked = !clickedNode.Checked; + } } - public void OnTreeViewHandleCreated() + private void TreeViewDoubleClick(object sender, EventArgs e) { - treeView.Refresh(); // Ensure the treeview is always up to date after creating handle (data is set and might be changed before enabling the delayed event handlers) + OnTreeNodeDoubleClick(); } - private IEnumerable GetAllChildNodes(TreeNode node) + private void OnTreeNodeDoubleClick() { - foreach (var childNode in node.Nodes) + if (TreeNodeDoubleClick != null) { - yield return childNode; + TreeNodeDoubleClick(treeView.SelectedNode, EventArgs.Empty); + } + } - foreach (var childChildNode in GetAllChildNodes(childNode)) + private void TreeViewDragDrop(object sender, DragEventArgs e) + { + ClearPlaceHolders(); + + Point point = treeView.PointToClient(new Point(e.X, e.Y)); + var nodeOver = treeView.GetNodeAt(point); + + var nodeDragging = e.Data.GetData(typeof(TreeNode)) as TreeNode; + + if (nodeOver == null || nodeDragging == null) + { + if (nodeOver != null) { - yield return childChildNode; + e.Effect = DragDropEffects.All; } + + return; } + + // Handle dragged items which were originally higher up in the tree under the same parent (all indices shift by one) + if (e.Effect.Equals(DragDropEffects.Move) && nodeDragging.Parent == nodeDropTarget && nodeOver.Index > nodeDragging.Index) + { + if (dropAtLocation > 0) + { + dropAtLocation--; + } + } + + // Ensure the drop location is never < 0 + if (dropAtLocation < 0) + { + dropAtLocation = 0; + } + + var treeNodeInfo = GetTreeNodeInfoForData(nodeDropTarget.Tag); + + try + { + if (treeNodeInfo.OnDrop != null) + { + treeNodeInfo.OnDrop(nodeDragging, nodeDropTarget, ToDragOperation(e.Effect), dropAtLocation); + } + } + catch (Exception ex) + { + Log.Error(string.Format(Resources.TreeView_TreeViewDragDrop_Error_during_drag_drop_0_, ex.Message)); + } } - private void RememberExpandedState(TreeNode node) + private void TreeViewDragOver(object sender, DragEventArgs e) { - if (updatingExpandedState) + if (lastDragOverPoint.X == e.X && lastDragOverPoint.Y == e.Y) { return; } - updatingExpandedState = true; + lastDragOverPoint = new Point(e.X, e.Y); - // we need to remember all loaded nodes since after clear / build we have no idea anymore which nodes were loaded - expandedNodePaths = GetAllChildNodes(node).Where(n => n.IsExpanded).Select(n => n.FullPath).ToArray(); - expandedStateRootNode = node; + var point = treeView.PointToClient(lastDragOverPoint); + var nodeOver = treeView.GetNodeAt(point); + var nodeDragging = e.Data.GetData(typeof(TreeNode)) as TreeNode; + + if (nodeOver == null || nodeDragging == null || nodeOver == nodeDragging || IsChildOf(nodeOver, nodeDragging)) + { + ClearPlaceHolders(); + + return; + } + + ScrollIntoView(point, nodeOver, sender); + + PlaceholderLocation placeholderLocation = GetPlaceHoldersLocation(nodeDragging, nodeOver, e); + + if (null == nodeDropTarget) + { + return; + } + + var treeNodeInfo = GetTreeNodeInfoForData(nodeDropTarget.Tag); + + DragOperations allowedOperations = treeNodeInfo.CanDrop != null + ? treeNodeInfo.CanDrop(nodeDragging, nodeDropTarget, ToDragOperation(e.AllowedEffect)) + : DragOperations.None; + + e.Effect = ToDragDropEffects(allowedOperations); + + if (PlaceholderLocation.None == placeholderLocation) + { + return; + } + + // Determine whether ot not the node can be dropped based on the allowed operations. + // A node can also be a valid drop traget if it is the root item (nodeDragging.Parent == null). + var dragOperations = treeNodeInfo.CanDrop != null + ? treeNodeInfo.CanDrop(nodeDragging, nodeDropTarget, allowedOperations) + : DragOperations.None; + + if (DragOperations.None != dragOperations) + { + DrawPlaceholder(nodeOver, placeholderLocation); + } + else + { + ClearPlaceHolders(); + + e.Effect = DragDropEffects.None; + } } - private void RestoreExpandedState(TreeNode node) + private void TreeViewItemDrag(object sender, ItemDragEventArgs e) { - if (!updatingExpandedState || node != expandedStateRootNode) + // gather allowed effects for the current item. + var sourceNode = (TreeNode)e.Item; + var treeNodeInfo = GetTreeNodeInfoForData(sourceNode.Tag); + + DragOperations dragOperation = treeNodeInfo.CanDrag != null + ? treeNodeInfo.CanDrag(sourceNode.Tag, sourceNode) + : DragOperations.None; + + DragDropEffects effects = ToDragDropEffects(dragOperation); + + if (effects == DragDropEffects.None) { return; } - GetAllChildNodes(node).Where(n => expandedNodePaths.Contains(n.FullPath)).ToArray().ForEachElementDo(n => n.Expand()); - expandedStateRootNode = null; - updatingExpandedState = false; + // store both treenode and tag of treenode in dataobject + // to be dragged. + IDataObject dataObject = new DataObject(); + dataObject.SetData(typeof(TreeNode), sourceNode); + + if (sourceNode.Tag != null) + { + dataObject.SetData(sourceNode.Tag.GetType(), sourceNode.Tag); + } + + treeView.DoDragDrop(dataObject, effects); } - private bool HasChildren(TreeNode treeNode) + private void TreeViewDragLeave(object sender, EventArgs e) { - return GetChildNodeObjects(treeNode).Any(); + ClearPlaceHolders(); } - private IEnumerable GetChildNodeObjects(TreeNode treeNode) + private void TreeViewDrawNode(object sender, DrawTreeNodeEventArgs e) { - return (AskNodePresenter(treeNode, p => p.GetChildNodeObjects(treeNode.Tag), null) ?? - new object[0]).OfType(); + e.DrawDefault = false; + + var selected = (e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected; + + e.Node.DrawNode(GetTreeNodeInfoForData(e.Node.Tag), e.Graphics, selected); } - private T AskNodePresenter(TreeNode node, Func nodePresenterFunction, T defaultValue) + private void DrawPlaceholder(TreeNode node, PlaceholderLocation location) { - if (node == null || node.Tag == null) + if (lastPlaceholderNode == node && lastPlaceholderLocation == location) { - return defaultValue; + return; } - var nodePresenter = node.Presenter; - if (nodePresenter == null) + ClearPlaceHolders(); + + lastPlaceholderNode = node; + lastPlaceholderLocation = location; + + placeHolderGraphics = treeView.CreateGraphics(); + node.DrawPlaceHolder(location, treeView.CreateGraphics()); + } + + private void ClearPlaceHolders() + { + if (placeHolderGraphics != null) { - return defaultValue; + lastPlaceholderNode = null; + + treeView.Refresh(); + + placeHolderGraphics.Dispose(); + placeHolderGraphics = null; } + } - return nodePresenterFunction(nodePresenter); + private DragOperations ToDragOperation(DragDropEffects dragDropEffects) + { + return (DragOperations) Enum.Parse(typeof(DragOperations), dragDropEffects.ToString()); } - private void CreateRootNode() + private bool IsChildOf(TreeNode childNode, TreeNode node) { - var rootNode = new TreeNode(treeView) + while (childNode != null && childNode.Parent != null) { - Tag = data - }; + if (childNode.Parent.Equals(node)) + { + return true; + } - UpdateNode(null, rootNode, data); + childNode = childNode.Parent; // Walk up the tree + } - treeView.Nodes.Add(rootNode); + return false; + } - if (HasChildren(rootNode)) + private static void ScrollIntoView(Point point, TreeNode nodeOver, object sender) + { + var treeView = sender as TreeView; + if (treeView == null) { - rootNode.HasChildren = true; - rootNode.Expand(); + return; } + int delta = treeView.Height - point.Y; + if ((delta < treeView.Height / 2) && (delta > 0)) + { + var nextVisibleNode = nodeOver.NextVisibleNode; + if (nextVisibleNode != null) + { + nextVisibleNode.EnsureVisible(); + } + } + if ((delta > treeView.Height / 2) && (delta < treeView.Height)) + { + var previousVisibleNode = nodeOver.PrevVisibleNode; + if (previousVisibleNode != null) + { + previousVisibleNode.EnsureVisible(); + } + } } - private ITreeNodePresenter GetNodePresenterForType(Type type) + private PlaceholderLocation GetPlaceHoldersLocation(TreeNode nodeDragging, TreeNode nodeOver, DragEventArgs e) { - var nodePresentersForType = nodePresenters.Where(p => p.NodeTagType == type).ToList(); + var loc = PlaceholderLocation.None; + int offsetY = treeView.PointToClient(Cursor.Position).Y - nodeOver.Bounds.Top; - if (!nodePresentersForType.Any() && type.BaseType != null) + if (offsetY < nodeOver.Bounds.Height / 3 && nodeDragging.NextNode != nodeOver) { - // Walk up the class hierarchy... ignore interfaces - return GetNodePresenterForType(type.BaseType); + if (nodeOver.Parent != null) + { + var treeNodeInfo = GetTreeNodeInfoForData(nodeOver.Parent.Tag); + if (treeNodeInfo.CanInsert != null && treeNodeInfo.CanInsert(nodeDragging, nodeOver)) + { + nodeDropTarget = nodeOver.Parent; + dropAtLocation = nodeOver.Parent == null ? 0 : nodeOver.Parent.Nodes.IndexOf(nodeOver); + loc = PlaceholderLocation.Top; + } + else + { + nodeDropTarget = nodeOver; + dropAtLocation = 0; + loc = PlaceholderLocation.Middle; + } + } + else + { + nodeDropTarget = nodeOver; + dropAtLocation = 0; + loc = PlaceholderLocation.Middle; + } } + else if ((nodeOver.Parent != null) && (offsetY > nodeOver.Bounds.Height - nodeOver.Bounds.Height / 3) && + nodeDragging.PrevNode != nodeOver) + { + var treeNodeInfo = GetTreeNodeInfoForData(nodeOver.Parent.Tag); + if (treeNodeInfo.CanInsert != null && treeNodeInfo.CanInsert(nodeDragging, nodeOver)) + { + nodeDropTarget = nodeOver.Parent; + dropAtLocation = nodeOver.Parent == null + ? 0 + : nodeOver.Parent.Nodes.IndexOf(nodeOver) + 1; + loc = PlaceholderLocation.Bottom; + } + else + { + nodeDropTarget = nodeOver; + dropAtLocation = 0; + loc = PlaceholderLocation.Middle; + } + } + else if (nodeDragging != nodeOver && offsetY < nodeOver.Bounds.Height - nodeOver.Bounds.Height / 4 + && offsetY > nodeOver.Bounds.Height / 4) + { + nodeDropTarget = nodeOver; + dropAtLocation = 0; + loc = PlaceholderLocation.Middle; + } - // filter base node presenter types - var types = nodePresentersForType.Select(np => np.GetType()).ToList(); - var nodePresenterType = types.Except(types.Where(bt => types.Any(t => t.IsSubclassOf(bt)))).FirstOrDefault(); + if (loc == PlaceholderLocation.None || + (loc == PlaceholderLocation.Middle && nodeDropTarget == nodeDragging.Parent)) + { + ClearPlaceHolders(); + e.Effect = DragDropEffects.None; + } + return loc; + } - return nodePresenterType != null - ? nodePresentersForType.FirstOrDefault(p => p.GetType() == nodePresenterType) - : null; + private DragDropEffects ToDragDropEffects(DragOperations operation) + { + return (DragDropEffects) Enum.Parse(typeof(DragDropEffects), operation.ToString()); } - private void UpdateNode(TreeNode parentNode, TreeNode node, object nodeData) + # endregion + + # region Event handling + + private void OnNodeUpdated(TreeNode treeNode) { - var presenter = node.Presenter; + if (NodeUpdated != null) + { + NodeUpdated(treeNode, EventArgs.Empty); + } + } - if (presenter == null) + private void OnNodeDataDeleted(TreeNode node) + { + if (NodeDataDeleted != null) { - presenter = ResolveNodePresenterForData(nodeData); - node.Presenter = presenter; + NodeDataDeleted(this, new TreeNodeDataDeletedEventArgs(node.Tag)); } + } - if (presenter == null) + # endregion + + # region Nested types + + private class TreeNodeObserver : IDisposable, IObserver + { + private readonly TreeNode treeNode; + private readonly TreeViewController controller; + + public TreeNodeObserver(TreeNode treeNode, TreeViewController controller) { - var message = String.Format(Resources.TreeViewController_UpdateNode_Can_t_find_INodePresenter_for_0_make_sure_you_added_it_to_Presenters_collection_of_a_TreeView, nodeData); + this.treeNode = treeNode; + this.controller = controller; - throw new ArgumentException(message); + var observable = treeNode.Tag as IObservable; + if (observable != null) + { + observable.Attach(this); + } } - node.Tag = nodeData; - presenter.UpdateNode(parentNode, node, nodeData); - RefreshChildNodes(node); + public void Dispose() + { + var observable = treeNode.Tag as IObservable; + if (observable != null) + { + observable.Detach(this); + } + } + + public void UpdateObserver() + { + controller.UpdateNode(treeNode); + } } - /// - /// Delegate required to perform asynchronous calls to . - /// - delegate void UpdateNodeInvokeDelegate(TreeNode treeNode, object tag); + # endregion + + public void Dispose() + { + treeView.BeforeLabelEdit -= TreeViewBeforeLabelEdit; + treeView.AfterLabelEdit -= TreeViewAfterLabelEdit; + treeView.AfterCheck -= TreeViewAfterCheck; + treeView.KeyDown -= TreeViewKeyDown; + treeView.MouseClick -= TreeViewMouseClick; + treeView.DoubleClick -= TreeNodeDoubleClick; + treeView.DragDrop -= TreeViewDragDrop; + treeView.DragOver -= TreeViewDragOver; + treeView.ItemDrag -= TreeViewItemDrag; + treeView.DragLeave -= TreeViewDragLeave; + treeView.DrawNode -= TreeViewDrawNode; + } } } \ No newline at end of file Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Controls.TreeView/TreeViewNodePresenterBase.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs =================================================================== diff -u -re96306bc32984aa50c6d1162167214024ddcf59a -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs (.../ContextMenuBuilder.cs) (revision e96306bc32984aa50c6d1162167214024ddcf59a) +++ Core/Common/src/Core.Common.Gui/ContextMenu/ContextMenuBuilder.cs (.../ContextMenuBuilder.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,7 +1,7 @@ using System; using System.Windows.Forms; +using Core.Common.Controls.TreeView; using Core.Common.Gui.Properties; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; namespace Core.Common.Gui.ContextMenu { @@ -29,15 +29,16 @@ /// The from which /// to obtain information to render and bind actions to the items of the . /// If null, this builder will not render items which require this type of information. - /// The for which to create a . + /// The for which to create a . + /// The to use while creating the . /// Thrown when the required object instances could not be created based on /// the or . - public ContextMenuBuilder(IApplicationFeatureCommands featureCommandHandler, IExportImportCommandHandler importExportHandler, IViewCommands viewsCommandsHandler, TreeNode treeNode) + public ContextMenuBuilder(IApplicationFeatureCommands featureCommandHandler, IExportImportCommandHandler importExportHandler, IViewCommands viewsCommandsHandler, TreeNode treeNode, TreeNodeInfo treeNodeInfo) { try { guiItemsFactory = new GuiContextMenuItemFactory(featureCommandHandler, importExportHandler, viewsCommandsHandler, treeNode); - treeViewItemsFactory = new TreeViewContextMenuItemFactory(treeNode); + treeViewItemsFactory = new TreeViewContextMenuItemFactory(treeNode, treeNodeInfo); } catch (ArgumentNullException e) { Index: Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs =================================================================== diff -u -re96306bc32984aa50c6d1162167214024ddcf59a -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision e96306bc32984aa50c6d1162167214024ddcf59a) +++ Core/Common/src/Core.Common.Gui/ContextMenu/GuiContextMenuItemFactory.cs (.../GuiContextMenuItemFactory.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,7 +1,6 @@ using System; using System.Windows.Forms; using Core.Common.Gui.Properties; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; namespace Core.Common.Gui.ContextMenu { Index: Core/Common/src/Core.Common.Gui/ContextMenu/IContextMenuBuilder.cs =================================================================== diff -u -re96306bc32984aa50c6d1162167214024ddcf59a -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/ContextMenu/IContextMenuBuilder.cs (.../IContextMenuBuilder.cs) (revision e96306bc32984aa50c6d1162167214024ddcf59a) +++ Core/Common/src/Core.Common.Gui/ContextMenu/IContextMenuBuilder.cs (.../IContextMenuBuilder.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -10,52 +10,52 @@ { /// - /// Adds an item to the , which starts edit mode for the name of . + /// Adds an item to the , which starts edit mode for the name of . /// /// The itself. IContextMenuBuilder AddRenameItem(); /// - /// Adds an item to the , which deletes the . + /// Adds an item to the , which deletes the . /// /// The itself. IContextMenuBuilder AddDeleteItem(); /// - /// Adds an item to the , which expands the . + /// Adds an item to the , which expands the . /// /// The itself. IContextMenuBuilder AddExpandAllItem(); /// - /// Adds an item to the , which collapses the . + /// Adds an item to the , which collapses the . /// /// The itself. IContextMenuBuilder AddCollapseAllItem(); /// - /// Adds an item to the , which opens a view for the data of the . + /// Adds an item to the , which opens a view for the data of the . /// /// The itself. /// Thrown when the was not passed on construction. IContextMenuBuilder AddOpenItem(); /// - /// Adds an item to the , which exports the data of the . + /// Adds an item to the , which exports the data of the . /// /// The itself. /// Thrown when the was not passed on construction. IContextMenuBuilder AddExportItem(); /// - /// Adds an item to the , which imports the data of the . + /// Adds an item to the , which imports the data of the . /// /// The itself. /// Thrown when the was not passed on construction. IContextMenuBuilder AddImportItem(); /// - /// Adds an item to the , which shows properties of the data of the . + /// Adds an item to the , which shows properties of the data of the . /// /// The itself. /// Thrown when the was not passed on construction. Index: Core/Common/src/Core.Common.Gui/ContextMenu/TreeViewContextMenuItemFactory.cs =================================================================== diff -u -r0a3a0d3226ece309a818f677ce409de660b88f0b -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/ContextMenu/TreeViewContextMenuItemFactory.cs (.../TreeViewContextMenuItemFactory.cs) (revision 0a3a0d3226ece309a818f677ce409de660b88f0b) +++ Core/Common/src/Core.Common.Gui/ContextMenu/TreeViewContextMenuItemFactory.cs (.../TreeViewContextMenuItemFactory.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,9 +1,8 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Windows.Forms; +using Core.Common.Controls.TreeView; using Core.Common.Gui.Properties; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; namespace Core.Common.Gui.ContextMenu { @@ -15,19 +14,28 @@ internal class TreeViewContextMenuItemFactory { private readonly TreeNode treeNode; + private readonly TreeNodeInfo treeNodeInfo; /// /// Creates a new instance of for the given . /// - /// The for which to create . + /// The for which to create the objects. + /// The to use while creating the objects. /// Thrown when is null. - public TreeViewContextMenuItemFactory(TreeNode treeNode) + public TreeViewContextMenuItemFactory(TreeNode treeNode, TreeNodeInfo treeNodeInfo) { if (treeNode == null) { throw new ArgumentNullException("treeNode", Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node); } + + if (treeNodeInfo == null) + { + throw new ArgumentNullException("treeNodeInfo", Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node_info); + } + this.treeNode = treeNode; + this.treeNodeInfo = treeNodeInfo; } /// @@ -41,9 +49,9 @@ { ToolTipText = Resources.Rename_ToolTip, Image = Resources.RenameIcon, - Enabled = treeNode.Presenter.CanRenameNode(treeNode) + Enabled = treeNodeInfo.CanRename != null && treeNodeInfo.CanRename(treeNode) }; - toolStripMenuItem.Click += (s, e) => treeNode.TreeView.StartLabelEdit(treeNode); + toolStripMenuItem.Click += (s, e) => treeNode.BeginEdit(); return toolStripMenuItem; } @@ -58,9 +66,9 @@ { ToolTipText = Resources.Delete_ToolTip, Image = Resources.DeleteIcon, - Enabled = treeNode.Presenter.CanRemove(treeNode.Parent.Tag, treeNode.Tag) + Enabled = treeNodeInfo.CanRemove != null && treeNodeInfo.CanRemove(treeNode.Tag, treeNode.Parent != null ? treeNode.Parent.Tag : null) }; - toolStripMenuItem.Click += (s, e) => treeNode.TreeView.TryDeleteNodeData(treeNode); + toolStripMenuItem.Click += (s, e) => ((Controls.TreeView.TreeView) treeNode.TreeView).TreeViewController.DeleteNode(treeNode, treeNodeInfo); return toolStripMenuItem; } @@ -71,14 +79,14 @@ /// The created . public ToolStripItem CreateExpandAllItem() { - IList children = treeNode.Nodes; + var children = treeNode.Nodes.OfType(); var toolStripMenuItem = new ToolStripMenuItem(Resources.Expand_all) { ToolTipText = Resources.Expand_all_ToolTip, Image = Resources.ExpandAllIcon, - Enabled = children != null && children.Any() + Enabled = children.Any() }; - toolStripMenuItem.Click += (s, e) => treeNode.TreeView.ExpandAll(treeNode); + toolStripMenuItem.Click += (s, e) => ((Controls.TreeView.TreeView) treeNode.TreeView).TreeViewController.ExpandAll(treeNode); return toolStripMenuItem; } @@ -89,14 +97,14 @@ /// The created . public ToolStripItem CreateCollapseAllItem() { - IList children = treeNode.Nodes; + var children = treeNode.Nodes.OfType(); var toolStripMenuItem = new ToolStripMenuItem(Resources.Collapse_all) { ToolTipText = Resources.Collapse_all_ToolTip, Image = Resources.CollapseAllIcon, - Enabled = children != null && children.Any() + Enabled = children.Any() }; - toolStripMenuItem.Click += (s, e) => treeNode.TreeView.CollapseAll(treeNode); + toolStripMenuItem.Click += (s, e) => ((Controls.TreeView.TreeView) treeNode.TreeView).TreeViewController.CollapseAll(treeNode); return toolStripMenuItem; } } Index: Core/Common/src/Core.Common.Gui/GuiPlugin.cs =================================================================== diff -u -ra119a7e860d0d62362c2cd2742d03a4543a2232a -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/GuiPlugin.cs (.../GuiPlugin.cs) (revision a119a7e860d0d62362c2cd2742d03a4543a2232a) +++ Core/Common/src/Core.Common.Gui/GuiPlugin.cs (.../GuiPlugin.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -62,14 +62,6 @@ } /// - /// Node presenters which can be provided by the gui plugin. - /// - public virtual IEnumerable GetProjectTreeViewNodePresenters() - { - yield break; - } - - /// /// This method returns an enumeration of . /// /// The enumeration of provided by the . Index: Core/Common/src/Core.Common.Gui/IContextMenuBuilderProvider.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/IContextMenuBuilderProvider.cs (.../IContextMenuBuilderProvider.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Core/Common/src/Core.Common.Gui/IContextMenuBuilderProvider.cs (.../IContextMenuBuilderProvider.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,6 +1,6 @@ using System.Windows.Forms; +using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; namespace Core.Common.Gui { @@ -13,12 +13,14 @@ /// Returns a new for creating a /// for the given . /// - /// The to have the + /// The to have the /// create a for. + /// The to use while creating the + /// . /// The which can be used to create a /// for . /// Thrown when the instance could /// not be created. - IContextMenuBuilder Get(TreeNode treeNode); + IContextMenuBuilder Get(TreeNode treeNode, TreeNodeInfo treeNodeInfo); } } \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs =================================================================== diff -u -r173074e74e9230239f9862df6e5630fb1c5569f5 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 173074e74e9230239f9862df6e5630fb1c5569f5) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -576,6 +576,15 @@ } /// + /// Looks up a localized string similar to Kan geen element in het contextmenu creëren zonder dat informatie over de knoop bekend is.. + /// + public static string ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node_info { + get { + return ResourceManager.GetString("ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node_info", resourceCulture); + } + } + + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap control_play { @@ -1914,16 +1923,6 @@ } /// - /// Looks up a localized string similar to Er ging iets fout bij het ophalen van de 'NodePresenters' van alle plugins.. - /// - public static string ProjectExplorerGuiPlugin_FillProjectTreeViewNodePresentersFromPlugins_Could_not_retrieve_NodePresenters_for_a_plugin { - get { - return ResourceManager.GetString("ProjectExplorerGuiPlugin_FillProjectTreeViewNodePresentersFromPlugins_Could_not_r" + - "etrieve_NodePresenters_for_a_plugin", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Ei&genschappen. /// public static string Properties { Index: Core/Common/src/Core.Common.Gui/Properties/Resources.resx =================================================================== diff -u -r173074e74e9230239f9862df6e5630fb1c5569f5 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision 173074e74e9230239f9862df6e5630fb1c5569f5) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -799,6 +799,9 @@ Kan geen element in het contextmenu creëren zonder dat de knoop bekend is. + + Kan geen element in het contextmenu creëren zonder dat informatie over de knoop bekend is. + &Openen @@ -847,9 +850,6 @@ Kan geen instanties maken van de benodigde objecten. - - Er ging iets fout bij het ophalen van de 'NodePresenters' van alle plugins. - Licht Used for displaying ColorTheme.Light in combo box. Index: Core/Common/src/Core.Common.Gui/RingtoetsGui.cs =================================================================== diff -u -ra22387226e61ab8633b670aea078f26900ed1883 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/src/Core.Common.Gui/RingtoetsGui.cs (.../RingtoetsGui.cs) (revision a22387226e61ab8633b670aea078f26900ed1883) +++ Core/Common/src/Core.Common.Gui/RingtoetsGui.cs (.../RingtoetsGui.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -7,7 +7,7 @@ using System.Diagnostics; using System.Linq; using System.Reflection; -using System.Windows; +using System.Windows.Forms; using Core.Common.Base.Data; using Core.Common.Base.Plugin; @@ -30,6 +30,7 @@ using log4net.Repository.Hierarchy; using SplashScreen = Core.Common.Gui.Forms.SplashScreen.SplashScreen; +using Application = System.Windows.Application; using WindowsApplication = System.Windows.Forms.Application; namespace Core.Common.Gui @@ -359,7 +360,7 @@ return; } - var node = ProjectExplorer.TreeView.GetNodeByTag(view.Data); + var node = ProjectExplorer.TreeView.TreeViewController.GetNodeByTag(view.Data); if (node != null) { DocumentViews.SetTooltip(view, node.FullPath); @@ -721,9 +722,9 @@ #region Implementation: IContextMenuBuilderProvider - public IContextMenuBuilder Get(TreeNode treeNode) + public IContextMenuBuilder Get(TreeNode treeNode, TreeNodeInfo treeNodeInfo) { - return new ContextMenuBuilder(appFeatureApplicationCommands, exportImportCommandHandler, ViewCommands, treeNode); + return new ContextMenuBuilder(appFeatureApplicationCommands, exportImportCommandHandler, ViewCommands, treeNode, treeNodeInfo); } #endregion Index: Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs =================================================================== diff -u -r81982c798fc50dab94c8f1eb8799c04242515564 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs (.../FileImportActivityTest.cs) (revision 81982c798fc50dab94c8f1eb8799c04242515564) +++ Core/Common/test/Core.Common.Base.Test/Service/FileImportActivityTest.cs (.../FileImportActivityTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -138,15 +138,20 @@ } [Test] - public void Finish_FileImportActivityWithFileImporter_NoLogicPerformed() + public void Finish_FileImportActivityWithFileImporterAndObservableTarget_ObserversOfTargetAreNotified() { // Setup var mocks = new MockRepository(); var fileImporter = mocks.Stub(); - var target = new object(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + var target = new ObservableList(); + target.Attach(observer); + var fileImportActivity = new FileImportActivity(fileImporter, target, ""); // Call Index: Core/Common/test/Core.Common.Controls.TreeView.Test/Core.Common.Controls.TreeView.Test.csproj =================================================================== diff -u -rcc570ccd4f17971ce651ead28207aae3399919d1 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Controls.TreeView.Test/Core.Common.Controls.TreeView.Test.csproj (.../Core.Common.Controls.TreeView.Test.csproj) (revision cc570ccd4f17971ce651ead28207aae3399919d1) +++ Core/Common/test/Core.Common.Controls.TreeView.Test/Core.Common.Controls.TreeView.Test.csproj (.../Core.Common.Controls.TreeView.Test.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -63,8 +63,6 @@ - - Index: Core/Common/test/Core.Common.Controls.TreeView.Test/TreeNodeExpandCollapseStateTest.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Controls.TreeView.Test/TreeNodeExpandCollapseStateTest.cs (.../TreeNodeExpandCollapseStateTest.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Core/Common/test/Core.Common.Controls.TreeView.Test/TreeNodeExpandCollapseStateTest.cs (.../TreeNodeExpandCollapseStateTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,381 +1,381 @@ -using System; -using System.Collections.Generic; - -using NUnit.Framework; -using Rhino.Mocks; - -namespace Core.Common.Controls.TreeView.Test -{ - [TestFixture] - public class TreeNodeExpandCollapseStateTest - { - [Test] - public void ParameteredConstructor_NodeIsNull_ThrowArgumentNullException() - { - // Call - TestDelegate call = () => new TreeNodeExpandCollapseState(null); - - // Assert - var exception = Assert.Throws(call); - string customMessagePart = exception.Message.Split(new []{Environment.NewLine}, StringSplitOptions.None)[0]; - Assert.AreEqual("Knoop moet opgegeven zijn om diens toestand op te kunnen nemen.", customMessagePart); - } - - [Test] - public void ParameterdConstructor_NodeTagIsNull_ThrowArgumentException() - { - // Setup - var mocks = new MockRepository(); - var node = mocks.StrictMock(); - node.Expect(n => n.Tag).Return(null); - mocks.ReplayAll(); - - // Call - TestDelegate call = () => new TreeNodeExpandCollapseState(node); - - // Assert - var exception = Assert.Throws(call); - string customMessagePart = exception.Message.Split(new[] { Environment.NewLine }, StringSplitOptions.None)[0]; - Assert.AreEqual("Knoop data moet aanwezig zijn om de toestand van diens knoop op te kunnen nemen.", customMessagePart); - mocks.VerifyAll(); - } - - [Test] - public void Restore_SingleNodeCollapsed_CollapseNode() - { - // Setup - var sourceData = new object(); - var mocks = new MockRepository(); - - var sourceNode = mocks.StrictMock(); - sourceNode.Expect(n => n.IsExpanded).Return(false); - sourceNode.Expect(n => n.Tag).Return(sourceData); - sourceNode.Stub(n => n.Nodes).Return(new List()); - - var targetNode = mocks.StrictMock(); - targetNode.Expect(n => n.IsExpanded).Return(true); - targetNode.Expect(n => n.Tag).Return(sourceData); - targetNode.Expect(n => n.Collapse()); - targetNode.Stub(n => n.Nodes).Return(new List()); - - mocks.ReplayAll(); - - var nodeState = new TreeNodeExpandCollapseState(sourceNode); - - // Call - nodeState.Restore(targetNode); - - // Assert - mocks.VerifyAll(); - } - - [Test] - public void Restore_SingleNodeExpanded_ExpandNode() - { - // Setup - var sourceData = new object(); - var mocks = new MockRepository(); - - var sourceNode = mocks.StrictMock(); - sourceNode.Expect(n => n.IsExpanded).Return(true); - sourceNode.Expect(n => n.Tag).Return(sourceData); - sourceNode.Stub(n => n.Nodes).Return(new List()); - - var targetNode = mocks.StrictMock(); - targetNode.Expect(n => n.IsExpanded).Return(false); - targetNode.Expect(n => n.Expand()); - targetNode.Expect(n => n.Tag).Return(sourceData); - targetNode.Stub(n => n.Nodes).Return(new List()); - - mocks.ReplayAll(); - - var nodeState = new TreeNodeExpandCollapseState(sourceNode); - - // Call - nodeState.Restore(targetNode); - - // Assert - mocks.VerifyAll(); - } - - [Test] - [TestCase(true)] - [TestCase(false)] - public void Restore_SingleNodeAndTargetInSameState_DoNothing(bool isExpanded) - { - // Setup - var sourceData = new object(); - var mocks = new MockRepository(); - - var sourceNode = mocks.StrictMock(); - sourceNode.Expect(n => n.IsExpanded).Return(isExpanded); - sourceNode.Expect(n => n.Tag).Return(sourceData); - sourceNode.Stub(n => n.Nodes).Return(new List()); - - var targetNode = mocks.StrictMock(); - targetNode.Expect(n => n.IsExpanded).Return(isExpanded); - targetNode.Expect(n => n.Tag).Return(sourceData); - targetNode.Stub(n => n.Nodes).Return(new List()); - - mocks.ReplayAll(); - - var nodeState = new TreeNodeExpandCollapseState(sourceNode); - - // Call - nodeState.Restore(targetNode); - - // Assert - mocks.VerifyAll(); - } - - [Test] - public void Restore_TargetNodeNotSameTag_ThrowArgumentException() - { - // Setup - var sourceData = new object(); - var targetData = new object(); - var mocks = new MockRepository(); - - var sourceNode = mocks.Stub(); - sourceNode.Stub(n => n.IsExpanded).Return(true); - sourceNode.Tag = sourceData; - sourceNode.Stub(n => n.Nodes).Return(new List()); - - var targetNode = mocks.Stub(); - targetNode.Tag = targetData; - targetNode.Stub(n => n.Nodes).Return(new List()); - - mocks.ReplayAll(); - - var nodeState = new TreeNodeExpandCollapseState(sourceNode); - - // Call - TestDelegate call = () => nodeState.Restore(targetNode); - - // Assert - var exception = Assert.Throws(call); - string userMessage = exception.Message.Split(new []{Environment.NewLine}, StringSplitOptions.None)[0]; - Assert.AreEqual("Knoop heeft niet dezelfde data als de opgenomen knoop.", userMessage); - mocks.VerifyAll(); - } - - [Test] - public void Restore_NodeWithExpandedChild_ExpandChildNode() - { - // Setup - var sourceData = new object(); - var childData = new object(); - - var mocks = new MockRepository(); - - var stubNode = mocks.Stub(); - stubNode.Tag = new object(); - stubNode.Stub(n => n.Nodes).Return(new List()); - - var sourceChildNode = mocks.Stub(); - sourceChildNode.Tag = childData; - sourceChildNode.Stub(n => n.IsExpanded).Return(true); - sourceChildNode.Stub(n => n.Nodes).Return(new List - { - stubNode - }); - - var sourceNode = mocks.Stub(); - sourceNode.Stub(n => n.IsExpanded).Return(true); - sourceNode.Tag = sourceData; - sourceNode.Stub(n => n.Nodes).Return(new List - { - sourceChildNode - }); - - var targetChildNode = mocks.StrictMock(); - targetChildNode.Stub(n => n.Tag).Return(childData); - targetChildNode.Stub(n => n.IsExpanded).Return(false); - targetChildNode.Expect(n => n.Expand()); - targetChildNode.Stub(n => n.Nodes).Return(new List - { - stubNode - }); - - var targetNode = mocks.Stub(); - targetNode.Stub(n => n.IsExpanded).Return(true); - targetNode.Tag = sourceData; - targetNode.Stub(n => n.Nodes).Return(new List - { - targetChildNode - }); - - mocks.ReplayAll(); - - var nodeState = new TreeNodeExpandCollapseState(sourceNode); - - // Call - nodeState.Restore(targetNode); - - // Assert - mocks.VerifyAll(); - } - - [Test] - public void Restore_NodeWithCollapsedChild_CollapseChildNode() - { - // Setup - var sourceData = new object(); - var childData = new object(); - - var mocks = new MockRepository(); - - var stubNode = mocks.Stub(); - stubNode.Tag = new object(); - stubNode.Stub(n => n.Nodes).Return(new List()); - - var sourceChildNode = mocks.Stub(); - sourceChildNode.Tag = childData; - sourceChildNode.Stub(n => n.IsExpanded).Return(false); - sourceChildNode.Stub(n => n.Nodes).Return(new List - { - stubNode - }); - - var sourceNode = mocks.Stub(); - sourceNode.Stub(n => n.IsExpanded).Return(true); - sourceNode.Tag = sourceData; - sourceNode.Stub(n => n.Nodes).Return(new List - { - sourceChildNode - }); - - var targetChildNode = mocks.StrictMock(); - targetChildNode.Stub(n => n.Tag).Return(childData); - targetChildNode.Stub(n => n.IsExpanded).Return(true); - targetChildNode.Expect(n => n.Collapse()); - targetChildNode.Stub(n => n.Nodes).Return(new List - { - stubNode - }); - - var targetNode = mocks.Stub(); - targetNode.Stub(n => n.IsExpanded).Return(true); - targetNode.Tag = sourceData; - targetNode.Stub(n => n.Nodes).Return(new List - { - targetChildNode - }); - - mocks.ReplayAll(); - - var nodeState = new TreeNodeExpandCollapseState(sourceNode); - - // Call - nodeState.Restore(targetNode); - - // Assert - mocks.VerifyAll(); - } - - [Test] - public void Restore_NodeWithChildAddedAfterRecordingState_IgnoreChild() - { - // Setup - var sourceData = new object(); - var childData = new object(); - - var mocks = new MockRepository(); - - var stubNode = mocks.Stub(); - stubNode.Tag = new object(); - stubNode.Stub(n => n.Nodes).Return(new List()); - - var sourceNode = mocks.Stub(); - sourceNode.Stub(n => n.IsExpanded).Return(true); - sourceNode.Tag = sourceData; - sourceNode.Stub(n => n.Nodes).Return(new List()); - - var targetChildNode = mocks.StrictMock(); - targetChildNode.Stub(n => n.Tag).Return(childData); - targetChildNode.Stub(n => n.Nodes).Return(new List - { - stubNode - }); - - var targetNode = mocks.Stub(); - targetNode.Stub(n => n.IsExpanded).Return(true); - targetNode.Tag = sourceData; - targetNode.Stub(n => n.Nodes).Return(new List - { - targetChildNode - }); - - mocks.ReplayAll(); - - var nodeState = new TreeNodeExpandCollapseState(sourceNode); - - // Call - nodeState.Restore(targetNode); - - // Assert - mocks.VerifyAll(); - } - - [Test] - public void Restore_NodeWithDifferentEqualDataInstances_RestoreState() - { - // Setup - var data1 = new IntegerWrapperWithCustomEquals - { - WrappedInteger = 1 - }; - var data2 = new IntegerWrapperWithCustomEquals - { - WrappedInteger = 1 - }; - - var mocks = new MockRepository(); - var sourceNode = mocks.StrictMock(); - sourceNode.Expect(n => n.IsExpanded).Return(false); - sourceNode.Expect(n => n.Tag).Return(data1); - sourceNode.Stub(n => n.Nodes).Return(new List()); - - var targetNode = mocks.StrictMock(); - targetNode.Expect(n => n.IsExpanded).Return(true); - targetNode.Expect(n => n.Tag).Return(data2); - targetNode.Expect(n => n.Collapse()); - targetNode.Stub(n => n.Nodes).Return(new List()); - - mocks.ReplayAll(); - - // Precondition: - Assert.True(data1.Equals(data2)); - Assert.True(data2.Equals(data1)); - Assert.AreNotSame(data1, data2); - - var nodeState = new TreeNodeExpandCollapseState(sourceNode); - - // Call - nodeState.Restore(targetNode); - - // Assert - mocks.VerifyAll(); - } - - private class IntegerWrapperWithCustomEquals - { - public int WrappedInteger { get; set; } - - public override bool Equals(object obj) - { - var otherIntWrapper = obj as IntegerWrapperWithCustomEquals; - if (otherIntWrapper != null) - { - return WrappedInteger.Equals(otherIntWrapper.WrappedInteger); - } - return base.Equals(obj); - } - - public override int GetHashCode() - { - return WrappedInteger.GetHashCode(); - } - } - } -} \ No newline at end of file +//using System; +//using System.Collections.Generic; +//using System.Windows.Forms; +//using NUnit.Framework; +//using Rhino.Mocks; +// +//namespace Core.Common.Controls.TreeView.Test +//{ +// [TestFixture] +// public class TreeNodeExpandCollapseStateTest +// { +// [Test] +// public void ParameteredConstructor_NodeIsNull_ThrowArgumentNullException() +// { +// // Call +// TestDelegate call = () => new TreeNodeExpandCollapseState(null); +// +// // Assert +// var exception = Assert.Throws(call); +// string customMessagePart = exception.Message.Split(new []{Environment.NewLine}, StringSplitOptions.None)[0]; +// Assert.AreEqual("Knoop moet opgegeven zijn om diens toestand op te kunnen nemen.", customMessagePart); +// } +// +// [Test] +// public void ParameterdConstructor_NodeTagIsNull_ThrowArgumentException() +// { +// // Setup +// var mocks = new MockRepository(); +// var node = mocks.StrictMock(); +// node.Expect(n => n.Tag).Return(null); +// mocks.ReplayAll(); +// +// // Call +// TestDelegate call = () => new TreeNodeExpandCollapseState(node); +// +// // Assert +// var exception = Assert.Throws(call); +// string customMessagePart = exception.Message.Split(new[] { Environment.NewLine }, StringSplitOptions.None)[0]; +// Assert.AreEqual("Knoop data moet aanwezig zijn om de toestand van diens knoop op te kunnen nemen.", customMessagePart); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void Restore_SingleNodeCollapsed_CollapseNode() +// { +// // Setup +// var sourceData = new object(); +// var mocks = new MockRepository(); +// +// var sourceNode = mocks.StrictMock(); +// sourceNode.Expect(n => n.IsExpanded).Return(false); +// sourceNode.Expect(n => n.Tag).Return(sourceData); +// sourceNode.Stub(n => n.Nodes).Return(new List()); +// +// var targetNode = mocks.StrictMock(); +// targetNode.Expect(n => n.IsExpanded).Return(true); +// targetNode.Expect(n => n.Tag).Return(sourceData); +// targetNode.Expect(n => n.Collapse()); +// targetNode.Stub(n => n.Nodes).Return(new List()); +// +// mocks.ReplayAll(); +// +// var nodeState = new TreeNodeExpandCollapseState(sourceNode); +// +// // Call +// nodeState.Restore(targetNode); +// +// // Assert +// mocks.VerifyAll(); +// } +// +// [Test] +// public void Restore_SingleNodeExpanded_ExpandNode() +// { +// // Setup +// var sourceData = new object(); +// var mocks = new MockRepository(); +// +// var sourceNode = mocks.StrictMock(); +// sourceNode.Expect(n => n.IsExpanded).Return(true); +// sourceNode.Expect(n => n.Tag).Return(sourceData); +// sourceNode.Stub(n => n.Nodes).Return(new List()); +// +// var targetNode = mocks.StrictMock(); +// targetNode.Expect(n => n.IsExpanded).Return(false); +// targetNode.Expect(n => n.Expand()); +// targetNode.Expect(n => n.Tag).Return(sourceData); +// targetNode.Stub(n => n.Nodes).Return(new List()); +// +// mocks.ReplayAll(); +// +// var nodeState = new TreeNodeExpandCollapseState(sourceNode); +// +// // Call +// nodeState.Restore(targetNode); +// +// // Assert +// mocks.VerifyAll(); +// } +// +// [Test] +// [TestCase(true)] +// [TestCase(false)] +// public void Restore_SingleNodeAndTargetInSameState_DoNothing(bool isExpanded) +// { +// // Setup +// var sourceData = new object(); +// var mocks = new MockRepository(); +// +// var sourceNode = mocks.StrictMock(); +// sourceNode.Expect(n => n.IsExpanded).Return(isExpanded); +// sourceNode.Expect(n => n.Tag).Return(sourceData); +// sourceNode.Stub(n => n.Nodes).Return(new List()); +// +// var targetNode = mocks.StrictMock(); +// targetNode.Expect(n => n.IsExpanded).Return(isExpanded); +// targetNode.Expect(n => n.Tag).Return(sourceData); +// targetNode.Stub(n => n.Nodes).Return(new List()); +// +// mocks.ReplayAll(); +// +// var nodeState = new TreeNodeExpandCollapseState(sourceNode); +// +// // Call +// nodeState.Restore(targetNode); +// +// // Assert +// mocks.VerifyAll(); +// } +// +// [Test] +// public void Restore_TargetNodeNotSameTag_ThrowArgumentException() +// { +// // Setup +// var sourceData = new object(); +// var targetData = new object(); +// var mocks = new MockRepository(); +// +// var sourceNode = mocks.Stub(); +// sourceNode.Stub(n => n.IsExpanded).Return(true); +// sourceNode.Tag = sourceData; +// sourceNode.Stub(n => n.Nodes).Return(new List()); +// +// var targetNode = mocks.Stub(); +// targetNode.Tag = targetData; +// targetNode.Stub(n => n.Nodes).Return(new List()); +// +// mocks.ReplayAll(); +// +// var nodeState = new TreeNodeExpandCollapseState(sourceNode); +// +// // Call +// TestDelegate call = () => nodeState.Restore(targetNode); +// +// // Assert +// var exception = Assert.Throws(call); +// string userMessage = exception.Message.Split(new []{Environment.NewLine}, StringSplitOptions.None)[0]; +// Assert.AreEqual("Knoop heeft niet dezelfde data als de opgenomen knoop.", userMessage); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void Restore_NodeWithExpandedChild_ExpandChildNode() +// { +// // Setup +// var sourceData = new object(); +// var childData = new object(); +// +// var mocks = new MockRepository(); +// +// var stubNode = mocks.Stub(); +// stubNode.Tag = new object(); +// stubNode.Stub(n => n.Nodes).Return(new List()); +// +// var sourceChildNode = mocks.Stub(); +// sourceChildNode.Tag = childData; +// sourceChildNode.Stub(n => n.IsExpanded).Return(true); +// sourceChildNode.Stub(n => n.Nodes).Return(new List +// { +// stubNode +// }); +// +// var sourceNode = mocks.Stub(); +// sourceNode.Stub(n => n.IsExpanded).Return(true); +// sourceNode.Tag = sourceData; +// sourceNode.Stub(n => n.Nodes).Return(new List +// { +// sourceChildNode +// }); +// +// var targetChildNode = mocks.StrictMock(); +// targetChildNode.Stub(n => n.Tag).Return(childData); +// targetChildNode.Stub(n => n.IsExpanded).Return(false); +// targetChildNode.Expect(n => n.Expand()); +// targetChildNode.Stub(n => n.Nodes).Return(new List +// { +// stubNode +// }); +// +// var targetNode = mocks.Stub(); +// targetNode.Stub(n => n.IsExpanded).Return(true); +// targetNode.Tag = sourceData; +// targetNode.Stub(n => n.Nodes).Return(new List +// { +// targetChildNode +// }); +// +// mocks.ReplayAll(); +// +// var nodeState = new TreeNodeExpandCollapseState(sourceNode); +// +// // Call +// nodeState.Restore(targetNode); +// +// // Assert +// mocks.VerifyAll(); +// } +// +// [Test] +// public void Restore_NodeWithCollapsedChild_CollapseChildNode() +// { +// // Setup +// var sourceData = new object(); +// var childData = new object(); +// +// var mocks = new MockRepository(); +// +// var stubNode = mocks.Stub(); +// stubNode.Tag = new object(); +// stubNode.Stub(n => n.Nodes).Return(new List()); +// +// var sourceChildNode = mocks.Stub(); +// sourceChildNode.Tag = childData; +// sourceChildNode.Stub(n => n.IsExpanded).Return(false); +// sourceChildNode.Stub(n => n.Nodes).Return(new List +// { +// stubNode +// }); +// +// var sourceNode = mocks.Stub(); +// sourceNode.Stub(n => n.IsExpanded).Return(true); +// sourceNode.Tag = sourceData; +// sourceNode.Stub(n => n.Nodes).Return(new List +// { +// sourceChildNode +// }); +// +// var targetChildNode = mocks.StrictMock(); +// targetChildNode.Stub(n => n.Tag).Return(childData); +// targetChildNode.Stub(n => n.IsExpanded).Return(true); +// targetChildNode.Expect(n => n.Collapse()); +// targetChildNode.Stub(n => n.Nodes).Return(new List +// { +// stubNode +// }); +// +// var targetNode = mocks.Stub(); +// targetNode.Stub(n => n.IsExpanded).Return(true); +// targetNode.Tag = sourceData; +// targetNode.Stub(n => n.Nodes).Return(new List +// { +// targetChildNode +// }); +// +// mocks.ReplayAll(); +// +// var nodeState = new TreeNodeExpandCollapseState(sourceNode); +// +// // Call +// nodeState.Restore(targetNode); +// +// // Assert +// mocks.VerifyAll(); +// } +// +// [Test] +// public void Restore_NodeWithChildAddedAfterRecordingState_IgnoreChild() +// { +// // Setup +// var sourceData = new object(); +// var childData = new object(); +// +// var mocks = new MockRepository(); +// +// var stubNode = mocks.Stub(); +// stubNode.Tag = new object(); +// stubNode.Stub(n => n.Nodes).Return(new List()); +// +// var sourceNode = mocks.Stub(); +// sourceNode.Stub(n => n.IsExpanded).Return(true); +// sourceNode.Tag = sourceData; +// sourceNode.Stub(n => n.Nodes).Return(new List()); +// +// var targetChildNode = mocks.StrictMock(); +// targetChildNode.Stub(n => n.Tag).Return(childData); +// targetChildNode.Stub(n => n.Nodes).Return(new List +// { +// stubNode +// }); +// +// var targetNode = mocks.Stub(); +// targetNode.Stub(n => n.IsExpanded).Return(true); +// targetNode.Tag = sourceData; +// targetNode.Stub(n => n.Nodes).Return(new List +// { +// targetChildNode +// }); +// +// mocks.ReplayAll(); +// +// var nodeState = new TreeNodeExpandCollapseState(sourceNode); +// +// // Call +// nodeState.Restore(targetNode); +// +// // Assert +// mocks.VerifyAll(); +// } +// +// [Test] +// public void Restore_NodeWithDifferentEqualDataInstances_RestoreState() +// { +// // Setup +// var data1 = new IntegerWrapperWithCustomEquals +// { +// WrappedInteger = 1 +// }; +// var data2 = new IntegerWrapperWithCustomEquals +// { +// WrappedInteger = 1 +// }; +// +// var mocks = new MockRepository(); +// var sourceNode = mocks.StrictMock(); +// sourceNode.Expect(n => n.IsExpanded).Return(false); +// sourceNode.Expect(n => n.Tag).Return(data1); +// sourceNode.Stub(n => n.Nodes).Return(new List()); +// +// var targetNode = mocks.StrictMock(); +// targetNode.Expect(n => n.IsExpanded).Return(true); +// targetNode.Expect(n => n.Tag).Return(data2); +// targetNode.Expect(n => n.Collapse()); +// targetNode.Stub(n => n.Nodes).Return(new List()); +// +// mocks.ReplayAll(); +// +// // Precondition: +// Assert.True(data1.Equals(data2)); +// Assert.True(data2.Equals(data1)); +// Assert.AreNotSame(data1, data2); +// +// var nodeState = new TreeNodeExpandCollapseState(sourceNode); +// +// // Call +// nodeState.Restore(targetNode); +// +// // Assert +// mocks.VerifyAll(); +// } +// +// private class IntegerWrapperWithCustomEquals +// { +// public int WrappedInteger { get; set; } +// +// public override bool Equals(object obj) +// { +// var otherIntWrapper = obj as IntegerWrapperWithCustomEquals; +// if (otherIntWrapper != null) +// { +// return WrappedInteger.Equals(otherIntWrapper.WrappedInteger); +// } +// return base.Equals(obj); +// } +// +// public override int GetHashCode() +// { +// return WrappedInteger.GetHashCode(); +// } +// } +// } +//} \ No newline at end of file Index: Core/Common/test/Core.Common.Controls.TreeView.Test/TreeNodeGraphicExtensionsTest.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Controls.TreeView.Test/TreeNodeGraphicExtensionsTest.cs (.../TreeNodeGraphicExtensionsTest.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Core/Common/test/Core.Common.Controls.TreeView.Test/TreeNodeGraphicExtensionsTest.cs (.../TreeNodeGraphicExtensionsTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,62 +1,62 @@ -using System.Drawing; -using NUnit.Framework; -using Rhino.Mocks; - -namespace Core.Common.Controls.TreeView.Test -{ - [TestFixture] - public class TreeNodeGraphicExtensionsTest - { - [Test] - public void TestIsOnCheckbox() - { - var mocks = new MockRepository(); - var treeNode = mocks.Stub(); - - treeNode.ShowCheckBox = false; - - mocks.ReplayAll(); - - var pointOnCheckbox = new Point(25, 5); - var bounds = new Rectangle(40, 0, 200, 16); - - Assert.IsFalse(TreeNodeGraphicExtensions.IsOnCheckBox(null, new Point())); - Assert.IsFalse(treeNode.IsOnCheckBox(pointOnCheckbox)); - - // Change node expectations to have a checkbox - mocks.BackToRecord(treeNode, BackToRecordOptions.PropertyBehavior); - treeNode.ShowCheckBox = true; - Expect.Call(treeNode.Bounds).Return(bounds); - treeNode.Replay(); - - Assert.IsTrue(treeNode.IsOnCheckBox(pointOnCheckbox)); - } - - [Test] - public void TestIsOnExpandButton() - { - var mocks = new MockRepository(); - var treeNode = mocks.Stub(); - - treeNode.HasChildren = true; - Expect.Call(treeNode.TreeView).Return(new TreeView()); - - mocks.ReplayAll(); - - var pointOnExpandButton = new Point(5, 5); - var bounds = new Rectangle(40, 0, 200, 16); - - Assert.IsFalse(TreeNodeGraphicExtensions.IsOnExpandButton(null, new Point())); - Assert.IsFalse(treeNode.IsOnExpandButton(pointOnExpandButton)); - - // Change node expectations to have a checkbox - mocks.BackToRecord(treeNode, BackToRecordOptions.PropertyBehavior); - - treeNode.HasChildren = true; - Expect.Call(treeNode.Bounds).Return(bounds); - treeNode.Replay(); - - Assert.IsTrue(treeNode.IsOnExpandButton(pointOnExpandButton)); - } - } -} \ No newline at end of file +//using System.Drawing; +//using NUnit.Framework; +//using Rhino.Mocks; +// +//namespace Core.Common.Controls.TreeView.Test +//{ +// [TestFixture] +// public class TreeNodeGraphicExtensionsTest +// { +// [Test] +// public void TestIsOnCheckbox() +// { +// var mocks = new MockRepository(); +// var treeNode = mocks.Stub(); +// +// treeNode.ShowCheckBox = false; +// +// mocks.ReplayAll(); +// +// var pointOnCheckbox = new Point(25, 5); +// var bounds = new Rectangle(40, 0, 200, 16); +// +// Assert.IsFalse(TreeNodeGraphicExtensions.IsOnCheckBox(null, new Point())); +// Assert.IsFalse(treeNode.IsOnCheckBox(pointOnCheckbox)); +// +// // Change node expectations to have a checkbox +// mocks.BackToRecord(treeNode, BackToRecordOptions.PropertyBehavior); +// treeNode.ShowCheckBox = true; +// Expect.Call(treeNode.Bounds).Return(bounds); +// treeNode.Replay(); +// +// Assert.IsTrue(treeNode.IsOnCheckBox(pointOnCheckbox)); +// } +// +// [Test] +// public void TestIsOnExpandButton() +// { +// var mocks = new MockRepository(); +// var treeNode = mocks.Stub(); +// +// treeNode.HasChildren = true; +// Expect.Call(treeNode.TreeView).Return(new TreeView()); +// +// mocks.ReplayAll(); +// +// var pointOnExpandButton = new Point(5, 5); +// var bounds = new Rectangle(40, 0, 200, 16); +// +// Assert.IsFalse(TreeNodeGraphicExtensions.IsOnExpandButton(null, new Point())); +// Assert.IsFalse(treeNode.IsOnExpandButton(pointOnExpandButton)); +// +// // Change node expectations to have a checkbox +// mocks.BackToRecord(treeNode, BackToRecordOptions.PropertyBehavior); +// +// treeNode.HasChildren = true; +// Expect.Call(treeNode.Bounds).Return(bounds); +// treeNode.Replay(); +// +// Assert.IsTrue(treeNode.IsOnExpandButton(pointOnExpandButton)); +// } +// } +//} \ No newline at end of file Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Controls.TreeView.Test/TreeNodeListTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Controls.TreeView.Test/TreeNodeTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewControllerTest.cs =================================================================== diff -u -rb81978adc73edcf368115b58fd37f34dc7fb6ab5 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewControllerTest.cs (.../TreeViewControllerTest.cs) (revision b81978adc73edcf368115b58fd37f34dc7fb6ab5) +++ Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewControllerTest.cs (.../TreeViewControllerTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,558 +1,635 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Core.Common.Utils.Reflection; -using NUnit.Framework; -using Rhino.Mocks; - -namespace Core.Common.Controls.TreeView.Test -{ - [TestFixture] - public class TreeViewControllerTest - { - [Test] - [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Structuurweergave mag niet leeg zijn.")] - public void ConstructWithoutTreeView() - { - new TreeViewController(null); - } - - [Test] - public void ResolveNodePresenterForDataWalksUpClassHierarchy() - { - var mocks = new MockRepository(); - var treeview = mocks.StrictMock(); - - mocks.ReplayAll(); - - var controller = new TreeViewController(treeview); - var baseClassNodePresenter = new BaseClassNodePresenter(); - var subClassNodePresenter = new SubClassNodePresenter(); - - controller.RegisterNodePresenter(baseClassNodePresenter); - controller.RegisterNodePresenter(subClassNodePresenter); - - Assert.AreEqual(subClassNodePresenter, controller.ResolveNodePresenterForData(new SubClass())); - - mocks.VerifyAll(); - } - - [Test] - public void ResolveNodePresenterForDataReturnsNullIfNotFound() - { - var mocks = new MockRepository(); - var treeview = mocks.StrictMock(); - - mocks.ReplayAll(); - - var presenter = new TreeViewController(treeview); - Assert.IsNull(presenter.ResolveNodePresenterForData(new SubClass())); - - mocks.VerifyAll(); - } - - [Test] - public void ResolveNodePresenterForDataReturnsNullIfItemIsNull() - { - var mocks = new MockRepository(); - var treeview = mocks.StrictMock(); - - Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); - - mocks.ReplayAll(); - - var presenter = new TreeViewController(treeview); - Assert.IsNull(presenter.ResolveNodePresenterForData(null)); - - mocks.VerifyAll(); - } - - [Test] - public void ResolveNodePresenterCanMatchOnInterface() - { - var mocks = new MockRepository(); - var treeview = mocks.StrictMock(); - - mocks.ReplayAll(); - - var presenter = new TreeViewController(treeview); - - var interfaceNodePresenter = new SomeInterfaceNodePresenter(); - var interfaceImplementor = new SubClass(); - presenter.RegisterNodePresenter(interfaceNodePresenter); - - Assert.AreEqual(interfaceNodePresenter, presenter.ResolveNodePresenterForData(interfaceImplementor)); - - mocks.VerifyAll(); - } - - [Test] - public void TestOnNodeChecked() - { - var mocks = new MockRepository(); - - var treeNode = mocks.Stub(); - var treeview = mocks.StrictMock(); - var nodePresenter = mocks.StrictMock(); - - nodePresenter.TreeView = treeview; - treeNode.Presenter = nodePresenter; - - Expect.Call(() => nodePresenter.OnNodeChecked(treeNode)); - - treeNode.Tag = new object(); - Expect.Call(treeNode.IsUpdating).Return(true); - - mocks.ReplayAll(); - - var controller = new TreeViewController(treeview); - controller.RegisterNodePresenter(nodePresenter); - - controller.OnNodeChecked(treeNode); - - mocks.BackToRecord(treeNode); - treeNode.Tag = new object(); - treeNode.Presenter = nodePresenter; - Expect.Call(treeNode.IsUpdating).Return(false); - mocks.Replay(treeNode); - - controller.OnNodeChecked(treeNode); - - mocks.VerifyAll(); - } - - [Test] - [ExpectedException(ExpectedMessage = "Niet in staat om een presentatieobject te vinden voor niet geïnitialiseerd object.")] - public void TestOnNodeCheckedWithNodeWithoutTagValue() - { - var mocks = new MockRepository(); - - var treeNode = mocks.Stub(); - var treeview = mocks.StrictMock(); - - treeNode.Tag = null; - mocks.ReplayAll(); - - var presenter = new TreeViewController(treeview); - - mocks.VerifyAll(); - - presenter.OnNodeChecked(treeNode); - } - - [Test] - public void TestSetData() - { - var mocks = new MockRepository(); - - var treeview = mocks.StrictMock(); - var nodePresenter = mocks.StrictMock(); - var nodes = new List(); - - nodePresenter.TreeView = treeview; - - Expect.Call(treeview.Nodes).Return(nodes).Repeat.Any(); - Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); - treeview.SelectedNode = null; - LastCall.On(treeview).IgnoreArguments(); - - Expect.Call(nodePresenter.NodeTagType).Return(typeof(object)).Repeat.Any(); - Expect.Call(nodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Any(); - Expect.Call(() => nodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); - - mocks.ReplayAll(); - - var presenter = new TreeViewController(treeview); - presenter.RegisterNodePresenter(nodePresenter); - - presenter.Data = new object(); - - Assert.AreEqual(1, nodes.Count); - mocks.VerifyAll(); - } - - [Test] - public void TestSetDataWithNull() - { - var mocks = new MockRepository(); - - var treeview = mocks.Stub(); - var nodes = new List(); - - Expect.Call(treeview.Nodes).Return(nodes).Repeat.Any(); - - mocks.ReplayAll(); - - var presenter = new TreeViewController(treeview) - { - Data = null - }; - - Assert.IsNull(presenter.Data); - - Assert.AreEqual(0, nodes.Count); - mocks.VerifyAll(); - } - - [Test] - public void TestRefreshChildNodesOfNodeWithoutChildren() - { - var mocks = new MockRepository(); - - var treeView = mocks.Stub(); - - var treeViewController = new TreeViewController(treeView); - - var parentNodePresenter = mocks.Stub(); - treeViewController.RegisterNodePresenter(parentNodePresenter); - - var nodes = new List(); - Expect.Call(treeView.Nodes).Return(nodes).Repeat.Any(); - Expect.Call(treeView.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); - - Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); - Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Twice(); - Expect.Call(() => parentNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); - mocks.ReplayAll(); - - treeViewController.Data = new Parent(); - - // should not create create sub nodes - treeViewController.RefreshChildNodes(nodes[0]); - - Assert.AreEqual(0, nodes[0].Nodes.Count); - - mocks.VerifyAll(); - } - - [Test] - public void TestRefreshChildNodesOfExpandedNode() - { - var mocks = new MockRepository(); - var parentNodePresenter = mocks.StrictMock(); - var childNodePresenter = mocks.StrictMock(); - - var treeview = new TreeView(); - var parent = new Parent(); - var child1 = new Child(); - var child2 = new Child(); - - parent.Children.AddRange(new[] - { - child1, - child2 - }); - - parentNodePresenter.TreeView = treeview; - Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); - Expect.Call(() => parentNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); - Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(parent.Children).Repeat.Any(); - - childNodePresenter.TreeView = treeview; - Expect.Call(childNodePresenter.NodeTagType).Return(typeof(Child)).Repeat.Any(); - Expect.Call(() => childNodePresenter.UpdateNode(null, null, null)).IgnoreArguments().Repeat.Times(3); - Expect.Call(childNodePresenter.GetChildNodeObjects(parent)).Return(parent.Children).Repeat.Any(); - Expect.Call(childNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Any(); - - mocks.ReplayAll(); - - var controller = TypeUtils.GetField(treeview, "controller"); - controller.RegisterNodePresenter(parentNodePresenter); - controller.RegisterNodePresenter(childNodePresenter); - - controller.Data = parent; - - var parentNode = treeview.Nodes[0]; - - // setting the controller.Data creates a root node and expands it if it has children - Assert.AreEqual(2, parentNode.Nodes.Count); - - // simulate removing child2 from parent by changing the number of children returned by the parent node presenter - parentNodePresenter.BackToRecord(BackToRecordOptions.All); - Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); - Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(new[] - { - child1 - }); - parentNodePresenter.Replay(); - - // updates the tree view to the new parent node state (parent has 1 child item) - controller.RefreshChildNodes(parentNode); - - Assert.AreEqual(1, parentNode.Nodes.Count); - - mocks.VerifyAll(); - } - - [Test] - public void TestRefreshChildNodesOfUnExpandedNode() - { - var mocks = new MockRepository(); - - var parentNodePresenter = mocks.StrictMock(); - var childNodePresenter = mocks.StrictMock(); - - var treeview = new TreeView(); - var parent = new Parent(); - var child1 = new Child(); - var child2 = new Child(); - - parentNodePresenter.TreeView = treeview; - Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); - Expect.Call(() => parentNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); - Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(new[] - { - child1, - child2 - }).Repeat.Any(); - - childNodePresenter.TreeView = treeview; - Expect.Call(childNodePresenter.NodeTagType).Return(typeof(Child)).Repeat.Any(); - Expect.Call(() => childNodePresenter.UpdateNode(null, null, null)).IgnoreArguments().Repeat.Times(4); - Expect.Call(childNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Any(); - - mocks.ReplayAll(); - - var controller = TypeUtils.GetField(treeview, "controller"); - controller.RegisterNodePresenter(parentNodePresenter); - controller.RegisterNodePresenter(childNodePresenter); - - controller.Data = parent; - - var parentNode = treeview.Nodes[0]; - - parentNode.Collapse(); - controller.RefreshChildNodes(parentNode); - - Assert.AreEqual(2, parentNode.Nodes.Count); - - mocks.VerifyAll(); - } - - [Test] - public void TestRefreshLoadedNode() - { - var mocks = new MockRepository(); - - var parentTreeNode = mocks.StrictMock(); - var childTreeNode = mocks.StrictMock(); - var treeview = mocks.StrictMock(); - var parentNodePresenter = mocks.StrictMock(); - var childNodePresenter = mocks.StrictMock(); - - var parent = new Parent(); - var child = new Child(); - var subNodes = new List - { - childTreeNode - }; - - Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); - Expect.Call(treeview.BeginUpdate).IgnoreArguments().Repeat.Any(); - Expect.Call(treeview.EndUpdate).IgnoreArguments().Repeat.Any(); - Expect.Call(treeview.InvokeRequired).Return(false).Repeat.Any(); - - parentTreeNode.HasChildren = true; - Expect.Call(parentTreeNode.Tag).Return(parent).Repeat.Any(); - Expect.Call(parentTreeNode.Parent).Return(null); - Expect.Call(parentTreeNode.Nodes).Return(subNodes).Repeat.Any(); - Expect.Call(parentTreeNode.Presenter).Return(parentNodePresenter).Repeat.Any(); - - childTreeNode.HasChildren = false; - Expect.Call(childTreeNode.Tag).Return(child).Repeat.Any(); - Expect.Call(childTreeNode.Parent).Return(parentTreeNode).Repeat.Any(); - Expect.Call(childTreeNode.Nodes).Return(new List()).Repeat.Any(); - Expect.Call(childTreeNode.Presenter).Return(childNodePresenter).Repeat.Any(); - - parentNodePresenter.TreeView = treeview; - Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); - Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(new[] - { - child - }).Repeat.Any(); - - childNodePresenter.TreeView = treeview; - Expect.Call(childNodePresenter.NodeTagType).Return(typeof(Child)).Repeat.Any(); - Expect.Call(childNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Any(); - - // expect 1 update call for the parent & child - Expect.Call(() => parentNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); - Expect.Call(() => childNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); - - mocks.ReplayAll(); - - var controller = new TreeViewController(treeview); - controller.RegisterNodePresenter(parentNodePresenter); - controller.RegisterNodePresenter(childNodePresenter); - - controller.UpdateNode(parentTreeNode); - - mocks.VerifyAll(); - } - - [Test] - public void TestCanRenameNode() - { - var mocks = new MockRepository(); - var treeview = mocks.StrictMock(); - var treeNode = mocks.StrictMock(); - var nodePresenter = mocks.StrictMock(); - var tag = new object(); - - Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); - Expect.Call(treeNode.Tag).Return(tag).Repeat.Any(); - Expect.Call(treeNode.Presenter).Return(null); - Expect.Call(treeNode.Presenter).Return(nodePresenter); - - nodePresenter.TreeView = treeview; - //Expect.Call(nodePresenter.IsPresenterForNode(null)).IgnoreArguments().Return(true); - Expect.Call(nodePresenter.NodeTagType).Return(typeof(object)).Repeat.Any(); - - // node presenter decides if a node can be renamed - Expect.Call(nodePresenter.CanRenameNode(null)).IgnoreArguments().Return(true); - - mocks.ReplayAll(); - - var presenter = new TreeViewController(treeview); - - // no node - Assert.IsFalse(presenter.CanRenameNode(null)); - - // no node presenter - Assert.IsFalse(presenter.CanRenameNode(treeNode)); - - presenter.RegisterNodePresenter(nodePresenter); - - // node presenter decides - Assert.IsTrue(presenter.CanRenameNode(treeNode)); - - mocks.VerifyAll(); - } - - [Test] - public void TestCanDeleteNode() - { - var mocks = new MockRepository(); - var nodePresenter = mocks.StrictMock(); - var treeNode = mocks.StrictMock(); - var treeview = mocks.StrictMock(); - var tag = new object(); - - nodePresenter.TreeView = treeview; - //Expect.Call(nodePresenter.IsPresenterForNode(null)).IgnoreArguments().Return(true); - Expect.Call(nodePresenter.NodeTagType).Return(typeof(object)).Repeat.Any(); - - // node presenter decides if a node can be removed - Expect.Call(nodePresenter.CanRemove(null, null)).IgnoreArguments().Return(true); - - Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); - Expect.Call(treeNode.Tag).Return(tag).Repeat.Any(); - Expect.Call(treeNode.Parent).Return(null); - Expect.Call(treeNode.Presenter).Return(null); - Expect.Call(treeNode.Presenter).Return(nodePresenter); - - mocks.ReplayAll(); - - var controller = new TreeViewController(treeview); - - // no node - Assert.IsFalse(controller.CanDeleteNode(null)); - - // no node presenter - Assert.IsFalse(controller.CanDeleteNode(treeNode)); - - controller.RegisterNodePresenter(nodePresenter); - - // node presenter decides - Assert.IsTrue(controller.CanDeleteNode(treeNode)); - - mocks.VerifyAll(); - } - - [Test] - public void RegisterNodePresenter_ItemNotRegisteredYet_AddItemToAvailableNodePresenters() - { - // Setup - var mocks = new MockRepository(); - var treeView = mocks.Stub(); - var nodePresenter = mocks.Stub(); - mocks.ReplayAll(); - - var controller = new TreeViewController(treeView); - - // Call - controller.RegisterNodePresenter(nodePresenter); - - // Assert - CollectionAssert.Contains(controller.NodePresenters, nodePresenter); - Assert.AreEqual(1, controller.NodePresenters.Count()); - mocks.VerifyAll(); - } - - [Test] - public void RegisterNodePresenter_ItemAlreadyRegistered_DoNothing() - { - // Setup - var mocks = new MockRepository(); - var treeView = mocks.Stub(); - var nodePresenter = mocks.Stub(); - mocks.ReplayAll(); - - var controller = new TreeViewController(treeView); - - // Call - controller.RegisterNodePresenter(nodePresenter); - controller.RegisterNodePresenter(nodePresenter); - - // Assert - CollectionAssert.Contains(controller.NodePresenters, nodePresenter); - Assert.AreEqual(1, controller.NodePresenters.Count()); - mocks.VerifyAll(); - } - - private class Parent - { - public Parent() - { - Children = new List(); - } - - public List Children { get; set; } - - public string Name { get; set; } - } - - private class Child - { - private string Name { get; set; } - - public override string ToString() - { - return Name; - } - } - - private interface ISomeInterface { } - - //for review: should we really split this class into 4 very small files? - //seems to me the relationships are less clear then but more consequent with the rest.. - private class BaseClass { } - - private class SubClass : BaseClass, ISomeInterface { } - - private class SomeInterfaceNodePresenter : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, ISomeInterface nodeData) { } - } - - private class SubClassNodePresenter : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, SubClass nodeData) { } - } - - private class BaseClassNodePresenter : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, BaseClass nodeData) { } - } - } -} \ No newline at end of file +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using Core.Common.Utils.Reflection; +//using NUnit.Framework; +//using Rhino.Mocks; +// +//namespace Core.Common.Controls.TreeView.Test +//{ +// [TestFixture] +// public class TreeViewControllerTest +// { +// [Test] +// [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Structuurweergave mag niet leeg zijn.")] +// public void ConstructWithoutTreeView() +// { +// new TreeViewController(null); +// } +// +// [Test] +// public void ResolveNodePresenterForDataWalksUpClassHierarchy() +// { +// var mocks = new MockRepository(); +// var treeview = mocks.StrictMock(); +// +// mocks.ReplayAll(); +// +// var controller = new TreeViewController(treeview); +// var baseClassNodePresenter = new BaseClassNodePresenter(); +// var subClassNodePresenter = new SubClassNodePresenter(); +// +// controller.RegisterNodePresenter(baseClassNodePresenter); +// controller.RegisterNodePresenter(subClassNodePresenter); +// +// Assert.AreEqual(subClassNodePresenter, controller.ResolveNodePresenterForData(new SubClass())); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void ResolveNodePresenterForDataReturnsNullIfNotFound() +// { +// var mocks = new MockRepository(); +// var treeview = mocks.StrictMock(); +// +// mocks.ReplayAll(); +// +// var presenter = new TreeViewController(treeview); +// Assert.IsNull(presenter.ResolveNodePresenterForData(new SubClass())); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void ResolveNodePresenterForDataReturnsNullIfItemIsNull() +// { +// var mocks = new MockRepository(); +// var treeview = mocks.StrictMock(); +// +// Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); +// +// mocks.ReplayAll(); +// +// var presenter = new TreeViewController(treeview); +// Assert.IsNull(presenter.ResolveNodePresenterForData(null)); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void ResolveNodePresenterCanMatchOnInterface() +// { +// var mocks = new MockRepository(); +// var treeview = mocks.StrictMock(); +// +// mocks.ReplayAll(); +// +// var presenter = new TreeViewController(treeview); +// +// var interfaceNodePresenter = new SomeInterfaceNodePresenter(); +// var interfaceImplementor = new SubClass(); +// presenter.RegisterNodePresenter(interfaceNodePresenter); +// +// Assert.AreEqual(interfaceNodePresenter, presenter.ResolveNodePresenterForData(interfaceImplementor)); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void TestOnNodeChecked() +// { +// var mocks = new MockRepository(); +// +// var treeNode = mocks.Stub(); +// var treeview = mocks.StrictMock(); +// var nodePresenter = mocks.StrictMock(); +// +// nodePresenter.TreeView = treeview; +// treeNode.Presenter = nodePresenter; +// +// Expect.Call(() => nodePresenter.OnNodeChecked(treeNode)); +// +// treeNode.Tag = new object(); +// Expect.Call(treeNode.IsUpdating).Return(true); +// +// mocks.ReplayAll(); +// +// var controller = new TreeViewController(treeview); +// controller.RegisterNodePresenter(nodePresenter); +// +// controller.OnNodeChecked(treeNode); +// +// mocks.BackToRecord(treeNode); +// treeNode.Tag = new object(); +// treeNode.Presenter = nodePresenter; +// Expect.Call(treeNode.IsUpdating).Return(false); +// mocks.Replay(treeNode); +// +// controller.OnNodeChecked(treeNode); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// [ExpectedException(ExpectedMessage = "Niet in staat om een presentatieobject te vinden voor niet geïnitialiseerd object.")] +// public void TestOnNodeCheckedWithNodeWithoutTagValue() +// { +// var mocks = new MockRepository(); +// +// var treeNode = mocks.Stub(); +// var treeview = mocks.StrictMock(); +// +// treeNode.Tag = null; +// mocks.ReplayAll(); +// +// var presenter = new TreeViewController(treeview); +// +// mocks.VerifyAll(); +// +// presenter.OnNodeChecked(treeNode); +// } +// +// [Test] +// public void TestSetData() +// { +// var mocks = new MockRepository(); +// +// var treeview = mocks.StrictMock(); +// var nodePresenter = mocks.StrictMock(); +// var nodes = new List(); +// +// nodePresenter.TreeView = treeview; +// +// Expect.Call(treeview.Nodes).Return(nodes).Repeat.Any(); +// Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); +// treeview.SelectedNode = null; +// LastCall.On(treeview).IgnoreArguments(); +// +// Expect.Call(nodePresenter.NodeTagType).Return(typeof(object)).Repeat.Any(); +// Expect.Call(nodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Any(); +// Expect.Call(() => nodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); +// +// mocks.ReplayAll(); +// +// var presenter = new TreeViewController(treeview); +// presenter.RegisterNodePresenter(nodePresenter); +// +// presenter.Data = new object(); +// +// Assert.AreEqual(1, nodes.Count); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void TestSetDataWithNull() +// { +// var mocks = new MockRepository(); +// +// var treeview = mocks.Stub(); +// var nodes = new List(); +// +// Expect.Call(treeview.Nodes).Return(nodes).Repeat.Any(); +// +// mocks.ReplayAll(); +// +// var presenter = new TreeViewController(treeview) +// { +// Data = null +// }; +// +// Assert.IsNull(presenter.Data); +// +// Assert.AreEqual(0, nodes.Count); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void TestRefreshChildNodesOfNodeWithoutChildren() +// { +// var mocks = new MockRepository(); +// +// var treeView = mocks.Stub(); +// +// var treeViewController = new TreeViewController(treeView); +// +// var parentNodePresenter = mocks.Stub(); +// treeViewController.RegisterNodePresenter(parentNodePresenter); +// +// var nodes = new List(); +// Expect.Call(treeView.Nodes).Return(nodes).Repeat.Any(); +// Expect.Call(treeView.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); +// +// Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); +// Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Twice(); +// Expect.Call(() => parentNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); +// mocks.ReplayAll(); +// +// treeViewController.Data = new Parent(); +// +// // should not create create sub nodes +// treeViewController.RefreshChildNodes(nodes[0]); +// +// Assert.AreEqual(0, nodes[0].Nodes.Count); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void TestRefreshChildNodesOfExpandedNode() +// { +// var mocks = new MockRepository(); +// var parentNodePresenter = mocks.StrictMock(); +// var childNodePresenter = mocks.StrictMock(); +// +// var treeview = new TreeView(); +// var parent = new Parent(); +// var child1 = new Child(); +// var child2 = new Child(); +// +// parent.Children.AddRange(new[] +// { +// child1, +// child2 +// }); +// +// parentNodePresenter.TreeView = treeview; +// Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); +// Expect.Call(() => parentNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); +// Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(parent.Children).Repeat.Any(); +// +// childNodePresenter.TreeView = treeview; +// Expect.Call(childNodePresenter.NodeTagType).Return(typeof(Child)).Repeat.Any(); +// Expect.Call(() => childNodePresenter.UpdateNode(null, null, null)).IgnoreArguments().Repeat.Times(3); +// Expect.Call(childNodePresenter.GetChildNodeObjects(parent)).Return(parent.Children).Repeat.Any(); +// Expect.Call(childNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Any(); +// +// mocks.ReplayAll(); +// +// var controller = TypeUtils.GetField(treeview, "controller"); +// controller.RegisterNodePresenter(parentNodePresenter); +// controller.RegisterNodePresenter(childNodePresenter); +// +// controller.Data = parent; +// +// var parentNode = treeview.Nodes[0]; +// +// // setting the controller.Data creates a root node and expands it if it has children +// Assert.AreEqual(2, parentNode.Nodes.Count); +// +// // simulate removing child2 from parent by changing the number of children returned by the parent node presenter +// parentNodePresenter.BackToRecord(BackToRecordOptions.All); +// Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); +// Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(new[] +// { +// child1 +// }); +// parentNodePresenter.Replay(); +// +// // updates the tree view to the new parent node state (parent has 1 child item) +// controller.RefreshChildNodes(parentNode); +// +// Assert.AreEqual(1, parentNode.Nodes.Count); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void TestRefreshChildNodesOfUnExpandedNode() +// { +// var mocks = new MockRepository(); +// +// var parentNodePresenter = mocks.StrictMock(); +// var childNodePresenter = mocks.StrictMock(); +// +// var treeview = new TreeView(); +// var parent = new Parent(); +// var child1 = new Child(); +// var child2 = new Child(); +// +// parentNodePresenter.TreeView = treeview; +// Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); +// Expect.Call(() => parentNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); +// Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(new[] +// { +// child1, +// child2 +// }).Repeat.Any(); +// +// childNodePresenter.TreeView = treeview; +// Expect.Call(childNodePresenter.NodeTagType).Return(typeof(Child)).Repeat.Any(); +// Expect.Call(() => childNodePresenter.UpdateNode(null, null, null)).IgnoreArguments().Repeat.Times(4); +// Expect.Call(childNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Any(); +// +// mocks.ReplayAll(); +// +// var controller = TypeUtils.GetField(treeview, "controller"); +// controller.RegisterNodePresenter(parentNodePresenter); +// controller.RegisterNodePresenter(childNodePresenter); +// +// controller.Data = parent; +// +// var parentNode = treeview.Nodes[0]; +// +// parentNode.Collapse(); +// controller.RefreshChildNodes(parentNode); +// +// Assert.AreEqual(2, parentNode.Nodes.Count); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void TestRefreshLoadedNode() +// { +// var mocks = new MockRepository(); +// +// var parentTreeNode = mocks.StrictMock(); +// var childTreeNode = mocks.StrictMock(); +// var treeview = mocks.StrictMock(); +// var parentNodePresenter = mocks.StrictMock(); +// var childNodePresenter = mocks.StrictMock(); +// +// var parent = new Parent(); +// var child = new Child(); +// var subNodes = new List +// { +// childTreeNode +// }; +// +// Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); +// Expect.Call(treeview.BeginUpdate).IgnoreArguments().Repeat.Any(); +// Expect.Call(treeview.EndUpdate).IgnoreArguments().Repeat.Any(); +// Expect.Call(treeview.InvokeRequired).Return(false).Repeat.Any(); +// +// parentTreeNode.HasChildren = true; +// Expect.Call(parentTreeNode.Tag).Return(parent).Repeat.Any(); +// Expect.Call(parentTreeNode.Parent).Return(null); +// Expect.Call(parentTreeNode.Nodes).Return(subNodes).Repeat.Any(); +// Expect.Call(parentTreeNode.Presenter).Return(parentNodePresenter).Repeat.Any(); +// +// childTreeNode.HasChildren = false; +// Expect.Call(childTreeNode.Tag).Return(child).Repeat.Any(); +// Expect.Call(childTreeNode.Parent).Return(parentTreeNode).Repeat.Any(); +// Expect.Call(childTreeNode.Nodes).Return(new List()).Repeat.Any(); +// Expect.Call(childTreeNode.Presenter).Return(childNodePresenter).Repeat.Any(); +// +// parentNodePresenter.TreeView = treeview; +// Expect.Call(parentNodePresenter.NodeTagType).Return(typeof(Parent)).Repeat.Any(); +// Expect.Call(parentNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(new[] +// { +// child +// }).Repeat.Any(); +// +// childNodePresenter.TreeView = treeview; +// Expect.Call(childNodePresenter.NodeTagType).Return(typeof(Child)).Repeat.Any(); +// Expect.Call(childNodePresenter.GetChildNodeObjects(null)).IgnoreArguments().Return(Enumerable.Empty()).Repeat.Any(); +// +// // expect 1 update call for the parent & child +// Expect.Call(() => parentNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); +// Expect.Call(() => childNodePresenter.UpdateNode(null, null, null)).IgnoreArguments(); +// +// mocks.ReplayAll(); +// +// var controller = new TreeViewController(treeview); +// controller.RegisterNodePresenter(parentNodePresenter); +// controller.RegisterNodePresenter(childNodePresenter); +// +// controller.UpdateNode(parentTreeNode); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void TestCanRenameNode() +// { +// var mocks = new MockRepository(); +// var treeview = mocks.StrictMock(); +// var treeNode = mocks.StrictMock(); +// var nodePresenter = mocks.StrictMock(); +// var tag = new object(); +// +// Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); +// Expect.Call(treeNode.Tag).Return(tag).Repeat.Any(); +// Expect.Call(treeNode.Presenter).Return(null); +// Expect.Call(treeNode.Presenter).Return(nodePresenter); +// +// nodePresenter.TreeView = treeview; +// //Expect.Call(nodePresenter.IsPresenterForNode(null)).IgnoreArguments().Return(true); +// Expect.Call(nodePresenter.NodeTagType).Return(typeof(object)).Repeat.Any(); +// +// // node presenter decides if a node can be renamed +// Expect.Call(nodePresenter.CanRenameNode(null)).IgnoreArguments().Return(true); +// +// mocks.ReplayAll(); +// +// var presenter = new TreeViewController(treeview); +// +// // no node +// Assert.IsFalse(presenter.CanRenameNode(null)); +// +// // no node presenter +// Assert.IsFalse(presenter.CanRenameNode(treeNode)); +// +// presenter.RegisterNodePresenter(nodePresenter); +// +// // node presenter decides +// Assert.IsTrue(presenter.CanRenameNode(treeNode)); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void TestCanDeleteNode() +// { +// var mocks = new MockRepository(); +// var nodePresenter = mocks.StrictMock(); +// var treeNode = mocks.StrictMock(); +// var treeview = mocks.StrictMock(); +// var tag = new object(); +// +// nodePresenter.TreeView = treeview; +// //Expect.Call(nodePresenter.IsPresenterForNode(null)).IgnoreArguments().Return(true); +// Expect.Call(nodePresenter.NodeTagType).Return(typeof(object)).Repeat.Any(); +// +// // node presenter decides if a node can be removed +// Expect.Call(nodePresenter.CanRemove(null, null)).IgnoreArguments().Return(true); +// +// Expect.Call(treeview.GetNodeByTag(null)).IgnoreArguments().Return(null).Repeat.Any(); +// Expect.Call(treeNode.Tag).Return(tag).Repeat.Any(); +// Expect.Call(treeNode.Parent).Return(null); +// Expect.Call(treeNode.Presenter).Return(null); +// Expect.Call(treeNode.Presenter).Return(nodePresenter); +// +// mocks.ReplayAll(); +// +// var controller = new TreeViewController(treeview); +// +// // no node +// Assert.IsFalse(controller.CanDeleteNode(null)); +// +// // no node presenter +// Assert.IsFalse(controller.CanDeleteNode(treeNode)); +// +// controller.RegisterNodePresenter(nodePresenter); +// +// // node presenter decides +// Assert.IsTrue(controller.CanDeleteNode(treeNode)); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// public void RegisterNodePresenter_ItemNotRegisteredYet_AddItemToAvailableNodePresenters() +// { +// // Setup +// var mocks = new MockRepository(); +// var treeView = mocks.Stub(); +// var nodePresenter = mocks.Stub(); +// mocks.ReplayAll(); +// +// var controller = new TreeViewController(treeView); +// +// // Call +// controller.RegisterNodePresenter(nodePresenter); +// +// // Assert +// CollectionAssert.Contains(controller.NodePresenters, nodePresenter); +// Assert.AreEqual(1, controller.NodePresenters.Count()); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void RegisterNodePresenter_ItemAlreadyRegistered_DoNothing() +// { +// // Setup +// var mocks = new MockRepository(); +// var treeView = mocks.Stub(); +// var nodePresenter = mocks.Stub(); +// mocks.ReplayAll(); +// +// var controller = new TreeViewController(treeView); +// +// // Call +// controller.RegisterNodePresenter(nodePresenter); +// controller.RegisterNodePresenter(nodePresenter); +// +// // Assert +// CollectionAssert.Contains(controller.NodePresenters, nodePresenter); +// Assert.AreEqual(1, controller.NodePresenters.Count()); +// mocks.VerifyAll(); +// } +// +// private class Parent +// { +// public Parent() +// { +// Children = new List(); +// } +// +// public List Children { get; set; } +// +// public string Name { get; set; } +// } +// +// private class Child +// { +// private string Name { get; set; } +// +// public override string ToString() +// { +// return Name; +// } +// } +// +// private interface ISomeInterface { } +// +// private class BaseClass { } +// +// private class SubClass : BaseClass, ISomeInterface { } +// +// private class SomeInterfaceNodePresenter : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, ISomeInterface nodeData) { } +// } +// +// private class SubClassNodePresenter : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, SubClass nodeData) { } +// } +// +// private class BaseClassNodePresenter : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, BaseClass nodeData) { } +// } +// +// # region Refactor +// +//// [Test] +//// public void Clear_ChildrenSubscribed_ChildrenUnsubscribe() +//// { +//// // Setup +//// var mocks = new MockRepository(); +//// var treeView = mocks.Stub(); +//// var someTreeNodeCollectionContainer = new System.Windows.Forms.TreeNode(); +//// var parentNode = new TreeNode(treeView); +//// var childNode = new TreeNode(treeView); +//// var childChildNode = new TreeNode(treeView); +//// +//// var parentData = mocks.Stub(); +//// var childData = mocks.Stub(); +//// var childChildData = mocks.Stub(); +//// +//// parentData.Expect(p => p.Attach(parentNode)); +//// childData.Expect(p => p.Attach(childNode)); +//// childChildData.Expect(p => p.Attach(childChildNode)); +//// +//// parentData.Expect(p => p.Detach(parentNode)); +//// childData.Expect(p => p.Detach(childNode)); +//// childChildData.Expect(p => p.Detach(childChildNode)); +//// +//// mocks.ReplayAll(); +//// +//// parentNode.Tag = parentData; +//// childNode.Tag = childData; +//// childChildNode.Tag = childChildData; +//// +//// var treeNodeList = new TreeNodeList(someTreeNodeCollectionContainer.Nodes); +//// treeNodeList.Add(parentNode); +//// treeNodeList.Add(childNode); +//// treeNodeList.Add(childChildNode); +//// +//// // Call +//// treeNodeList.Clear(); +//// +//// // Assert +//// mocks.VerifyAll(); +//// } +// +//// [Test] +//// public void TestTextLengthLimit() +//// { +//// var node = new TreeNode(null); +//// +//// var largeText = ""; +//// for (var i = 0; i <= 24; i++) +//// { +//// largeText += "1234567890"; +//// } +//// +//// node.Text = largeText; +//// Assert.AreEqual(250, node.Text.Length); +//// +//// node.Text = largeText + "123456789"; +//// Assert.AreEqual(259, node.Text.Length); +//// +//// node.Text = largeText + "1234567890"; +//// Assert.AreEqual(259, node.Text.Length, "Text length limit should be 259"); +//// } +//// +//// [Test] +//// public void TestTextSetToNull() +//// { +//// var node = new TreeNode(null); +//// +//// var originalText = "test"; +//// node.Text = originalText; +//// Assert.AreEqual(originalText, node.Text); +//// +//// node.Text = null; +//// Assert.AreEqual("", node.Text); +//// } +// +// # endregion +// } +//} \ No newline at end of file Index: Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewNodePresenterBaseTest.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewNodePresenterBaseTest.cs (.../TreeViewNodePresenterBaseTest.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewNodePresenterBaseTest.cs (.../TreeViewNodePresenterBaseTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,368 +1,368 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Core.Common.Base; -using Core.Common.TestUtil; -using NUnit.Framework; - -using Rhino.Mocks; - -namespace Core.Common.Controls.TreeView.Test -{ - [TestFixture] - public class TreeViewNodePresenterBaseTest - { - private static IEnumerable GetAllNodes(IEnumerable nodes) - { - var result = new List(); - if (nodes == null) - { - return result; - } - - foreach (var node in nodes) - { - result.Add(node); - result.AddRange(GetAllNodes(node.Nodes)); - } - return result; - } - - #region Remove - - [Test] - public void OnCollectionRemoveWithCollectionBasedNodePresenter() - { - var group = new TestGroup(); - var child1 = new TestPerson - { - Name = "child1" - }; - var child2 = new TestPerson - { - Name = "child2" - }; - group.Children.Add(child1); - group.Children.Add(child2); - - using (var treeView = new TreeView()) - { - treeView.RegisterNodePresenter(new GroupNodePresenterUsingCollection()); - treeView.RegisterNodePresenter(new PersonNodePresenter()); - treeView.Data = group; - - WindowsFormsTestHelper.Show(treeView); - - Assert.AreEqual(3, GetAllNodes(treeView.Nodes).Count()); - - group.Children.Remove(child1); - group.NotifyObservers(); - - Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); - - WindowsFormsTestHelper.CloseAll(); - } - } - - [Test] - public void ModifyCollectionShouldUpdateNodeHasChildren() - { - var group = new TestGroup(); - var child1 = new TestPerson - { - Name = "child1" - }; - group.Children.Add(child1); - - using (var treeView = new TreeView()) - { - treeView.RegisterNodePresenter(new GroupNodePresenterUsingCollection()); - treeView.RegisterNodePresenter(new PersonNodePresenter()); - treeView.Data = group; - - var groupNode = treeView.Nodes[0]; - Assert.AreEqual(true, groupNode.HasChildren); - - WindowsFormsTestHelper.Show(treeView); - - group.Children.Remove(child1); - group.NotifyObservers(); - - Assert.AreEqual(false, groupNode.HasChildren); - - group.Children.Add(child1); - group.NotifyObservers(); - - Assert.AreEqual(true, groupNode.HasChildren); - - WindowsFormsTestHelper.CloseAll(); - } - } - - [Test] - public void OnCollectionRemoveWithPropertyBasedNodePresenter() - { - var group = new TestGroup(); - var child1 = new TestPerson - { - Name = "child1" - }; - var child2 = new TestPerson - { - Name = "child2" - }; - group.Children.Add(child1); - group.Children.Add(child2); - - using (var treeView = new TreeView()) - { - treeView.RegisterNodePresenter(new GroupNodePresenterUsingProperty()); - treeView.RegisterNodePresenter(new PersonNodePresenter()); - treeView.Data = group; - - WindowsFormsTestHelper.Show(treeView); - - Assert.AreEqual(3, GetAllNodes(treeView.Nodes).Count()); - - group.Children.Remove(child1); - group.NotifyObservers(); - - Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); - - WindowsFormsTestHelper.CloseAll(); - } - } - - [Test] - public void OnWrongCollectionRemove() - { - var group = new TestGroup(); - var person = new TestPerson - { - Name = "adolecent" - }; - group.Children.Add(person); - group.Adults.Add(person); - - using (var treeView = new TreeView()) - { - treeView.RegisterNodePresenter(new GroupNodePresenterUsingCollection()); - treeView.RegisterNodePresenter(new PersonNodePresenter()); - treeView.Data = group; - - Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); - - group.Adults.Remove(person); - - Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); - } - } - - #endregion Remove - - #region Add - - [Test] - public void OnCollectionAddWithCollectionBasedNodePresenter() - { - var group = new TestGroup(); - var child1 = new TestPerson - { - Name = "child1" - }; - var child2 = new TestPerson - { - Name = "child2" - }; - - using (var treeView = new TreeView()) - { - treeView.RegisterNodePresenter(new GroupNodePresenterUsingCollection()); - treeView.RegisterNodePresenter(new PersonNodePresenter()); - treeView.Data = group; - - WindowsFormsTestHelper.Show(treeView); - - group.Children.Add(child1); - group.NotifyObservers(); - - Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); - - group.Children.Add(child2); - group.NotifyObservers(); - - Assert.AreEqual(3, GetAllNodes(treeView.Nodes).Count()); - - WindowsFormsTestHelper.CloseAll(); - } - } - - [Test] - public void OnCollectionAddWithPropertyBasedNodePresenter() - { - var group = new TestGroup(); - var child1 = new TestPerson - { - Name = "child1" - }; - var child2 = new TestPerson - { - Name = "child2" - }; - - using (var treeView = new TreeView()) - { - treeView.RegisterNodePresenter(new GroupNodePresenterUsingProperty()); - treeView.RegisterNodePresenter(new PersonNodePresenter()); - treeView.Data = group; - - WindowsFormsTestHelper.Show(treeView); - - Assert.AreEqual(1, GetAllNodes(treeView.Nodes).Count()); - - group.Children.Add(child1); - group.NotifyObservers(); - - Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); - - group.Children.Add(child2); - group.NotifyObservers(); - - Assert.AreEqual(3, GetAllNodes(treeView.Nodes).Count()); - - WindowsFormsTestHelper.CloseAll(); - } - } - - #endregion Add - - [Test] - public void CanInsert_Always_ReturnFalse() - { - // Setup - var mocks = new MockRepository(); - var node = mocks.StrictMock(); - var targetNode = mocks.StrictMock(); - mocks.ReplayAll(); - - var nodeData = new TestPerson(); - - var nodePresenter = new SimpleTreeViewNodePresenter(); - - // Call - var insertionAllowed = nodePresenter.CanInsert(nodeData, node, targetNode); - - // Assert - Assert.IsFalse(insertionAllowed); - mocks.VerifyAll(); - } - - [Test] - public void CanDrop_Always_ReturnNone() - { - // Setup - var mocks = new MockRepository(); - var node = mocks.StrictMock(); - var targetNode = mocks.StrictMock(); - mocks.ReplayAll(); - - var nodeData = new TestPerson(); - - var nodePresenter = new SimpleTreeViewNodePresenter(); - - // Call - var dropOperations = nodePresenter.CanDrop(nodeData, node, targetNode, DragOperations.Move); - - // Assert - Assert.AreEqual(DragOperations.None, dropOperations); - mocks.VerifyAll(); - } - - [Test] - public void CanDrag_Always_ReturnNone() - { - // Setup - var mocks = new MockRepository(); - mocks.ReplayAll(); - - var nodeData = new TestPerson(); - - var nodePresenter = new SimpleTreeViewNodePresenter(); - - // Call - var dragOperations = nodePresenter.CanDrag(nodeData); - - // Assert - Assert.AreEqual(DragOperations.None, dragOperations); - mocks.VerifyAll(); - } - - #region Test Classes - - private class TestPerson : Observable - { - public string Name { get; set; } - - public TestGroup TestGroup { get; set; } - } - - private class TestGroup : Observable - { - public TestGroup() - { - Children = new ObservableList(); - Adults = new ObservableList(); - } - - public string Name { get; set; } - - public ObservableList Children { get; set; } - - public ObservableList Adults { get; set; } - } - - private class SimpleTreeViewNodePresenter : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, TestPerson nodeData) - { - throw new System.NotImplementedException(); - } - } - - private class GroupNodePresenterUsingCollection : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, TestGroup nodeData) - { - node.Text = nodeData.Name; - } - - public override IEnumerable GetChildNodeObjects(TestGroup parentNodeData) - { - return parentNodeData.Children; - } - } - - private class GroupNodePresenterUsingProperty : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, TestGroup nodeData) - { - node.Text = nodeData.Name; - } - - public override IEnumerable GetChildNodeObjects(TestGroup parentNodeData) - { - return parentNodeData.Children; - } - } - - private class PersonNodePresenter : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, TestPerson nodeData) - { - node.Text = nodeData.Name; - } - } - - #endregion - } -} \ No newline at end of file +//using System.Collections; +//using System.Collections.Generic; +//using System.Linq; +//using Core.Common.Base; +//using Core.Common.TestUtil; +//using NUnit.Framework; +// +//using Rhino.Mocks; +// +//namespace Core.Common.Controls.TreeView.Test +//{ +// [TestFixture] +// public class TreeViewNodePresenterBaseTest +// { +// private static IEnumerable GetAllNodes(IEnumerable nodes) +// { +// var result = new List(); +// if (nodes == null) +// { +// return result; +// } +// +// foreach (var node in nodes) +// { +// result.Add(node); +// result.AddRange(GetAllNodes(node.Nodes)); +// } +// return result; +// } +// +// #region Remove +// +// [Test] +// public void OnCollectionRemoveWithCollectionBasedNodePresenter() +// { +// var group = new TestGroup(); +// var child1 = new TestPerson +// { +// Name = "child1" +// }; +// var child2 = new TestPerson +// { +// Name = "child2" +// }; +// group.Children.Add(child1); +// group.Children.Add(child2); +// +// using (var treeView = new TreeView()) +// { +// treeView.RegisterNodePresenter(new GroupNodePresenterUsingCollection()); +// treeView.RegisterNodePresenter(new PersonNodePresenter()); +// treeView.Data = group; +// +// WindowsFormsTestHelper.Show(treeView); +// +// Assert.AreEqual(3, GetAllNodes(treeView.Nodes).Count()); +// +// group.Children.Remove(child1); +// group.NotifyObservers(); +// +// Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); +// +// WindowsFormsTestHelper.CloseAll(); +// } +// } +// +// [Test] +// public void ModifyCollectionShouldUpdateNodeHasChildren() +// { +// var group = new TestGroup(); +// var child1 = new TestPerson +// { +// Name = "child1" +// }; +// group.Children.Add(child1); +// +// using (var treeView = new TreeView()) +// { +// treeView.RegisterNodePresenter(new GroupNodePresenterUsingCollection()); +// treeView.RegisterNodePresenter(new PersonNodePresenter()); +// treeView.Data = group; +// +// var groupNode = treeView.Nodes[0]; +// Assert.AreEqual(true, groupNode.HasChildren); +// +// WindowsFormsTestHelper.Show(treeView); +// +// group.Children.Remove(child1); +// group.NotifyObservers(); +// +// Assert.AreEqual(false, groupNode.HasChildren); +// +// group.Children.Add(child1); +// group.NotifyObservers(); +// +// Assert.AreEqual(true, groupNode.HasChildren); +// +// WindowsFormsTestHelper.CloseAll(); +// } +// } +// +// [Test] +// public void OnCollectionRemoveWithPropertyBasedNodePresenter() +// { +// var group = new TestGroup(); +// var child1 = new TestPerson +// { +// Name = "child1" +// }; +// var child2 = new TestPerson +// { +// Name = "child2" +// }; +// group.Children.Add(child1); +// group.Children.Add(child2); +// +// using (var treeView = new TreeView()) +// { +// treeView.RegisterNodePresenter(new GroupNodePresenterUsingProperty()); +// treeView.RegisterNodePresenter(new PersonNodePresenter()); +// treeView.Data = group; +// +// WindowsFormsTestHelper.Show(treeView); +// +// Assert.AreEqual(3, GetAllNodes(treeView.Nodes).Count()); +// +// group.Children.Remove(child1); +// group.NotifyObservers(); +// +// Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); +// +// WindowsFormsTestHelper.CloseAll(); +// } +// } +// +// [Test] +// public void OnWrongCollectionRemove() +// { +// var group = new TestGroup(); +// var person = new TestPerson +// { +// Name = "adolecent" +// }; +// group.Children.Add(person); +// group.Adults.Add(person); +// +// using (var treeView = new TreeView()) +// { +// treeView.RegisterNodePresenter(new GroupNodePresenterUsingCollection()); +// treeView.RegisterNodePresenter(new PersonNodePresenter()); +// treeView.Data = group; +// +// Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); +// +// group.Adults.Remove(person); +// +// Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); +// } +// } +// +// #endregion Remove +// +// #region Add +// +// [Test] +// public void OnCollectionAddWithCollectionBasedNodePresenter() +// { +// var group = new TestGroup(); +// var child1 = new TestPerson +// { +// Name = "child1" +// }; +// var child2 = new TestPerson +// { +// Name = "child2" +// }; +// +// using (var treeView = new TreeView()) +// { +// treeView.RegisterNodePresenter(new GroupNodePresenterUsingCollection()); +// treeView.RegisterNodePresenter(new PersonNodePresenter()); +// treeView.Data = group; +// +// WindowsFormsTestHelper.Show(treeView); +// +// group.Children.Add(child1); +// group.NotifyObservers(); +// +// Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); +// +// group.Children.Add(child2); +// group.NotifyObservers(); +// +// Assert.AreEqual(3, GetAllNodes(treeView.Nodes).Count()); +// +// WindowsFormsTestHelper.CloseAll(); +// } +// } +// +// [Test] +// public void OnCollectionAddWithPropertyBasedNodePresenter() +// { +// var group = new TestGroup(); +// var child1 = new TestPerson +// { +// Name = "child1" +// }; +// var child2 = new TestPerson +// { +// Name = "child2" +// }; +// +// using (var treeView = new TreeView()) +// { +// treeView.RegisterNodePresenter(new GroupNodePresenterUsingProperty()); +// treeView.RegisterNodePresenter(new PersonNodePresenter()); +// treeView.Data = group; +// +// WindowsFormsTestHelper.Show(treeView); +// +// Assert.AreEqual(1, GetAllNodes(treeView.Nodes).Count()); +// +// group.Children.Add(child1); +// group.NotifyObservers(); +// +// Assert.AreEqual(2, GetAllNodes(treeView.Nodes).Count()); +// +// group.Children.Add(child2); +// group.NotifyObservers(); +// +// Assert.AreEqual(3, GetAllNodes(treeView.Nodes).Count()); +// +// WindowsFormsTestHelper.CloseAll(); +// } +// } +// +// #endregion Add +// +// [Test] +// public void CanInsert_Always_ReturnFalse() +// { +// // Setup +// var mocks = new MockRepository(); +// var node = mocks.StrictMock(); +// var targetNode = mocks.StrictMock(); +// mocks.ReplayAll(); +// +// var nodeData = new TestPerson(); +// +// var nodePresenter = new SimpleTreeViewNodePresenter(); +// +// // Call +// var insertionAllowed = nodePresenter.CanInsert(nodeData, node, targetNode); +// +// // Assert +// Assert.IsFalse(insertionAllowed); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void CanDrop_Always_ReturnNone() +// { +// // Setup +// var mocks = new MockRepository(); +// var node = mocks.StrictMock(); +// var targetNode = mocks.StrictMock(); +// mocks.ReplayAll(); +// +// var nodeData = new TestPerson(); +// +// var nodePresenter = new SimpleTreeViewNodePresenter(); +// +// // Call +// var dropOperations = nodePresenter.CanDrop(nodeData, node, targetNode, DragOperations.Move); +// +// // Assert +// Assert.AreEqual(DragOperations.None, dropOperations); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void CanDrag_Always_ReturnNone() +// { +// // Setup +// var mocks = new MockRepository(); +// mocks.ReplayAll(); +// +// var nodeData = new TestPerson(); +// +// var nodePresenter = new SimpleTreeViewNodePresenter(); +// +// // Call +// var dragOperations = nodePresenter.CanDrag(nodeData); +// +// // Assert +// Assert.AreEqual(DragOperations.None, dragOperations); +// mocks.VerifyAll(); +// } +// +// #region Test Classes +// +// private class TestPerson : Observable +// { +// public string Name { get; set; } +// +// public TestGroup TestGroup { get; set; } +// } +// +// private class TestGroup : Observable +// { +// public TestGroup() +// { +// Children = new ObservableList(); +// Adults = new ObservableList(); +// } +// +// public string Name { get; set; } +// +// public ObservableList Children { get; set; } +// +// public ObservableList Adults { get; set; } +// } +// +// private class SimpleTreeViewNodePresenter : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, TestPerson nodeData) +// { +// throw new System.NotImplementedException(); +// } +// } +// +// private class GroupNodePresenterUsingCollection : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, TestGroup nodeData) +// { +// node.Text = nodeData.Name; +// } +// +// public override IEnumerable GetChildNodeObjects(TestGroup parentNodeData) +// { +// return parentNodeData.Children; +// } +// } +// +// private class GroupNodePresenterUsingProperty : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, TestGroup nodeData) +// { +// node.Text = nodeData.Name; +// } +// +// public override IEnumerable GetChildNodeObjects(TestGroup parentNodeData) +// { +// return parentNodeData.Children; +// } +// } +// +// private class PersonNodePresenter : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, TestPerson nodeData) +// { +// node.Text = nodeData.Name; +// } +// } +// +// #endregion +// } +//} \ No newline at end of file Index: Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewTest.cs =================================================================== diff -u -r0d17d6adbe5df05db51e20685df0a47944fa6a30 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewTest.cs (.../TreeViewTest.cs) (revision 0d17d6adbe5df05db51e20685df0a47944fa6a30) +++ Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewTest.cs (.../TreeViewTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,495 +1,495 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading; -using System.Windows.Forms; -using Core.Common.Base; -using Core.Common.TestUtil; -using NUnit.Extensions.Forms; -using NUnit.Framework; -using Rhino.Mocks; - -namespace Core.Common.Controls.TreeView.Test -{ - [TestFixture] - public class TreeViewTest : NUnitFormTest - { - private readonly MockRepository mockRepository = new MockRepository(); - - /// - /// Assure the correct node is returned containing a specific tag - /// - [Test] - public void GetNodeByTag() - { - var o1 = new object(); - - var treeView = new TreeView(); - TreeNode node = treeView.NewNode(); - node.Tag = o1; - treeView.Nodes.Add(node); - TreeNode node1 = treeView.GetNodeByTag(o1); - Assert.AreEqual(node, node1); - } - - /// - /// Assure a nodepresenter is returned that corresponds to the given datatype - /// - [Test] - public void GetNodePresenterForDataType() - { - var presenter = mockRepository.Stub(); - Expect.Call(presenter.NodeTagType).Return(typeof(object)); - var treeView = new TreeView(); - - //treeview is assigned to presenter when it's added to the list of nodepresenters - treeView.RegisterNodePresenter(presenter); - Assert.AreEqual(treeView, presenter.TreeView); - - mockRepository.ReplayAll(); - Assert.AreEqual(presenter, treeView.GetTreeViewNodePresenter(new object())); - mockRepository.VerifyAll(); - } - - [Test] - public void HideSelectionIsFalseByDefault() - { - Assert.IsFalse(new TreeView().HideSelection); - } - - [Test] - public void RefreshShouldNotRefreshNodesWhichAreNotLoaded() - { - var treeView = new TreeView(); - - var parent = new Parent - { - Name = "parent1" - }; - var child = new Child(); - parent.Children.Add(child); - - var parentNodePresenter = new ParentNodePresenter(); - var childNodePresenter = new ChildNodePresenter(); - - treeView.RegisterNodePresenter(parentNodePresenter); - treeView.RegisterNodePresenter(childNodePresenter); - - childNodePresenter.AfterUpdate += - delegate { Assert.Fail("Child nodes which are not loaded should not be updated"); }; - - treeView.Refresh(); - } - - [Test] - public void NodeShouldRememberExpansionHistory() - { - // create tree view with 3 nodes - // - // node1 - // node2 - // node3 - var treeView = new TreeView(); - - var node1 = treeView.NewNode(); - - var node2 = treeView.NewNode(); - node1.Nodes.Add(node2); - - var node3 = treeView.NewNode(); - node2.Nodes.Add(node3); - - treeView.Nodes.Add(node1); - - // expand all nodes - treeView.ExpandAll(); - - // collapse and expand root node - node1.Collapse(); - node1.Expand(); - - // asserts - Assert.IsTrue(node2.IsExpanded, "node2 should remain expanded after parent node is collapsed/expanded"); - } - - [Test] - public void NodeCreatedWithNodePresentersShouldRememberExpansionHistory() - { - // n1 - // n2 - // n3 - var parent = new Child - { - Name = "n1", Children = - { - new Child - { - Name = "n2", Children = - { - new Child - { - Name = "n3" - } - } - } - } - }; - - var treeView = new TreeView(); - treeView.RegisterNodePresenter(new ChildNodePresenter()); - treeView.Data = parent; - - // expand / collapse / expand - treeView.ExpandAll(); - - treeView.Nodes[0].Collapse(); - treeView.Nodes[0].Expand(); - - // checks - Assert.IsTrue(treeView.Nodes[0].Nodes[0].IsExpanded, "n2 remains expanded after collapse / expand of parent node"); - } - - [Test] - public void AddChildNodes() - { - var treeView = new TreeView(); - - var node1 = treeView.NewNode(); - treeView.Nodes.Add(node1); - - var node2 = treeView.NewNode(); - var node3 = treeView.NewNode(); - node1.Nodes.Add(node2); - node1.Nodes.Add(node3); - - Assert.AreEqual(2, node1.Nodes.Count); - } - - [Test] - public void NodesAreNotClearedAfterExpand() - { - var treeView = new TreeView(); - - var node1 = treeView.NewNode(); - treeView.Nodes.Add(node1); - - var node2 = treeView.NewNode(); - var node3 = treeView.NewNode(); - node1.Nodes.Add(node2); - node1.Nodes.Add(node3); - - node1.Expand(); - - Assert.AreEqual(2, node1.Nodes.Count); - } - - [Test] - public void SelectedNodeSetToRootNodeAfterDataSet() - { - var treeView = new TreeView(); - treeView.RegisterNodePresenter(new ParentNodePresenter()); - - var rootObject = new Parent(); - - // set data to tree view - treeView.Data = rootObject; - - Assert.NotNull(treeView.SelectedNode); - Assert.AreSame(rootObject, treeView.SelectedNode.Tag); - } - - /// - /// In some cases every refresh of the tree view returns a new object as a child item (e.g. folder which does not exist in the Data objects). - /// - /// Actually this is a design problem, objects which do not exist in the - /// - [Test] - public void TreeNodesRemainExpandedForDynamicNodes() - { - var treeView = new TreeView(); - treeView.RegisterNodePresenter(new DynamicParentNodePresenter()); - treeView.RegisterNodePresenter(new ChildNodePresenter()); - - var parent = new Parent(); - treeView.Data = parent; - - try - { - WindowsFormsTestHelper.Show(treeView); // show it to make sure that expand / refresh node really loads nodes. - - treeView.ExpandAll(); - treeView.Refresh(); - - // asserts - Assert.IsTrue(treeView.Nodes[0].Nodes[0].IsExpanded, "node remains expanded"); - } - finally - { - WindowsFormsTestHelper.CloseAll(); - } - } - - /// - /// If node deleted then selection should go to it's parent. In case, by some reason, there is no node selected after all selection should go to the very first node. - /// - [Test] - public void DeletedNodeMovesSelectionToItsParentNode() - { - var parent = new Parent - { - Name = "Parent" - }; - var child = new Child - { - Name = "Child" - }; - var grandchild = new Child - { - Name = "GrandChild" - }; - parent.Children.Add(child); - child.Children.Add(grandchild); - - DialogBoxHandler = (name, wnd) => - { - var messageBox = new MessageBoxTester(wnd); - Assert.AreEqual("Weet u zeker dat u het volgende element wilt verwijderen: GrandChild", messageBox.Text); - Assert.AreEqual("Bevestigen", messageBox.Title); - messageBox.ClickOk(); - }; - - int dataDeletedCallCount = 0; - using (var treeView = new TreeView()) - { - treeView.DataDeleted += (sender, args) => - { - Assert.AreSame(treeView, sender); - Assert.AreSame(grandchild, args.DeletedDataInstance); - dataDeletedCallCount++; - }; - treeView.RegisterNodePresenter(new ParentNodePresenter()); - treeView.RegisterNodePresenter(new ChildNodePresenter()); - - treeView.Data = parent; - - try - { - WindowsFormsTestHelper.Show(treeView); // show it to make sure that expand / refresh node really loads nodes. - - treeView.ExpandAll(); - - treeView.SelectedNode = treeView.GetNodeByTag(grandchild); - treeView.TryDeleteSelectedNodeData(); - - treeView.ExpandAll(); - - Assert.AreEqual(treeView.SelectedNode, treeView.GetNodeByTag(child)); - } - finally - { - WindowsFormsTestHelper.CloseAll(); - } - Assert.AreEqual(1, dataDeletedCallCount); - } - } - - [Test] - public void TreeViewUpdateOnManyPropertyChangesShouldBeFast() - { - var parent = new Child - { - Name = "parent" - }; - - for (var i = 0; i < 100; i++) - { - parent.Children.Add(new Child - { - Name = i.ToString() - }); - } - - // measure time to perform action without tree view - Func processingAction = () => - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var rnd = new Random(); - for (var i = 0; i < 99; i++) - { - var child = parent.Children[rnd.Next(99)]; - child.Name = i.ToString(); - } - stopwatch.Stop(); - - return stopwatch.ElapsedMilliseconds; - }; - - Console.WriteLine(@"Elapsed time to perform action without tree view: " + processingAction()); - - var treeView = new TreeView(); - treeView.RegisterNodePresenter(new ChildNodePresenter()); - - // expand / collapse / expand - treeView.ExpandAll(); - - double elapsedMillisecondsWithTreeView = 0; - Action
onShow = delegate - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - elapsedMillisecondsWithTreeView = processingAction(); - Console.WriteLine(@"Elapsed time to perform action with tree view: " + elapsedMillisecondsWithTreeView); - - stopwatch.Stop(); - Console.WriteLine(@"Elapsed time to refresh tree view: " + stopwatch.ElapsedMilliseconds); - }; - - WindowsFormsTestHelper.ShowModal(treeView, onShow); - - TestHelper.AssertIsFasterThan(10, () => Thread.Sleep((int) elapsedMillisecondsWithTreeView)); - } - - [Test] - public void RegisterNodePresenter_NodePresenterNotRegisteredYet_NodePresenterAddedToAvailablePresenters() - { - // Setup - var mocks = new MockRepository(); - var nodePresenter = mocks.Stub(); - mocks.ReplayAll(); - - var treeView = new TreeView(); - - // Call - treeView.RegisterNodePresenter(nodePresenter); - - // Assert - CollectionAssert.Contains(treeView.NodePresenters, nodePresenter); - Assert.AreEqual(1, treeView.NodePresenters.Count()); - mocks.VerifyAll(); - } - - [Test] - public void RegisterNodePresenter_NodePresenterAlreadyRegistered_DoNothing() - { - // Setup - var mocks = new MockRepository(); - var nodePresenter = mocks.Stub(); - mocks.ReplayAll(); - - var treeView = new TreeView(); - - // Call - treeView.RegisterNodePresenter(nodePresenter); - treeView.RegisterNodePresenter(nodePresenter); - - // Assert - CollectionAssert.Contains(treeView.NodePresenters, nodePresenter); - Assert.AreEqual(1, treeView.NodePresenters.Count()); - mocks.VerifyAll(); - } - - private class DynamicParentNodePresenter : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, Parent nodeData) - { - node.Text = nodeData.Name; - } - - public override IEnumerable GetChildNodeObjects(Parent parentNodeData) - { - // always returns a single child with the same name - yield return new Child - { - Name = "child", Children = - { - new Child - { - Name = "grandchild" - } - } - }; - } - } - - private class Parent : Observable - { - public readonly IList Children = new List(); - public string Name { get; set; } - } - - private class Child : Observable - { - public Child() - { - Children = new List(); - } - - public string Name { get; set; } - public IList Children { get; set; } - } - - private class ParentNodePresenter : TreeViewNodePresenterBase - { - public override void UpdateNode(TreeNode parentNode, TreeNode node, Parent nodeData) - { - node.Text = nodeData.Name; - } - - public override IEnumerable GetChildNodeObjects(Parent parentNodeData) - { - return parentNodeData.Children; - } - } - - private class ChildNodePresenter : TreeViewNodePresenterBase - { - public event EventHandler AfterUpdate; - - /// - /// Specifies if node can be deleted by user - /// - protected override bool CanRemove(Child nodeData) - { - return true; - } - - protected override bool RemoveNodeData(object parentNodeData, Child nodeData) - { - if (parentNodeData is Parent) - { - ((Parent)parentNodeData).Children.Remove(nodeData); - ((Parent)parentNodeData).NotifyObservers(); - } - else - { - if (parentNodeData is Child) - { - ((Child)parentNodeData).Children.Remove(nodeData); - ((Child)parentNodeData).NotifyObservers(); - } - } - - return true; - } - - public override void UpdateNode(TreeNode parentNode, TreeNode node, Child nodeData) - { - node.Text = nodeData.Name; - - if (AfterUpdate != null) - { - AfterUpdate(this, null); - } - } - - public override IEnumerable GetChildNodeObjects(Child parentNodeData) - { - return parentNodeData.Children; - } - } - } -} \ No newline at end of file +//using System; +//using System.Collections; +//using System.Collections.Generic; +//using System.Diagnostics; +//using System.Linq; +//using System.Threading; +//using System.Windows.Forms; +//using Core.Common.Base; +//using Core.Common.TestUtil; +//using NUnit.Extensions.Forms; +//using NUnit.Framework; +//using Rhino.Mocks; +// +//namespace Core.Common.Controls.TreeView.Test +//{ +// [TestFixture] +// public class TreeViewTest : NUnitFormTest +// { +// private readonly MockRepository mockRepository = new MockRepository(); +// +// /// +// /// Assure the correct node is returned containing a specific tag +// /// +// [Test] +// public void GetNodeByTag() +// { +// var o1 = new object(); +// +// var treeView = new TreeView(); +// TreeNode node = treeView.NewNode(); +// node.Tag = o1; +// treeView.Nodes.Add(node); +// TreeNode node1 = treeView.GetNodeByTag(o1); +// Assert.AreEqual(node, node1); +// } +// +// /// +// /// Assure a nodepresenter is returned that corresponds to the given datatype +// /// +// [Test] +// public void GetNodePresenterForDataType() +// { +// var presenter = mockRepository.Stub(); +// Expect.Call(presenter.NodeTagType).Return(typeof(object)); +// var treeView = new TreeView(); +// +// //treeview is assigned to presenter when it's added to the list of nodepresenters +// treeView.RegisterNodePresenter(presenter); +// Assert.AreEqual(treeView, presenter.TreeView); +// +// mockRepository.ReplayAll(); +// Assert.AreEqual(presenter, treeView.GetTreeViewNodePresenter(new object())); +// mockRepository.VerifyAll(); +// } +// +// [Test] +// public void HideSelectionIsFalseByDefault() +// { +// Assert.IsFalse(new TreeView().HideSelection); +// } +// +// [Test] +// public void RefreshShouldNotRefreshNodesWhichAreNotLoaded() +// { +// var treeView = new TreeView(); +// +// var parent = new Parent +// { +// Name = "parent1" +// }; +// var child = new Child(); +// parent.Children.Add(child); +// +// var parentNodePresenter = new ParentNodePresenter(); +// var childNodePresenter = new ChildNodePresenter(); +// +// treeView.RegisterNodePresenter(parentNodePresenter); +// treeView.RegisterNodePresenter(childNodePresenter); +// +// childNodePresenter.AfterUpdate += +// delegate { Assert.Fail("Child nodes which are not loaded should not be updated"); }; +// +// treeView.Refresh(); +// } +// +// [Test] +// public void NodeShouldRememberExpansionHistory() +// { +// // create tree view with 3 nodes +// // +// // node1 +// // node2 +// // node3 +// var treeView = new TreeView(); +// +// var node1 = treeView.NewNode(); +// +// var node2 = treeView.NewNode(); +// node1.Nodes.Add(node2); +// +// var node3 = treeView.NewNode(); +// node2.Nodes.Add(node3); +// +// treeView.Nodes.Add(node1); +// +// // expand all nodes +// treeView.ExpandAll(); +// +// // collapse and expand root node +// node1.Collapse(); +// node1.Expand(); +// +// // asserts +// Assert.IsTrue(node2.IsExpanded, "node2 should remain expanded after parent node is collapsed/expanded"); +// } +// +// [Test] +// public void NodeCreatedWithNodePresentersShouldRememberExpansionHistory() +// { +// // n1 +// // n2 +// // n3 +// var parent = new Child +// { +// Name = "n1", Children = +// { +// new Child +// { +// Name = "n2", Children = +// { +// new Child +// { +// Name = "n3" +// } +// } +// } +// } +// }; +// +// var treeView = new TreeView(); +// treeView.RegisterNodePresenter(new ChildNodePresenter()); +// treeView.Data = parent; +// +// // expand / collapse / expand +// treeView.ExpandAll(); +// +// treeView.Nodes[0].Collapse(); +// treeView.Nodes[0].Expand(); +// +// // checks +// Assert.IsTrue(treeView.Nodes[0].Nodes[0].IsExpanded, "n2 remains expanded after collapse / expand of parent node"); +// } +// +// [Test] +// public void AddChildNodes() +// { +// var treeView = new TreeView(); +// +// var node1 = treeView.NewNode(); +// treeView.Nodes.Add(node1); +// +// var node2 = treeView.NewNode(); +// var node3 = treeView.NewNode(); +// node1.Nodes.Add(node2); +// node1.Nodes.Add(node3); +// +// Assert.AreEqual(2, node1.Nodes.Count); +// } +// +// [Test] +// public void NodesAreNotClearedAfterExpand() +// { +// var treeView = new TreeView(); +// +// var node1 = treeView.NewNode(); +// treeView.Nodes.Add(node1); +// +// var node2 = treeView.NewNode(); +// var node3 = treeView.NewNode(); +// node1.Nodes.Add(node2); +// node1.Nodes.Add(node3); +// +// node1.Expand(); +// +// Assert.AreEqual(2, node1.Nodes.Count); +// } +// +// [Test] +// public void SelectedNodeSetToRootNodeAfterDataSet() +// { +// var treeView = new TreeView(); +// treeView.RegisterNodePresenter(new ParentNodePresenter()); +// +// var rootObject = new Parent(); +// +// // set data to tree view +// treeView.Data = rootObject; +// +// Assert.NotNull(treeView.SelectedNode); +// Assert.AreSame(rootObject, treeView.SelectedNode.Tag); +// } +// +// /// +// /// In some cases every refresh of the tree view returns a new object as a child item (e.g. folder which does not exist in the Data objects). +// /// +// /// Actually this is a design problem, objects which do not exist in the +// /// +// [Test] +// public void TreeNodesRemainExpandedForDynamicNodes() +// { +// var treeView = new TreeView(); +// treeView.RegisterNodePresenter(new DynamicParentNodePresenter()); +// treeView.RegisterNodePresenter(new ChildNodePresenter()); +// +// var parent = new Parent(); +// treeView.Data = parent; +// +// try +// { +// WindowsFormsTestHelper.Show(treeView); // show it to make sure that expand / refresh node really loads nodes. +// +// treeView.ExpandAll(); +// treeView.Refresh(); +// +// // asserts +// Assert.IsTrue(treeView.Nodes[0].Nodes[0].IsExpanded, "node remains expanded"); +// } +// finally +// { +// WindowsFormsTestHelper.CloseAll(); +// } +// } +// +// /// +// /// If node deleted then selection should go to it's parent. In case, by some reason, there is no node selected after all selection should go to the very first node. +// /// +// [Test] +// public void DeletedNodeMovesSelectionToItsParentNode() +// { +// var parent = new Parent +// { +// Name = "Parent" +// }; +// var child = new Child +// { +// Name = "Child" +// }; +// var grandchild = new Child +// { +// Name = "GrandChild" +// }; +// parent.Children.Add(child); +// child.Children.Add(grandchild); +// +// DialogBoxHandler = (name, wnd) => +// { +// var messageBox = new MessageBoxTester(wnd); +// Assert.AreEqual("Weet u zeker dat u het volgende element wilt verwijderen: GrandChild", messageBox.Text); +// Assert.AreEqual("Bevestigen", messageBox.Title); +// messageBox.ClickOk(); +// }; +// +// int dataDeletedCallCount = 0; +// using (var treeView = new TreeView()) +// { +// treeView.DataDeleted += (sender, args) => +// { +// Assert.AreSame(treeView, sender); +// Assert.AreSame(grandchild, args.DeletedDataInstance); +// dataDeletedCallCount++; +// }; +// treeView.RegisterNodePresenter(new ParentNodePresenter()); +// treeView.RegisterNodePresenter(new ChildNodePresenter()); +// +// treeView.Data = parent; +// +// try +// { +// WindowsFormsTestHelper.Show(treeView); // show it to make sure that expand / refresh node really loads nodes. +// +// treeView.ExpandAll(); +// +// treeView.SelectedNode = treeView.GetNodeByTag(grandchild); +// treeView.TryDeleteSelectedNodeData(); +// +// treeView.ExpandAll(); +// +// Assert.AreEqual(treeView.SelectedNode, treeView.GetNodeByTag(child)); +// } +// finally +// { +// WindowsFormsTestHelper.CloseAll(); +// } +// Assert.AreEqual(1, dataDeletedCallCount); +// } +// } +// +// [Test] +// public void TreeViewUpdateOnManyPropertyChangesShouldBeFast() +// { +// var parent = new Child +// { +// Name = "parent" +// }; +// +// for (var i = 0; i < 100; i++) +// { +// parent.Children.Add(new Child +// { +// Name = i.ToString() +// }); +// } +// +// // measure time to perform action without tree view +// Func processingAction = () => +// { +// var stopwatch = new Stopwatch(); +// stopwatch.Start(); +// var rnd = new Random(); +// for (var i = 0; i < 99; i++) +// { +// var child = parent.Children[rnd.Next(99)]; +// child.Name = i.ToString(); +// } +// stopwatch.Stop(); +// +// return stopwatch.ElapsedMilliseconds; +// }; +// +// Console.WriteLine(@"Elapsed time to perform action without tree view: " + processingAction()); +// +// var treeView = new TreeView(); +// treeView.RegisterNodePresenter(new ChildNodePresenter()); +// +// // expand / collapse / expand +// treeView.ExpandAll(); +// +// double elapsedMillisecondsWithTreeView = 0; +// Action onShow = delegate +// { +// var stopwatch = new Stopwatch(); +// stopwatch.Start(); +// +// elapsedMillisecondsWithTreeView = processingAction(); +// Console.WriteLine(@"Elapsed time to perform action with tree view: " + elapsedMillisecondsWithTreeView); +// +// stopwatch.Stop(); +// Console.WriteLine(@"Elapsed time to refresh tree view: " + stopwatch.ElapsedMilliseconds); +// }; +// +// WindowsFormsTestHelper.ShowModal(treeView, onShow); +// +// TestHelper.AssertIsFasterThan(10, () => Thread.Sleep((int) elapsedMillisecondsWithTreeView)); +// } +// +// [Test] +// public void RegisterNodePresenter_NodePresenterNotRegisteredYet_NodePresenterAddedToAvailablePresenters() +// { +// // Setup +// var mocks = new MockRepository(); +// var nodePresenter = mocks.Stub(); +// mocks.ReplayAll(); +// +// var treeView = new TreeView(); +// +// // Call +// treeView.RegisterNodePresenter(nodePresenter); +// +// // Assert +// CollectionAssert.Contains(treeView.NodePresenters, nodePresenter); +// Assert.AreEqual(1, treeView.NodePresenters.Count()); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void RegisterNodePresenter_NodePresenterAlreadyRegistered_DoNothing() +// { +// // Setup +// var mocks = new MockRepository(); +// var nodePresenter = mocks.Stub(); +// mocks.ReplayAll(); +// +// var treeView = new TreeView(); +// +// // Call +// treeView.RegisterNodePresenter(nodePresenter); +// treeView.RegisterNodePresenter(nodePresenter); +// +// // Assert +// CollectionAssert.Contains(treeView.NodePresenters, nodePresenter); +// Assert.AreEqual(1, treeView.NodePresenters.Count()); +// mocks.VerifyAll(); +// } +// +// private class DynamicParentNodePresenter : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, Parent nodeData) +// { +// node.Text = nodeData.Name; +// } +// +// public override IEnumerable GetChildNodeObjects(Parent parentNodeData) +// { +// // always returns a single child with the same name +// yield return new Child +// { +// Name = "child", Children = +// { +// new Child +// { +// Name = "grandchild" +// } +// } +// }; +// } +// } +// +// private class Parent : Observable +// { +// public readonly IList Children = new List(); +// public string Name { get; set; } +// } +// +// private class Child : Observable +// { +// public Child() +// { +// Children = new List(); +// } +// +// public string Name { get; set; } +// public IList Children { get; set; } +// } +// +// private class ParentNodePresenter : TreeViewNodePresenterBase +// { +// public override void UpdateNode(TreeNode parentNode, TreeNode node, Parent nodeData) +// { +// node.Text = nodeData.Name; +// } +// +// public override IEnumerable GetChildNodeObjects(Parent parentNodeData) +// { +// return parentNodeData.Children; +// } +// } +// +// private class ChildNodePresenter : TreeViewNodePresenterBase +// { +// public event EventHandler AfterUpdate; +// +// /// +// /// Specifies if node can be deleted by user +// /// +// protected override bool CanRemove(Child nodeData) +// { +// return true; +// } +// +// protected override bool RemoveNodeData(object parentNodeData, Child nodeData) +// { +// if (parentNodeData is Parent) +// { +// ((Parent)parentNodeData).Children.Remove(nodeData); +// ((Parent)parentNodeData).NotifyObservers(); +// } +// else +// { +// if (parentNodeData is Child) +// { +// ((Child)parentNodeData).Children.Remove(nodeData); +// ((Child)parentNodeData).NotifyObservers(); +// } +// } +// +// return true; +// } +// +// public override void UpdateNode(TreeNode parentNode, TreeNode node, Child nodeData) +// { +// node.Text = nodeData.Name; +// +// if (AfterUpdate != null) +// { +// AfterUpdate(this, null); +// } +// } +// +// public override IEnumerable GetChildNodeObjects(Child parentNodeData) +// { +// return parentNodeData.Children; +// } +// } +// } +//} \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderTest.cs =================================================================== diff -u -re96306bc32984aa50c6d1162167214024ddcf59a -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderTest.cs (.../ContextMenuBuilderTest.cs) (revision e96306bc32984aa50c6d1162167214024ddcf59a) +++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderTest.cs (.../ContextMenuBuilderTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,12 +1,10 @@ -using System.Collections.Generic; -using System.Windows.Forms; +using System.Windows.Forms; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Properties; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; namespace Core.Common.Gui.Test.ContextMenu { @@ -25,7 +23,7 @@ public void Constructor_NoTreeNode_ThrowsContextMenuBuilderException() { // Call - TestDelegate test = () => new ContextMenuBuilder(null, null, null, null); + TestDelegate test = () => new ContextMenuBuilder(null, null, null, null, null); // Assert var message = Assert.Throws(test).Message; @@ -37,12 +35,13 @@ { // Setup var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); var importExportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); mocks.ReplayAll(); // Call - TestDelegate test = () => new ContextMenuBuilder(null, importExportHandlerMock, viewCommandsMock, treeNodeMock); + TestDelegate test = () => new ContextMenuBuilder(null, importExportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Assert var message = Assert.Throws(test).Message; @@ -56,12 +55,13 @@ { // Setup var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); var applicationFeatureCommandsMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); mocks.ReplayAll(); // Call - TestDelegate test = () => new ContextMenuBuilder(applicationFeatureCommandsMock, null, viewCommandsMock, treeNodeMock); + TestDelegate test = () => new ContextMenuBuilder(applicationFeatureCommandsMock, null, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Assert var message = Assert.Throws(test).Message; @@ -77,10 +77,11 @@ var applicationFeatureCommandsMockMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); mocks.ReplayAll(); // Call - TestDelegate test = () => new ContextMenuBuilder(applicationFeatureCommandsMockMock, exportImportHandlerMock, null, treeNodeMock); + TestDelegate test = () => new ContextMenuBuilder(applicationFeatureCommandsMockMock, exportImportHandlerMock, null, treeNodeMock, treeNodeInfoMock); // Assert var message = Assert.Throws(test).Message; @@ -97,10 +98,11 @@ var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); mocks.ReplayAll(); // Call - TestDelegate test = () => new ContextMenuBuilder(applicationFeatureCommandsMockMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + TestDelegate test = () => new ContextMenuBuilder(applicationFeatureCommandsMockMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Assert Assert.DoesNotThrow(test); @@ -116,9 +118,10 @@ var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMockMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMockMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Call var result = builder.Build(); @@ -137,16 +140,14 @@ var applicationFeatureCommandsMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); - - var treeNodePresenterMock = mocks.StrictMock(); var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); - treeNodeMock.Expect(tn => tn.Presenter).Return(treeNodePresenterMock); - treeNodePresenterMock.Expect(tn => tn.CanRenameNode(treeNodeMock)).Return(true); + treeNodeInfoMock.CanRename = treeNode => treeNode == treeNodeMock; mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Call var result = builder.AddRenameItem().Build(); @@ -168,21 +169,21 @@ var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); - var treeNodePresenterMock = mocks.StrictMock(); var treeParentNodeMock = mocks.StrictMock(); var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); - treeNodeMock.Expect(tn => tn.Parent).Return(treeParentNodeMock); - treeNodeMock.Expect(tn => tn.Presenter).Return(treeNodePresenterMock); + treeNodeMock.Stub(tn => tn.Parent).Return(treeParentNodeMock); var nodeData = new object(); var parentData = new object(); treeNodeMock.Expect(tn => tn.Tag).Return(nodeData); treeParentNodeMock.Expect(tn => tn.Tag).Return(parentData); - treeNodePresenterMock.Expect(tn => tn.CanRemove(parentData, nodeData)).Return(true); + treeNodeInfoMock.CanRemove = (nd, pnd) => nd == nodeData && pnd == parentData; + mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Call var result = builder.AddDeleteItem().Build(); @@ -205,17 +206,17 @@ var applicationFeatureCommandsMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); - var treeNodeMock = mocks.StrictMock(); - IList children = new List(); + var treeNode= new TreeNode(); + var treeNodeInfoMock = mocks.StrictMock(); + if (hasChildren) { - children.Add(treeNodeMock); + treeNode.Nodes.Add(new TreeNode()); } - treeNodeMock.Expect(tn => tn.Nodes).Return(children); mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNode, treeNodeInfoMock); // Call var result = builder.AddExpandAllItem().Build(); @@ -238,17 +239,17 @@ var applicationFeatureCommandsMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); - var treeNodeMock = mocks.StrictMock(); - IList children = new List(); + var treeNode = new TreeNode(); + var treeNodeInfoMock = mocks.StrictMock(); + if (hasChildren) { - children.Add(treeNodeMock); + treeNode.Nodes.Add(new TreeNode()); } - treeNodeMock.Expect(tn => tn.Nodes).Return(children); mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNode, treeNodeInfoMock); // Call var result = builder.AddCollapseAllItem().Build(); @@ -272,6 +273,7 @@ var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); var treeNodeMock = mocks.Stub(); + var treeNodeInfoMock = mocks.Stub(); var nodeData = new object(); viewCommandsMock.Expect(ch => ch.CanOpenViewFor(nodeData)).Return(hasViewForNodeData); @@ -280,7 +282,7 @@ treeNodeMock.Tag = nodeData; - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Call var result = builder.AddOpenItem().Build(); @@ -305,13 +307,14 @@ var viewCommandsMock = mocks.StrictMock(); var nodeData = new object(); var treeNodeMock = mocks.Stub(); + var treeNodeInfoMock = mocks.Stub(); exportImportHandlerMock.Expect(ch => ch.CanExportFrom(nodeData)).Return(hasExportersForNodeData); mocks.ReplayAll(); treeNodeMock.Tag = nodeData; - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Call var result = builder.AddExportItem().Build(); @@ -336,13 +339,14 @@ var viewCommandsMock = mocks.StrictMock(); var nodeData = new object(); var treeNodeMock = mocks.Stub(); + var treeNodeInfoMock = mocks.Stub(); exportImportHandlerMock.Expect(ch => ch.CanImportOn(nodeData)).Return(hasImportersForNodeData); mocks.ReplayAll(); treeNodeMock.Tag = nodeData; - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Call var result = builder.AddImportItem().Build(); @@ -367,14 +371,15 @@ var viewCommandsMock = mocks.StrictMock(); var nodeData = new object(); var treeNodeMock = mocks.Stub(); + var treeNodeInfoMock = mocks.Stub(); applicationFeatureCommandsMock.Expect(ch => ch.CanShowPropertiesFor(nodeData)).Return(hasPropertiesForNodeData); mocks.ReplayAll(); treeNodeMock.Tag = nodeData; - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Call var result = builder.AddPropertiesItem().Build(); @@ -393,12 +398,13 @@ { // Setup var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.Stub(); var applicationFeatureCommandsMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); var item = new StrictContextMenuItem(null,null,null,null); // Call @@ -418,12 +424,13 @@ { // Setup var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.Stub(); var applicationFeatureCommandsMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); // Call var result = builder.AddSeparator().Build(); @@ -442,12 +449,13 @@ { // Setup var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.Stub(); var applicationFeatureCommandsMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); var someItem = new StrictContextMenuItem(null, null, null, null); @@ -474,12 +482,13 @@ { // Setup var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.Stub(); var applicationFeatureCommandsMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); var someItem = new StrictContextMenuItem(null, null, null, null); var someOtherItem = new StrictContextMenuItem(null, null, null, null); @@ -510,12 +519,13 @@ { // Setup var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.Stub(); var applicationFeatureCommandsMock = mocks.StrictMock(); var exportImportHandlerMock = mocks.StrictMock(); var viewCommandsMock = mocks.StrictMock(); mocks.ReplayAll(); - var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock); + var builder = new ContextMenuBuilder(applicationFeatureCommandsMock, exportImportHandlerMock, viewCommandsMock, treeNodeMock, treeNodeInfoMock); builder.AddCustomItem(new StrictContextMenuItem(null, null, null, null)); Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs =================================================================== diff -u -r9cd7d7c7ebb37cca5cb0d1e3016da81a2cdf5e00 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision 9cd7d7c7ebb37cca5cb0d1e3016da81a2cdf5e00) +++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/GuiContextMenuItemFactoryTest.cs (.../GuiContextMenuItemFactoryTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,5 +1,5 @@ using System; -using Core.Common.Controls.TreeView; +using System.Windows.Forms; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Properties; using Core.Common.TestUtil; Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/TreeViewContextMenuItemFactoryTest.cs =================================================================== diff -u -rd7da4fd9051547085f0cbbec790eda9cb8ca7f14 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Gui.Test/ContextMenu/TreeViewContextMenuItemFactoryTest.cs (.../TreeViewContextMenuItemFactoryTest.cs) (revision d7da4fd9051547085f0cbbec790eda9cb8ca7f14) +++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/TreeViewContextMenuItemFactoryTest.cs (.../TreeViewContextMenuItemFactoryTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,16 +1,18 @@ using System; -using System.Collections.Generic; +using System.Windows.Forms; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Properties; using Core.Common.TestUtil; +using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; +using TreeView = Core.Common.Controls.TreeView.TreeView; namespace Core.Common.Gui.Test.ContextMenu { [TestFixture] - public class TreeViewContextMenuItemFactoryTest + public class TreeViewContextMenuItemFactoryTest : NUnitFormTest { private MockRepository mocks; @@ -23,8 +25,11 @@ [Test] public void Constructor_WithoutTreeNode_ThrowsArgumentNullException() { + // Setup + var treeNodeInfoMock = mocks.StrictMock(); + // Call - TestDelegate test = () => new TreeViewContextMenuItemFactory(null); + TestDelegate test = () => new TreeViewContextMenuItemFactory(null, treeNodeInfoMock); // Assert var message = Assert.Throws(test).Message; @@ -33,15 +38,33 @@ } [Test] + public void Constructor_WithoutTreeNodeInfo_ThrowsArgumentNullException() + { + // Setup + var treeNodeMock = mocks.StrictMock(); + + mocks.ReplayAll(); + + // Call + TestDelegate test = () => new TreeViewContextMenuItemFactory(treeNodeMock, null); + + // Assert + var message = Assert.Throws(test).Message; + StringAssert.StartsWith(Resources.ContextMenuItemFactory_Can_not_create_context_menu_items_without_tree_node_info, message); + StringAssert.EndsWith("treeNodeInfo", message); + } + + [Test] public void Constructor_WithTreeNode_DoesNotThrow() { // Setup - var strictMock = mocks.StrictMock(); + var treeNodeMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); mocks.ReplayAll(); - + // Call - TestDelegate test = () => new TreeViewContextMenuItemFactory(strictMock); + TestDelegate test = () => new TreeViewContextMenuItemFactory(treeNodeMock, treeNodeInfoMock); // Assert Assert.DoesNotThrow(test); @@ -55,28 +78,44 @@ public void CreateDeleteItem_DependingOnCanDelete_ItemWithDeleteFunctionWillBeEnabled(bool canDelete) { // Setup + var treeView = new TreeView(); var treeNodeMock = mocks.StrictMock(); var treeParentNodeMock = mocks.StrictMock(); - var treeNodePresenterMock = mocks.StrictMock(); - var treeViewMock = mocks.StrictMock(); - var arg1 = new object(); - var arg2 = new object(); + var treeNodeInfoMock = mocks.StrictMock(); - treeNodeMock.Expect(tn => tn.Presenter).Return(treeNodePresenterMock); - treeNodeMock.Expect(tn => tn.Parent).Return(treeParentNodeMock); - treeNodeMock.Expect(tn => tn.Tag).Return(arg2); - treeParentNodeMock.Expect(tn => tn.Tag).Return(arg1); - treeNodePresenterMock.Expect(tnp => tnp.CanRemove(arg1, arg2)).Return(canDelete); + var parentNodeData = new object(); + var nodeData = new object(); + treeNodeMock.Stub(tn => tn.Text).Return(""); + treeNodeMock.Stub(tn => tn.Parent).Return(treeParentNodeMock); + treeNodeMock.Stub(tn => tn.Tag).Return(nodeData); + treeParentNodeMock.Stub(tn => tn.Tag).Return(parentNodeData); + + treeNodeInfoMock.CanRemove = (nd, pnd) => + { + if (nd == nodeData && pnd == parentNodeData) + { + return canDelete; + } + + return !canDelete; + }; + if (canDelete) { - treeNodeMock.Expect(tn => tn.TreeView).Return(treeViewMock); - treeViewMock.Expect(tv => tv.TryDeleteNodeData(treeNodeMock)); + treeNodeMock.Expect(tn => tn.TreeView).Return(treeView); + + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + + messageBox.ClickOk(); + }; } mocks.ReplayAll(); - var factory = new TreeViewContextMenuItemFactory(treeNodeMock); + var factory = new TreeViewContextMenuItemFactory(treeNodeMock, treeNodeInfoMock); // Call var item = factory.CreateDeleteItem(); @@ -98,21 +137,26 @@ { // Setup var treeNodeMock = mocks.StrictMock(); - var treeNodePresenterMock = mocks.StrictMock(); - var treeViewMock = mocks.StrictMock(); + var treeNodeInfoMock = mocks.StrictMock(); - treeNodeMock.Expect(tn => tn.Presenter).Return(treeNodePresenterMock); - treeNodePresenterMock.Expect(tnp => tnp.CanRenameNode(treeNodeMock)).Return(canRename); + treeNodeInfoMock.CanRename = tn => + { + if (tn == treeNodeMock) + { + return canRename; + } + return !canRename; + }; + if (canRename) { - treeNodeMock.Expect(tn => tn.TreeView).Return(treeViewMock); - treeViewMock.Expect(tv => tv.StartLabelEdit(treeNodeMock)); + treeNodeMock.Expect(tv => tv.BeginEdit()); } mocks.ReplayAll(); - var factory = new TreeViewContextMenuItemFactory(treeNodeMock); + var factory = new TreeViewContextMenuItemFactory(treeNodeMock, treeNodeInfoMock); // Call var item = factory.CreateRenameItem(); @@ -133,25 +177,22 @@ public void CreateExpandAllItem_DependingOnChildNodes_ItemWithExpandFunctionWillBeEnabled(bool hasChildren) { // Setup - var treeNodeMock = mocks.StrictMock(); - var treeViewMock = mocks.StrictMock(); - if (hasChildren) - { - treeNodeMock.Expect(tn => tn.TreeView).Return(treeViewMock); - treeViewMock.Expect(tv => tv.ExpandAll(treeNodeMock)); - } + var treeNode = new TreeNode(); + var treeView = new TreeView(); + var treeNodeInfo = new TreeNodeInfo(); - var children = new List(); + treeView.Nodes.Add(treeNode); if (hasChildren) { - children.Add(mocks.StrictMock()); + treeNode.Nodes.Add(new TreeNode()); + treeNodeInfo.ChildNodeObjects = o => new object[] { new TreeNode() }; } - treeNodeMock.Expect(tn => tn.Nodes).Return(children); - mocks.ReplayAll(); + var factory = new TreeViewContextMenuItemFactory(treeNode, treeNodeInfo); - var factory = new TreeViewContextMenuItemFactory(treeNodeMock); + // Precondition + Assert.IsFalse(treeNode.IsExpanded); // Call var item = factory.CreateExpandAllItem(); @@ -162,6 +203,7 @@ Assert.AreEqual(Resources.Expand_all_ToolTip, item.ToolTipText); TestHelper.AssertImagesAreEqual(Resources.ExpandAllIcon, item.Image); Assert.AreEqual(hasChildren, item.Enabled); + Assert.AreEqual(hasChildren, treeNode.IsExpanded); mocks.VerifyAll(); } @@ -172,26 +214,24 @@ public void CreateCollapseAllItem_DependingOnChildNodes_ItemWithCollapseFunctionWillBeEnabled(bool hasChildren) { // Setup - var treeNodeMock = mocks.StrictMock(); - var treeViewMock = mocks.StrictMock(); - if (hasChildren) - { - treeNodeMock.Expect(tn => tn.TreeView).Return(treeViewMock); - treeViewMock.Expect(tv => tv.CollapseAll(treeNodeMock)); - } - var children = new List(); + var treeNode = new TreeNode(); + var treeView = new TreeView(); + var treeNodeInfo = new TreeNodeInfo(); + treeView.Nodes.Add(treeNode); + if (hasChildren) { - children.Add(mocks.StrictMock()); + treeNode.Expand(); + treeNode.Nodes.Add(new TreeNode()); + treeNodeInfo.ChildNodeObjects = o => new object[] { new TreeNode() }; + + // Precondition + Assert.IsTrue(treeNode.IsExpanded); } - treeNodeMock.Expect(tn => tn.Nodes).Return(children); + var factory = new TreeViewContextMenuItemFactory(treeNode, treeNodeInfo); - mocks.ReplayAll(); - - var factory = new TreeViewContextMenuItemFactory(treeNodeMock); - // Call var item = factory.CreateCollapseAllItem(); item.PerformClick(); @@ -201,6 +241,7 @@ Assert.AreEqual(Resources.Collapse_all_ToolTip, item.ToolTipText); TestHelper.AssertImagesAreEqual(Resources.CollapseAllIcon, item.Image); Assert.AreEqual(hasChildren, item.Enabled); + Assert.IsFalse(treeNode.IsExpanded); mocks.VerifyAll(); } Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -r770547be3030f73473282742f9a63ca6805ff74b -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 770547be3030f73473282742f9a63ca6805ff74b) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -37,6 +37,9 @@ ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True + + ..\..\..\..\lib\NUnitForms.dll + Index: Core/Common/test/Core.Common.Gui.TestUtil/ContextMenu/SimpleContextMenuBuilderProvider.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Common/test/Core.Common.Gui.TestUtil/ContextMenu/SimpleContextMenuBuilderProvider.cs (.../SimpleContextMenuBuilderProvider.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Core/Common/test/Core.Common.Gui.TestUtil/ContextMenu/SimpleContextMenuBuilderProvider.cs (.../SimpleContextMenuBuilderProvider.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,4 +1,5 @@ using System; +using System.Windows.Forms; using Core.Common.Controls.TreeView; using Core.Common.Gui.ContextMenu; @@ -26,7 +27,7 @@ this.contextMenuBuilder = contextMenuBuilder; } - public IContextMenuBuilder Get(TreeNode treeNode) + public IContextMenuBuilder Get(TreeNode treeNode, TreeNodeInfo treeNodeInfo) { return contextMenuBuilder; } Index: Core/Plugins/src/Core.Plugins.OxyPlot/Core.Plugins.OxyPlot.csproj =================================================================== diff -u -rc5672681b9872a622ff718acd6975118ad59474f -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/src/Core.Plugins.OxyPlot/Core.Plugins.OxyPlot.csproj (.../Core.Plugins.OxyPlot.csproj) (revision c5672681b9872a622ff718acd6975118ad59474f) +++ Core/Plugins/src/Core.Plugins.OxyPlot/Core.Plugins.OxyPlot.csproj (.../Core.Plugins.OxyPlot.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -67,9 +67,6 @@ ChartDataView.cs - - - Component @@ -82,8 +79,6 @@ - - Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.OxyPlot/Legend/AreaDataNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.OxyPlot/Legend/ChartDataNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.OxyPlot/Legend/ChartNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendController.cs =================================================================== diff -u -r002ceaccea1dc8e92d6e88d41dd39b1f5d7b7e0d -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendController.cs (.../LegendController.cs) (revision 002ceaccea1dc8e92d6e88d41dd39b1f5d7b7e0d) +++ Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendController.cs (.../LegendController.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,7 +1,5 @@ using System; -using System.Resources; using Core.Common.Controls.Views; -using Core.Components.Charting; using Core.Components.Charting.Data; using Core.Components.OxyPlot.Forms; Index: Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendTreeView.cs =================================================================== diff -u -re4f84ca3793e7f556bca95eaeb294d22b13cdf51 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendTreeView.cs (.../LegendTreeView.cs) (revision e4f84ca3793e7f556bca95eaeb294d22b13cdf51) +++ Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LegendTreeView.cs (.../LegendTreeView.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,6 +1,12 @@ -using Core.Common.Controls.TreeView; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; using Core.Components.Charting.Data; using Core.Components.OxyPlot.Forms; +using OxyPlotResources = Core.Plugins.OxyPlot.Properties.Resources; +using GuiResources = Core.Common.Gui.Properties.Resources; +using TreeView = Core.Common.Controls.TreeView.TreeView; namespace Core.Plugins.OxyPlot.Legend { @@ -14,10 +20,45 @@ /// public LegendTreeView() { - RegisterNodePresenter(new LineDataNodePresenter()); - RegisterNodePresenter(new PointDataNodePresenter()); - RegisterNodePresenter(new AreaDataNodePresenter()); - RegisterNodePresenter(new ChartNodePresenter()); + TreeViewController.RegisterTreeNodeInfo(new TreeNodeInfo + { + Text = pointData => OxyPlotResources.ChartDataNodePresenter_Point_data_label, + Image = pointData => OxyPlotResources.PointsIcon, + CanDrag = (pointData, sourceNode) => DragOperations.Move, + CanCheck = pointData => true, + IsChecked = pointData => pointData.IsVisible, + OnNodeChecked = PointBasedChartDataOnNodeChecked + }); + + TreeViewController.RegisterTreeNodeInfo(new TreeNodeInfo + { + Text = lineData => OxyPlotResources.ChartDataNodePresenter_Line_data_label, + Image = lineData => OxyPlotResources.LineIcon, + CanDrag = (lineData, sourceNode) => DragOperations.Move, + CanCheck = lineData => true, + IsChecked = lineData => lineData.IsVisible, + OnNodeChecked = PointBasedChartDataOnNodeChecked + }); + + TreeViewController.RegisterTreeNodeInfo(new TreeNodeInfo + { + Text = areaData => OxyPlotResources.ChartDataNodePresenter_Area_data_label, + Image = areaData => OxyPlotResources.AreaIcon, + CanDrag = (areaData, sourceNode) => DragOperations.Move, + CanCheck = areaData => true, + IsChecked = areaData => areaData.IsVisible, + OnNodeChecked = PointBasedChartDataOnNodeChecked + }); + + TreeViewController.RegisterTreeNodeInfo(new TreeNodeInfo + { + Text = baseChart => OxyPlotResources.General_Chart, + Image = baseChart => GuiResources.folder, + ChildNodeObjects = baseChart => baseChart.List.Reverse().Cast().ToArray(), + CanDrop = BaseChartCanDrop, + CanInsert = BaseChartCanInsert, + OnDrop = BaseChartOnDrop + }); } /// @@ -27,11 +68,11 @@ { get { - return (ChartData) Data; + return (ChartData) TreeViewController.Data; } set { - Data = value; + TreeViewController.Data = value; if (value == null) { @@ -42,8 +83,55 @@ protected override void Dispose(bool disposing) { - Data = null; + ChartData = null; base.Dispose(disposing); } + + # region ChartData + + private void PointBasedChartDataOnNodeChecked(TreeNode node) + { + var pointBasedChartData = node.Tag as PointBasedChartData; + if (pointBasedChartData != null) + { + pointBasedChartData.IsVisible = node.Checked; + + var parentData = node.Parent != null ? node.Parent.Tag as IObservable : null; + if (parentData != null) + { + parentData.NotifyObservers(); + } + } + } + + # endregion + + # region ChartDataCollection + + private DragOperations BaseChartCanDrop(TreeNode sourceNode, TreeNode targetNode, DragOperations validOperations) + { + if (sourceNode.Tag is ChartData) + { + return validOperations; + } + + return DragOperations.None; + } + + private bool BaseChartCanInsert(TreeNode sourceNode, TreeNode targetNode) + { + return sourceNode.Tag is ChartData; + } + + private void BaseChartOnDrop(TreeNode sourceNode, TreeNode targetNode, DragOperations operation, int position) + { + var draggedData = (ChartData) sourceNode.Tag; + var target = (ChartDataCollection) targetNode.Tag; + target.List.Remove(draggedData); + target.List.Insert(target.List.Count - position, draggedData); + target.NotifyObservers(); + } + + # endregion } } \ No newline at end of file Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.OxyPlot/Legend/LineDataNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.OxyPlot/Legend/PointDataNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/Core.Plugins.ProjectExplorer.csproj =================================================================== diff -u -r232a51f976c9b38d71ed9eb959bcf4004cbb4ded -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/src/Core.Plugins.ProjectExplorer/Core.Plugins.ProjectExplorer.csproj (.../Core.Plugins.ProjectExplorer.csproj) (revision 232a51f976c9b38d71ed9eb959bcf4004cbb4ded) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/Core.Plugins.ProjectExplorer.csproj (.../Core.Plugins.ProjectExplorer.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -88,8 +88,6 @@ - - UserControl Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/src/Core.Plugins.ProjectExplorer/NodePresenters/ProjectNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs =================================================================== diff -u -r6e66175397887e29939dfbab9cad678db91011b6 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs (.../ProjectExplorer.cs) (revision 6e66175397887e29939dfbab9cad678db91011b6) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs (.../ProjectExplorer.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -65,7 +65,7 @@ public void ScrollTo(object o) { - var nodeToSelect = TreeView.GetNodeByTag(o); + var nodeToSelect = TreeView.TreeViewController.GetNodeByTag(o); if (nodeToSelect == null) { Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs =================================================================== diff -u -r6e66175397887e29939dfbab9cad678db91011b6 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs (.../ProjectExplorerGuiPlugin.cs) (revision 6e66175397887e29939dfbab9cad678db91011b6) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorerGuiPlugin.cs (.../ProjectExplorerGuiPlugin.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,21 +1,17 @@ -using System; using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; using Core.Common.Controls.TreeView; using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms; -using Core.Common.Gui.Properties; using Core.Common.Utils.Extensions; -using Core.Plugins.ProjectExplorer.Exceptions; -using Core.Plugins.ProjectExplorer.NodePresenters; +using ProjectExplorerResources = Core.Plugins.ProjectExplorer.Properties.Resources; namespace Core.Plugins.ProjectExplorer { public class ProjectExplorerGuiPlugin : GuiPlugin { - private readonly IList projectTreeViewNodePresenters; - private IToolViewController toolViewController; private IDocumentViewController documentViewController; private IViewCommands viewCommands; @@ -27,7 +23,6 @@ public ProjectExplorerGuiPlugin() { Instance = this; - projectTreeViewNodePresenters = new List(); } public override IRibbonCommandHandler RibbonCommandHandler @@ -72,18 +67,34 @@ } } - /// - /// Get the defined for the . - /// - /// An of . - /// Thrown when either: - /// - /// is null - /// is null - /// - public override IEnumerable GetProjectTreeViewNodePresenters() + public override IEnumerable GetTreeNodeInfos() { - yield return new ProjectNodePresenter(Gui, projectCommands); + yield return new TreeNodeInfo + { + Text = project => project.Name, + Image = project => ProjectExplorerResources.Project, + ChildNodeObjects = project => project.Items.ToArray(), + ContextMenuStrip = (project, sourceNode, treeNodeInfo) => + { + var addItem = new StrictContextMenuItem( + ProjectExplorerResources.AddItem, + ProjectExplorerResources.AddItem_ToolTip, + ProjectExplorerResources.plus, + (s, e) => Gui.ProjectCommands.AddNewItem(project)); + + return Gui.Get(sourceNode, treeNodeInfo) + .AddCustomItem(addItem) + .AddSeparator() + .AddImportItem() + .AddExportItem() + .AddSeparator() + .AddExpandAllItem() + .AddCollapseAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + }; } public override IEnumerable GetChildDataWithViewDefinitions(object dataObject) @@ -104,14 +115,16 @@ public void InitializeProjectTreeView() { - if ((ProjectExplorer == null) || (ProjectExplorer.IsDisposed)) + if (ProjectExplorer == null || ProjectExplorer.IsDisposed) { ProjectExplorer = new ProjectExplorer(applicationSelection, viewCommands, projectOwner, documentViewController); - UpdateProjectTreeViewWithRegisteredNodePresenters(); + Gui.Plugins + .SelectMany(pluginGui => pluginGui.GetTreeNodeInfos()) + .ForEachElementDo(tni => ProjectExplorer.ProjectTreeView.TreeView.TreeViewController.RegisterTreeNodeInfo(tni)); ProjectExplorer.ProjectTreeView.Project = projectOwner.Project; - ProjectExplorer.ProjectTreeView.TreeView.OnUpdate += (s, e) => documentViewController.UpdateToolTips(); + ProjectExplorer.ProjectTreeView.TreeView.TreeViewController.NodeUpdated += (s, e) => documentViewController.UpdateToolTips(); ProjectExplorer.Text = Properties.Resources.ProjectExplorerPluginGui_InitializeProjectTreeView_Project_Explorer; } @@ -123,8 +136,6 @@ { base.Activate(); - FillProjectTreeViewNodePresentersFromPlugins(); - InitializeProjectTreeView(); projectOwner.ProjectOpened += ApplicationProjectOpened; @@ -139,11 +150,6 @@ ProjectExplorer = null; } - foreach (var projectTreeViewNodePresenter in projectTreeViewNodePresenters) - { - projectTreeViewNodePresenter.TreeView = null; - } - projectTreeViewNodePresenters.Clear(); base.Dispose(); } @@ -153,29 +159,8 @@ projectOwner.ProjectOpened -= ApplicationProjectOpened; projectOwner.ProjectClosing -= ApplicationProjectClosed; toolViewController.ToolWindowViews.Remove(ProjectExplorer); - - //should the 'instance' be set to null as well??? } - /// - /// Query all node presenters from and registers them. - /// - private void FillProjectTreeViewNodePresentersFromPlugins() - { - var pluginGuis = guiPluginsHost.Plugins; - - try - { - pluginGuis - .SelectMany(pluginGui => pluginGui.GetProjectTreeViewNodePresenters()) - .ForEachElementDo(np => projectTreeViewNodePresenters.Add(np)); - } - catch (ArgumentNullException e) - { - throw new ProjectExplorerGuiPluginException(Resources.ProjectExplorerGuiPlugin_FillProjectTreeViewNodePresentersFromPlugins_Could_not_retrieve_NodePresenters_for_a_plugin, e); - } - } - private void ApplicationProjectClosed(Project project) { ProjectExplorer.ProjectTreeView.Project = null; @@ -185,13 +170,5 @@ { ProjectExplorer.ProjectTreeView.Project = project; } - - private void UpdateProjectTreeViewWithRegisteredNodePresenters() - { - foreach (var np in projectTreeViewNodePresenters) - { - ProjectExplorer.ProjectTreeView.TreeView.RegisterNodePresenter(np); - } - } } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectTreeView.cs =================================================================== diff -u -ra6df46f9508fcedf716bb84ec0076d7df104155f -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectTreeView.cs (.../ProjectTreeView.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) +++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectTreeView.cs (.../ProjectTreeView.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,9 +1,9 @@ using System; using System.Windows.Forms; using Core.Common.Base.Data; +using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; using Core.Common.Gui; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; using TreeView = Core.Common.Controls.TreeView.TreeView; namespace Core.Plugins.ProjectExplorer @@ -42,16 +42,15 @@ { AllowDrop = true }; - treeView.DataDeleted += ProjectDataDeleted; + treeView.TreeViewController.TreeNodeDoubleClick += TreeViewDoubleClick; + + treeView.TreeViewController.NodeDataDeleted += ProjectDataDeleted; treeView.NodeMouseClick += TreeViewNodeMouseClick; - treeView.DoubleClick += TreeViewDoubleClick; - treeView.SelectedNodeChanged += TreeViewSelectedNodeChanged; + treeView.AfterSelect += TreeViewSelectedNodeChanged; treeView.Dock = DockStyle.Fill; - treeView.OnProcessCmdKey = OnProcessCmdKey; - Controls.Add(treeView); } @@ -90,7 +89,7 @@ } project = value as Project; - treeView.Data = project; + treeView.TreeViewController.Data = project; if (project != null) { @@ -108,7 +107,7 @@ UnsubscribeProjectEvents(); } - treeView.Data = null; + treeView.TreeViewController.Data = null; treeView.Dispose(); base.Dispose(); @@ -127,7 +126,7 @@ return; } - TreeNode node = treeView.GetNodeByTag(applicationSelection.Selection); + TreeNode node = treeView.TreeViewController.GetNodeByTag(applicationSelection.Selection); if (node != null) { treeView.SelectedNode = node; @@ -145,43 +144,9 @@ selectingNode = false; } - private bool OnProcessCmdKey(Keys keyData) - { - if (treeView.SelectedNode == null) - { - return false; - } - - if (keyData == Keys.Enter) - { - viewCommands.OpenViewForSelection(); - - return true; - } - - if (keyData == Keys.Delete) - { - treeView.TryDeleteSelectedNodeData(); - - return true; - } - - if (keyData == Keys.Escape) - { - if (documentViewController.DocumentViews.ActiveView != null) - { - ((Control)documentViewController.DocumentViews.ActiveView).Focus(); - } - - return true; - } - - return false; - } - private void TreeViewNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { - treeView.SelectedNode = ((TreeNode) e.Node); + treeView.SelectedNode = e.Node; } private void SubscribeProjectEvents() @@ -203,13 +168,13 @@ { if (!Equals(applicationSelection.Selection, TreeView.SelectedNode.Tag)) { - // Necessary if WinForms skips single click event (see TOOLS-8722)... + // Necessary if WinForms skips single click event applicationSelection.Selection = TreeView.SelectedNode.Tag; } viewCommands.OpenViewForSelection(); } - private void ProjectDataDeleted(object sender, TreeView.TreeViewDataDeletedEventArgs e) + private void ProjectDataDeleted(object sender, TreeNodeDataDeletedEventArgs e) { viewCommands.RemoveAllViewsForItem(e.DeletedDataInstance); } Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/ChartingRibbonTest.cs =================================================================== diff -u -rf9058d5293ecb785069c5b6b4c554dc6800ee771 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/ChartingRibbonTest.cs (.../ChartingRibbonTest.cs) (revision f9058d5293ecb785069c5b6b4c554dc6800ee771) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/ChartingRibbonTest.cs (.../ChartingRibbonTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -265,7 +265,7 @@ var ribbon = new ChartingRibbon(); chart.Expect(c => c.IsPanningEnabled).Return(buttonChecked).Repeat.Twice(); - chart.Expect(c => c.IsRectangleZoomingEnabled).Return(buttonChecked).Repeat.Twice(); ; + chart.Expect(c => c.IsRectangleZoomingEnabled).Return(buttonChecked).Repeat.Twice(); mocks.ReplayAll(); Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Commands/ToggleLegendViewCommandTest.cs =================================================================== diff -u -ra70fac40e34e16bed007b1d0d4e437d91c89d0cb -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Commands/ToggleLegendViewCommandTest.cs (.../ToggleLegendViewCommandTest.cs) (revision a70fac40e34e16bed007b1d0d4e437d91c89d0cb) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Commands/ToggleLegendViewCommandTest.cs (.../ToggleLegendViewCommandTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,15 +1,10 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Core.Common.Controls.Commands; -using Core.Common.Controls.Views; -using Core.Common.Gui; +using Core.Common.Controls.Commands; using Core.Plugins.OxyPlot.Commands; using Core.Plugins.OxyPlot.Legend; using NUnit.Framework; using Rhino.Mocks; -namespace Core.Plugins.OxyPlot.Test +namespace Core.Plugins.OxyPlot.Test.Commands { [TestFixture] public class ToggleLegendViewCommandTest Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Core.Plugins.OxyPlot.Test.csproj =================================================================== diff -u -ra6cb591651331c7e1a881bea6c41d77553821ab8 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Core.Plugins.OxyPlot.Test.csproj (.../Core.Plugins.OxyPlot.Test.csproj) (revision a6cb591651331c7e1a881bea6c41d77553821ab8) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Core.Plugins.OxyPlot.Test.csproj (.../Core.Plugins.OxyPlot.Test.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -62,14 +62,13 @@ - - - - + + + - + Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/AreaDataNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/AreaDataTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/AreaDataTreeNodeInfoTest.cs (revision 0) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/AreaDataTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,194 @@ +using System; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using Core.Components.Charting.Data; +using Core.Plugins.OxyPlot.Legend; +using Core.Plugins.OxyPlot.Properties; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Plugins.OxyPlot.Test.Legend +{ + [TestFixture] + public class AreaDataTreeNodeInfoTest + { + private MockRepository mocks; + private LegendTreeView legendTreeView; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + legendTreeView = new LegendTreeView(); + info = legendTreeView.TreeViewController.TreeNodeInfos.First(tni => tni.TagType == typeof(AreaData)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(AreaData), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ContextMenuStrip); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Setup + var areaData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var text = info.Text(areaData); + + // Assert + Assert.AreEqual(Resources.ChartDataNodePresenter_Area_data_label, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var areaData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var image = info.Image(areaData); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.AreaIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void CanDrag_Always_ReturnsDragOperationsMove() + { + // Setup + var treeNode = new TreeNode(); + var areaData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var dragOperations = info.CanDrag(areaData, treeNode); + + // Assert + Assert.AreEqual(DragOperations.Move, dragOperations); + + mocks.VerifyAll(); + } + + [Test] + public void CanCheck_Always_ReturnsTrue() + { + // Setup + var areaData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var canCheck = info.CanCheck(areaData); + + // Assert + Assert.IsTrue(canCheck); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void IsChecked_Always_ReturnsAccordingToVisibleStateOfAreaData(bool isVisible) + { + // Setup + var areaData = mocks.StrictMock(Enumerable.Empty>()); + + areaData.IsVisible = isVisible; + + mocks.ReplayAll(); + + // Call + var canCheck = info.IsChecked(areaData); + + // Assert + Assert.AreEqual(isVisible, canCheck); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void OnNodeChecked_AreaDataNodeWithoutParent_SetsAreaDataVisibility(bool initialVisibleState) + { + // Setup + var areaData = mocks.StrictMock(Enumerable.Empty>()); + var areaDataTreeNode = new TreeNode + { + Tag = areaData + }; + + mocks.ReplayAll(); + + areaData.IsVisible = initialVisibleState; + areaDataTreeNode.Checked = !initialVisibleState; + + // Call + info.OnNodeChecked(areaDataTreeNode); + + // Assert + Assert.AreEqual(!initialVisibleState, areaData.IsVisible); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void OnNodeChecked_AreaDataNodeWithObservableParent_SetsAreaDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) + { + // Setup + var observable = mocks.StrictMock(); + var areaData = mocks.StrictMock(Enumerable.Empty>()); + var areaDataTreeNode = new TreeNode + { + Tag = areaData + }; + var parentNode = new TreeNode + { + Tag = observable + }; + + observable.Expect(o => o.NotifyObservers()); + + mocks.ReplayAll(); + + areaData.IsVisible = initialVisibleState; + parentNode.Nodes.Add(areaDataTreeNode); + areaDataTreeNode.Checked = !initialVisibleState; + + // Call + info.OnNodeChecked(areaDataTreeNode); + + // Assert + Assert.AreEqual(!initialVisibleState, areaData.IsVisible); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (revision 0) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,278 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using Core.Components.Charting.Data; +using Core.Plugins.OxyPlot.Legend; +using NUnit.Framework; +using Rhino.Mocks; +using Resources = Core.Plugins.OxyPlot.Properties.Resources; +using GuiResources = Core.Common.Gui.Properties.Resources; + +namespace Core.Plugins.OxyPlot.Test.Legend +{ + [TestFixture] + public class ChartDataCollectionTreeNodeInfoTest + { + private MockRepository mocks; + private LegendTreeView legendTreeView; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + legendTreeView = new LegendTreeView(); + info = legendTreeView.TreeViewController.TreeNodeInfos.First(tni => tni.TagType == typeof(ChartDataCollection)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(ChartDataCollection), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ContextMenuStrip); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Setup + var chartDataCollection = mocks.StrictMock(new List()); + + mocks.ReplayAll(); + + // Call + var text = info.Text(chartDataCollection); + + // Assert + Assert.AreEqual(Resources.General_Chart, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var chartDataCollection = mocks.StrictMock(new List()); + + mocks.ReplayAll(); + + // Call + var image = info.Image(chartDataCollection); + + // Assert + TestHelper.AssertImagesAreEqual(GuiResources.folder, image); + + mocks.VerifyAll(); + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildsOnDataReversed() + { + // Setup + var chartData1 = mocks.StrictMock(); + var chartData2 = mocks.StrictMock(); + var chartData3 = mocks.StrictMock(); + var chartDataCollection = mocks.StrictMock(new List + { + chartData1, + chartData2, + chartData3 + }); + + mocks.ReplayAll(); + + // Call + var objects = info.ChildNodeObjects(chartDataCollection); + + // Assert + CollectionAssert.AreEqual(new[] { chartData3, chartData2, chartData1 }, objects); + + mocks.VerifyAll(); + } + + [Test] + [TestCase(DragOperations.Move)] + [TestCase(DragOperations.None)] + public void CanDrop_SourceNodeTagIsNoChartData_ReturnsDragOperationsNone(DragOperations validDragOperations) + { + // Setup + var chartDataCollection = mocks.StrictMock(new List()); + var targetNode = new TreeNode + { + Tag = chartDataCollection + }; + var sourceNode = new TreeNode { Tag = new object() }; + + mocks.ReplayAll(); + + // Call + var validOperations = info.CanDrop(sourceNode, targetNode, validDragOperations); + + // Assert + Assert.AreEqual(DragOperations.None, validOperations); + + mocks.VerifyAll(); + } + + [Test] + [TestCase(DragOperations.Move)] + [TestCase(DragOperations.None)] + public void CanDrop_SourceNodeTagIsChartData_ReturnsGivenDragOperations(DragOperations validDragOperations) + { + // Setup + var chartData = mocks.StrictMock(); + var chartDataCollection = mocks.StrictMock(new List()); + var targetNode = new TreeNode + { + Tag = chartDataCollection + }; + var sourceNode = new TreeNode { Tag = chartData }; + + mocks.ReplayAll(); + + // Call + var validOperations = info.CanDrop(sourceNode, targetNode, validDragOperations); + + // Assert + Assert.AreEqual(validDragOperations, validOperations); + + mocks.VerifyAll(); + } + + [Test] + public void CanDrop_SourceNodeTagIsNoChartData_ReturnsFalse() + { + // Setup + var chartDataCollection = mocks.StrictMock(new List()); + var targetNode = new TreeNode + { + Tag = chartDataCollection + }; + var sourceNode = new TreeNode { Tag = new object() }; + + mocks.ReplayAll(); + + // Call + var canInsert = info.CanInsert(sourceNode, targetNode); + + // Assert + Assert.IsFalse(canInsert); + + mocks.VerifyAll(); + } + + [Test] + public void CanDrop_SourceNodeTagIsChartData_ReturnsTrue() + { + // Setup + var chartData = mocks.StrictMock(); + var chartDataCollection = mocks.StrictMock(new List()); + var targetNode = new TreeNode + { + Tag = chartDataCollection + }; + var sourceNode = new TreeNode { Tag = chartData }; + + mocks.ReplayAll(); + + // Call + var canInsert = info.CanInsert(sourceNode, targetNode); + + // Assert + Assert.IsTrue(canInsert); + + mocks.VerifyAll(); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void OnDrop_ChartDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + var chartData1 = mocks.StrictMock(); + var chartData2 = mocks.StrictMock(); + var chartData3 = mocks.StrictMock(); + var chartDataCollection = mocks.StrictMock(new List + { + chartData1, + chartData2, + chartData3 + }); + var targetNode = new TreeNode + { + Tag = chartDataCollection + }; + var sourceNode = new TreeNode { Tag = chartData1 }; + + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + chartDataCollection.Attach(observer); + + // Call + info.OnDrop(sourceNode, targetNode, DragOperations.Move, position); + + // Assert + var reversedIndex = 2 - position; + Assert.AreSame(chartData1, chartDataCollection.List.ElementAt(reversedIndex)); + + mocks.VerifyAll(); // UpdateObserver should be called + } + + [Test] + [TestCase(-50)] + [TestCase(-1)] + [TestCase(3)] + [TestCase(50)] + public void OnDrop_ChartDataMovedToPositionOutsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + var chartData1 = mocks.StrictMock(); + var chartData2 = mocks.StrictMock(); + var chartData3 = mocks.StrictMock(); + var chartDataCollection = mocks.StrictMock(new List + { + chartData1, + chartData2, + chartData3 + }); + var targetNode = new TreeNode + { + Tag = chartDataCollection + }; + var sourceNode = new TreeNode { Tag = chartData1 }; + + chartDataCollection.Attach(observer); + + mocks.ReplayAll(); + + // Call + TestDelegate test = () => info.OnDrop(sourceNode, targetNode, DragOperations.Move, position); + + // Assert + Assert.Throws(test); + + mocks.VerifyAll(); // UpdateObserver should be not called + } + } +} \ No newline at end of file Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/ChartDataNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/ChartNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LegendTreeViewTest.cs =================================================================== diff -u -rf06219d23b21e655d547d493092db216c6abc72a -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LegendTreeViewTest.cs (.../LegendTreeViewTest.cs) (revision f06219d23b21e655d547d493092db216c6abc72a) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LegendTreeViewTest.cs (.../LegendTreeViewTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using Core.Common.Base; -using Core.Common.Utils.Reflection; using Core.Components.Charting.Data; using Core.Plugins.OxyPlot.Legend; using NUnit.Framework; @@ -19,11 +16,11 @@ var view = new LegendTreeView(); // Assert - Assert.AreEqual(4, view.NodePresenters.Count()); - Assert.IsInstanceOf(view.NodePresenters.ElementAt(0)); - Assert.IsInstanceOf(view.NodePresenters.ElementAt(1)); - Assert.IsInstanceOf(view.NodePresenters.ElementAt(2)); - Assert.IsInstanceOf(view.NodePresenters.ElementAt(3)); + Assert.AreEqual(4, view.TreeViewController.TreeNodeInfos.Count()); + Assert.AreEqual(typeof(PointData), view.TreeViewController.TreeNodeInfos.ElementAt(0).TagType); + Assert.AreEqual(typeof(LineData), view.TreeViewController.TreeNodeInfos.ElementAt(1).TagType); + Assert.AreEqual(typeof(AreaData), view.TreeViewController.TreeNodeInfos.ElementAt(2).TagType); + Assert.AreEqual(typeof(ChartDataCollection), view.TreeViewController.TreeNodeInfos.ElementAt(3).TagType); Assert.IsNull(view.ChartData); } @@ -40,7 +37,7 @@ tree.Dispose(); // Assert - Assert.IsNull(tree.Data); + Assert.IsNull(tree.ChartData); } private class TestChartData : ChartDataCollection Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LegendViewTest.cs =================================================================== diff -u -r74cd1965818ae9b23da6cad8776b7da2868be4a7 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LegendViewTest.cs (.../LegendViewTest.cs) (revision 74cd1965818ae9b23da6cad8776b7da2868be4a7) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LegendViewTest.cs (.../LegendViewTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -3,7 +3,6 @@ using System.Windows.Forms; using Core.Common.Controls.Views; using Core.Components.Charting.Data; -using Core.Components.OxyPlot.Forms; using Core.Plugins.OxyPlot.Legend; using Core.Plugins.OxyPlot.Properties; using NUnit.Framework; Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LineDataNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LineDataTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LineDataTreeNodeInfoTest.cs (revision 0) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/LineDataTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,174 @@ +using System; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using Core.Components.Charting.Data; +using Core.Plugins.OxyPlot.Legend; +using Core.Plugins.OxyPlot.Properties; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Plugins.OxyPlot.Test.Legend +{ + [TestFixture] + public class LineDataTreeNodeInfoTest + { + private MockRepository mocks; + private LegendTreeView legendTreeView; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + legendTreeView = new LegendTreeView(); + info = legendTreeView.TreeViewController.TreeNodeInfos.First(tni => tni.TagType == typeof(LineData)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(LineData), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ContextMenuStrip); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Setup + var lineData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var text = info.Text(lineData); + + // Assert + Assert.AreEqual(Resources.ChartDataNodePresenter_Line_data_label, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var lineData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var image = info.Image(lineData); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.LineIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void CanDrag_Always_ReturnsDragOperationsMove() + { + // Setup + var treeNode = new TreeNode(); + var lineData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var dragOperations = info.CanDrag(lineData, treeNode); + + // Assert + Assert.AreEqual(DragOperations.Move, dragOperations); + + mocks.VerifyAll(); + } + + [Test] + public void CanCheck_Always_ReturnsTrue() + { + // Setup + var lineData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var canCheck = info.CanCheck(lineData); + + // Assert + Assert.IsTrue(canCheck); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void LineDataNodeWithoutParent_SetsLineDataVisibility(bool initialVisibleState) + { + // Setup + var lineData = mocks.StrictMock(Enumerable.Empty>()); + var lineDataTreeNode = new TreeNode + { + Tag = lineData + }; + + mocks.ReplayAll(); + + lineData.IsVisible = initialVisibleState; + lineDataTreeNode.Checked = !initialVisibleState; + + // Call + info.OnNodeChecked(lineDataTreeNode); + + // Assert + Assert.AreEqual(!initialVisibleState, lineData.IsVisible); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void OnNodeChecked_LineDataNodeWithObservableParent_SetsLineDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) + { + // Setup + var observable = mocks.StrictMock(); + var lineData = mocks.StrictMock(Enumerable.Empty>()); + var lineDataTreeNode = new TreeNode + { + Tag = lineData + }; + var parentNode = new TreeNode + { + Tag = observable + }; + + observable.Expect(o => o.NotifyObservers()); + + mocks.ReplayAll(); + + lineData.IsVisible = initialVisibleState; + parentNode.Nodes.Add(lineDataTreeNode); + lineDataTreeNode.Checked = !initialVisibleState; + + // Call + info.OnNodeChecked(lineDataTreeNode); + + // Assert + Assert.AreEqual(!initialVisibleState, lineData.IsVisible); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/PointDataNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/PointDataTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/PointDataTreeNodeInfoTest.cs (revision 0) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/PointDataTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,194 @@ +using System; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using Core.Components.Charting.Data; +using Core.Plugins.OxyPlot.Legend; +using Core.Plugins.OxyPlot.Properties; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Plugins.OxyPlot.Test.Legend +{ + [TestFixture] + public class PointDataTreeNodeInfoTest + { + private MockRepository mocks; + private LegendTreeView legendTreeView; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + legendTreeView = new LegendTreeView(); + info = legendTreeView.TreeViewController.TreeNodeInfos.First(tni => tni.TagType == typeof(PointData)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PointData), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ContextMenuStrip); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Setup + var pointData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var text = info.Text(pointData); + + // Assert + Assert.AreEqual(Resources.ChartDataNodePresenter_Point_data_label, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var pointData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var image = info.Image(pointData); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.PointsIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void CanDrag_Always_ReturnsDragOperationsMove() + { + // Setup + var treeNode = new TreeNode(); + var pointData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var dragOperations = info.CanDrag(pointData, treeNode); + + // Assert + Assert.AreEqual(DragOperations.Move, dragOperations); + + mocks.VerifyAll(); + } + + [Test] + public void CanCheck_Always_ReturnsTrue() + { + // Setup + var pointData = mocks.StrictMock(Enumerable.Empty>()); + + mocks.ReplayAll(); + + // Call + var canCheck = info.CanCheck(pointData); + + // Assert + Assert.IsTrue(canCheck); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void IsChecked_Always_ReturnsAccordingToVisibleStateOfPointsData(bool isVisible) + { + // Setup + var pointData = mocks.StrictMock(Enumerable.Empty>()); + + pointData.IsVisible = isVisible; + + mocks.ReplayAll(); + + // Call + var canCheck = info.IsChecked(pointData); + + // Assert + Assert.AreEqual(isVisible, canCheck); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void PointDataNodeWithoutParent_SetsPointDataVisibility(bool initialVisibleState) + { + // Setup + var pointData = mocks.StrictMock(Enumerable.Empty>()); + var pointDataTreeNode = new TreeNode + { + Tag = pointData + }; + + mocks.ReplayAll(); + + pointData.IsVisible = initialVisibleState; + pointDataTreeNode.Checked = !initialVisibleState; + + // Call + info.OnNodeChecked(pointDataTreeNode); + + // Assert + Assert.AreEqual(!initialVisibleState, pointData.IsVisible); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void OnNodeChecked_PointDataNodeWithObservableParent_SetsPointDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) + { + // Setup + var observable = mocks.StrictMock(); + var pointData = mocks.StrictMock(Enumerable.Empty>()); + var pointDataTreeNode = new TreeNode + { + Tag = pointData + }; + var parentNode = new TreeNode + { + Tag = observable + }; + + observable.Expect(o => o.NotifyObservers()); + + mocks.ReplayAll(); + + pointData.IsVisible = initialVisibleState; + parentNode.Nodes.Add(pointDataTreeNode); + pointDataTreeNode.Checked = !initialVisibleState; + + // Call + info.OnNodeChecked(pointDataTreeNode); + + // Assert + Assert.AreEqual(!initialVisibleState, pointData.IsVisible); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Core.Plugins.ProjectExplorer.Test.csproj =================================================================== diff -u -r2b85017de31a5cf9de36c15730d179290c2013d0 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Core.Plugins.ProjectExplorer.Test.csproj (.../Core.Plugins.ProjectExplorer.Test.csproj) (revision 2b85017de31a5cf9de36c15730d179290c2013d0) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Core.Plugins.ProjectExplorer.Test.csproj (.../Core.Plugins.ProjectExplorer.Test.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -81,7 +81,7 @@ - + Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/NodePresenters/ProjectNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs =================================================================== diff -u -r6e66175397887e29939dfbab9cad678db91011b6 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs (.../ProjectExplorerGuiPluginTest.cs) (revision 6e66175397887e29939dfbab9cad678db91011b6) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectExplorerGuiPluginTest.cs (.../ProjectExplorerGuiPluginTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,7 +1,6 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; - using Core.Common.Base.Data; using Core.Common.Base.Plugin; using Core.Common.Controls.TreeView; @@ -14,84 +13,141 @@ [TestFixture] public class ProjectExplorerGuiPluginTest { - private IGui gui; - private MockRepository mocks; - private ApplicationCore applicationCore; - private ITreeNodePresenter mockNodePresenter; - private ProjectExplorerGuiPlugin projectExplorerPluginGui; - - [SetUp] - public void SetUp() + [Test] + public void RegisteringTreeNodeAddsToTreeView() { - mocks = new MockRepository(); - gui = mocks.Stub(); + // Setup + var mocks = new MockRepository(); + var applicationCore = new ApplicationCore(); + var guiStub = mocks.Stub(); + var otherGuiPlugin = mocks.Stub(); - var project = new Project(); - var plugin = mocks.Stub(); - var pluginGui = mocks.Stub(); - projectExplorerPluginGui = new ProjectExplorerGuiPlugin(); + guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + otherGuiPlugin.Expect(g => g.GetTreeNodeInfos()).Return(new List { new TreeNodeInfo { TagType = typeof(int) } }); - gui.Expect(g => g.SelectionChanged += Arg>.Is.Anything).Repeat.Any(); - gui.Expect(g => g.SelectionChanged -= Arg>.Is.Anything).Repeat.Any(); - gui.Expect(g => g.ProjectOpened += Arg>.Is.Anything).Repeat.Any(); - gui.Expect(g => g.ProjectOpened -= Arg>.Is.Anything).Repeat.Any(); - gui.Expect(g => g.ProjectClosing += Arg>.Is.Anything).Repeat.Any(); - gui.Expect(g => g.ProjectClosing -= Arg>.Is.Anything).Repeat.Any(); - gui.Expect(g => g.ToolWindowViews).Return(mocks.Stub()).Repeat.Any(); - gui.Expect(g => g.DocumentViews).Return(mocks.Stub()).Repeat.Any(); - gui.Expect(g => g.Plugins).Return(new List - { - projectExplorerPluginGui, pluginGui - }).Repeat.Any(); - gui.Stub(g=>g.ApplicationCommands).Return(mocks.StrictMock()); - gui.Stub(g => g.ProjectCommands).Return(mocks.StrictMock()); - gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + Expect.Call(guiStub.ApplicationCore).Return(applicationCore).Repeat.Any(); - gui.Project = project; + guiStub.Expect(g => g.SelectionChanged += Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.SelectionChanged -= Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ProjectOpened += Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ProjectOpened -= Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ProjectClosing += Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ProjectClosing -= Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ToolWindowViews).Return(mocks.Stub()).Repeat.Any(); + guiStub.Expect(g => g.DocumentViews).Return(mocks.Stub()).Repeat.Any(); - //create and register a custom np - mockNodePresenter = mocks.Stub(); - pluginGui.Expect(g => g.GetProjectTreeViewNodePresenters()).Return(new[] + guiStub.Replay(); + + using (var projectExplorerGuiPlugin = new ProjectExplorerGuiPlugin { - mockNodePresenter - }); + Gui = guiStub + }) + { + guiStub.Expect(g => g.Plugins).Return(new List + { + projectExplorerGuiPlugin, otherGuiPlugin + }).Repeat.Any(); - applicationCore = new ApplicationCore(); - gui.Expect(g => g.ApplicationCore).Return(applicationCore).Repeat.Any(); + mocks.ReplayAll(); - mocks.ReplayAll(); + // Call + projectExplorerGuiPlugin.Activate(); - projectExplorerPluginGui.Gui = gui; + // Assert + TreeNodeInfo[] treeNodeInfos = projectExplorerGuiPlugin.ProjectExplorer.TreeView.TreeViewController.TreeNodeInfos.ToArray(); + Assert.AreEqual(2, treeNodeInfos.Length); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(Project))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(int))); + } - gui.ApplicationCore.AddPlugin(plugin); + mocks.VerifyAll(); } [Test] - public void RegisteringTreeNodeAddsToTreeView() + public void ReopeningProjectExplorerKeepsCustomNodePresenter() { - projectExplorerPluginGui.Activate(); //this will create the projecttreeview. + // Setup + var mocks = new MockRepository(); + var applicationCore = new ApplicationCore(); + var guiStub = mocks.Stub(); + var otherGuiPlugin = mocks.Stub(); - var projectTreeView = projectExplorerPluginGui.ProjectExplorer.TreeView; - Assert.IsTrue(projectTreeView.NodePresenters.Contains(mockNodePresenter)); + guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); + otherGuiPlugin.Stub(g => g.GetTreeNodeInfos()).Return(new List { new TreeNodeInfo { TagType = typeof(int) } }); + Expect.Call(guiStub.ApplicationCore).Return(applicationCore).Repeat.Any(); + + guiStub.Expect(g => g.SelectionChanged += Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.SelectionChanged -= Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ProjectOpened += Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ProjectOpened -= Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ProjectClosing += Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ProjectClosing -= Arg>.Is.Anything).Repeat.Any(); + guiStub.Expect(g => g.ToolWindowViews).Return(mocks.Stub()).Repeat.Any(); + guiStub.Expect(g => g.DocumentViews).Return(mocks.Stub()).Repeat.Any(); + + guiStub.Replay(); + + using (var projectExplorerGuiPlugin = new ProjectExplorerGuiPlugin + { + Gui = guiStub + }) + { + guiStub.Expect(g => g.Plugins).Return(new List + { + projectExplorerGuiPlugin, otherGuiPlugin + }).Repeat.Any(); + + mocks.ReplayAll(); + + // Call + projectExplorerGuiPlugin.Activate(); // This will create the project treeview + projectExplorerGuiPlugin.ProjectExplorer.Dispose(); // This is somewhat similar to closing the treeview + projectExplorerGuiPlugin.InitializeProjectTreeView(); // This is what the show command does + + // Assert + TreeNodeInfo[] treeNodeInfos = projectExplorerGuiPlugin.ProjectExplorer.TreeView.TreeViewController.TreeNodeInfos.ToArray(); + Assert.AreEqual(2, treeNodeInfos.Length); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(Project))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(int))); + } + mocks.VerifyAll(); } [Test] - public void ReopeningProjectExplorerKeepsCustomNodePresenter() + public void GetTreeNodeInfos_ReturnsSupportedTreeNodeInfos() { - projectExplorerPluginGui.Activate(); //this will create the projecttreeview. + // setup + var mocks = new MockRepository(); + var applicationCore = new ApplicationCore(); - //this is somewhat similar to closing the treeview.. - projectExplorerPluginGui.ProjectExplorer.Dispose(); + var guiStub = mocks.Stub(); + guiStub.Stub(g => g.ApplicationCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.ProjectCommands).Return(mocks.Stub()); + guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); - //this is what the show command does - projectExplorerPluginGui.InitializeProjectTreeView(); + Expect.Call(guiStub.ApplicationCore).Return(applicationCore).Repeat.Any(); - //assert all is well again - var projectTreeView = projectExplorerPluginGui.ProjectExplorer.TreeView; - Assert.IsTrue(projectTreeView.NodePresenters.Contains(mockNodePresenter)); + mocks.ReplayAll(); + using (var guiPlugin = new ProjectExplorerGuiPlugin + { + Gui = guiStub + }) + { + // call + TreeNodeInfo[] treeNodeInfos = guiPlugin.GetTreeNodeInfos().ToArray(); + + // assert + Assert.AreEqual(1, treeNodeInfos.Length); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(Project))); + } + mocks.VerifyAll(); } Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectTreeViewTest.cs =================================================================== diff -u -ra6df46f9508fcedf716bb84ec0076d7df104155f -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectTreeViewTest.cs (.../ProjectTreeViewTest.cs) (revision a6df46f9508fcedf716bb84ec0076d7df104155f) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/ProjectTreeViewTest.cs (.../ProjectTreeViewTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,11 +1,11 @@ using System; using System.Configuration; using System.Linq; +using System.Windows.Forms; using Core.Common.Base.Data; using Core.Common.Base.Plugin; using Core.Common.Controls.TreeView; using Core.Common.Gui; -using Core.Plugins.ProjectExplorer.NodePresenters; using NUnit.Extensions.Forms; using NUnit.Framework; @@ -47,29 +47,26 @@ }; object item = 1; - var project = new Project(); project.Items.Add(item); + bool removedCalled = false; + var mocks = new MockRepository(); - var menuBuilderProvider = mocks.Stub(); - var integerNodePresenter = mocks.Stub(); - integerNodePresenter.Expect(np => np.CanRemove(project, item)).Return(true); - integerNodePresenter.Expect(np => np.RemoveNodeData(project, item)).Return(true); - integerNodePresenter.Stub(np => np.NodeTagType).Return(typeof(int)); - integerNodePresenter.Stub(np => np.UpdateNode(null, null, null)).IgnoreArguments(); - integerNodePresenter.Stub(np => np.GetChildNodeObjects(item)).Return(new object[0]); + var projectTreeNodeInfo = mocks.Stub>(); + projectTreeNodeInfo.ChildNodeObjects = p => p.Items.ToArray(); - var projectCommands = mocks.Stub(); + var integerTreeNodeInfo = mocks.Stub(); + integerTreeNodeInfo.TagType = typeof(int); + integerTreeNodeInfo.CanRemove = (nd, pnd) => nd == item && pnd == project; + integerTreeNodeInfo.OnNodeRemoved = (nd, pnd) => removedCalled = true; var commandHandler = mocks.Stub(); commandHandler.Expect(ch => ch.RemoveAllViewsForItem(item)); - var projectOwner = mocks.Stub(); projectOwner.Stub(g => g.ProjectOpened += Arg>.Is.Anything); projectOwner.Stub(g => g.ProjectOpened -= Arg>.Is.Anything); - var selectionStub = mocks.Stub(); selectionStub.Stub(g => g.SelectionChanged += Arg>.Is.Anything); selectionStub.Stub(g => g.SelectionChanged -= Arg>.Is.Anything); @@ -80,16 +77,18 @@ using (var projectTree = new ProjectTreeView(selectionStub, commandHandler, projectOwner, documentViewController)) { - projectTree.TreeView.RegisterNodePresenter(new ProjectNodePresenter(menuBuilderProvider, projectCommands)); - projectTree.TreeView.RegisterNodePresenter(integerNodePresenter); + projectTree.TreeView.TreeViewController.RegisterTreeNodeInfo(projectTreeNodeInfo); + projectTree.TreeView.TreeViewController.RegisterTreeNodeInfo(integerTreeNodeInfo); projectTree.Project = project; // Call - projectTree.TreeView.SelectedNode = projectTree.TreeView.Nodes[0].Nodes.First(); - projectTree.TreeView.TryDeleteSelectedNodeData(); + var nodeToDelete = projectTree.TreeView.Nodes[0].Nodes.OfType().First(); + projectTree.TreeView.TreeViewController.DeleteNode(nodeToDelete, integerTreeNodeInfo); } // Assert + Assert.IsTrue(removedCalled); + mocks.VerifyAll(); } } Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/TreeNodeInfos/ProjectTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/TreeNodeInfos/ProjectTreeNodeInfoTest.cs (revision 0) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/TreeNodeInfos/ProjectTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,172 @@ +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base.Data; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using Core.Plugins.ProjectExplorer.Properties; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Plugins.ProjectExplorer.Test.TreeNodeInfos +{ + [TestFixture] + public class ProjectTreeNodeInfoTest + { + private MockRepository mocks; + private ProjectExplorerGuiPlugin plugin; + private Common.Controls.TreeView.TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new ProjectExplorerGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(Project)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(Project), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var project = mocks.StrictMock(); + var testName = "ttt"; + project.Name = testName; + + mocks.ReplayAll(); + + // Call + var text = info.Text(project); + + // Assert + Assert.AreEqual(testName, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var project = mocks.StrictMock(); + + mocks.ReplayAll(); + + // Call + var image = info.Image(project); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.Project, image); + + mocks.VerifyAll(); + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildsOnData() + { + // Setup + var object1 = new object(); + var object2 = new object(); + var project = mocks.StrictMock(); + + project.Items.Add(object1); + project.Items.Add(object2); + + mocks.ReplayAll(); + + // Call + var objects = info.ChildNodeObjects(project); + + // Assert + CollectionAssert.AreEqual(new [] { object1, object2 }, objects); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var treeNode = new TreeNode(); + var gui = mocks.StrictMultiMock(); + var menuBuilderMock = mocks.StrictMock(); + var projectCommandsMock = mocks.StrictMock(); + var viewCommandsMock = mocks.StrictMock(); + + gui.Expect(g => g.Get(treeNode, info)).Return(menuBuilderMock); + gui.Expect(g => g.ProjectCommands).Return(projectCommandsMock); + gui.Expect(g => g.ViewCommands).Return(viewCommandsMock); + + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, treeNode, info); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_Always_AddsAddItem() + { + // Setup + var project = new Project(); + var treeNode = new TreeNode(); + var guiMock = mocks.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var projectCommandsMock = mocks.StrictMock(); + var viewCommandsMock = mocks.StrictMock(); + + guiMock.Stub(g => g.Get(treeNode, info)).Return(menuBuilder); + guiMock.Stub(g => g.ProjectCommands).Return(projectCommandsMock); + guiMock.Stub(g => g.ViewCommands).Return(viewCommandsMock); + projectCommandsMock.Expect(g => g.AddNewItem(project)); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + var result = info.ContextMenuStrip(project, treeNode, info); + + result.Items[0].PerformClick(); + + // Assert + TestHelper.AssertContextMenuStripContainsItem(result, 0, Resources.AddItem, Resources.AddItem_ToolTip, Resources.plus); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/NodePresenters/CategoryTreeFolderNodePresenter.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Common/src/Ringtoets.Common.Forms/NodePresenters/CategoryTreeFolderNodePresenter.cs (.../CategoryTreeFolderNodePresenter.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/NodePresenters/CategoryTreeFolderNodePresenter.cs (.../CategoryTreeFolderNodePresenter.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,62 +1,62 @@ -using System; -using System.Collections; -using System.Drawing; -using System.Windows.Forms; -using Core.Common.Gui; -using Ringtoets.Common.Forms.PresentationObjects; -using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; - -namespace Ringtoets.Common.Forms.NodePresenters -{ - /// - /// Node presenter for . - /// - public class CategoryTreeFolderNodePresenter : RingtoetsNodePresenterBase - { - /// - /// Creates a new instance of , which uses the - /// to create and bind its . - /// - /// The - /// to use for building a . - /// Thrown when no was provided. - public CategoryTreeFolderNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) { } - - protected override void UpdateNode(TreeNode parentNode, TreeNode node, CategoryTreeFolder nodeData) - { - node.Text = nodeData.Name; - node.Image = GetFolderIcon(nodeData.Category); - node.ForegroundColor = Color.FromKnownColor(KnownColor.ControlText); - } - - protected override IEnumerable GetChildNodeObjects(CategoryTreeFolder nodeData) - { - return nodeData.Contents; - } - - protected override ContextMenuStrip GetContextMenu(TreeNode node, CategoryTreeFolder nodeData) - { - return contextMenuBuilderProvider - .Get(node) - .AddExpandAllItem() - .AddCollapseAllItem() - .Build(); - } - - private Image GetFolderIcon(TreeFolderCategory category) - { - switch (category) - { - case TreeFolderCategory.General: - return RingtoetsCommonFormsResources.GeneralFolderIcon; - case TreeFolderCategory.Input: - return RingtoetsCommonFormsResources.InputFolderIcon; - case TreeFolderCategory.Output: - return RingtoetsCommonFormsResources.OutputFolderIcon; - default: - throw new NotImplementedException(); - } - } - } -} \ No newline at end of file +//using System; +//using System.Collections; +//using System.Drawing; +//using System.Windows.Forms; +//using Core.Common.Gui; +//using Ringtoets.Common.Forms.PresentationObjects; +//using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +//using TreeNode = Core.Common.Controls.TreeView.TreeNode; +// +//namespace Ringtoets.Common.Forms.NodePresenters +//{ +// /// +// /// Node presenter for . +// /// +// public class CategoryTreeFolderNodePresenter : RingtoetsNodePresenterBase +// { +// /// +// /// Creates a new instance of , which uses the +// /// to create and bind its . +// /// +// /// The +// /// to use for building a . +// /// Thrown when no was provided. +// public CategoryTreeFolderNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) { } +// +// protected override void UpdateNode(TreeNode parentNode, TreeNode node, CategoryTreeFolder nodeData) +// { +// node.Text = nodeData.Name; +// node.Image = GetFolderIcon(nodeData.Category); +// node.ForegroundColor = Color.FromKnownColor(KnownColor.ControlText); +// } +// +// protected override IEnumerable GetChildNodeObjects(CategoryTreeFolder nodeData) +// { +// return nodeData.Contents; +// } +// +// protected override ContextMenuStrip GetContextMenu(TreeNode node, CategoryTreeFolder nodeData) +// { +// return contextMenuBuilderProvider +// .Get(node) +// .AddExpandAllItem() +// .AddCollapseAllItem() +// .Build(); +// } +// +// private Image GetFolderIcon(TreeFolderCategory category) +// { +// switch (category) +// { +// case TreeFolderCategory.General: +// return RingtoetsCommonFormsResources.GeneralFolderIcon; +// case TreeFolderCategory.Input: +// return RingtoetsCommonFormsResources.InputFolderIcon; +// case TreeFolderCategory.Output: +// return RingtoetsCommonFormsResources.OutputFolderIcon; +// default: +// throw new NotImplementedException(); +// } +// } +// } +//} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/NodePresenters/RingtoetsNodePresenterBase.cs =================================================================== diff -u -r2f45fd13d134ed6bdfcdb0967d07516beb30409c -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Common/src/Ringtoets.Common.Forms/NodePresenters/RingtoetsNodePresenterBase.cs (.../RingtoetsNodePresenterBase.cs) (revision 2f45fd13d134ed6bdfcdb0967d07516beb30409c) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/NodePresenters/RingtoetsNodePresenterBase.cs (.../RingtoetsNodePresenterBase.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,184 +1,184 @@ -using System; -using System.Collections; -using System.Linq; -using System.Windows.Forms; - -using Core.Common.Controls.TreeView; -using Core.Common.Gui; -using Ringtoets.Common.Forms.Properties; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; -using TreeView = Core.Common.Controls.TreeView.TreeView; - -namespace Ringtoets.Common.Forms.NodePresenters -{ - /// - /// Implements in a featureless way as possible, - /// to serve as a base class for all node presenters. - /// - /// The data object class corresponding with the node. - public abstract class RingtoetsNodePresenterBase : ITreeNodePresenter - { - protected readonly IContextMenuBuilderProvider contextMenuBuilderProvider; - - /// - /// Creates a new instance of , which uses the - /// to create and bind its . - /// - /// The - /// to use for building a . - /// Thrown when no was provided. - public RingtoetsNodePresenterBase(IContextMenuBuilderProvider contextMenuBuilderProvider) - { - if (contextMenuBuilderProvider == null) - { - throw new ArgumentNullException("contextMenuBuilderProvider", Core.Common.Gui.Properties.Resources.NodePresenter_ContextMenuBuilderProvider_required); - } - this.contextMenuBuilderProvider = contextMenuBuilderProvider; - } - - public TreeView TreeView { get; set; } - - public Type NodeTagType - { - get - { - return typeof(T); - } - } - - public void UpdateNode(TreeNode parentNode, TreeNode node, object nodeData) - { - UpdateNode(parentNode, node, (T)nodeData); - } - - public IEnumerable GetChildNodeObjects(object parentNodeData) - { - return GetChildNodeObjects((T)parentNodeData).Cast(); - } - - public virtual bool CanRenameNode(TreeNode node) - { - return false; - } - - public virtual bool CanRenameNodeTo(TreeNode node, string newName) - { - return false; - } - - public void OnNodeRenamed(object nodeData, string newName) - { - var data = (T)nodeData; - OnNodeRenamed(data, newName); - } - - public virtual void OnNodeChecked(TreeNode node) - { - // Not a checked node - } - - public DragOperations CanDrag(object nodeData) - { - return CanDrag((T)nodeData); - } - - public virtual DragOperations CanDrop(object item, TreeNode sourceNode, TreeNode targetNode, DragOperations validOperations) - { - return DragOperations.None; - } - - public virtual bool CanInsert(object item, TreeNode sourceNode, TreeNode targetNode) - { - return false; - } - - public void OnDragDrop(object item, object itemParent, object target, DragOperations operation, int position) - { - OnDragDrop(item, itemParent, (T)target, operation, position); - } - - public ContextMenuStrip GetContextMenu(TreeNode node, object nodeData) - { - return GetContextMenu(node, (T)nodeData); - } - - public bool CanRemove(object parentNodeData, object nodeData) - { - return CanRemove(parentNodeData, (T)nodeData); - } - - public bool RemoveNodeData(object parentNodeData, object nodeData) - { - return RemoveNodeData(parentNodeData, (T)nodeData); - } - - /// - /// Typed implementation of method . - /// - /// - protected abstract void UpdateNode(TreeNode parentNode, TreeNode node, T nodeData); - - /// - /// Typed implementation of method . - /// - /// - protected virtual IEnumerable GetChildNodeObjects(T nodeData) - { - return Enumerable.Empty(); - } - - /// - /// Typed implementation of method . - /// - /// - protected virtual void OnNodeRenamed(T nodeData, string newName) - { - throw new InvalidOperationException(string.Format(Resources.RingtoetsNodePresenterBase_OnNodeRenamed_Cannot_rename_tree_node_of_type_0_, GetType().Name)); - } - - /// - /// Typed implementation of method . - /// - /// - protected virtual DragOperations CanDrag(T nodeData) - { - return DragOperations.None; - } - - /// - /// Typed implementation of method . - /// - /// - protected virtual void OnDragDrop(object item, object itemParent, T target, DragOperations operation, int position) - { - // Do nothing - } - - /// - /// Typed implementation of method . - /// - /// - protected virtual ContextMenuStrip GetContextMenu(TreeNode node, T nodeData) - { - return null; - } - - /// - /// Typed implementation of method . - /// - /// - protected virtual bool CanRemove(object parentNodeData, T nodeData) - { - return false; - } - - /// - /// Typed implementation of method . - /// - /// - protected virtual bool RemoveNodeData(object parentNodeData, T nodeData) - { - throw new InvalidOperationException(String.Format(Resources.RingtoetsNodePresenterBase_RemoveNodeData_Cannot_delete_node_of_type_0_, GetType().Name)); - } - } -} \ No newline at end of file +//using System; +//using System.Collections; +//using System.Linq; +//using System.Windows.Forms; +// +//using Core.Common.Controls.TreeView; +//using Core.Common.Gui; +//using Ringtoets.Common.Forms.Properties; +//using TreeNode = Core.Common.Controls.TreeView.TreeNode; +//using TreeView = Core.Common.Controls.TreeView.TreeView; +// +//namespace Ringtoets.Common.Forms.NodePresenters +//{ +// /// +// /// Implements in a featureless way as possible, +// /// to serve as a base class for all node presenters. +// /// +// /// The data object class corresponding with the node. +// public abstract class RingtoetsNodePresenterBase : ITreeNodePresenter +// { +// protected readonly IContextMenuBuilderProvider contextMenuBuilderProvider; +// +// /// +// /// Creates a new instance of , which uses the +// /// to create and bind its . +// /// +// /// The +// /// to use for building a . +// /// Thrown when no was provided. +// public RingtoetsNodePresenterBase(IContextMenuBuilderProvider contextMenuBuilderProvider) +// { +// if (contextMenuBuilderProvider == null) +// { +// throw new ArgumentNullException("contextMenuBuilderProvider", Core.Common.Gui.Properties.Resources.NodePresenter_ContextMenuBuilderProvider_required); +// } +// this.contextMenuBuilderProvider = contextMenuBuilderProvider; +// } +// +// public TreeView TreeView { get; set; } +// +// public Type NodeTagType +// { +// get +// { +// return typeof(T); +// } +// } +// +// public void UpdateNode(TreeNode parentNode, TreeNode node, object nodeData) +// { +// UpdateNode(parentNode, node, (T)nodeData); +// } +// +// public IEnumerable GetChildNodeObjects(object parentNodeData) +// { +// return GetChildNodeObjects((T)parentNodeData).Cast(); +// } +// +// public virtual bool CanRenameNode(TreeNode node) +// { +// return false; +// } +// +// public virtual bool CanRenameNodeTo(TreeNode node, string newName) +// { +// return false; +// } +// +// public void OnNodeRenamed(object nodeData, string newName) +// { +// var data = (T)nodeData; +// OnNodeRenamed(data, newName); +// } +// +// public virtual void OnNodeChecked(TreeNode node) +// { +// // Not a checked node +// } +// +// public DragOperations CanDrag(object nodeData) +// { +// return CanDrag((T)nodeData); +// } +// +// public virtual DragOperations CanDrop(object item, TreeNode sourceNode, TreeNode targetNode, DragOperations validOperations) +// { +// return DragOperations.None; +// } +// +// public virtual bool CanInsert(object item, TreeNode sourceNode, TreeNode targetNode) +// { +// return false; +// } +// +// public void OnDragDrop(object item, object itemParent, object target, DragOperations operation, int position) +// { +// OnDragDrop(item, itemParent, (T)target, operation, position); +// } +// +// public ContextMenuStrip GetContextMenu(TreeNode node, object nodeData) +// { +// return GetContextMenu(node, (T)nodeData); +// } +// +// public bool CanRemove(object parentNodeData, object nodeData) +// { +// return CanRemove(parentNodeData, (T)nodeData); +// } +// +// public bool RemoveNodeData(object parentNodeData, object nodeData) +// { +// return RemoveNodeData(parentNodeData, (T)nodeData); +// } +// +// /// +// /// Typed implementation of method . +// /// +// /// +// protected abstract void UpdateNode(TreeNode parentNode, TreeNode node, T nodeData); +// +// /// +// /// Typed implementation of method . +// /// +// /// +// protected virtual IEnumerable GetChildNodeObjects(T nodeData) +// { +// return Enumerable.Empty(); +// } +// +// /// +// /// Typed implementation of method . +// /// +// /// +// protected virtual void OnNodeRenamed(T nodeData, string newName) +// { +// throw new InvalidOperationException(string.Format(Resources.RingtoetsNodePresenterBase_OnNodeRenamed_Cannot_rename_tree_node_of_type_0_, GetType().Name)); +// } +// +// /// +// /// Typed implementation of method . +// /// +// /// +// protected virtual DragOperations CanDrag(T nodeData) +// { +// return DragOperations.None; +// } +// +// /// +// /// Typed implementation of method . +// /// +// /// +// protected virtual void OnDragDrop(object item, object itemParent, T target, DragOperations operation, int position) +// { +// // Do nothing +// } +// +// /// +// /// Typed implementation of method . +// /// +// /// +// protected virtual ContextMenuStrip GetContextMenu(TreeNode node, T nodeData) +// { +// return null; +// } +// +// /// +// /// Typed implementation of method . +// /// +// /// +// protected virtual bool CanRemove(object parentNodeData, T nodeData) +// { +// return false; +// } +// +// /// +// /// Typed implementation of method . +// /// +// /// +// protected virtual bool RemoveNodeData(object parentNodeData, T nodeData) +// { +// throw new InvalidOperationException(String.Format(Resources.RingtoetsNodePresenterBase_RemoveNodeData_Cannot_delete_node_of_type_0_, GetType().Name)); +// } +// } +//} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/CategoryTreeFolder.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/CategoryTreeFolder.cs (.../CategoryTreeFolder.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/CategoryTreeFolder.cs (.../CategoryTreeFolder.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,8 +1,7 @@ using System.Collections; using System.Linq; +using System.Windows.Forms; -using Core.Common.Controls.TreeView; - namespace Ringtoets.Common.Forms.PresentationObjects { /// @@ -16,7 +15,7 @@ /// The name of the category folder. /// The contents of the folder. /// Optional: The category descriptor of the folder. Default: . - public CategoryTreeFolder(string name, IEnumerable contents, TreeFolderCategory category = TreeFolderCategory.General) + public CategoryTreeFolder(string name, IList contents, TreeFolderCategory category = TreeFolderCategory.General) { Name = name; Contents = contents.OfType().ToArray(); @@ -31,11 +30,59 @@ /// /// Gets the contents of the folder. /// - public IEnumerable Contents { get; private set; } + public IList Contents { get; private set; } /// /// Gets the category of the folder. /// public TreeFolderCategory Category { get; private set; } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != GetType()) + { + return false; + } + + return Equals((CategoryTreeFolder) obj); + } + + public override int GetHashCode() + { + return Contents.Cast().Aggregate(Name != null ? Name.GetHashCode() : 0, (current, content) => current ^ content.GetHashCode()); + } + + private bool Equals(CategoryTreeFolder other) + { + if (Name != other.Name) + { + return false; + } + + if (Contents.Count != other.Contents.Count) + { + return false; + } + + for (var i = 0; i < Contents.Count; i++) + { + if (!Contents[i].Equals(other.Contents[i])) + { + return false; + } + } + + return true; + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/CategoryTreeFolderNodePresenterTest.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/CategoryTreeFolderNodePresenterTest.cs (.../CategoryTreeFolderNodePresenterTest.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/CategoryTreeFolderNodePresenterTest.cs (.../CategoryTreeFolderNodePresenterTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,203 +1,203 @@ -using System; -using System.Collections; -using System.Drawing; -using Core.Common.Controls.TreeView; -using Core.Common.Gui; -using Core.Common.Gui.ContextMenu; -using Core.Common.TestUtil; -using NUnit.Framework; - -using Rhino.Mocks; - -using Ringtoets.Common.Forms.NodePresenters; -using Ringtoets.Common.Forms.PresentationObjects; - -using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; -using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; - -namespace Ringtoets.Common.Forms.Test.NodePresenters -{ - [TestFixture] - public class CategoryTreeFolderNodePresenterTest - { - private MockRepository mockRepository; - - [SetUp] - public void SetUp() - { - mockRepository = new MockRepository(); - } - - [Test] - public void Constructor_NoMenuBuilderProvider_ArgumentNullException() - { - // Call - TestDelegate test = () => new CategoryTreeFolderNodePresenter(null); - - // Assert - var message = Assert.Throws(test).Message; - StringAssert.StartsWith(CoreCommonGuiResources.NodePresenter_ContextMenuBuilderProvider_required, message); - StringAssert.EndsWith("contextMenuBuilderProvider", message); - } - - [Test] - public void Constructor_ParamsSet_ExpectedValues() - { - // Call - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); - - // Assert - Assert.IsInstanceOf>(nodePresenter); - Assert.AreEqual(typeof(CategoryTreeFolder), nodePresenter.NodeTagType); - Assert.IsNull(nodePresenter.TreeView); - mockRepository.VerifyAll(); - } - - [Test] - [TestCase(TreeFolderCategory.General)] - [TestCase(TreeFolderCategory.Input)] - [TestCase(TreeFolderCategory.Output)] - public void UpdateNode_ForCategory_InitializeNode(TreeFolderCategory category) - { - // Setup - var parentNode = mockRepository.StrictMock(); - var currentNode = mockRepository.Stub(); - currentNode.ForegroundColor = Color.AliceBlue; - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - - mockRepository.ReplayAll(); - - var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); - var folder = new CategoryTreeFolder("Cool name", new object[0], category); - - // Call - nodePresenter.UpdateNode(parentNode, currentNode, folder); - - // Assert - Assert.AreEqual(folder.Name, currentNode.Text); - Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), currentNode.ForegroundColor); - TestHelper.AssertImagesAreEqual(GetExpectedIconForCategory(category), currentNode.Image); - mockRepository.VerifyAll(); - } - - [Test] - public void CanRenamedNode_Always_ReturnFalse() - { - // Setup - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); - - // Call - var isRenamingAllowed = nodePresenter.CanRenameNode(null); - - // Assert - Assert.IsFalse(isRenamingAllowed); - mockRepository.VerifyAll(); - } - - [Test] - public void CanRenamedNodeTo_Always_ReturnFalse() - { - // Setup - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); - - // Call - var isRenamingAllowed = nodePresenter.CanRenameNodeTo(null, ""); - - // Assert - Assert.IsFalse(isRenamingAllowed); - mockRepository.VerifyAll(); - } - - [Test] - public void CanRemove_Always_ReturnFalse() - { - // Setup - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); - - // Call - var isRenamingAllowed = nodePresenter.CanRemove(null, null); - - // Assert - Assert.IsFalse(isRenamingAllowed); - mockRepository.VerifyAll(); - } - - [Test] - public void GetChildNodeObjects_FolderHasContents_ReturnContents() - { - // Setup - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var folder = new CategoryTreeFolder("", new[] - { - new object(), - new object() - }); - - var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); - - // Call - IEnumerable children = nodePresenter.GetChildNodeObjects(folder); - - // Assert - CollectionAssert.AreEqual(folder.Contents, children); - mockRepository.VerifyAll(); - } - - [Test] - [TestCase(true)] - [TestCase(false)] - public void GetContextMenu_ContextMenuBuilderProviderSet_HaveImportSurfaceLinesItemInContextMenu(bool commonItemsEnabled) - { - // Setup - var folder = new CategoryTreeFolder("", new object[0]); - var nodeMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - var menuBuilderMock = mockRepository.StrictMock(); - - menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.Build()).Return(null); - - contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock); - - mockRepository.ReplayAll(); - - var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); - - // Call - nodePresenter.GetContextMenu(nodeMock, folder); - - // Assert - mockRepository.VerifyAll(); - } - - private Image GetExpectedIconForCategory(TreeFolderCategory category) - { - switch (category) - { - case TreeFolderCategory.General: - return RingtoetsFormsResources.GeneralFolderIcon; - case TreeFolderCategory.Input: - return RingtoetsFormsResources.InputFolderIcon; - case TreeFolderCategory.Output: - return RingtoetsFormsResources.OutputFolderIcon; - default: - throw new NotImplementedException(); - } - } - } -} \ No newline at end of file +//using System; +//using System.Collections; +//using System.Drawing; +//using Core.Common.Controls.TreeView; +//using Core.Common.Gui; +//using Core.Common.Gui.ContextMenu; +//using Core.Common.TestUtil; +//using NUnit.Framework; +// +//using Rhino.Mocks; +// +//using Ringtoets.Common.Forms.NodePresenters; +//using Ringtoets.Common.Forms.PresentationObjects; +// +//using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; +//using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; +// +//namespace Ringtoets.Common.Forms.Test.NodePresenters +//{ +// [TestFixture] +// public class CategoryTreeFolderNodePresenterTest +// { +// private MockRepository mockRepository; +// +// [SetUp] +// public void SetUp() +// { +// mockRepository = new MockRepository(); +// } +// +// [Test] +// public void Constructor_NoMenuBuilderProvider_ArgumentNullException() +// { +// // Call +// TestDelegate test = () => new CategoryTreeFolderNodePresenter(null); +// +// // Assert +// var message = Assert.Throws(test).Message; +// StringAssert.StartsWith(CoreCommonGuiResources.NodePresenter_ContextMenuBuilderProvider_required, message); +// StringAssert.EndsWith("contextMenuBuilderProvider", message); +// } +// +// [Test] +// public void Constructor_ParamsSet_ExpectedValues() +// { +// // Call +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); +// +// // Assert +// Assert.IsInstanceOf>(nodePresenter); +// Assert.AreEqual(typeof(CategoryTreeFolder), nodePresenter.NodeTagType); +// Assert.IsNull(nodePresenter.TreeView); +// mockRepository.VerifyAll(); +// } +// +// [Test] +// [TestCase(TreeFolderCategory.General)] +// [TestCase(TreeFolderCategory.Input)] +// [TestCase(TreeFolderCategory.Output)] +// public void UpdateNode_ForCategory_InitializeNode(TreeFolderCategory category) +// { +// // Setup +// var parentNode = mockRepository.StrictMock(); +// var currentNode = mockRepository.Stub(); +// currentNode.ForegroundColor = Color.AliceBlue; +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// +// mockRepository.ReplayAll(); +// +// var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); +// var folder = new CategoryTreeFolder("Cool name", new object[0], category); +// +// // Call +// nodePresenter.UpdateNode(parentNode, currentNode, folder); +// +// // Assert +// Assert.AreEqual(folder.Name, currentNode.Text); +// Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), currentNode.ForegroundColor); +// TestHelper.AssertImagesAreEqual(GetExpectedIconForCategory(category), currentNode.Image); +// mockRepository.VerifyAll(); +// } +// +// [Test] +// public void CanRenamedNode_Always_ReturnFalse() +// { +// // Setup +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); +// +// // Call +// var isRenamingAllowed = nodePresenter.CanRenameNode(null); +// +// // Assert +// Assert.IsFalse(isRenamingAllowed); +// mockRepository.VerifyAll(); +// } +// +// [Test] +// public void CanRenamedNodeTo_Always_ReturnFalse() +// { +// // Setup +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); +// +// // Call +// var isRenamingAllowed = nodePresenter.CanRenameNodeTo(null, ""); +// +// // Assert +// Assert.IsFalse(isRenamingAllowed); +// mockRepository.VerifyAll(); +// } +// +// [Test] +// public void CanRemove_Always_ReturnFalse() +// { +// // Setup +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); +// +// // Call +// var isRenamingAllowed = nodePresenter.CanRemove(null, null); +// +// // Assert +// Assert.IsFalse(isRenamingAllowed); +// mockRepository.VerifyAll(); +// } +// +// [Test] +// public void GetChildNodeObjects_FolderHasContents_ReturnContents() +// { +// // Setup +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var folder = new CategoryTreeFolder("", new[] +// { +// new object(), +// new object() +// }); +// +// var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); +// +// // Call +// IEnumerable children = nodePresenter.GetChildNodeObjects(folder); +// +// // Assert +// CollectionAssert.AreEqual(folder.Contents, children); +// mockRepository.VerifyAll(); +// } +// +// [Test] +// [TestCase(true)] +// [TestCase(false)] +// public void GetContextMenu_ContextMenuBuilderProviderSet_HaveImportSurfaceLinesItemInContextMenu(bool commonItemsEnabled) +// { +// // Setup +// var folder = new CategoryTreeFolder("", new object[0]); +// var nodeMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// var menuBuilderMock = mockRepository.StrictMock(); +// +// menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); +// menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); +// menuBuilderMock.Expect(mb => mb.Build()).Return(null); +// +// contextMenuBuilderProviderMock.Expect(cmp => cmp.Get(nodeMock)).Return(menuBuilderMock); +// +// mockRepository.ReplayAll(); +// +// var nodePresenter = new CategoryTreeFolderNodePresenter(contextMenuBuilderProviderMock); +// +// // Call +// nodePresenter.GetContextMenu(nodeMock, folder); +// +// // Assert +// mockRepository.VerifyAll(); +// } +// +// private Image GetExpectedIconForCategory(TreeFolderCategory category) +// { +// switch (category) +// { +// case TreeFolderCategory.General: +// return RingtoetsFormsResources.GeneralFolderIcon; +// case TreeFolderCategory.Input: +// return RingtoetsFormsResources.InputFolderIcon; +// case TreeFolderCategory.Output: +// return RingtoetsFormsResources.OutputFolderIcon; +// default: +// throw new NotImplementedException(); +// } +// } +// } +//} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/RingtoetsNodePresenterBaseTest.cs =================================================================== diff -u -r2f45fd13d134ed6bdfcdb0967d07516beb30409c -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/RingtoetsNodePresenterBaseTest.cs (.../RingtoetsNodePresenterBaseTest.cs) (revision 2f45fd13d134ed6bdfcdb0967d07516beb30409c) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/RingtoetsNodePresenterBaseTest.cs (.../RingtoetsNodePresenterBaseTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,308 +1,308 @@ -using System; -using System.Linq; - -using Core.Common.Controls.TreeView; -using Core.Common.Gui; -using Core.Common.Gui.Properties; -using NUnit.Framework; - -using Rhino.Mocks; - -using Ringtoets.Common.Forms.NodePresenters; - -namespace Ringtoets.Common.Forms.Test.NodePresenters -{ - [TestFixture] - public class RingtoetsNodePresenterBaseTest - { - private MockRepository mockRepository; - - [SetUp] - public void SetUp() - { - mockRepository = new MockRepository(); - } - - [Test] - public void Constructor_NoMenuBuilderProvider_ArgumentNullException() - { - // Call - TestDelegate test = () => new SimpleRingtoetsNodePresenterBase(null); - - // Assert - var message = Assert.Throws(test).Message; - StringAssert.StartsWith(Resources.NodePresenter_ContextMenuBuilderProvider_required, message); - StringAssert.EndsWith("contextMenuBuilderProvider", message); - } - - [Test] - public void Constructor_ParamsSet_ExpectedValues() - { - // Setup - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - - mockRepository.ReplayAll(); - - // Call - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Assert - Assert.AreEqual(typeof(double), nodePresenter.NodeTagType); - Assert.IsNull(nodePresenter.TreeView); - - mockRepository.VerifyAll(); - } - - [Test] - public void UpdateNode_WithData_DoNothing() - { - // Setup - var parentNode = mockRepository.StrictMock(); - var pipingNode = mockRepository.StrictMock(); - var nodeData = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - nodePresenter.UpdateNode(parentNode, pipingNode, nodeData); - - // Assert - mockRepository.VerifyAll(); // Expect no calls on mocks - } - - [Test] - public void GetChildNodeObjects_Always_ReturnNoChildData() - { - // Setup - var dataMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - var children = nodePresenter.GetChildNodeObjects(dataMock).OfType().ToArray(); - - // Assert - CollectionAssert.IsEmpty(children); - mockRepository.VerifyAll(); // Expect no calls on tree node - } - - [Test] - public void CanRenameNode_Always_ReturnFalse() - { - // Setup - var nodeMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - var renameAllowed = nodePresenter.CanRenameNode(nodeMock); - - // Assert - Assert.IsFalse(renameAllowed); - mockRepository.VerifyAll(); // Expect no calls on tree node - } - - [Test] - public void CanRenameNodeTo_Always_ReturnFalse() - { - // Setup - var nodeMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - var renameAllowed = nodePresenter.CanRenameNodeTo(nodeMock, ""); - - // Assert - Assert.IsFalse(renameAllowed); - mockRepository.ReplayAll(); // Expect no calls on tree node - } - - [Test] - public void OnNodeRenamed_Always_ThrowInvalidOperationException() - { - // Setup - var dataMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - TestDelegate call = () => { nodePresenter.OnNodeRenamed(dataMock, ""); }; - - // Assert - var exception = Assert.Throws(call); - var expectedMessage = string.Format("Kan knoop uit boom van type {0} niet hernoemen.", nodePresenter.GetType().Name); - Assert.AreEqual(expectedMessage, exception.Message); - mockRepository.ReplayAll(); // Expect no calls on tree node - } - - [Test] - public void OnNodeChecked_Always_DoNothing() - { - // Setup - var nodeMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - nodePresenter.OnNodeChecked(nodeMock); - - // Assert - mockRepository.VerifyAll(); // Expect no calls on tree node - } - - [Test] - public void CanDrag_Always_ReturnNone() - { - // Setup - var dataMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - DragOperations dragAllowed = nodePresenter.CanDrag(dataMock); - - // Assert - Assert.AreEqual(DragOperations.None, dragAllowed); - mockRepository.VerifyAll(); - } - - [Test] - public void CanDrop_Always_ReturnNone() - { - // Setup - var dataMock = mockRepository.StrictMock(); - var sourceMock = mockRepository.StrictMock(); - var targetMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - DragOperations dropAllowed = nodePresenter.CanDrop(dataMock, sourceMock, targetMock, DragOperations.Move); - - // Assert - Assert.AreEqual(DragOperations.None, dropAllowed); - mockRepository.VerifyAll(); // Expect no calls on mockRepository. - } - - [Test] - public void CanInsert_Always_ReturnFalse() - { - // Setup - var dataMock = mockRepository.StrictMock(); - var sourceMock = mockRepository.StrictMock(); - var targetMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - bool insertionAllowed = nodePresenter.CanInsert(dataMock, sourceMock, targetMock); - - // Assert - Assert.IsFalse(insertionAllowed); - mockRepository.VerifyAll(); // Expect no calls on arguments - } - - [Test] - public void OnDragDrop_Always_DoNothing() - { - // Setup - var dataMock = mockRepository.StrictMock(); - var sourceParentNodeMock = mockRepository.StrictMock(); - var targetParentNodeDataMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - nodePresenter.OnDragDrop(dataMock, sourceParentNodeMock, targetParentNodeDataMock, DragOperations.Move, 2); - - // Assert - mockRepository.VerifyAll(); // Expect no calls on arguments - } - - [Test] - public void GetContextMenu_Always_ReturnsNull() - { - // Setup - var nodeMock = mockRepository.StrictMock(); - var dataMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - var contextMenu = nodePresenter.GetContextMenu(nodeMock, dataMock); - - // Assert - Assert.IsNull(contextMenu); - mockRepository.VerifyAll(); // Expect no calls on arguments - } - - [Test] - public void CanRemove_Always_ReturnFalse() - { - // Setup - var dataMock = mockRepository.StrictMock(); - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - bool removalAllowed = nodePresenter.CanRemove(null, dataMock); - - // Assert - Assert.IsFalse(removalAllowed); - mockRepository.VerifyAll(); // Expect no calls on arguments - } - - [Test] - public void RemoveNodeData_Always_ThrowInvalidOperationException() - { - // Setup - var contextMenuBuilderProviderMock = mockRepository.StrictMock(); - - mockRepository.ReplayAll(); - - var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); - - // Call - TestDelegate call = () => nodePresenter.RemoveNodeData(null, new object()); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual(String.Format("Kan knoop uit boom van type {0} niet verwijderen.", nodePresenter.GetType().Name), exception.Message); - - mockRepository.VerifyAll(); - } - - private class SimpleRingtoetsNodePresenterBase : RingtoetsNodePresenterBase - { - protected override void UpdateNode(TreeNode parentNode, TreeNode node, T nodeData) {} - public SimpleRingtoetsNodePresenterBase(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) {} - } - } -} \ No newline at end of file +//using System; +//using System.Linq; +// +//using Core.Common.Controls.TreeView; +//using Core.Common.Gui; +//using Core.Common.Gui.Properties; +//using NUnit.Framework; +// +//using Rhino.Mocks; +// +//using Ringtoets.Common.Forms.NodePresenters; +// +//namespace Ringtoets.Common.Forms.Test.NodePresenters +//{ +// [TestFixture] +// public class RingtoetsNodePresenterBaseTest +// { +// private MockRepository mockRepository; +// +// [SetUp] +// public void SetUp() +// { +// mockRepository = new MockRepository(); +// } +// +// [Test] +// public void Constructor_NoMenuBuilderProvider_ArgumentNullException() +// { +// // Call +// TestDelegate test = () => new SimpleRingtoetsNodePresenterBase(null); +// +// // Assert +// var message = Assert.Throws(test).Message; +// StringAssert.StartsWith(Resources.NodePresenter_ContextMenuBuilderProvider_required, message); +// StringAssert.EndsWith("contextMenuBuilderProvider", message); +// } +// +// [Test] +// public void Constructor_ParamsSet_ExpectedValues() +// { +// // Setup +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// +// mockRepository.ReplayAll(); +// +// // Call +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Assert +// Assert.AreEqual(typeof(double), nodePresenter.NodeTagType); +// Assert.IsNull(nodePresenter.TreeView); +// +// mockRepository.VerifyAll(); +// } +// +// [Test] +// public void UpdateNode_WithData_DoNothing() +// { +// // Setup +// var parentNode = mockRepository.StrictMock(); +// var pipingNode = mockRepository.StrictMock(); +// var nodeData = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// nodePresenter.UpdateNode(parentNode, pipingNode, nodeData); +// +// // Assert +// mockRepository.VerifyAll(); // Expect no calls on mocks +// } +// +// [Test] +// public void GetChildNodeObjects_Always_ReturnNoChildData() +// { +// // Setup +// var dataMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// var children = nodePresenter.GetChildNodeObjects(dataMock).OfType().ToArray(); +// +// // Assert +// CollectionAssert.IsEmpty(children); +// mockRepository.VerifyAll(); // Expect no calls on tree node +// } +// +// [Test] +// public void CanRenameNode_Always_ReturnFalse() +// { +// // Setup +// var nodeMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// var renameAllowed = nodePresenter.CanRenameNode(nodeMock); +// +// // Assert +// Assert.IsFalse(renameAllowed); +// mockRepository.VerifyAll(); // Expect no calls on tree node +// } +// +// [Test] +// public void CanRenameNodeTo_Always_ReturnFalse() +// { +// // Setup +// var nodeMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// var renameAllowed = nodePresenter.CanRenameNodeTo(nodeMock, ""); +// +// // Assert +// Assert.IsFalse(renameAllowed); +// mockRepository.ReplayAll(); // Expect no calls on tree node +// } +// +// [Test] +// public void OnNodeRenamed_Always_ThrowInvalidOperationException() +// { +// // Setup +// var dataMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// TestDelegate call = () => { nodePresenter.OnNodeRenamed(dataMock, ""); }; +// +// // Assert +// var exception = Assert.Throws(call); +// var expectedMessage = string.Format("Kan knoop uit boom van type {0} niet hernoemen.", nodePresenter.GetType().Name); +// Assert.AreEqual(expectedMessage, exception.Message); +// mockRepository.ReplayAll(); // Expect no calls on tree node +// } +// +// [Test] +// public void OnNodeChecked_Always_DoNothing() +// { +// // Setup +// var nodeMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// nodePresenter.OnNodeChecked(nodeMock); +// +// // Assert +// mockRepository.VerifyAll(); // Expect no calls on tree node +// } +// +// [Test] +// public void CanDrag_Always_ReturnNone() +// { +// // Setup +// var dataMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// DragOperations dragAllowed = nodePresenter.CanDrag(dataMock); +// +// // Assert +// Assert.AreEqual(DragOperations.None, dragAllowed); +// mockRepository.VerifyAll(); +// } +// +// [Test] +// public void CanDrop_Always_ReturnNone() +// { +// // Setup +// var dataMock = mockRepository.StrictMock(); +// var sourceMock = mockRepository.StrictMock(); +// var targetMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// DragOperations dropAllowed = nodePresenter.CanDrop(dataMock, sourceMock, targetMock, DragOperations.Move); +// +// // Assert +// Assert.AreEqual(DragOperations.None, dropAllowed); +// mockRepository.VerifyAll(); // Expect no calls on mockRepository. +// } +// +// [Test] +// public void CanInsert_Always_ReturnFalse() +// { +// // Setup +// var dataMock = mockRepository.StrictMock(); +// var sourceMock = mockRepository.StrictMock(); +// var targetMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// bool insertionAllowed = nodePresenter.CanInsert(dataMock, sourceMock, targetMock); +// +// // Assert +// Assert.IsFalse(insertionAllowed); +// mockRepository.VerifyAll(); // Expect no calls on arguments +// } +// +// [Test] +// public void OnDragDrop_Always_DoNothing() +// { +// // Setup +// var dataMock = mockRepository.StrictMock(); +// var sourceParentNodeMock = mockRepository.StrictMock(); +// var targetParentNodeDataMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// nodePresenter.OnDragDrop(dataMock, sourceParentNodeMock, targetParentNodeDataMock, DragOperations.Move, 2); +// +// // Assert +// mockRepository.VerifyAll(); // Expect no calls on arguments +// } +// +// [Test] +// public void GetContextMenu_Always_ReturnsNull() +// { +// // Setup +// var nodeMock = mockRepository.StrictMock(); +// var dataMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// var contextMenu = nodePresenter.GetContextMenu(nodeMock, dataMock); +// +// // Assert +// Assert.IsNull(contextMenu); +// mockRepository.VerifyAll(); // Expect no calls on arguments +// } +// +// [Test] +// public void CanRemove_Always_ReturnFalse() +// { +// // Setup +// var dataMock = mockRepository.StrictMock(); +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// bool removalAllowed = nodePresenter.CanRemove(null, dataMock); +// +// // Assert +// Assert.IsFalse(removalAllowed); +// mockRepository.VerifyAll(); // Expect no calls on arguments +// } +// +// [Test] +// public void RemoveNodeData_Always_ThrowInvalidOperationException() +// { +// // Setup +// var contextMenuBuilderProviderMock = mockRepository.StrictMock(); +// +// mockRepository.ReplayAll(); +// +// var nodePresenter = new SimpleRingtoetsNodePresenterBase(contextMenuBuilderProviderMock); +// +// // Call +// TestDelegate call = () => nodePresenter.RemoveNodeData(null, new object()); +// +// // Assert +// var exception = Assert.Throws(call); +// Assert.AreEqual(String.Format("Kan knoop uit boom van type {0} niet verwijderen.", nodePresenter.GetType().Name), exception.Message); +// +// mockRepository.VerifyAll(); +// } +// +// private class SimpleRingtoetsNodePresenterBase : RingtoetsNodePresenterBase +// { +// protected override void UpdateNode(TreeNode parentNode, TreeNode node, T nodeData) {} +// public SimpleRingtoetsNodePresenterBase(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) {} +// } +// } +//} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/CategoryTreeFolderTest.cs =================================================================== diff -u -r80ebf3911f46c8fde95702b7723e4457b4fd80ea -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/CategoryTreeFolderTest.cs (.../CategoryTreeFolderTest.cs) (revision 80ebf3911f46c8fde95702b7723e4457b4fd80ea) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/CategoryTreeFolderTest.cs (.../CategoryTreeFolderTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,4 +1,5 @@ -using NUnit.Framework; +using System.Collections; +using NUnit.Framework; using Ringtoets.Common.Forms.PresentationObjects; @@ -45,5 +46,107 @@ Assert.AreNotSame(contents, treeFolder.Contents); CollectionAssert.AreEqual(contents, treeFolder.Contents); } + + [Test] + public void Equals_ObjectToEqualToIsNull_ResultShouldBeNotEqual() + { + // Setup + var treeFolder = new CategoryTreeFolder("", new object[0]); + + // Call & Assert + Assert.AreNotEqual(treeFolder, null); + } + + [Test] + public void Equals_ObjectToEqualToIsOfDifferentType_ResultShouldBeNotEqual() + { + // Setup + var enumerable = new object[0]; + var treeFolder = new CategoryTreeFolder("", enumerable); + + // Call & Assert + Assert.AreNotEqual(treeFolder, new TestCategoryTreeFolder("", enumerable)); + } + + [Test] + public void Equals_ObjectToEqualToIsSameObject_ResultShouldBeEqual() + { + // Setup + var treeFolder = new CategoryTreeFolder("", new object[0]); + + // Call & Assert + Assert.AreEqual(treeFolder, treeFolder); + } + + [Test] + public void Equals_ObjectToEqualToIsCategoryTreeFolderWithDifferentName_ResultShouldNotBeEqual() + { + // Setup + var enumerable = new object[0]; + var treeFolder1 = new CategoryTreeFolder("", enumerable); + var treeFolder2 = new CategoryTreeFolder("", enumerable); + + // Call & Assert + Assert.AreNotEqual(treeFolder1, treeFolder2); + } + + [Test] + public void Equals_ObjectToEqualToIsCategoryTreeFolderWithDifferentAmountOfContents_ResultShouldNotBeEqual() + { + // Setup + var treeFolder1 = new CategoryTreeFolder("", new object[] { }); + var treeFolder2 = new CategoryTreeFolder("", new[] { new object() }); + + // Call & Assert + Assert.AreNotEqual(treeFolder1, treeFolder2); + } + + [Test] + public void Equals_ObjectToEqualToIsCategoryTreeFolderWithDifferentContents_ResultShouldNotBeEqual() + { + // Setup + var treeFolder1 = new CategoryTreeFolder("", new[] { 1, 2 }); + var treeFolder2 = new CategoryTreeFolder("", new[] { 1, 3 }); + + // Call & Assert + Assert.AreNotEqual(treeFolder1, treeFolder2); + } + + [Test] + public void Equals_ObjectToEqualToIsCategoryTreeFolderWithSameNameAndSameContents_ResultShouldBeEqual() + { + // Setup + var enumerable = new object[0]; + var treeFolder1 = new CategoryTreeFolder("", enumerable); + var treeFolder2 = new CategoryTreeFolder("", enumerable); + + // Call & Assert + Assert.AreEqual(treeFolder1, treeFolder2); + } + + [Test] + public void GetHashCode_EqualCategoryTreeFolders_AreEqual() + { + // Setup + var enumerable = new[] { 1, 2, new object() }; + var treeFolder1 = new CategoryTreeFolder("", enumerable); + var treeFolder2 = new CategoryTreeFolder("", enumerable); + + // Precondition + Assert.AreEqual(treeFolder1, treeFolder1); + Assert.AreEqual(treeFolder1, treeFolder2); + + // Call & Assert + Assert.AreEqual(treeFolder1.GetHashCode(), treeFolder1.GetHashCode()); + Assert.AreEqual(treeFolder1.GetHashCode(), treeFolder2.GetHashCode()); + } + + private class TestCategoryTreeFolder : CategoryTreeFolder + { + public TestCategoryTreeFolder(string name, IList contents, TreeFolderCategory category = TreeFolderCategory.General) : base(name, contents, category) + { + + } + } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/AssessmentSectionBaseNodePresenter.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/AssessmentSectionBaseNodePresenter.cs (.../AssessmentSectionBaseNodePresenter.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/AssessmentSectionBaseNodePresenter.cs (.../AssessmentSectionBaseNodePresenter.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,94 +1,94 @@ -using System; -using System.Collections; -using System.Drawing; -using System.Windows.Forms; -using Core.Common.Base.Data; -using Core.Common.Gui; -using Ringtoets.Common.Forms.NodePresenters; -using Ringtoets.Integration.Data; -using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; - -namespace Ringtoets.Integration.Forms.NodePresenters -{ - /// - /// Node presenter for items in the tree view. - /// - public class AssessmentSectionBaseNodePresenter : RingtoetsNodePresenterBase - { - /// - /// Creates a new instance of , which uses the - /// to create and bind its . - /// - /// The - /// to use for building a . - /// Thrown when no was provided. - public AssessmentSectionBaseNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) { } - - public override bool CanRenameNode(TreeNode node) - { - return true; - } - - public override bool CanRenameNodeTo(TreeNode node, string newName) - { - return true; - } - - protected override void UpdateNode(TreeNode parentNode, TreeNode node, AssessmentSectionBase nodeData) - { - node.Text = nodeData.Name; - node.Image = RingtoetsFormsResources.AssessmentSectionFolderIcon; - node.ForegroundColor = Color.FromKnownColor(KnownColor.ControlText); - } - - protected override IEnumerable GetChildNodeObjects(AssessmentSectionBase nodeData) - { - yield return nodeData.ReferenceLine; - yield return nodeData.FailureMechanismContribution; - yield return nodeData.HydraulicBoundaryDatabase; - foreach (var failureMechanism in nodeData.GetFailureMechanisms()) - { - yield return failureMechanism; - } - } - - protected override void OnNodeRenamed(AssessmentSectionBase nodeData, string newName) - { - nodeData.Name = newName; - nodeData.NotifyObservers(); - } - - protected override bool CanRemove(object parentNodeData, AssessmentSectionBase nodeData) - { - return true; - } - - protected override bool RemoveNodeData(object parentNodeData, AssessmentSectionBase nodeData) - { - var parentProject = (Project) parentNodeData; - - parentProject.Items.Remove(nodeData); - parentProject.NotifyObservers(); - - return true; - } - - protected override ContextMenuStrip GetContextMenu(TreeNode node, AssessmentSectionBase nodeData) - { - return contextMenuBuilderProvider - .Get(node) - .AddRenameItem() - .AddDeleteItem() - .AddSeparator() - .AddImportItem() - .AddExportItem() - .AddSeparator() - .AddExpandAllItem() - .AddCollapseAllItem() - .AddSeparator() - .AddPropertiesItem() - .Build(); - } - } -} \ No newline at end of file +//using System; +//using System.Collections; +//using System.Drawing; +//using System.Windows.Forms; +//using Core.Common.Base.Data; +//using Core.Common.Gui; +//using Ringtoets.Common.Forms.NodePresenters; +//using Ringtoets.Integration.Data; +//using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; +//using TreeNode = Core.Common.Controls.TreeView.TreeNode; +// +//namespace Ringtoets.Integration.Forms.NodePresenters +//{ +// /// +// /// Node presenter for items in the tree view. +// /// +// public class AssessmentSectionBaseNodePresenter : RingtoetsNodePresenterBase +// { +// /// +// /// Creates a new instance of , which uses the +// /// to create and bind its . +// /// +// /// The +// /// to use for building a . +// /// Thrown when no was provided. +// public AssessmentSectionBaseNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) { } +// +// public override bool CanRenameNode(TreeNode node) +// { +// return true; +// } +// +// public override bool CanRenameNodeTo(TreeNode node, string newName) +// { +// return true; +// } +// +// protected override void UpdateNode(TreeNode parentNode, TreeNode node, AssessmentSectionBase nodeData) +// { +// node.Text = nodeData.Name; +// node.Image = RingtoetsFormsResources.AssessmentSectionFolderIcon; +// node.ForegroundColor = Color.FromKnownColor(KnownColor.ControlText); +// } +// +// protected override IEnumerable GetChildNodeObjects(AssessmentSectionBase nodeData) +// { +// yield return nodeData.ReferenceLine; +// yield return nodeData.FailureMechanismContribution; +// yield return nodeData.HydraulicBoundaryDatabase; +// foreach (var failureMechanism in nodeData.GetFailureMechanisms()) +// { +// yield return failureMechanism; +// } +// } +// +// protected override void OnNodeRenamed(AssessmentSectionBase nodeData, string newName) +// { +// nodeData.Name = newName; +// nodeData.NotifyObservers(); +// } +// +// protected override bool CanRemove(object parentNodeData, AssessmentSectionBase nodeData) +// { +// return true; +// } +// +// protected override bool RemoveNodeData(object parentNodeData, AssessmentSectionBase nodeData) +// { +// var parentProject = (Project) parentNodeData; +// +// parentProject.Items.Remove(nodeData); +// parentProject.NotifyObservers(); +// +// return true; +// } +// +// protected override ContextMenuStrip GetContextMenu(TreeNode node, AssessmentSectionBase nodeData) +// { +// return contextMenuBuilderProvider +// .Get(node) +// .AddRenameItem() +// .AddDeleteItem() +// .AddSeparator() +// .AddImportItem() +// .AddExportItem() +// .AddSeparator() +// .AddExpandAllItem() +// .AddCollapseAllItem() +// .AddSeparator() +// .AddPropertiesItem() +// .Build(); +// } +// } +//} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismContributionNodePresenter.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismContributionNodePresenter.cs (.../FailureMechanismContributionNodePresenter.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismContributionNodePresenter.cs (.../FailureMechanismContributionNodePresenter.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,32 +1,32 @@ -using System.Drawing; -using System.Windows.Forms; -using Core.Common.Gui; -using Ringtoets.Common.Forms.NodePresenters; -using Ringtoets.Integration.Data.Contribution; -using Ringtoets.Integration.Forms.Properties; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; - -namespace Ringtoets.Integration.Forms.NodePresenters -{ - public class FailureMechanismContributionNodePresenter : RingtoetsNodePresenterBase - { - public FailureMechanismContributionNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) {} - - protected override void UpdateNode(TreeNode parentNode, TreeNode node, FailureMechanismContribution nodeData) - { - node.Text = Data.Properties.Resources.FailureMechanismContribution_DisplayName; - node.ForegroundColor = Color.FromKnownColor(KnownColor.ControlText); - node.Image = Resources.GenericInputOutputIcon; - } - - protected override ContextMenuStrip GetContextMenu(TreeNode node, FailureMechanismContribution nodeData) - { - return contextMenuBuilderProvider - .Get(node) - .AddOpenItem() - .AddSeparator() - .AddExportItem() - .Build(); - } - } -} \ No newline at end of file +//using System.Drawing; +//using System.Windows.Forms; +//using Core.Common.Gui; +//using Ringtoets.Common.Forms.NodePresenters; +//using Ringtoets.Integration.Data.Contribution; +//using Ringtoets.Integration.Forms.Properties; +//using TreeNode = Core.Common.Controls.TreeView.TreeNode; +// +//namespace Ringtoets.Integration.Forms.NodePresenters +//{ +// public class FailureMechanismContributionNodePresenter : RingtoetsNodePresenterBase +// { +// public FailureMechanismContributionNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) {} +// +// protected override void UpdateNode(TreeNode parentNode, TreeNode node, FailureMechanismContribution nodeData) +// { +// node.Text = Data.Properties.Resources.FailureMechanismContribution_DisplayName; +// node.ForegroundColor = Color.FromKnownColor(KnownColor.ControlText); +// node.Image = Resources.GenericInputOutputIcon; +// } +// +// protected override ContextMenuStrip GetContextMenu(TreeNode node, FailureMechanismContribution nodeData) +// { +// return contextMenuBuilderProvider +// .Get(node) +// .AddOpenItem() +// .AddSeparator() +// .AddExportItem() +// .Build(); +// } +// } +//} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismNodePresenter.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismNodePresenter.cs (.../FailureMechanismNodePresenter.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/FailureMechanismNodePresenter.cs (.../FailureMechanismNodePresenter.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,86 +1,86 @@ -using System; -using System.Collections; -using System.Drawing; -using System.Windows.Forms; -using Core.Common.Gui; -using Core.Common.Gui.ContextMenu; -using Ringtoets.Common.Forms.NodePresenters; -using Ringtoets.Common.Forms.PresentationObjects; -using Ringtoets.Integration.Data.Placeholders; -using Ringtoets.Integration.Forms.Properties; - -using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; - -namespace Ringtoets.Integration.Forms.NodePresenters -{ - public class FailureMechanismNodePresenter : RingtoetsNodePresenterBase - { - /// - /// Creates a new instance of , which uses the - /// to create and bind its . - /// - /// The - /// to use for building a . - /// Thrown when no was provided. - public FailureMechanismNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) { } - - protected override void UpdateNode(TreeNode parentNode, TreeNode node, FailureMechanismPlaceholder nodeData) - { - node.Text = nodeData.Name; - node.ForegroundColor = Color.FromKnownColor(KnownColor.GrayText); - node.Image = Resources.FailureMechanismIcon; - } - - protected override IEnumerable GetChildNodeObjects(FailureMechanismPlaceholder nodeData) - { - yield return new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetInputs(nodeData), TreeFolderCategory.Input); - yield return new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Outputs_DisplayName, GetOutputs(nodeData), TreeFolderCategory.Output); - } - - protected override ContextMenuStrip GetContextMenu(TreeNode node, FailureMechanismPlaceholder nodeData) - { - var calculateItem = new StrictContextMenuItem( - RingtoetsCommonFormsResources.Calculate_all, - RingtoetsCommonFormsResources.Calculate_all_ToolTip, - RingtoetsCommonFormsResources.CalculateAllIcon, - null) - { - Enabled = false - }; - var clearOutputItem = new StrictContextMenuItem( - RingtoetsCommonFormsResources.Clear_all_output, - RingtoetsCommonFormsResources.Clear_all_output_ToolTip, - RingtoetsCommonFormsResources.ClearIcon, null - ) - { - Enabled = false - }; - - return contextMenuBuilderProvider.Get(node) - .AddCustomItem(calculateItem) - .AddCustomItem(clearOutputItem) - .AddSeparator() - .AddImportItem() - .AddExportItem() - .AddSeparator() - .AddExpandAllItem() - .AddCollapseAllItem() - .AddSeparator() - .AddPropertiesItem() - .Build(); - } - - private IEnumerable GetInputs(FailureMechanismPlaceholder nodeData) - { - yield return nodeData.SectionDivisions; - yield return nodeData.Locations; - yield return nodeData.BoundaryConditions; - } - - private IEnumerable GetOutputs(FailureMechanismPlaceholder nodeData) - { - yield return nodeData.AssessmentResult; - } - } -} \ No newline at end of file +//using System; +//using System.Collections; +//using System.Drawing; +//using System.Windows.Forms; +//using Core.Common.Gui; +//using Core.Common.Gui.ContextMenu; +//using Ringtoets.Common.Forms.NodePresenters; +//using Ringtoets.Common.Forms.PresentationObjects; +//using Ringtoets.Integration.Data.Placeholders; +//using Ringtoets.Integration.Forms.Properties; +// +//using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +//using TreeNode = Core.Common.Controls.TreeView.TreeNode; +// +//namespace Ringtoets.Integration.Forms.NodePresenters +//{ +// public class FailureMechanismNodePresenter : RingtoetsNodePresenterBase +// { +// /// +// /// Creates a new instance of , which uses the +// /// to create and bind its . +// /// +// /// The +// /// to use for building a . +// /// Thrown when no was provided. +// public FailureMechanismNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) { } +// +// protected override void UpdateNode(TreeNode parentNode, TreeNode node, FailureMechanismPlaceholder nodeData) +// { +// node.Text = nodeData.Name; +// node.ForegroundColor = Color.FromKnownColor(KnownColor.GrayText); +// node.Image = Resources.FailureMechanismIcon; +// } +// +// protected override IEnumerable GetChildNodeObjects(FailureMechanismPlaceholder nodeData) +// { +// yield return new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetInputs(nodeData), TreeFolderCategory.Input); +// yield return new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Outputs_DisplayName, GetOutputs(nodeData), TreeFolderCategory.Output); +// } +// +// protected override ContextMenuStrip GetContextMenu(TreeNode node, FailureMechanismPlaceholder nodeData) +// { +// var calculateItem = new StrictContextMenuItem( +// RingtoetsCommonFormsResources.Calculate_all, +// RingtoetsCommonFormsResources.Calculate_all_ToolTip, +// RingtoetsCommonFormsResources.CalculateAllIcon, +// null) +// { +// Enabled = false +// }; +// var clearOutputItem = new StrictContextMenuItem( +// RingtoetsCommonFormsResources.Clear_all_output, +// RingtoetsCommonFormsResources.Clear_all_output_ToolTip, +// RingtoetsCommonFormsResources.ClearIcon, null +// ) +// { +// Enabled = false +// }; +// +// return contextMenuBuilderProvider.Get(node) +// .AddCustomItem(calculateItem) +// .AddCustomItem(clearOutputItem) +// .AddSeparator() +// .AddImportItem() +// .AddExportItem() +// .AddSeparator() +// .AddExpandAllItem() +// .AddCollapseAllItem() +// .AddSeparator() +// .AddPropertiesItem() +// .Build(); +// } +// +// private IEnumerable GetInputs(FailureMechanismPlaceholder nodeData) +// { +// yield return nodeData.SectionDivisions; +// yield return nodeData.Locations; +// yield return nodeData.BoundaryConditions; +// } +// +// private IEnumerable GetOutputs(FailureMechanismPlaceholder nodeData) +// { +// yield return nodeData.AssessmentResult; +// } +// } +//} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs (.../PlaceholderWithReadonlyNameNodePresenter.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/NodePresenters/PlaceholderWithReadonlyNameNodePresenter.cs (.../PlaceholderWithReadonlyNameNodePresenter.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,78 +1,78 @@ -using System; -using System.Drawing; -using System.Windows.Forms; -using Core.Common.Gui; -using Core.Common.Gui.ContextMenu; -using Ringtoets.Common.Forms.NodePresenters; -using Ringtoets.Common.Placeholder; -using Ringtoets.Integration.Forms.Properties; -using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; - -namespace Ringtoets.Integration.Forms.NodePresenters -{ - /// - /// Node presenter class for - /// - public class PlaceholderWithReadonlyNameNodePresenter : RingtoetsNodePresenterBase - { - /// - /// Creates a new instance of , which uses the - /// to create and bind its . - /// - /// The - /// to use for building a . - /// Thrown when no was provided. - public PlaceholderWithReadonlyNameNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) { } - - protected override void UpdateNode(TreeNode parentNode, TreeNode node, PlaceholderWithReadonlyName nodeData) - { - node.Text = nodeData.Name; - node.ForegroundColor = Color.FromKnownColor(KnownColor.GrayText); - node.Image = GetIconForPlaceholder(nodeData); - } - - protected override ContextMenuStrip GetContextMenu(TreeNode node, PlaceholderWithReadonlyName nodeData) - { - IContextMenuBuilder menuBuilder = contextMenuBuilderProvider.Get(node); - - if (nodeData is InputPlaceholder || nodeData is OutputPlaceholder) - { - menuBuilder.AddOpenItem(); - } - - if (nodeData is OutputPlaceholder) - { - var clearItem = new StrictContextMenuItem( - RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase, - RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase_ToolTip, - RingtoetsCommonFormsResources.ClearIcon, - null) - { - Enabled = false - }; - - menuBuilder.AddCustomItem(clearItem); - } - - if (nodeData is InputPlaceholder || nodeData is OutputPlaceholder) - { - menuBuilder.AddSeparator(); - } - return menuBuilder.AddImportItem() - .AddExportItem() - .AddSeparator() - .AddPropertiesItem() - .Build(); - } - - private static Bitmap GetIconForPlaceholder(PlaceholderWithReadonlyName nodeData) - { - if (nodeData is InputPlaceholder || nodeData is OutputPlaceholder) - { - return Resources.GenericInputOutputIcon; - } - return Resources.PlaceholderIcon; - } - } -} \ No newline at end of file +//using System; +//using System.Drawing; +//using System.Windows.Forms; +//using Core.Common.Gui; +//using Core.Common.Gui.ContextMenu; +//using Ringtoets.Common.Forms.NodePresenters; +//using Ringtoets.Common.Placeholder; +//using Ringtoets.Integration.Forms.Properties; +//using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +//using TreeNode = Core.Common.Controls.TreeView.TreeNode; +// +//namespace Ringtoets.Integration.Forms.NodePresenters +//{ +// /// +// /// Node presenter class for +// /// +// public class PlaceholderWithReadonlyNameNodePresenter : RingtoetsNodePresenterBase +// { +// /// +// /// Creates a new instance of , which uses the +// /// to create and bind its . +// /// +// /// The +// /// to use for building a . +// /// Thrown when no was provided. +// public PlaceholderWithReadonlyNameNodePresenter(IContextMenuBuilderProvider contextMenuBuilderProvider) : base(contextMenuBuilderProvider) { } +// +// protected override void UpdateNode(TreeNode parentNode, TreeNode node, PlaceholderWithReadonlyName nodeData) +// { +// node.Text = nodeData.Name; +// node.ForegroundColor = Color.FromKnownColor(KnownColor.GrayText); +// node.Image = GetIconForPlaceholder(nodeData); +// } +// +// protected override ContextMenuStrip GetContextMenu(TreeNode node, PlaceholderWithReadonlyName nodeData) +// { +// IContextMenuBuilder menuBuilder = contextMenuBuilderProvider.Get(node); +// +// if (nodeData is InputPlaceholder || nodeData is OutputPlaceholder) +// { +// menuBuilder.AddOpenItem(); +// } +// +// if (nodeData is OutputPlaceholder) +// { +// var clearItem = new StrictContextMenuItem( +// RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase, +// RingtoetsCommonFormsResources.FailureMechanism_InputsOutputs_Erase_ToolTip, +// RingtoetsCommonFormsResources.ClearIcon, +// null) +// { +// Enabled = false +// }; +// +// menuBuilder.AddCustomItem(clearItem); +// } +// +// if (nodeData is InputPlaceholder || nodeData is OutputPlaceholder) +// { +// menuBuilder.AddSeparator(); +// } +// return menuBuilder.AddImportItem() +// .AddExportItem() +// .AddSeparator() +// .AddPropertiesItem() +// .Build(); +// } +// +// private static Bitmap GetIconForPlaceholder(PlaceholderWithReadonlyName nodeData) +// { +// if (nodeData is InputPlaceholder || nodeData is OutputPlaceholder) +// { +// return Resources.GenericInputOutputIcon; +// } +// return Resources.PlaceholderIcon; +// } +// } +//} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs =================================================================== diff -u -r98939d3757e99732f74f6345b5eb58c90e30a4d4 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision 98939d3757e99732f74f6345b5eb58c90e30a4d4) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -10,20 +10,17 @@ using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms; using Core.Common.Gui.Plugin; -using Ringtoets.Common.Forms.NodePresenters; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Placeholder; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.Contribution; using Ringtoets.Integration.Data.Placeholders; using Ringtoets.Integration.Data.Properties; -using Ringtoets.Integration.Forms.NodePresenters; using Ringtoets.Integration.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Views; using RingtoetsDataResources = Ringtoets.Integration.Data.Properties.Resources; using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; namespace Ringtoets.Integration.Plugin { @@ -68,28 +65,14 @@ } } - /// - /// Get the defined for the . - /// - /// An of . - /// Thrown when is null. - public override IEnumerable GetProjectTreeViewNodePresenters() - { - yield return new AssessmentSectionBaseNodePresenter(Gui); - yield return new FailureMechanismNodePresenter(Gui); - yield return new PlaceholderWithReadonlyNameNodePresenter(Gui); - yield return new CategoryTreeFolderNodePresenter(Gui); - yield return new FailureMechanismContributionNodePresenter(Gui); - } - public override IEnumerable GetTreeNodeInfos() { yield return new TreeNodeInfo { Text = assessmentSectionBase => assessmentSectionBase.Name, Image = assessmentSectionBase => RingtoetsFormsResources.AssessmentSectionFolderIcon, ChildNodeObjects = AssessmentSectionBaseChildNodeObjects, - ContextMenu = AssessmentSectionBaseContextMenu, + ContextMenuStrip = AssessmentSectionBaseContextMenuStrip, CanRename = assessmentSectionBase => true, OnNodeRenamed = AssessmentSectionBaseOnNodeRenamed, CanRemove = (assessmentSectionBase, parentNodeData) => true, @@ -100,36 +83,36 @@ { Text = failureMechanismPlaceholder => failureMechanismPlaceholder.Name, Image = failureMechanismPlaceholder => RingtoetsFormsResources.FailureMechanismIcon, - ForegroundColor = failureMechanismPlaceholder => Color.FromKnownColor(KnownColor.GrayText), + ForeColor = failureMechanismPlaceholder => Color.FromKnownColor(KnownColor.GrayText), ChildNodeObjects = FailureMechanismPlaceholderChildNodeObjects, - ContextMenu = FailureMechanismPlaceholderContextMenu + ContextMenuStrip = FailureMechanismPlaceholderContextMenuStrip }; yield return new TreeNodeInfo { Text = placeholderWithReadonlyName => placeholderWithReadonlyName.Name, Image = placeholderWithReadonlyName => GetIconForPlaceholder(placeholderWithReadonlyName), - ForegroundColor = placeholderWithReadonlyName => Color.FromKnownColor(KnownColor.GrayText), - ContextMenu = PlaceholderWithReadonlyNameContextMenu + ForeColor = placeholderWithReadonlyName => Color.FromKnownColor(KnownColor.GrayText), + ContextMenuStrip = PlaceholderWithReadonlyNameContextMenuStrip }; yield return new TreeNodeInfo { Text = categoryTreeFolder => categoryTreeFolder.Name, Image = categoryTreeFolder => GetFolderIcon(categoryTreeFolder.Category), ChildNodeObjects = categoryTreeFolder => categoryTreeFolder.Contents.Cast().ToArray(), - ContextMenu = CategoryTreeFolderContextMenu + ContextMenuStrip = CategoryTreeFolderContextMenu }; yield return new TreeNodeInfo { Text = failureMechanismContribution => RingtoetsDataResources.FailureMechanismContribution_DisplayName, Image = failureMechanismContribution => RingtoetsFormsResources.GenericInputOutputIcon, - ContextMenu = (failureMechanismContribution, sourceNode) => Gui.Get(sourceNode) - .AddOpenItem() - .AddSeparator() - .AddExportItem() - .Build() + ContextMenuStrip = (failureMechanismContribution, sourceNode, treeNodeInfo) => Gui.Get(sourceNode, treeNodeInfo) + .AddOpenItem() + .AddSeparator() + .AddExportItem() + .Build() }; } @@ -163,9 +146,9 @@ parentProject.NotifyObservers(); } - private ContextMenuStrip AssessmentSectionBaseContextMenu(AssessmentSectionBase nodeData, TreeNode node) + private ContextMenuStrip AssessmentSectionBaseContextMenuStrip(AssessmentSectionBase nodeData, TreeNode node, TreeNodeInfo treeNodeInfo) { - return Gui.Get(node) + return Gui.Get(node, treeNodeInfo) .AddRenameItem() .AddDeleteItem() .AddSeparator() @@ -196,19 +179,25 @@ }; } - private IEnumerable GetInputs(FailureMechanismPlaceholder nodeData) + private IList GetInputs(FailureMechanismPlaceholder nodeData) { - yield return nodeData.SectionDivisions; - yield return nodeData.Locations; - yield return nodeData.BoundaryConditions; + return new ArrayList + { + nodeData.SectionDivisions, + nodeData.Locations, + nodeData.BoundaryConditions + }; } - private IEnumerable GetOutputs(FailureMechanismPlaceholder nodeData) + private IList GetOutputs(FailureMechanismPlaceholder nodeData) { - yield return nodeData.AssessmentResult; + return new ArrayList + { + nodeData.AssessmentResult + }; } - private ContextMenuStrip FailureMechanismPlaceholderContextMenu(FailureMechanismPlaceholder nodeData, TreeNode node) + private ContextMenuStrip FailureMechanismPlaceholderContextMenuStrip(FailureMechanismPlaceholder nodeData, TreeNode node, TreeNodeInfo treeNodeInfo) { var calculateItem = new StrictContextMenuItem( RingtoetsCommonFormsResources.Calculate_all, @@ -227,7 +216,7 @@ Enabled = false }; - return Gui.Get(node) + return Gui.Get(node, treeNodeInfo) .AddCustomItem(calculateItem) .AddCustomItem(clearOutputItem) .AddSeparator() @@ -254,9 +243,9 @@ return RingtoetsFormsResources.PlaceholderIcon; } - private ContextMenuStrip PlaceholderWithReadonlyNameContextMenu(PlaceholderWithReadonlyName nodeData, TreeNode node) + private ContextMenuStrip PlaceholderWithReadonlyNameContextMenuStrip(PlaceholderWithReadonlyName nodeData, TreeNode node, TreeNodeInfo treeNodeInfo) { - IContextMenuBuilder menuBuilder = Gui.Get(node); + IContextMenuBuilder menuBuilder = Gui.Get(node, treeNodeInfo); if (nodeData is InputPlaceholder || nodeData is OutputPlaceholder) { @@ -307,9 +296,9 @@ } } - private ContextMenuStrip CategoryTreeFolderContextMenu(CategoryTreeFolder nodeData, TreeNode node) + private ContextMenuStrip CategoryTreeFolderContextMenu(CategoryTreeFolder nodeData, TreeNode node, TreeNodeInfo treeNodeInfo) { - return Gui.Get(node) + return Gui.Get(node, treeNodeInfo) .AddExpandAllItem() .AddCollapseAllItem() .Build(); Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/AssessmentSectionBaseNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/FailureMechanismContributionNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/FailureMechanismNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/PlaceholderWithReadonlyNameNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -r148b5639633795054317d492507c072ee0bd5ada -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 148b5639633795054317d492507c072ee0bd5ada) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -58,10 +58,10 @@ - - - - + + + + @@ -119,6 +119,10 @@ {ad0cdc89-0a00-4068-aeec-9838863c2fe8} Ringtoets.Integration.Forms + + {C8383B76-B3F1-4E6E-B56C-527B469FA20A} + Ringtoets.Integration.Plugin + Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionBaseTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionBaseTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionBaseTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,230 @@ +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.Contribution; +using Ringtoets.Integration.Plugin; +using RingtoetsIntegrationFormsResources = Ringtoets.Integration.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class AssessmentSectionBaseTreeNodeInfoTest + { + private MockRepository mocks; + private RingtoetsGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new RingtoetsGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(AssessmentSectionBase)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(AssessmentSectionBase), info.TagType); + + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var assessmentSection = mocks.StrictMock(); + var testName = "ttt"; + assessmentSection.Name = testName; + + mocks.ReplayAll(); + + // Call + var text = info.Text(assessmentSection); + + // Assert + Assert.AreEqual(testName, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var assessmentSection = mocks.StrictMock(); + + mocks.ReplayAll(); + + // Call + var image = info.Image(assessmentSection); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsIntegrationFormsResources.AssessmentSectionFolderIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildsOnData() + { + // Setup + var failureMechanism = mocks.StrictMock(); + failureMechanism.Expect(f => f.Name).Return("some name"); + failureMechanism.Expect(f => f.Contribution).Return(100); + + mocks.ReplayAll(); + + var failureMechanismList = new List { failureMechanism }; + var contribution = new FailureMechanismContribution(failureMechanismList, 10.0, 2); + var assessmentSection = new TestAssessmentSectionBase(contribution, failureMechanismList); + + // Call + var objects = info.ChildNodeObjects(assessmentSection); + + // Assert + var collection = new List(); + collection.Add(assessmentSection.ReferenceLine); + collection.Add(contribution); + collection.Add(assessmentSection.HydraulicBoundaryDatabase); + collection.Add(failureMechanism); + CollectionAssert.AreEqual(collection, objects); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var treeNode = new TreeNode(); + + var gui = mocks.StrictMultiMock(); + var menuBuilderMock = mocks.StrictMock(); + gui.Expect(g => g.Get(treeNode, info)).Return(menuBuilderMock); + + menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, treeNode, info); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void CanRename_Always_ReturnsTrue() + { + // Call + var canRename = info.CanRename(null); + + // Assert + Assert.IsTrue(canRename); + } + + [Test] + public void OnNodeRenamed_WithData_SetProjectNameWithNotification() + { + // Setup + var assessmentSectionObserver = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + + assessmentSectionObserver.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + assessmentSection.Attach(assessmentSectionObserver); + + // Call + const string newName = "New Name"; + info.OnNodeRenamed(assessmentSection, newName); + + // Assert + Assert.AreEqual(newName, assessmentSection.Name); + mocks.VerifyAll(); + } + + [Test] + public void CanRemove_Always_ReturnsTrue() + { + // Call + var canRemove = info.CanRemove(null, null); + + // Assert + Assert.IsTrue(canRemove); + } + + [Test] + public void RemoveNodeData_ProjectWithAssessmentSection_ReturnTrueAndRemoveAssessmentSection() + { + // Setup + var observerMock = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + + observerMock.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var project = new Project(); + project.Items.Add(assessmentSection); + project.Attach(observerMock); + + + // Call + info.OnNodeRemoved(assessmentSection, project); + + // Assert + CollectionAssert.DoesNotContain(project.Items, assessmentSection); + mocks.VerifyAll(); + } + } + + public class TestAssessmentSectionBase : AssessmentSectionBase { + + private IEnumerable failureMechanisms; + + public TestAssessmentSectionBase(FailureMechanismContribution contribution, IEnumerable failureMechanisms) + { + FailureMechanismContribution = contribution; + this.failureMechanisms = failureMechanisms; + } + + public override IEnumerable GetFailureMechanisms() + { + return failureMechanisms; + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismContributionTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismContributionTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismContributionTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,101 @@ +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Integration.Data.Contribution; +using Ringtoets.Integration.Plugin; +using RingtoetsIntegrationFormsResources = Ringtoets.Integration.Forms.Properties.Resources; +using RingtoetsIntegrationDataResources = Ringtoets.Integration.Data.Properties.Resources; + +namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class FailureMechanismContributionTreeNodeInfoTest + { + private MockRepository mocks; + private RingtoetsGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new RingtoetsGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailureMechanismContribution)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(FailureMechanismContribution), info.TagType); + + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Call + var text = info.Text(null); + + // Assert + Assert.AreEqual(RingtoetsIntegrationDataResources.FailureMechanismContribution_DisplayName, text); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsIntegrationFormsResources.GenericInputOutputIcon, image); + + mocks.VerifyAll(); + } + + + [Test] + public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, nodeMock, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismPlaceholderTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismPlaceholderTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismPlaceholderTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,171 @@ +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Integration.Data.Placeholders; +using Ringtoets.Integration.Plugin; +using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class FailureMechanismPlaceholderTreeNodeInfoTest + { + private MockRepository mocks; + private RingtoetsGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new RingtoetsGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailureMechanismPlaceholder)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(FailureMechanismPlaceholder), info.TagType); + + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var testName = "ttt"; + var placeholder = new FailureMechanismPlaceholder(testName); + + // Call + var text = info.Text(placeholder); + + // Assert + Assert.AreEqual(testName, text); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.FailureMechanismIcon, image); + } + + [Test] + public void ForeColor_Always_ReturnsGrayText() + { + // Call + var textColor = info.ForeColor(null); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + } + + [Test] + public void ChildNodeObjects_Always_ReturnFoldersWithInputAndOutput() + { + // Setup + var failureMechanism = new FailureMechanismPlaceholder("test"); + + // Call + object[] children = info.ChildNodeObjects(failureMechanism).ToArray(); + + // Assert + Assert.AreEqual(2, children.Length); + var inputFolder = (CategoryTreeFolder)children[0]; + Assert.AreEqual("Invoer", inputFolder.Name); + Assert.AreEqual(TreeFolderCategory.Input, inputFolder.Category); + CollectionAssert.AreEqual(new[] + { + failureMechanism.SectionDivisions, + failureMechanism.Locations, + failureMechanism.BoundaryConditions + }, inputFolder.Contents); + + var outputFolder = (CategoryTreeFolder)children[1]; + Assert.AreEqual("Uitvoer", outputFolder.Name); + Assert.AreEqual(TreeFolderCategory.Output, outputFolder.Category); + Assert.AreEqual(new[]{failureMechanism.AssessmentResult}, outputFolder.Contents); + } + + [Test] + public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, nodeMock, info); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CalculateAllAndClearAllItemDisabled() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = new CustomItemsOnlyContextMenuBuilder(); + var nodeMock = mocks.StrictMock(); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + var menu = info.ContextMenuStrip(null, nodeMock, info); + + // Assert + mocks.VerifyAll(); + + TestHelper.AssertContextMenuStripContainsItem(menu, 0, RingtoetsCommonFormsResources.Calculate_all, RingtoetsCommonFormsResources.Calculate_all_ToolTip, RingtoetsCommonFormsResources.CalculateAllIcon, false); + TestHelper.AssertContextMenuStripContainsItem(menu, 1, RingtoetsCommonFormsResources.Clear_all_output, RingtoetsCommonFormsResources.Clear_all_output_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/PlaceholderWithReadonlyNameTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/PlaceholderWithReadonlyNameTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/PlaceholderWithReadonlyNameTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,191 @@ +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Placeholder; +using Ringtoets.Integration.Plugin; +using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class PlaceholderWithReadonlyNameTreeNodeInfoTest + { + private MockRepository mocks; + private RingtoetsGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new RingtoetsGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PlaceholderWithReadonlyName)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PlaceholderWithReadonlyName), info.TagType); + + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var testName = "ttt"; + var placeholder = new PlaceholderWithReadonlyName(testName); + + // Call + var text = info.Text(placeholder); + + // Assert + Assert.AreEqual(testName, text); + } + + [Test] + public void Image_OutputPlaceHolder_ReturnsGenericInputOutputIcon() + { + // Call + var image = info.Image(new OutputPlaceholder(string.Empty)); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.GenericInputOutputIcon, image); + } + + [Test] + public void Image_InputPlaceHolder_ReturnsGenericInputOutputIcon() + { + // Call + var image = info.Image(new InputPlaceholder(string.Empty)); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.GenericInputOutputIcon, image); + } + + [Test] + public void Image_PlaceHolder_ReturnsPlaceHolderIcon() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.PlaceholderIcon, image); + } + + [Test] + public void ForeColor_Always_ReturnsGrayText() + { + // Call + var textColor = info.ForeColor(null); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + } + + [Test] + public void GetContextMenu_OutputPlaceHolder_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddOpenItem()).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(new OutputPlaceholder(string.Empty), nodeMock, info); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_InputPlaceHolder_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddOpenItem()).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(new InputPlaceholder(string.Empty), nodeMock, info); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_PlaceHolder_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, nodeMock, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r148b5639633795054317d492507c072ee0bd5ada -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 148b5639633795054317d492507c072ee0bd5ada) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -91,10 +91,18 @@ {d749ee4c-ce50-4c17-bf01-9a953028c126} Core.Common.TestUtil + + {d4200f43-3f72-4f42-af0a-8ced416a38ec} + Ringtoets.Common.Data + {4d840673-3812-4338-a352-84854e32b8a0} Ringtoets.Common.Forms + + {E38C11E0-4384-44DD-9F5B-EE73D79FD7F5} + Ringtoets.Common.Placeholder + {11f1f874-45af-43e4-8ae5-15a5c9593e28} Ringtoets.Integration.Data Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs =================================================================== diff -u -r98939d3757e99732f74f6345b5eb58c90e30a4d4 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs (.../RingtoetsGuiPluginTest.cs) (revision 98939d3757e99732f74f6345b5eb58c90e30a4d4) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs (.../RingtoetsGuiPluginTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -5,9 +5,11 @@ using Core.Common.Gui; using NUnit.Framework; using Rhino.Mocks; -using Ringtoets.Common.Forms.NodePresenters; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Placeholder; using Ringtoets.Integration.Data; -using Ringtoets.Integration.Forms.NodePresenters; +using Ringtoets.Integration.Data.Contribution; +using Ringtoets.Integration.Data.Placeholders; using Ringtoets.Integration.Forms.PropertyClasses; namespace Ringtoets.Integration.Plugin.Test @@ -67,15 +69,15 @@ }) { // call - ITreeNodePresenter[] nodePresenters = guiPlugin.GetProjectTreeViewNodePresenters().ToArray(); + TreeNodeInfo[] treeNodeInfos = guiPlugin.GetTreeNodeInfos().ToArray(); // assert - Assert.AreEqual(5, nodePresenters.Length); - Assert.IsTrue(nodePresenters.Any(np => np is AssessmentSectionBaseNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PlaceholderWithReadonlyNameNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is FailureMechanismNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is CategoryTreeFolderNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is FailureMechanismContributionNodePresenter)); + Assert.AreEqual(5, treeNodeInfos.Length); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(AssessmentSectionBase))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(PlaceholderWithReadonlyName))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailureMechanismPlaceholder))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(CategoryTreeFolder))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailureMechanismContribution))); } mocks.VerifyAll(); } Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/EmptyPipingCalculationReportNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/EmptyPipingOutputNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingCalculationContextNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingCalculationGroupContextNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingFailureMechanismNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingInputContextNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingOutputNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingSoilProfileCollectionNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingSoilProfileNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingSurfaceLineCollectionNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingSurfaceLineNodePresenter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -rea23f63aaa17ddf43d3e5c753a53515a504ece38 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision ea23f63aaa17ddf43d3e5c753a53515a504ece38) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -49,16 +49,6 @@ Properties\GlobalAssembly.cs - - - - - - - - - - @@ -72,7 +62,6 @@ Resources.resx - Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs =================================================================== diff -u -rf7d7a919dec1b7d79672af043f268cde57aab0ba -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision f7d7a919dec1b7d79672af043f268cde57aab0ba) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; -using Core.Common.Base; using Core.Common.Base.IO; using log4net; using Ringtoets.Piping.Data; @@ -162,12 +161,6 @@ { targetCollection.Add(item); } - - var observableCollection = targetCollection as IObservable; - if (observableCollection != null) - { - observableCollection.NotifyObservers(); - } } private void NotifyProgress(string currentStepName, int currentStep, int totalNumberOfSteps) Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs =================================================================== diff -u -rf7d7a919dec1b7d79672af043f268cde57aab0ba -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision f7d7a919dec1b7d79672af043f268cde57aab0ba) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -3,7 +3,6 @@ using System.Drawing; using System.IO; using System.Linq; -using Core.Common.Base; using Core.Common.Base.IO; using log4net; @@ -209,12 +208,6 @@ { targetCollection.Add(readSurfaceLine); } - - var observableTarget = targetCollection as IObservable; - if (observableTarget != null) - { - observableTarget.NotifyObservers(); - } } private void HandleUserCancellingImport() Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs =================================================================== diff -u -r98939d3757e99732f74f6345b5eb58c90e30a4d4 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs (.../PipingGuiPlugin.cs) (revision 98939d3757e99732f74f6345b5eb58c90e30a4d4) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs (.../PipingGuiPlugin.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,5 +1,4 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -12,7 +11,6 @@ using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Piping.Data; -using Ringtoets.Piping.Forms.NodePresenters; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.PropertyClasses; using Ringtoets.Piping.Service; @@ -21,7 +19,6 @@ using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; using BaseResources = Core.Common.Base.Properties.Resources; -using TreeNode = Core.Common.Controls.TreeView.TreeNode; using TreeView = Core.Common.Controls.TreeView.TreeView; namespace Ringtoets.Piping.Plugin @@ -46,50 +43,21 @@ yield return new PropertyInfo(); } - /// - /// Get the defined for the . - /// - /// An of . - /// Thrown when is null. - public override IEnumerable GetProjectTreeViewNodePresenters() - { - yield return new PipingFailureMechanismNodePresenter(Gui) - { - RunActivitiesAction = activities => ActivityProgressDialogRunner.Run(Gui.MainWindow, activities) - }; - yield return new PipingCalculationContextNodePresenter(Gui) - { - RunActivityAction = activity => ActivityProgressDialogRunner.Run(Gui.MainWindow, activity) - }; - yield return new PipingCalculationGroupContextNodePresenter(Gui) - { - RunActivitiesAction = activities => ActivityProgressDialogRunner.Run(Gui.MainWindow, activities) - }; - yield return new PipingInputContextNodePresenter(Gui); - yield return new PipingSurfaceLineCollectionNodePresenter(Gui); - yield return new PipingSurfaceLineNodePresenter(Gui); - yield return new PipingSoilProfileCollectionNodePresenter(Gui); - yield return new PipingSoilProfileNodePresenter(Gui); - yield return new PipingOutputNodePresenter(Gui); - yield return new EmptyPipingOutputNodePresenter(Gui); - yield return new EmptyPipingCalculationReportNodePresenter(Gui); - } - public override IEnumerable GetTreeNodeInfos() { yield return new TreeNodeInfo { Text = pipingFailureMechanism => pipingFailureMechanism.Name, Image = pipingFailureMechanism => PipingFormsResources.PipingIcon, - ContextMenu = FailureMechanismContextMenu, - ChildNodeObjects = FailureMechanismChildNodeObjects + ContextMenuStrip = FailureMechanismContextMenuStrip, + ChildNodeObjects = FailureMechanismChildNodeObjects, }; yield return new TreeNodeInfo { Text = pipingCalculationContext => pipingCalculationContext.WrappedData.Name, Image = pipingCalculationContext => PipingFormsResources.PipingIcon, - ContextMenu = PipingCalculationContextContextMenu, + ContextMenuStrip = PipingCalculationContextContextMenuStrip, ChildNodeObjects = PipingCalculationContextChildNodeObjects, CanRename = pipingCalculationContext => true, OnNodeRenamed = PipingCalculationContextOnNodeRenamed, @@ -103,127 +71,118 @@ Text = pipingCalculationGroupContext => pipingCalculationGroupContext.WrappedData.Name, Image = pipingCalculationGroupContext => PipingFormsResources.FolderIcon, ChildNodeObjects = PipingCalculationGroupContextChildNodeObjects, - ContextMenu = PipingCalculationGroupContextContextMenu, + ContextMenuStrip = PipingCalculationGroupContextContextMenuStrip, CanRename = PipingCalculationGroupContextCanRenameNode, OnNodeRenamed = PipingCalculationGroupContextOnNodeRenamed, CanRemove = PipingCalculationGroupContextCanRemove, OnNodeRemoved = PipingCalculationGroupContextOnNodeRemoved, CanDrag = PipingCalculationGroupContextCanDrag, CanDrop = PipingCalculationGroupContextCanDrop, CanInsert = PipingCalculationGroupContextCanInsert, - OnDrop = PipingCalculationGroupContextOnDrop + OnDrop = PipingCalculationGroupContextOnDrop, }; yield return new TreeNodeInfo { Text = pipingInputContext => PipingFormsResources.PipingInputContextNodePresenter_NodeDisplayName, Image = pipingInputContext => PipingFormsResources.PipingInputIcon, - ContextMenu = (nodeData, node) => Gui - .Get(node) - .AddImportItem() - .AddExportItem() - .AddSeparator() - .AddPropertiesItem() - .Build() + ContextMenuStrip = (nodeData, node, treeNodeInfo) => Gui.Get(node, treeNodeInfo) + .AddImportItem() + .AddExportItem() + .AddSeparator() + .AddPropertiesItem() + .Build() }; yield return new TreeNodeInfo> { Text = ringtoetsPipingSurfaceLine => PipingFormsResources.PipingSurfaceLinesCollection_DisplayName, Image = ringtoetsPipingSurfaceLine => PipingFormsResources.FolderIcon, - ForegroundColor = ringtoetsPipingSurfaceLine => ringtoetsPipingSurfaceLine.Any() ? Color.FromKnownColor(KnownColor.ControlText) : Color.FromKnownColor(KnownColor.GrayText), + ForeColor = ringtoetsPipingSurfaceLine => ringtoetsPipingSurfaceLine.Any() ? Color.FromKnownColor(KnownColor.ControlText) : Color.FromKnownColor(KnownColor.GrayText), ChildNodeObjects = ringtoetsPipingSurfaceLine => ringtoetsPipingSurfaceLine.Cast().ToArray(), - ContextMenu = (nodeData, node) => Gui - .Get(node) - .AddImportItem() - .AddExportItem() - .AddSeparator() - .AddExpandAllItem() - .AddCollapseAllItem() - .Build() + ContextMenuStrip = (nodeData, node, treeNodeInfo) => Gui.Get(node, treeNodeInfo) + .AddImportItem() + .AddExportItem() + .AddSeparator() + .AddExpandAllItem() + .AddCollapseAllItem() + .Build() }; yield return new TreeNodeInfo { Text = pipingSurfaceLine => pipingSurfaceLine.Name, Image = pipingSurfaceLine => PipingFormsResources.PipingSurfaceLineIcon, - - ContextMenu = (nodeData, node) => Gui - .Get(node) - .AddPropertiesItem() - .Build() + ContextMenuStrip = (nodeData, node, treeNodeInfo) => Gui.Get(node, treeNodeInfo) + .AddPropertiesItem() + .Build() }; yield return new TreeNodeInfo> { Text = pipingSoilProfiles => PipingFormsResources.PipingSoilProfilesCollection_DisplayName, Image = pipingSoilProfiles => PipingFormsResources.FolderIcon, - ForegroundColor = pipingSoilProfiles => pipingSoilProfiles.Any() ? Color.FromKnownColor(KnownColor.ControlText) : Color.FromKnownColor(KnownColor.GrayText), + ForeColor = pipingSoilProfiles => pipingSoilProfiles.Any() ? Color.FromKnownColor(KnownColor.ControlText) : Color.FromKnownColor(KnownColor.GrayText), ChildNodeObjects = pipingSoilProfiles => pipingSoilProfiles.Cast().ToArray(), - ContextMenu = (nodeData, node) => Gui - .Get(node) - .AddImportItem() - .AddExportItem() - .AddSeparator() - .AddExpandAllItem() - .AddCollapseAllItem() - .Build() + ContextMenuStrip = (nodeData, node, treeNodeInfo) => Gui.Get(node, treeNodeInfo) + .AddImportItem() + .AddExportItem() + .AddSeparator() + .AddExpandAllItem() + .AddCollapseAllItem() + .Build() }; yield return new TreeNodeInfo { Text = pipingSoilProfile => pipingSoilProfile.Name, Image = pipingSoilProfile => PipingFormsResources.PipingSoilProfileIcon, - ContextMenu = (nodeData, node) => Gui - .Get(node) - .AddPropertiesItem() - .Build() + ContextMenuStrip = (nodeData, node, treeNodeInfo) => Gui.Get(node, treeNodeInfo) + .AddPropertiesItem() + .Build() }; yield return new TreeNodeInfo { Text = pipingOutput => PipingFormsResources.PipingOutput_DisplayName, Image = pipingOutput => PipingFormsResources.PipingOutputIcon, - ContextMenu = (nodeData, node) => Gui - .Get(node) - .AddExportItem() - .AddSeparator() - .AddPropertiesItem() - .Build() + ContextMenuStrip = (nodeData, node, treeNodeInfo) => Gui.Get(node, treeNodeInfo) + .AddExportItem() + .AddSeparator() + .AddPropertiesItem() + .Build() }; yield return new TreeNodeInfo { Text = emptyPipingOutput => PipingFormsResources.PipingOutput_DisplayName, Image = emptyPipingOutput => PipingFormsResources.PipingOutputIcon, - ForegroundColor = emptyPipingOutput => Color.FromKnownColor(KnownColor.GrayText), - ContextMenu = (nodeData, node) => Gui - .Get(node) - .AddExportItem() - .AddSeparator() - .AddPropertiesItem() - .Build() + ForeColor = emptyPipingOutput => Color.FromKnownColor(KnownColor.GrayText), + ContextMenuStrip = (nodeData, node, treeNodeInfo) => Gui.Get(node, treeNodeInfo) + .AddExportItem() + .AddSeparator() + .AddPropertiesItem() + .Build() }; yield return new TreeNodeInfo { Text = emptyPipingCalculationReport => PipingDataResources.CalculationReport_DisplayName, Image = emptyPipingCalculationReport => PipingFormsResources.PipingCalculationReportIcon, - ForegroundColor = emptyPipingCalculationReport => Color.FromKnownColor(KnownColor.GrayText), - ContextMenu = (nodeData, node) => Gui - .Get(node) - .AddOpenItem() - .AddSeparator() - .AddExportItem() - .AddSeparator() - .AddPropertiesItem() - .Build() + ForeColor = emptyPipingCalculationReport => Color.FromKnownColor(KnownColor.GrayText), + ContextMenuStrip = (nodeData, node, treeNodeInfo) => Gui.Get(node, treeNodeInfo) + .AddOpenItem() + .AddSeparator() + .AddExportItem() + .AddSeparator() + .AddPropertiesItem() + .Build() }; } # region PipingFailureMechanism TreeNodeInfo - private ContextMenuStrip FailureMechanismContextMenu(PipingFailureMechanism failureMechanism, TreeNode node) + private ContextMenuStrip FailureMechanismContextMenuStrip(PipingFailureMechanism failureMechanism, TreeNode node, TreeNodeInfo treeNodeInfo) { var addCalculationGroupItem = new StrictContextMenuItem( PipingFormsResources.PipingCalculationGroup_Add_PipingCalculationGroup, @@ -256,7 +215,7 @@ clearAllItem.ToolTipText = PipingFormsResources.PipingCalculationGroup_ClearOutput_No_calculation_with_output_to_clear; } - return Gui.Get(node) + return Gui.Get(node, treeNodeInfo) .AddCustomItem(addCalculationGroupItem) .AddCustomItem(addCalculationItem) .AddSeparator() @@ -341,7 +300,7 @@ Name = NamingHelper.GetUniqueName(failureMechanism.CalculationsGroup.Children, PipingDataResources.PipingCalculationGroup_DefaultName, c => c.Name) }; failureMechanism.CalculationsGroup.Children.Add(calculation); - failureMechanism.NotifyObservers(); + failureMechanism.CalculationsGroup.NotifyObservers(); SelectNewlyAddedPipingFailureMechanismItemInTreeView(failureMechanismNode); } @@ -353,7 +312,7 @@ Name = NamingHelper.GetUniqueName(failureMechanism.CalculationsGroup.Children, PipingDataResources.PipingCalculation_DefaultName, c => c.Name) }; failureMechanism.CalculationsGroup.Children.Add(calculation); - failureMechanism.NotifyObservers(); + failureMechanism.CalculationsGroup.NotifyObservers(); SelectNewlyAddedPipingFailureMechanismItemInTreeView(failureMechanismNode); } @@ -369,7 +328,7 @@ TreeNode failureMechanismsCalculationsNode = failureMechanismNode.Nodes[1]; // New childnode is appended at the end of PipingCalculationGroup: - TreeNode newlyAddedGroupNode = failureMechanismsCalculationsNode.Nodes.Last(); + TreeNode newlyAddedGroupNode = failureMechanismsCalculationsNode.Nodes.OfType().Last(); if (!failureMechanismsCalculationsNode.IsExpanded) { failureMechanismsCalculationsNode.Expand(); @@ -393,24 +352,30 @@ }; } - private static IEnumerable GetInputs(PipingFailureMechanism failureMechanism) + private static IList GetInputs(PipingFailureMechanism failureMechanism) { - yield return failureMechanism.SectionDivisions; - yield return failureMechanism.SurfaceLines; - yield return failureMechanism.SoilProfiles; - yield return failureMechanism.BoundaryConditions; + return new ArrayList + { + failureMechanism.SectionDivisions, + failureMechanism.SurfaceLines, + failureMechanism.SoilProfiles, + failureMechanism.BoundaryConditions + }; } - private IEnumerable GetOutputs(PipingFailureMechanism failureMechanism) + private IList GetOutputs(PipingFailureMechanism failureMechanism) { - yield return failureMechanism.AssessmentResult; + return new ArrayList + { + failureMechanism.AssessmentResult + }; } # endregion # region PipingCalculationContext TreeNodeInfo - private ContextMenuStrip PipingCalculationContextContextMenu(PipingCalculationContext nodeData, TreeNode node) + private ContextMenuStrip PipingCalculationContextContextMenuStrip(PipingCalculationContext nodeData, TreeNode node, TreeNodeInfo treeNodeInfo) { PipingCalculation calculation = nodeData.WrappedData; var validateItem = new StrictContextMenuItem(RingtoetsFormsResources.Validate, @@ -433,7 +398,7 @@ clearOutputItem.ToolTipText = PipingFormsResources.ClearOutput_No_output_to_clear; } - return Gui.Get(node) + return Gui.Get(node, treeNodeInfo) .AddCustomItem(validateItem) .AddCustomItem(calculateItem) .AddCustomItem(clearOutputItem) @@ -550,7 +515,7 @@ return childNodeObjects.ToArray(); } - private ContextMenuStrip PipingCalculationGroupContextContextMenu(PipingCalculationGroupContext nodeData, TreeNode node) + private ContextMenuStrip PipingCalculationGroupContextContextMenuStrip(PipingCalculationGroupContext nodeData, TreeNode node, TreeNodeInfo treeNodeInfo) { var group = nodeData.WrappedData; var addCalculationGroupItem = new StrictContextMenuItem( @@ -612,14 +577,14 @@ clearAllItem.ToolTipText = PipingFormsResources.PipingCalculationGroup_ClearOutput_No_calculation_with_output_to_clear; } - var builder = Gui.Get(node) - .AddCustomItem(addCalculationGroupItem) - .AddCustomItem(addCalculationItem) - .AddSeparator() - .AddCustomItem(validateAllItem) - .AddCustomItem(calculateAllItem) - .AddCustomItem(clearAllItem) - .AddSeparator(); + var builder = Gui.Get(node, treeNodeInfo) + .AddCustomItem(addCalculationGroupItem) + .AddCustomItem(addCalculationItem) + .AddSeparator() + .AddCustomItem(validateAllItem) + .AddCustomItem(calculateAllItem) + .AddCustomItem(clearAllItem) + .AddSeparator(); var isRenamable = PipingCalculationGroupContextCanRenameNode(node); var isRemovable = PipingCalculationGroupContextCanRemove(nodeData, node.Parent.Tag); @@ -740,9 +705,9 @@ return DragOperations.Move; } - private DragOperations PipingCalculationGroupContextCanDrop(object item, TreeNode sourceNode, TreeNode targetNode, DragOperations validOperations) + private DragOperations PipingCalculationGroupContextCanDrop(TreeNode sourceNode, TreeNode targetNode, DragOperations validOperations) { - if (GetAsIPipingCalculationItem(item) != null && NodesHaveSameParentFailureMechanism(sourceNode, targetNode)) + if (GetAsIPipingCalculationItem(sourceNode.Tag) != null && NodesHaveSameParentFailureMechanism(sourceNode, targetNode)) { return validOperations; } @@ -791,23 +756,23 @@ return sourceFailureMechanism; } - private bool PipingCalculationGroupContextCanInsert(object item, TreeNode sourceNode, TreeNode targetNode) + private bool PipingCalculationGroupContextCanInsert(TreeNode sourceNode, TreeNode targetNode) { - return GetAsIPipingCalculationItem(item) != null && NodesHaveSameParentFailureMechanism(sourceNode, targetNode); + return GetAsIPipingCalculationItem(sourceNode.Tag) != null && NodesHaveSameParentFailureMechanism(sourceNode, targetNode); } - private void PipingCalculationGroupContextOnDrop(object item, TreeNode sourceNode, TreeNode targetNode, DragOperations operation, int position) + private void PipingCalculationGroupContextOnDrop(TreeNode sourceNode, TreeNode targetNode, DragOperations operation, int position) { - IPipingCalculationItem pipingCalculationItem = GetAsIPipingCalculationItem(item); + IPipingCalculationItem pipingCalculationItem = GetAsIPipingCalculationItem(sourceNode.Tag); var originalOwnerContext = sourceNode.Parent.Tag as PipingCalculationGroupContext; var target = targetNode.Tag as PipingCalculationGroupContext; if (pipingCalculationItem != null && originalOwnerContext != null && target != null) { var isMoveWithinSameContainer = ReferenceEquals(targetNode.Tag, originalOwnerContext); - DroppingPipingCalculationInContainerStrategy dropHandler = GetDragDropStrategy(isMoveWithinSameContainer, originalOwnerContext, target, targetNode.TreeView); - dropHandler.Execute(item, pipingCalculationItem, position); + DroppingPipingCalculationInContainerStrategy dropHandler = GetDragDropStrategy(isMoveWithinSameContainer, originalOwnerContext, target, (TreeView) targetNode.TreeView); + dropHandler.Execute(sourceNode.Tag, pipingCalculationItem, position); } } @@ -827,7 +792,7 @@ { node.Expand(); } - TreeNode newlyAppendedNodeForNewItem = node.Nodes.Last(); + TreeNode newlyAppendedNodeForNewItem = node.Nodes.OfType().Last(); node.TreeView.SelectedNode = newlyAppendedNodeForNewItem; } @@ -858,13 +823,13 @@ /// The index of the new position within the new owner's collection. public virtual void Execute(object draggedDataObject, IPipingCalculationItem pipingCalculationItem, int newPosition) { - var targetRecordedNodeState = new TreeNodeExpandCollapseState(treeView.GetNodeByTag(target)); + var targetRecordedNodeState = new TreeNodeExpandCollapseState(treeView.TreeViewController.GetNodeByTag(target)); MoveCalculationItemToNewOwner(pipingCalculationItem, newPosition); NotifyObservers(); - TreeNode draggedNode = treeView.GetNodeByTag(draggedDataObject); + TreeNode draggedNode = treeView.TreeViewController.GetNodeByTag(draggedDataObject); UpdateTreeView(draggedNode, targetRecordedNodeState); } @@ -954,16 +919,16 @@ public override void Execute(object draggedDataObject, IPipingCalculationItem pipingCalculationItem, int newPosition) { - var targetRecordedNodeState = new TreeNodeExpandCollapseState(treeView.GetNodeByTag(target)); + var targetRecordedNodeState = new TreeNodeExpandCollapseState(treeView.TreeViewController.GetNodeByTag(target)); - recordedNodeState = new TreeNodeExpandCollapseState(treeView.GetNodeByTag(draggedDataObject)); + recordedNodeState = new TreeNodeExpandCollapseState(treeView.TreeViewController.GetNodeByTag(draggedDataObject)); EnsureDraggedNodeHasUniqueNameInNewOwner(pipingCalculationItem, target); MoveCalculationItemToNewOwner(pipingCalculationItem, newPosition); NotifyObservers(); - TreeNode draggedNode = treeView.GetNodeByTag(draggedDataObject); + TreeNode draggedNode = treeView.TreeViewController.GetNodeByTag(draggedDataObject); UpdateTreeView(draggedNode, targetRecordedNodeState); } @@ -973,7 +938,7 @@ recordedNodeState.Restore(draggedNode); if (renamed) { - treeView.StartLabelEdit(draggedNode); + draggedNode.BeginEdit(); } } Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/EmptyPipingCalculationReportNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/EmptyPipingOutputNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingCalculationContextNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingCalculationGroupContextNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingFailureMechanismNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingInputContextNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingOutputNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingSoilProfileCollectionNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingSoilProfileNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingSurfaceLineCollectionNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingSurfaceLineNodePresenterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -r148b5639633795054317d492507c072ee0bd5ada -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 148b5639633795054317d492507c072ee0bd5ada) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -59,22 +59,22 @@ - - - - + + + + - - + + - - - - - + + + + + @@ -141,6 +141,10 @@ {7cd038e1-e111-4969-aced-22c5bd2974e1} Ringtoets.Piping.Forms + + {1D3D58B6-EF7E-401E-92A0-104067D222EE} + Ringtoets.Piping.Plugin + {10b8d63d-87e8-46df-aca9-a8cf22ee8fb5} Ringtoets.Piping.Service Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/EmptyPipingCalculationReportTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/EmptyPipingCalculationReportTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/EmptyPipingCalculationReportTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,111 @@ +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Plugin; +using PipingDataResources = Ringtoets.Piping.Data.Properties.Resources; +using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class EmptyPipingCalculationReportTreeNodeInfoTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(EmptyPipingCalculationReport)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(EmptyPipingCalculationReport), info.TagType); + + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + + } + + [Test] + public void Text_Always_ReturnsName() + { + // Call + var text = info.Text(null); + + // Assert + Assert.AreEqual(PipingDataResources.CalculationReport_DisplayName, text); + } + + [Test] + public void Image_Always_ReturnsPlaceHolderIcon() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(PipingFormsResources.PipingCalculationReportIcon, image); + } + + [Test] + public void ForeColor_Always_ReturnsGrayText() + { + // Call + var textColor = info.ForeColor(null); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + } + + [Test] + public void GetContextMenu_Always_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, nodeMock, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/EmptyPipingOutputTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/EmptyPipingOutputTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/EmptyPipingOutputTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,106 @@ +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Plugin; +using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class EmptyPipingOutputTreeNodeInfoTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(EmptyPipingOutput)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(EmptyPipingOutput), info.TagType); + + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsFromResource() + { + // Call + var text = info.Text(null); + + // Assert + Assert.AreEqual(PipingFormsResources.PipingOutput_DisplayName, text); + } + + [Test] + public void Image_Always_ReturnsPlaceHolderIcon() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(PipingFormsResources.PipingOutputIcon, image); + } + + [Test] + public void ForeColor_Always_ReturnsGrayText() + { + // Call + var textColor = info.ForeColor(null); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + } + + [Test] + public void GetContextMenu_Always_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, nodeMock, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationContextTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationContextTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,633 @@ +using System; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Calculation.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Plugin; +using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class PipingCalculationContextTreeNodeInfoTest : NUnitFormTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingCalculationContext)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PipingCalculationContext), info.TagType); + + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsWrappedDataName() + { + // Setup + var testname = "testName"; + var calculation = new PipingCalculation + { + Name = testname + }; + var pipingCalculationContext = new PipingCalculationContext(calculation, + new[] + { + new RingtoetsPipingSurfaceLine() + }, + new[] + { + new TestPipingSoilProfile() + }); + // Call + var text = info.Text(pipingCalculationContext); + + // Assert + Assert.AreEqual(testname, text); + } + + [Test] + public void Image_Always_ReturnsPlaceHolderIcon() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(PipingFormsResources.PipingIcon, image); + } + + [Test] + public void GetChildNodeObjects_WithOutputData_ReturnOutputChildNode() + { + // Setup + var calculation = new PipingCalculation + { + Output = new PipingOutput(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) + }; + var pipingCalculationContext = new PipingCalculationContext(calculation, + new[] + { + new RingtoetsPipingSurfaceLine() + }, + new[] + { + new TestPipingSoilProfile() + }); + + // Call + var children = info.ChildNodeObjects(pipingCalculationContext).ToArray(); + + // Assert + Assert.AreEqual(4, children.Length); + Assert.AreSame(pipingCalculationContext.WrappedData.Comments, children[0]); + var pipingInputContext = (PipingInputContext)children[1]; + Assert.AreSame(pipingCalculationContext.WrappedData.InputParameters, pipingInputContext.WrappedData); + CollectionAssert.AreEqual(pipingCalculationContext.AvailablePipingSurfaceLines, pipingInputContext.AvailablePipingSurfaceLines); + CollectionAssert.AreEqual(pipingCalculationContext.AvailablePipingSoilProfiles, pipingInputContext.AvailablePipingSoilProfiles); + Assert.AreSame(pipingCalculationContext.WrappedData.Output, children[2]); + Assert.IsInstanceOf(children[3]); + } + + [Test] + public void GetChildNodeObjects_WithoutOutput_ReturnNoChildNodes() + { + // Setup + var pipingCalculationContext = new PipingCalculationContext(new PipingCalculation(), + Enumerable.Empty(), + Enumerable.Empty()); + + // Precondition + Assert.IsFalse(pipingCalculationContext.WrappedData.HasOutput); + + // Call + var children = info.ChildNodeObjects(pipingCalculationContext).ToArray(); + + // Assert + Assert.AreEqual(4, children.Length); + Assert.AreSame(pipingCalculationContext.WrappedData.Comments, children[0]); + var pipingInputContext = (PipingInputContext)children[1]; + Assert.AreSame(pipingCalculationContext.WrappedData.InputParameters, pipingInputContext.WrappedData); + CollectionAssert.AreEqual(pipingCalculationContext.AvailablePipingSurfaceLines, pipingInputContext.AvailablePipingSurfaceLines); + CollectionAssert.AreEqual(pipingCalculationContext.AvailablePipingSoilProfiles, pipingInputContext.AvailablePipingSoilProfiles); + + Assert.IsInstanceOf(children[2]); + Assert.IsInstanceOf(children[3]); + } + + [Test] + public void CanRenameNode_Always_ReturnTrue() + { + // Call + var renameAllowed = info.CanRename(null); + + // Assert + Assert.IsTrue(renameAllowed); + } + + [Test] + public void OnNodeRenamed_Always_SetNewNameToPipingCalculation() + { + // Setup + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var calculation = new PipingCalculation + { + Name = "" + }; + var pipingCalculationsInputs = new PipingCalculationContext(calculation, + Enumerable.Empty(), + Enumerable.Empty()); + pipingCalculationsInputs.Attach(observerMock); + + // Call + const string newName = ""; + info.OnNodeRenamed(pipingCalculationsInputs, newName); + + // Assert + Assert.AreEqual(newName, calculation.Name); + mocks.VerifyAll(); + } + + [Test] + public void CanDrag_Always_ReturnMove() + { + // Call + DragOperations dragAllowed = info.CanDrag(null, null); + + // Assert + Assert.AreEqual(DragOperations.Move, dragAllowed); + } + + [Test] + public void GetContextMenu_PipingCalculationWithoutOutput_ContextMenuItemClearOutputDisabled() + { + var gui = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + var calculation = new PipingCalculation(); + var nodeData = new PipingCalculationContext(calculation, + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + var contextMenu = info.ContextMenuStrip(nodeData, nodeMock, info); + + // Assert + mocks.VerifyAll(); // Expect no calls on arguments + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, RingtoetsCommonFormsResources.Validate, RingtoetsCommonFormsResources.Validate_ToolTip, RingtoetsCommonFormsResources.ValidateIcon); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 1, RingtoetsCommonFormsResources.Calculate, RingtoetsCommonFormsResources.Calculate_ToolTip, RingtoetsCommonFormsResources.CalculateIcon); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 2, PipingFormsResources.Clear_output, PipingFormsResources.ClearOutput_No_output_to_clear, RingtoetsCommonFormsResources.ClearIcon, false); + } + + [Test] + public void GetContextMenu_PipingCalculationWithOutput_ContextMenuItemClearOutputEnabled() + { + var gui = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + var calculation = new PipingCalculation + { + Output = new TestPipingOutput() + }; + var nodeData = new PipingCalculationContext(calculation, + Enumerable.Empty(), + Enumerable.Empty()); + + + // Call + var contextMenu = info.ContextMenuStrip(nodeData, nodeMock, info); + + // Assert + mocks.VerifyAll(); // Expect no calls on arguments + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, RingtoetsCommonFormsResources.Validate, RingtoetsCommonFormsResources.Validate_ToolTip, RingtoetsCommonFormsResources.ValidateIcon); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 1, RingtoetsCommonFormsResources.Calculate, RingtoetsCommonFormsResources.Calculate_ToolTip, RingtoetsCommonFormsResources.CalculateIcon); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 2, PipingFormsResources.Clear_output, PipingFormsResources.Clear_output_ToolTip, RingtoetsCommonFormsResources.ClearIcon); + } + + [Test] + public void GetContextMenu_Always_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilderMock = mocks.Stub(); + var nodeMock = mocks.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilderMock); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + var nodeData = new PipingCalculationContext(new PipingCalculation(), + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + info.ContextMenuStrip(nodeData, nodeMock, info); + + // Assert + mocks.VerifyAll(); // Expect no calls on arguments + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void CanRemove_ParentIsPipingCalculationGroupWithCalculation_ReturnTrue(bool groupNameEditable) + { + // Setup + var calculationToBeRemoved = new PipingCalculation(); + var group = new PipingCalculationGroup("", groupNameEditable); + group.Children.Add(calculationToBeRemoved); + + var calculationContext = new PipingCalculationContext(calculationToBeRemoved, + Enumerable.Empty(), + Enumerable.Empty()); + var groupContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + bool removalAllowed = info.CanRemove(calculationContext, groupContext); + + // Assert + Assert.IsTrue(removalAllowed); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void CanRemove_ParentIsPipingCalculationGroupWithoutCalculation_ReturnFalse(bool groupNameEditable) + { + // Setup + var calculationToBeRemoved = new PipingCalculation(); + var group = new PipingCalculationGroup("", groupNameEditable); + + var calculationContext = new PipingCalculationContext(calculationToBeRemoved, + Enumerable.Empty(), + Enumerable.Empty()); + var groupContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + bool removalAllowed = info.CanRemove(calculationContext, groupContext); + + // Assert + Assert.IsFalse(removalAllowed); + } + + [Test] + public void CanRemove_EverythingElse_ReturnFalse() + { + // Setup + var dataMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var nodeMock = new PipingCalculationContext(new PipingCalculation(), + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + bool removalAllowed = info.CanRemove(nodeMock, dataMock); + + // Assert + Assert.IsFalse(removalAllowed); + mocks.VerifyAll(); // Expect no calls on arguments + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void OnNodeRemoved_ParentIsPipingCalculationGroupContext_RemoveCalculationFromGroup(bool groupNameEditable) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var elementToBeRemoved = new PipingCalculation(); + + var group = new PipingCalculationGroup(); + group.Children.Add(elementToBeRemoved); + group.Children.Add(new PipingCalculation()); + group.Attach(observer); + + var calculationContext = new PipingCalculationContext(elementToBeRemoved, + Enumerable.Empty(), + Enumerable.Empty()); + var groupContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + // Precondition + Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); + Assert.AreEqual(2, group.Children.Count); + + // Call + info.OnNodeRemoved(calculationContext, groupContext); + + // Assert + Assert.AreEqual(1, group.Children.Count); + CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); + + mocks.VerifyAll(); + } + + [Test] + public void GivenInvalidPipingCalculation_WhenCalculatingFromContextMenu_ThenPipingCalculationNotifiesObserversAndLogMessageAdded() + { + // Given + var gui = mocks.DynamicMock(); + var mainWindow = mocks.DynamicMock(); + var observer = mocks.StrictMock(); + var treeNodeMock = mocks.StrictMock(); + + observer.Expect(o => o.UpdateObserver()); + + gui.Expect(cmp => cmp.Get(treeNodeMock, info)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Expect(g => g.MainWindow).Return(mainWindow); + + var expectedValidationMessageCount = 2; // No surfaceline or soil profile selected for calculation + var calculateContextMenuItemIndex = 1; + + mocks.ReplayAll(); + + DialogBoxHandler = (name, wnd) => + { + }; + + plugin.Gui = gui; + + var calculation = new PipingCalculation(); + calculation.Attach(observer); + + var pipingCalculationContext = new PipingCalculationContext(calculation, + Enumerable.Empty(), + Enumerable.Empty()); + + var contextMenuAdapter = info.ContextMenuStrip(pipingCalculationContext, treeNodeMock, info); + + // When + Action action = () => + { + contextMenuAdapter.Items[calculateContextMenuItemIndex].PerformClick(); + }; + + // Then + TestHelper.AssertLogMessages(action, messages => + { + var msgs = messages.GetEnumerator(); + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Validatie van 'Nieuwe berekening' gestart om: ", msgs.Current); + for (int i = 0; i < expectedValidationMessageCount; i++) + { + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Validatie mislukt: ", msgs.Current); + } + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Validatie van 'Nieuwe berekening' beëindigd om: ", msgs.Current); + }); + Assert.IsNull(calculation.Output); + + mocks.VerifyAll(); + } + + [Test] + public void GivenInvalidPipingCalculation_WhenValidatingFromContextMenu_ThenLogMessageAddedAndNoNotifyObserver() + { + // Given + var gui = mocks.DynamicMock(); + var observer = mocks.StrictMock(); + var treeNodeMock = mocks.StrictMock(); + + gui.Expect(cmp => cmp.Get(treeNodeMock, info)).Return(new CustomItemsOnlyContextMenuBuilder()); + + var expectedValidationMessageCount = 2; // No surfaceline or soil profile selected for calculation + var expectedStatusMessageCount = 2; + var expectedLogMessageCount = expectedValidationMessageCount + expectedStatusMessageCount; + + var validateContextMenuItemIndex = 0; + observer.Expect(o => o.UpdateObserver()).Repeat.Never(); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + var calculation = new PipingCalculation(); + calculation.Attach(observer); + + var pipingCalculationContext = new PipingCalculationContext(calculation, + Enumerable.Empty(), + Enumerable.Empty()); + var contextMenuAdapter = info.ContextMenuStrip(pipingCalculationContext, treeNodeMock, info); + + // When + Action action = () => contextMenuAdapter.Items[validateContextMenuItemIndex].PerformClick(); + + // Then + TestHelper.AssertLogMessagesCount(action, expectedLogMessageCount); + + mocks.VerifyAll(); + } + + [Test] + public void GivenValidPipingCalculation_WhenCalculatingFromContextMenu_ThenPipingCalculationNotifiesObservers() + { + // Given + var gui = mocks.DynamicMock(); + var mainWindow = mocks.DynamicMock(); + var observer = mocks.StrictMock(); + var treeNodeMock = mocks.StrictMock(); + + gui.Expect(g => g.Get(treeNodeMock, info)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Expect(g => g.MainWindow).Return(mainWindow); + + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + DialogBoxHandler = (name, wnd) => + { + }; + + plugin.Gui = gui; + + var calculateContextMenuItemIndex = 1; + var calculation = new PipingCalculation(); + var validPipingInput = new TestPipingInput(); + calculation.InputParameters.AssessmentLevel = validPipingInput.AssessmentLevel; + calculation.InputParameters.BeddingAngle = validPipingInput.BeddingAngle; + calculation.InputParameters.DampingFactorExit.Mean = validPipingInput.DampingFactorExit; + calculation.InputParameters.DarcyPermeability.Mean = validPipingInput.DarcyPermeability; + calculation.InputParameters.Diameter70.Mean = validPipingInput.Diameter70; + calculation.InputParameters.ExitPointXCoordinate = validPipingInput.ExitPointXCoordinate; + calculation.InputParameters.Gravity = validPipingInput.Gravity; + calculation.InputParameters.MeanDiameter70 = validPipingInput.MeanDiameter70; + calculation.InputParameters.PhreaticLevelExit.Mean = validPipingInput.PhreaticLevelExit; + calculation.InputParameters.PiezometricHeadExit = validPipingInput.PiezometricHeadExit; + calculation.InputParameters.PiezometricHeadPolder = validPipingInput.PiezometricHeadPolder; + calculation.InputParameters.SandParticlesVolumicWeight = validPipingInput.SandParticlesVolumicWeight; + calculation.InputParameters.SeepageLength.Mean = validPipingInput.SeepageLength; + calculation.InputParameters.SellmeijerModelFactor = validPipingInput.SellmeijerModelFactor; + calculation.InputParameters.SellmeijerReductionFactor = validPipingInput.SellmeijerReductionFactor; + calculation.InputParameters.ThicknessAquiferLayer.Mean = validPipingInput.ThicknessAquiferLayer; + calculation.InputParameters.ThicknessCoverageLayer.Mean = validPipingInput.ThicknessCoverageLayer; + calculation.InputParameters.UpliftModelFactor = validPipingInput.UpliftModelFactor; + calculation.InputParameters.WaterVolumetricWeight = validPipingInput.WaterVolumetricWeight; + calculation.InputParameters.WaterKinematicViscosity = validPipingInput.WaterKinematicViscosity; + calculation.InputParameters.WhitesDragCoefficient = validPipingInput.WhitesDragCoefficient; + calculation.InputParameters.SurfaceLine = validPipingInput.SurfaceLine; + calculation.InputParameters.SoilProfile = validPipingInput.SoilProfile; + + calculation.Attach(observer); + + var pipingCalculationContext = new PipingCalculationContext(calculation, + Enumerable.Empty(), + Enumerable.Empty()); + + var contextMenuAdapter = info.ContextMenuStrip(pipingCalculationContext, treeNodeMock, info); + + // When + Action action = () => + { + contextMenuAdapter.Items[calculateContextMenuItemIndex].PerformClick(); + }; + + // Then + TestHelper.AssertLogMessages(action, messages => + { + var msgs = messages.GetEnumerator(); + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Validatie van 'Nieuwe berekening' gestart om: ", msgs.Current); + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Validatie van 'Nieuwe berekening' beëindigd om: ", msgs.Current); + + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Berekening van 'Nieuwe berekening' gestart om: ", msgs.Current); + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Berekening van 'Nieuwe berekening' beëindigd om: ", msgs.Current); + }); + Assert.IsNotNull(calculation.Output); + + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GivenPipingCalculationWithOutput_WhenClearingOutputFromContextMenu_ThenPipingCalculationOutputClearedAndNotified(bool confirm) + { + // Given + var gui = mocks.DynamicMock(); + var observer = mocks.StrictMock(); + var treeNodeMock = mocks.StrictMock(); + gui.Expect(cmp => cmp.Get(treeNodeMock, info)).Return(new CustomItemsOnlyContextMenuBuilder()); + + int clearOutputItemPosition = 2; + if (confirm) + { + observer.Expect(o => o.UpdateObserver()); + } + + mocks.ReplayAll(); + + plugin.Gui = gui; + + var calculation = new PipingCalculation(); + calculation.Output = new TestPipingOutput(); + calculation.Attach(observer); + + var pipingCalculationContext = new PipingCalculationContext(calculation, + Enumerable.Empty(), + Enumerable.Empty()); + + var contextMenuAdapter = info.ContextMenuStrip(pipingCalculationContext, treeNodeMock, info); + + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBox.Text); + Assert.AreEqual("Bevestigen", messageBox.Title); + if (confirm) + { + messageBox.ClickOk(); + } + else + { + messageBox.ClickCancel(); + } + }; + + // When + contextMenuAdapter.Items[clearOutputItemPosition].PerformClick(); + + // Then + Assert.AreNotEqual(confirm, calculation.HasOutput); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,1608 @@ +using System; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Calculation.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Plugin; +using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; +using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class PipingCalculationGroupContextTreeNodeInfoTest : NUnitFormTest + { + private const int contextMenuAddCalculationGroupIndex = 0; + private const int contextMenuAddCalculationIndex = 1; + private const int contextMenuValidateAllIndex = 3; + private const int contextMenuCalculateAllIndex = 4; + private const int contextMenuClearOutputIndex = 5; + + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingCalculationGroupContext)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PipingCalculationGroupContext), info.TagType); + + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + } + + [Test] + public void CanDrag_WithParentNodeDefaultBehavior_ReturnMove() + { + // Setup + var group = new PipingCalculationGroup(); + var groupContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + var node = mocks.Stub(); + var parentNode = mocks.Stub(); + node.Expect(n => n.Parent).Return(parentNode); + mocks.ReplayAll(); + + // Call + DragOperations supportedOperation = info.CanDrag(groupContext, node); + + // Assert + Assert.AreEqual(DragOperations.Move, supportedOperation); + mocks.VerifyAll(); + } + + [Test] + public void CanDrag_ParentIsPipingFailureMechanism_ReturnNone() + { + // Setup + var pipingFailureMechanism = new PipingFailureMechanism(); + + var group = pipingFailureMechanism.CalculationsGroup; + var groupContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + var failureMechanismNode = mocks.Stub(); + failureMechanismNode.Tag = pipingFailureMechanism; + + var groupContextNode = mocks.Stub(); + groupContextNode.Tag = groupContext; + groupContextNode.Expect(n => n.Parent).Return(failureMechanismNode); + + mocks.ReplayAll(); + + // Call + DragOperations supportedOperation = info.CanDrag(groupContext, groupContextNode); + + // Assert + Assert.AreEqual(DragOperations.None, supportedOperation); + mocks.VerifyAll(); + } + + [Test] + [Combinatorial] + public void CanDropOrCanInsert_DraggingPipingCalculationItemContextOntoGroupNotContainingItem_ReturnMoveOrTrue( + [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, + [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) + { + // Setup + IPipingCalculationItem draggedItem; + object draggedItemContext; + CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext); + + PipingCalculationGroup targetGroup; + PipingCalculationGroupContext targetGroupContext; + CreatePipingCalculationGroupAndContext(out targetGroup, out targetGroupContext); + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(draggedItem); + failureMechanism.CalculationsGroup.Children.Add(targetGroup); + + #region Mock node tree for source and target in same failure mechanism + + var failureMechanismNode = mocks.Stub(); + failureMechanismNode.Tag = failureMechanism; + + var failureMechanismGroupNode = mocks.Stub(); + failureMechanismGroupNode.Tag = failureMechanism.CalculationsGroup; + failureMechanismGroupNode.Expect(n => n.Parent).Return(failureMechanismNode).Repeat.AtLeastOnce(); + + var calculationNode = mocks.Stub(); + calculationNode.Tag = draggedItemContext; + calculationNode.Expect(n => n.Parent).Return(failureMechanismGroupNode).Repeat.AtLeastOnce(); + + var targetGroupNode = mocks.Stub(); + targetGroupNode.Tag = targetGroupContext; + targetGroupNode.Expect(n => n.Parent).Return(failureMechanismGroupNode).Repeat.AtLeastOnce(); + + #endregion + + mocks.ReplayAll(); + + + switch (methodToTest) + { + case DragDropTestMethod.CanDrop: + // Call + DragOperations supportedOperations = info.CanDrop(calculationNode, targetGroupNode, DragOperations.Move); + + // Assert + Assert.AreEqual(DragOperations.Move, supportedOperations); + break; + case DragDropTestMethod.CanInsert: + // Call + bool canInsert = info.CanInsert(calculationNode, targetGroupNode); + + // Assert + Assert.IsTrue(canInsert); + break; + default: + Assert.Fail(methodToTest + " not supported."); + break; + } + mocks.VerifyAll(); + } + + [Test] + [Combinatorial] + public void CanDropOrInsert_DraggingCalculationItemContextOntoGroupNotContainingItemOtherFailureMechanism_ReturnNoneOrFalse( + [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, + [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) + { + // Setup + IPipingCalculationItem draggedItem; + object draggedItemContext; + CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext); + + var sourceFailureMechanism = new PipingFailureMechanism(); + sourceFailureMechanism.CalculationsGroup.Children.Add(draggedItem); + + PipingCalculationGroup targetGroup; + PipingCalculationGroupContext targetGroupContext; + CreatePipingCalculationGroupAndContext(out targetGroup, out targetGroupContext); + + var targetFailureMechanism = new PipingFailureMechanism(); + targetFailureMechanism.CalculationsGroup.Children.Add(targetGroup); + + #region Mock node tree for source IPipingCalculationItem + + var sourceFailureMechanismNode = mocks.Stub(); + sourceFailureMechanismNode.Tag = sourceFailureMechanism; + + var sourceFailureMechanismGroupNode = mocks.Stub(); + sourceFailureMechanismGroupNode.Tag = sourceFailureMechanism.CalculationsGroup; + sourceFailureMechanismGroupNode.Expect(n => n.Parent).Return(sourceFailureMechanismNode).Repeat.AtLeastOnce(); + + var calculationNode = mocks.Stub(); + calculationNode.Tag = draggedItemContext; + calculationNode.Expect(n => n.Parent).Return(sourceFailureMechanismGroupNode).Repeat.AtLeastOnce(); + + #endregion + + #region Mock node tree for target PipingCalculationGroup + + var targetFailureMechanismNode = mocks.Stub(); + targetFailureMechanismNode.Tag = targetFailureMechanism; + + var targetFailureMechanismGroupNode = mocks.Stub(); + targetFailureMechanismGroupNode.Tag = targetFailureMechanism.CalculationsGroup; + targetFailureMechanismGroupNode.Expect(n => n.Parent).Return(targetFailureMechanismNode).Repeat.AtLeastOnce(); + + var groupNode = mocks.Stub(); + groupNode.Tag = targetGroupContext; + groupNode.Expect(n => n.Parent).Return(targetFailureMechanismGroupNode).Repeat.AtLeastOnce(); + + #endregion + + mocks.ReplayAll(); + + switch (methodToTest) + { + case DragDropTestMethod.CanDrop: + // Call + DragOperations supportedOperations = info.CanDrop(calculationNode, groupNode, DragOperations.Move); + + // Assert + Assert.AreEqual(DragOperations.None, supportedOperations); + break; + case DragDropTestMethod.CanInsert: + // Call + bool canInsert = info.CanInsert(calculationNode, groupNode); + + // Assert + Assert.IsFalse(canInsert); + break; + default: + Assert.Fail(methodToTest + " not supported."); + break; + } + mocks.VerifyAll(); + } + +// [Test] +// [Combinatorial] +// public void OnDragDrop_DraggingPipingCalculationItemContextOntoGroupEnd_MoveCalculationItemInstanceToNewGroup( +// [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) +// { +// // Setup +// IPipingCalculationItem draggedItem; +// object draggedItemContext; +// CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext); +// +// PipingCalculationGroup originalOwnerGroup; +// PipingCalculationGroupContext originalOwnerGroupContext; +// CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext); +// originalOwnerGroup.Children.Add(draggedItem); +// +// PipingCalculationGroup newOwnerGroup; +// PipingCalculationGroupContext newOwnerGroupContext; +// CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext); +// +// var originalOwnerObserver = mocks.StrictMock(); +// originalOwnerObserver.Expect(o => o.UpdateObserver()); +// +// var updatewasCalled = false; +// var newOwnerObserver = CreateObserverStubWithUpdateExpectancy(invocation => updatewasCalled = true); +// +// var newOwnerGroupContextNode = new TreeNode +// { +// Tag = newOwnerGroupContext +// }; +// +// var originalOwnerGroupContextNode = new TreeNode +// { +// Tag = originalOwnerGroupContext +// }; +// +// var draggedItemContextNode = new TreeNode +// { +// Tag = draggedItemContext +// }; +// draggedItemContextNode.Collapse(); +// +// newOwnerGroupContextNode.Nodes.Add(draggedItemContextNode); +// +// mocks.ReplayAll(); +// +// var treeView = new Core.Common.Controls.TreeView.TreeView(); +// var root = new TreeNode(); +// treeView.Nodes.Add(root); +// root.Nodes.Add(originalOwnerGroupContextNode); +// root.Nodes.Add(newOwnerGroupContextNode); +// +// originalOwnerGroup.Attach(originalOwnerObserver); +// newOwnerGroup.Attach(newOwnerObserver); +// +// // Precondition: +// Assert.IsFalse(draggedItemContextNode.IsExpanded); +// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); +// CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); +// +// // Call +// info.OnDrop(draggedItemContextNode, newOwnerGroupContextNode, DragOperations.Move, newOwnerGroup.Children.Count); +// +// // Assert +// CollectionAssert.DoesNotContain(originalOwnerGroup.Children, draggedItem); +// CollectionAssert.Contains(newOwnerGroup.Children, draggedItem); +// Assert.AreSame(draggedItem, newOwnerGroup.Children.Last(), +// "Dragging node at the end of the target PipingCalculationGroup should put the dragged data at the end of 'newOwnerGroup'."); +// +// Assert.AreSame(draggedItemContextNode, draggedItemContextNode.TreeView.SelectedNode); +// Assert.IsTrue(newOwnerGroupContextNode.IsExpanded); +// Assert.IsFalse(draggedItemContextNode.IsExpanded); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// [Combinatorial] +// public void OnDragDrop_InsertingPipingCalculationItemContextAtDifferentLocationWithingSameGroup_ChangeItemIndexOfCalculationItem( +// [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType, +// [Values(0, 2)] int newIndex) +// { +// // Setup +// const string name = "Very cool name"; +// IPipingCalculationItem draggedItem; +// object draggedItemContext; +// CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext, name); +// +// var existingItemStub = mocks.Stub(); +// existingItemStub.Stub(i => i.Name).Return(""); +// +// PipingCalculationGroup originalOwnerGroup; +// PipingCalculationGroupContext originalOwnerGroupContext; +// CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext); +// originalOwnerGroup.Children.Add(existingItemStub); +// originalOwnerGroup.Children.Add(draggedItem); +// originalOwnerGroup.Children.Add(existingItemStub); +// +// bool updatewasCalled = false; +// var originalOwnerObserver = CreateObserverStubWithUpdateExpectancy(invocation => updatewasCalled = true); +// +// var existingItemStub1 = CreateStubTreeNode(); +// var existingItemStub2 = CreateStubTreeNode(); +// +// var preUpdateDraggedItemContextNode = CreateTreeNodeLeafForData(draggedItemContext); +// var postUpdateDraggedItemContextNode = CreateTreeNodeLeafForData(draggedItemContext); +// TreeNode[] preUpdateNewOwnerChildNodes = { existingItemStub1, preUpdateDraggedItemContextNode, existingItemStub2 }; +// var newOwnerGroupContextNode = CreateNodeStubToBeExpanded(originalOwnerGroupContext, preUpdateNewOwnerChildNodes, invocation => +// { +// if (updatewasCalled) +// { +// invocation.ReturnValue = new[] +// { +// existingItemStub1, +// postUpdateDraggedItemContextNode, +// existingItemStub2 +// }; +// } +// }); +// postUpdateDraggedItemContextNode.Expect(n => n.Parent).Return(newOwnerGroupContextNode); +// +// mocks.ReplayAll(); +// +// originalOwnerGroup.Attach(originalOwnerObserver); +// +// // Precondition: +// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); +// +// // Call +// info.OnDrop(preUpdateDraggedItemContextNode, newOwnerGroupContextNode, DragOperations.Move, newIndex); +// +// // Assert +// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); +// Assert.AreNotSame(draggedItem, originalOwnerGroup.Children[1], +// "Should have removed 'draggedItem' from its original location in the collection."); +// Assert.AreSame(draggedItem, originalOwnerGroup.Children[newIndex], +// "Dragging node to specific location within owning PipingCalculationGroup should put the dragged data at that index."); +// Assert.AreEqual(name, draggedItem.Name, +// "No renaming should occur when dragging within the same PipingCalculationGroup."); +// +// Assert.AreSame(postUpdateDraggedItemContextNode, postUpdateDraggedItemContextNode.TreeView.SelectedNode); +// +// Assert.IsTrue(newOwnerGroupContextNode.IsExpanded); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// [Combinatorial] +// public void OnDragDrop_DraggingPipingCalculationItemContextOntoGroupStartWithSameNamedItem_MoveCalculationItemInstanceToNewGroupAndRename( +// [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) +// { +// // Setup +// IPipingCalculationItem draggedItem; +// object draggedItemContext; +// CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext); +// +// PipingCalculationGroup originalOwnerGroup; +// PipingCalculationGroupContext originalOwnerGroupContext; +// CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext); +// originalOwnerGroup.Children.Add(draggedItem); +// +// PipingCalculationGroup newOwnerGroup; +// PipingCalculationGroupContext newOwnerGroupContext; +// CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext); +// +// var sameNamedItem = mocks.Stub(); +// sameNamedItem.Stub(i => i.Name).Return(draggedItem.Name); +// +// var updateWasCalled = false; +// var originalOwnerObserver = CreateObserverStubWithUpdateExpectancy(); +// var newOwnerObserver = CreateObserverStubWithUpdateExpectancy(invocation => updateWasCalled = true); +// +// var preUpdateCalculationContextNode = CreateExpandedNodeStub(draggedItemContext, new TreeNode[0]); +// var postUpdateCalculationContextNode = CreateNodeStubToBeExpanded(draggedItemContext, new TreeNode[0]); +// var newOwnerGroupContextNode = CreateNodeStubToBeExpanded(originalOwnerGroupContext, new TreeNode[0], invocation => +// { +// if (updateWasCalled) +// { +// invocation.ReturnValue = new[] +// { +// postUpdateCalculationContextNode +// }; +// } +// }); +// postUpdateCalculationContextNode.Expect(n => n.Parent).Return(newOwnerGroupContextNode); +// +// mocks.ReplayAll(); +// +// newOwnerGroup.Children.Add(sameNamedItem); +// +// originalOwnerGroup.Attach(originalOwnerObserver); +// newOwnerGroup.Attach(newOwnerObserver); +// +// // Precondition: +// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); +// CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); +// CollectionAssert.Contains(newOwnerGroup.Children.Select(c => c.Name), draggedItem.Name, +// "Name of the dragged item should already exist in new owner."); +// +// // Call +// info.OnDrop(preUpdateCalculationContextNode, newOwnerGroupContextNode, DragOperations.Move, 0); +// +// // Assert +// CollectionAssert.DoesNotContain(originalOwnerGroup.Children, draggedItem); +// CollectionAssert.Contains(newOwnerGroup.Children, draggedItem); +// Assert.AreSame(draggedItem, newOwnerGroup.Children.First(), +// "Dragging to insert node at start of newOwnerGroup should place the node at the start of the list."); +// switch (draggedItemType) +// { +// case PipingCalculationItemType.Calculation: +// Assert.AreEqual("Nieuwe berekening (1)", draggedItem.Name); +// break; +// case PipingCalculationItemType.Group: +// Assert.AreEqual("Nieuwe map (1)", draggedItem.Name); +// break; +// } +// +// Assert.AreSame(postUpdateCalculationContextNode, postUpdateCalculationContextNode.TreeView.SelectedNode); +// +// Assert.IsTrue(postUpdateCalculationContextNode.IsExpanded); +// Assert.IsTrue(newOwnerGroupContextNode.IsExpanded); +// +// mocks.VerifyAll(); +// } +// +// [Test] +// [Combinatorial] +// public void OnDragDrop_DraggingPipingCalculationItemContextOntoGroupWithOtherItems_ExpandedCollapsedStateOfOtherItemsRestored( +// [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) +// { +// // Setup +// IPipingCalculationItem draggedItem; +// object draggedItemContext; +// CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext); +// +// PipingCalculationGroup originalOwnerGroup; +// PipingCalculationGroupContext originalOwnerGroupContext; +// CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext); +// originalOwnerGroup.Children.Add(draggedItem); +// +// PipingCalculationGroup newOwnerGroup; +// PipingCalculationGroupContext newOwnerGroupContext; +// CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext); +// +// var updatewasCalled = false; +// var originalOwnerObserver = CreateObserverStubWithUpdateExpectancy(); +// var newOwnerObserver = CreateObserverStubWithUpdateExpectancy(methodInvocation => updatewasCalled = true); +// +// var nodeStub = CreateStubTreeNode(); +// TreeNode[] childNodesStub = { nodeStub }; +// +// var expandedNodeData = new object(); +// var preUpdateExpandedNode = CreateExpandedNodeStub(expandedNodeData, childNodesStub); +// var postUpdateExpandedNode = CreateNodeStubToBeExpanded(expandedNodeData, childNodesStub); +// +// var collapsedNodeData = new object(); +// var preUpdateCollapsedNode = CreateCollapsedNodeStub(collapsedNodeData, childNodesStub); +// var postUpdateCollapsedNode = CreateNodeStubToBeCollapsed(collapsedNodeData, childNodesStub); +// +// TreeNode[] preUpdateChildNodes = { preUpdateExpandedNode, preUpdateCollapsedNode }; +// TreeNode[] postUpdateChildNodes = { postUpdateExpandedNode, postUpdateCollapsedNode }; +// var newOwnerGroupContextNode = CreateNodeStubToBeExpanded(newOwnerGroupContext, preUpdateChildNodes, invocation => +// { +// if (updatewasCalled) +// { +// invocation.ReturnValue = postUpdateChildNodes; +// } +// }); +// +// var preUpdateDraggedItemContextNode = CreateTreeNodeLeafForData(draggedItemContext); +// var postUpdateDraggedItemContextNode = CreateNodeStubToBeCollapsed(draggedItemContext, new TreeNode[0]); +// postUpdateDraggedItemContextNode.Expect(n => n.Parent).Return(newOwnerGroupContextNode); +// +// mocks.ReplayAll(); +// +// originalOwnerGroup.Attach(originalOwnerObserver); +// newOwnerGroup.Attach(newOwnerObserver); +// +// // Precondition: +// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); +// CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); +// +// // Call +// info.OnDrop(preUpdateDraggedItemContextNode, postUpdateDraggedItemContextNode, DragOperations.Move, newOwnerGroup.Children.Count); +// +// // Assert +// CollectionAssert.DoesNotContain(originalOwnerGroup.Children, draggedItem); +// CollectionAssert.Contains(newOwnerGroup.Children, draggedItem); +// Assert.AreSame(draggedItem, newOwnerGroup.Children.Last(), +// "Dragging node at the end of the target PipingCalculationGroup should put the dragged data at the end of 'newOwnerGroup'."); +// +// Assert.AreSame(postUpdateDraggedItemContextNode, postUpdateDraggedItemContextNode.TreeView.SelectedNode); +// Assert.IsFalse(postUpdateCollapsedNode.IsExpanded); +// Assert.IsFalse(postUpdateDraggedItemContextNode.IsExpanded); +// Assert.IsTrue(postUpdateExpandedNode.IsExpanded); +// Assert.IsTrue(newOwnerGroupContextNode.IsExpanded); +// +// mocks.VerifyAll(); +// } + + [Test] + public void CanRenameNode_ParentIsPipingFailureMechanismNode_ReturnFalse() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var parentNode = mocks.Stub(); + parentNode.Tag = failureMechanism; + + var node = mocks.StrictMock(); + node.Expect(n => n.Parent).Return(parentNode); + + mocks.ReplayAll(); + + // Call + bool isRenamingAllowed = info.CanRename(node); + + // Assert + Assert.IsFalse(isRenamingAllowed); + mocks.VerifyAll(); + } + + [Test] + public void CanRenameNode_EverythingElse_ReturnTrue() + { + // Setup + var parentNode = mocks.Stub(); + parentNode.Tag = new object(); + + var node = mocks.StrictMock(); + node.Expect(n => n.Parent).Return(parentNode); + + mocks.ReplayAll(); + + // Call + bool isRenamingAllowed = info.CanRename(node); + + // Assert + Assert.IsTrue(isRenamingAllowed); + mocks.VerifyAll(); + } + + [Test] + public void OnNodeRenamed_WithData_RenameGroupAndNotifyObservers() + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var group = new PipingCalculationGroup(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + nodeData.Attach(observer); + + // Call + const string newName = "new name"; + info.OnNodeRenamed(nodeData, newName); + + // Assert + Assert.AreEqual(newName, group.Name); + mocks.VerifyAll(); + } + + [Test] + public void CanRemove_ParentIsFailureMechanism_ReturnFalse() + { + // Setup + var group = new PipingCalculationGroup(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var parentNodeData = new PipingFailureMechanism(); + parentNodeData.CalculationsGroup.Children.Add(group); + + mocks.ReplayAll(); + + // Call + bool isRemovalAllowed = info.CanRemove(nodeData, parentNodeData); + + // Assert + Assert.IsFalse(isRemovalAllowed); + mocks.VerifyAll(); + } + + [Test] + public void CanRemove_ParentIsPipingCalculationGroupContainingGroup_ReturnTrue() + { + // Setup + var group = new PipingCalculationGroup(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var parentGroup = new PipingCalculationGroup(); + parentGroup.Children.Add(group); + var parentNodeData = new PipingCalculationGroupContext(parentGroup, + Enumerable.Empty(), + Enumerable.Empty()); + + mocks.ReplayAll(); + + // Call + bool isRemovalAllowed = info.CanRemove(nodeData, parentNodeData); + + // Assert + Assert.IsTrue(isRemovalAllowed); + mocks.VerifyAll(); + } + + [Test] + public void CanRemove_ParentIsPipingCalculationGroupNotContainingGroup_ReturnFalse() + { + // Setup + var group = new PipingCalculationGroup(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var parentGroup = new PipingCalculationGroup(); + var parentNodeData = new PipingCalculationGroupContext(parentGroup, + Enumerable.Empty(), + Enumerable.Empty()); + + // Precondition + CollectionAssert.DoesNotContain(parentGroup.Children, group); + + // Call + bool isRemovalAllowed = info.CanRemove(nodeData, parentNodeData); + + // Assert + Assert.IsFalse(isRemovalAllowed); + } + + [Test] + public void CanRemove_ParentIsPipingCalculationGroupContainingGroup_RemoveGroupAndNotifyObservers() + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + var group = new PipingCalculationGroup(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var parentGroup = new PipingCalculationGroup(); + parentGroup.Children.Add(group); + var parentNodeData = new PipingCalculationGroupContext(parentGroup, + Enumerable.Empty(), + Enumerable.Empty()); + parentNodeData.Attach(observer); + + // Precondition + Assert.IsTrue(info.CanRemove(nodeData, parentNodeData)); + + // Call + info.OnNodeRemoved(nodeData, parentNodeData); + + // Assert + CollectionAssert.DoesNotContain(parentGroup.Children, group); + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_ChildOfGroupValidDataWithCalculationOutput_ReturnContextMenuWithAllItems() + { + // Setup + var gui = mocks.StrictMock(); + + var parentGroup = new PipingCalculationGroup(); + var group = new PipingCalculationGroup(); + + parentGroup.Children.Add(group); + group.Children.Add(new PipingCalculation + { + Output = new TestPipingOutput() + }); + + var parentData = new PipingCalculationGroupContext(parentGroup, + Enumerable.Empty(), + Enumerable.Empty()); + + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + var nodeParent = new TreeNode + { + Tag = parentData + }; + + var node = new TreeNode + { + Tag = nodeData + }; + nodeParent.Nodes.Add(node); + + var applicationFeatureCommandHandler = mocks.Stub(); + var exportImportHandler = mocks.Stub(); + var viewCommandsHandler = mocks.StrictMock(); + + var menuBuilder = new ContextMenuBuilder(applicationFeatureCommandHandler, exportImportHandler, viewCommandsHandler, node, info); + gui.Expect(g => g.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + ContextMenuStrip menu = info.ContextMenuStrip(nodeData, node, info); + + // Assert + Assert.AreEqual(17, menu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndex, + PipingFormsResources.PipingCalculationGroup_Add_PipingCalculationGroup, + "Voeg een nieuwe berekeningsmap toe aan deze berekeningsmap.", + PipingFormsResources.AddFolderIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndex, + PipingFormsResources.PipingCalculationGroup_Add_PipingCalculation, + "Voeg een nieuwe berekening toe aan deze berekeningsmap.", + PipingFormsResources.PipingIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex, + RingtoetsFormsResources.Validate_all, + "Valideer alle berekeningen binnen deze berekeningsmap.", + RingtoetsFormsResources.ValidateAllIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex, + RingtoetsFormsResources.Calculate_all, + "Valideer en voer alle berekeningen binnen deze berekeningsmap uit.", + RingtoetsFormsResources.CalculateAllIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearOutputIndex, + "&Wis alle uitvoer...", + "Wis de uitvoer van alle berekeningen binnen deze berekeningsmap.", + RingtoetsFormsResources.ClearIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, 7, + CoreCommonGuiResources.Rename, + CoreCommonGuiResources.Rename_ToolTip, + CoreCommonGuiResources.RenameIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, 8, + CoreCommonGuiResources.Delete, + CoreCommonGuiResources.Delete_ToolTip, + CoreCommonGuiResources.DeleteIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, 10, + CoreCommonGuiResources.Import, + CoreCommonGuiResources.Import_ToolTip, + CoreCommonGuiResources.ImportIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, 11, + CoreCommonGuiResources.Export, + CoreCommonGuiResources.Export_ToolTip, + CoreCommonGuiResources.ExportIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, 13, + CoreCommonGuiResources.Expand_all, + CoreCommonGuiResources.Expand_all_ToolTip, + CoreCommonGuiResources.ExpandAllIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, 14, + CoreCommonGuiResources.Collapse_all, + CoreCommonGuiResources.Collapse_all_ToolTip, + CoreCommonGuiResources.CollapseAllIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, 16, + CoreCommonGuiResources.Properties, + CoreCommonGuiResources.Properties_ToolTip, + CoreCommonGuiResources.PropertiesIcon, + false); + CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[2], menu.Items[6], menu.Items[9], menu.Items[12], menu.Items[15] }, typeof(ToolStripSeparator)); + + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_NotValidDataWithCalculationOutput_ReturnContextWithItems() + { + // Setup + var gui = mocks.StrictMock(); + var group = new PipingCalculationGroup(); + + group.Children.Add(new PipingCalculation + { + Output = new TestPipingOutput() + }); + + var parentData = new object(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var nodeParent = new TreeNode + { + Tag = parentData + }; + + var node = new TreeNode + { + Tag = group + }; + nodeParent.Nodes.Add(node); + + var applicationFeatureCommandHandler = mocks.Stub(); + var exportImportHandler = mocks.Stub(); + var viewCommandsHandler = mocks.StrictMock(); + + var menuBuilder = new ContextMenuBuilder(applicationFeatureCommandHandler, exportImportHandler, viewCommandsHandler, node, info); + gui.Expect(g => g.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + ContextMenuStrip menu = info.ContextMenuStrip(nodeData, node, info); + + // Assert + Assert.AreEqual(16, menu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndex, + PipingFormsResources.PipingCalculationGroup_Add_PipingCalculationGroup, + "Voeg een nieuwe berekeningsmap toe aan deze berekeningsmap.", + PipingFormsResources.AddFolderIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndex, + PipingFormsResources.PipingCalculationGroup_Add_PipingCalculation, + "Voeg een nieuwe berekening toe aan deze berekeningsmap.", + PipingFormsResources.PipingIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex, + RingtoetsFormsResources.Validate_all, + "Valideer alle berekeningen binnen deze berekeningsmap.", + RingtoetsFormsResources.ValidateAllIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex, + RingtoetsFormsResources.Calculate_all, + "Valideer en voer alle berekeningen binnen deze berekeningsmap uit.", + RingtoetsFormsResources.CalculateAllIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearOutputIndex, + "&Wis alle uitvoer...", + "Wis de uitvoer van alle berekeningen binnen deze berekeningsmap.", + RingtoetsFormsResources.ClearIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, 7, + CoreCommonGuiResources.Rename, + CoreCommonGuiResources.Rename_ToolTip, + CoreCommonGuiResources.RenameIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, 9, + CoreCommonGuiResources.Import, + CoreCommonGuiResources.Import_ToolTip, + CoreCommonGuiResources.ImportIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, 10, + CoreCommonGuiResources.Export, + CoreCommonGuiResources.Export_ToolTip, + CoreCommonGuiResources.ExportIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, 12, + CoreCommonGuiResources.Expand_all, + CoreCommonGuiResources.Expand_all_ToolTip, + CoreCommonGuiResources.ExpandAllIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, 13, + CoreCommonGuiResources.Collapse_all, + CoreCommonGuiResources.Collapse_all_ToolTip, + CoreCommonGuiResources.CollapseAllIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, 15, + CoreCommonGuiResources.Properties, + CoreCommonGuiResources.Properties_ToolTip, + CoreCommonGuiResources.PropertiesIcon, + false); + CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[2], menu.Items[6], menu.Items[8], menu.Items[11], menu.Items[14] }, typeof(ToolStripSeparator)); + + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_ParentWithFailureMechanism_ReturnContextMenuWithoutRenameRemove() + { + // Setup + var gui = mocks.StrictMock(); + var group = new PipingCalculationGroup(); + + group.Children.Add(new PipingCalculation + { + Output = new TestPipingOutput() + }); + + var parentData = new PipingFailureMechanism(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var nodeParent = new TreeNode + { + Tag = parentData + }; + + var node = new TreeNode + { + Tag = nodeData + }; + nodeParent.Nodes.Add(node); + + var applicationFeatureCommandHandler = mocks.Stub(); + var exportImportHandler = mocks.Stub(); + var viewCommandsHandler = mocks.StrictMock(); + + var menuBuilder = new ContextMenuBuilder(applicationFeatureCommandHandler, exportImportHandler, viewCommandsHandler, node, info); + gui.Expect(g => g.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + ContextMenuStrip menu = info.ContextMenuStrip(nodeData, node, info); + + // Assert + Assert.AreEqual(14, menu.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndex, + PipingFormsResources.PipingCalculationGroup_Add_PipingCalculationGroup, + "Voeg een nieuwe berekeningsmap toe aan deze berekeningsmap.", + PipingFormsResources.AddFolderIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndex, + PipingFormsResources.PipingCalculationGroup_Add_PipingCalculation, + "Voeg een nieuwe berekening toe aan deze berekeningsmap.", + PipingFormsResources.PipingIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex, + RingtoetsFormsResources.Validate_all, + "Valideer alle berekeningen binnen deze berekeningsmap.", + RingtoetsFormsResources.ValidateAllIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex, + RingtoetsFormsResources.Calculate_all, + "Valideer en voer alle berekeningen binnen deze berekeningsmap uit.", + RingtoetsFormsResources.CalculateAllIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearOutputIndex, + "&Wis alle uitvoer...", + "Wis de uitvoer van alle berekeningen binnen deze berekeningsmap.", + RingtoetsFormsResources.ClearIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, 7, + CoreCommonGuiResources.Import, + CoreCommonGuiResources.Import_ToolTip, + CoreCommonGuiResources.ImportIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, 8, + CoreCommonGuiResources.Export, + CoreCommonGuiResources.Export_ToolTip, + CoreCommonGuiResources.ExportIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, 10, + CoreCommonGuiResources.Expand_all, + CoreCommonGuiResources.Expand_all_ToolTip, + CoreCommonGuiResources.ExpandAllIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, 11, + CoreCommonGuiResources.Collapse_all, + CoreCommonGuiResources.Collapse_all_ToolTip, + CoreCommonGuiResources.CollapseAllIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, 13, + CoreCommonGuiResources.Properties, + CoreCommonGuiResources.Properties_ToolTip, + CoreCommonGuiResources.PropertiesIcon, + false); + CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[2], menu.Items[6], menu.Items[9], menu.Items[12] }, typeof(ToolStripSeparator)); + + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_GroupWithNoCalculations_ValidateAndCalculateAllDisabled() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var group = new PipingCalculationGroup(); + var parentData = new PipingFailureMechanism(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + var nodeParent = new TreeNode + { + Tag = parentData + }; + + var node = new TreeNode + { + Tag = nodeData + }; + nodeParent.Nodes.Add(node); + + gui.Expect(cmp => cmp.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + + // Call + ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, node, info); + + // Assert + ToolStripItem validateItem = contextMenu.Items[contextMenuValidateAllIndex]; + ToolStripItem calculateItem = contextMenu.Items[contextMenuCalculateAllIndex]; + Assert.IsFalse(validateItem.Enabled); + Assert.IsFalse(calculateItem.Enabled); + Assert.AreEqual(PipingFormsResources.PipingFailureMechanismNodePresenter_CreateCalculateAllItem_No_calculations_to_run, calculateItem.ToolTipText); + Assert.AreEqual(PipingFormsResources.PipingFailureMechanismNodePresenter_CreateValidateAllItem_No_calculations_to_validate, validateItem.ToolTipText); + + mocks.VerifyAll(); // Expect no calls on arguments + } + + + [Test] + public void GetContextMenu_ClickOnAddGroupItem_AddGroupToCalculationGroupAndNotifyObservers() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var group = new PipingCalculationGroup(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var calculationItem = mocks.Stub(); + calculationItem.Expect(ci => ci.Name).Return("Nieuwe map"); + + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + var newCalculationGroupContextNode = new TreeNode(); + + // Parent node of newly added item, should be expanded from collapsed state to show selected node: + var treeView = new System.Windows.Forms.TreeView(); + var parentNode = new TreeNode(); + var node = new TreeNode + { + Tag = nodeData + }; + node.Nodes.Add(newCalculationGroupContextNode); + node.Collapse(); + + parentNode.Nodes.Add(node); + + treeView.Nodes.Add(parentNode); + + gui.Expect(cmp => cmp.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + group.Children.Add(calculationItem); + + nodeData.Attach(observer); + + ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, node, info); + + // Precondition + Assert.AreEqual(1, group.Children.Count); + + // Call + contextMenu.Items[contextMenuAddCalculationGroupIndex].PerformClick(); + + // Assert + Assert.AreEqual(2, group.Children.Count); + var newlyAddedItem = group.Children.Last(); + Assert.IsInstanceOf(newlyAddedItem); + Assert.AreEqual("Nieuwe map (1)", newlyAddedItem.Name, + "An item with the same name default name already exists, therefore '(1)' needs to be appended."); + + Assert.AreSame(newCalculationGroupContextNode, treeView.SelectedNode, + "The node of the newly added item should be selected."); + + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_ClickOnAddCalculationItem_AddCalculationToCalculationGroupAndNotifyObservers() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var group = new PipingCalculationGroup(); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var calculationItem = mocks.Stub(); + calculationItem.Expect(ci => ci.Name).Return("Nieuwe berekening"); + + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + var newCalculationContextNode = new TreeNode(); + + // Parent node of newly added item, should be expanded from collapsed state to show selected node: + var treeView = new System.Windows.Forms.TreeView(); + var parentNode = new TreeNode(); + var node = new TreeNode + { + Tag = nodeData + }; + node.Nodes.Add(newCalculationContextNode); + node.Collapse(); + + parentNode.Nodes.Add(node); + + treeView.Nodes.Add(parentNode); + + gui.Expect(cmp => cmp.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + group.Children.Add(calculationItem); + + nodeData.Attach(observer); + + var contextMenu = info.ContextMenuStrip(nodeData, node, info); + + // Precondition + Assert.AreEqual(1, group.Children.Count); + + // Call + contextMenu.Items[contextMenuAddCalculationIndex].PerformClick(); + + // Assert + Assert.AreEqual(2, group.Children.Count); + var newlyAddedItem = group.Children.Last(); + Assert.IsInstanceOf(newlyAddedItem); + Assert.AreEqual("Nieuwe berekening (1)", newlyAddedItem.Name, + "An item with the same name default name already exists, therefore '(1)' needs to be appended."); + + Assert.AreSame(newCalculationContextNode, node.TreeView.SelectedNode, + "The node of the newly added item should be selected."); + + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_ClickOnValidateAllItem_ValidateAllChildCalculations() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var parentNode = new TreeNode(); + var node = new TreeNode(); + parentNode.Nodes.Add(node); + + gui.Expect(cmp => cmp.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + var validCalculation = PipingCalculationFactory.CreateCalculationWithValidInput(); + validCalculation.Name = "A"; + var invalidCalculation = PipingCalculationFactory.CreateCalculationWithInvalidData(); + invalidCalculation.Name = "B"; + + var childGroup = new PipingCalculationGroup(); + childGroup.Children.Add(validCalculation); + + var emptyChildGroup = new PipingCalculationGroup(); + + var group = new PipingCalculationGroup(); + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(invalidCalculation); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var contextMenu = info.ContextMenuStrip(nodeData, node, info); + + // Call + Action call = () => contextMenu.Items[contextMenuValidateAllIndex].PerformClick(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(6, msgs.Length); + StringAssert.StartsWith(String.Format("Validatie van '{0}' gestart om: ", validCalculation.Name), msgs[0]); + StringAssert.StartsWith(String.Format("Validatie van '{0}' beëindigd om: ", validCalculation.Name), msgs[1]); + + StringAssert.StartsWith(String.Format("Validatie van '{0}' gestart om: ", invalidCalculation.Name), msgs[2]); + // Some validation error from validation service + StringAssert.StartsWith(String.Format("Validatie van '{0}' beëindigd om: ", invalidCalculation.Name), msgs[5]); + }); + mocks.VerifyAll(); + } + + [Test] + public void GetContextMenu_ClickOnCalculateAllItem_ScheduleAllChildCalculations() + { + // Setup + var gui = mocks.StrictMock(); + var mainWindow = mocks.Stub(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var node = mocks.StrictMock(); + var parentNode = mocks.Stub(); + node.Expect(n => n.Parent).Return(parentNode).Repeat.Twice(); + + gui.Expect(g => g.Get(node, info)).Return(menuBuilder); + gui.Expect(g => g.MainWindow).Return(mainWindow); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + DialogBoxHandler = (name, wnd) => { }; + + var validCalculation = PipingCalculationFactory.CreateCalculationWithValidInput(); + validCalculation.Name = "A"; + var invalidCalculation = PipingCalculationFactory.CreateCalculationWithInvalidData(); + invalidCalculation.Name = "B"; + + var childGroup = new PipingCalculationGroup(); + childGroup.Children.Add(validCalculation); + + var emptyChildGroup = new PipingCalculationGroup(); + + var group = new PipingCalculationGroup(); + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(invalidCalculation); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + var contextMenu = info.ContextMenuStrip(nodeData, node, info); + + // Call + contextMenu.Items[contextMenuCalculateAllIndex].PerformClick(); + + // Assert + mocks.VerifyAll(); + } + + [Test] + [TestCase(false)] + [TestCase(true)] + public void GetContextMenu_ClickOnClearOutputItem_ClearOutputAllChildCalculationsAndNotifyCalculationObservers(bool confirm) + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var node = mocks.StrictMock(); + var parentNode = mocks.Stub(); + node.Expect(n => n.Parent).Return(parentNode).Repeat.Twice(); + + var calculation1Observer = mocks.StrictMock(); + var calculation2Observer = mocks.StrictMock(); + + if (confirm) + { + calculation1Observer.Expect(o => o.UpdateObserver()); + calculation2Observer.Expect(o => o.UpdateObserver()); + } + gui.Expect(cmp => cmp.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + var calculation1 = PipingCalculationFactory.CreateCalculationWithValidInput(); + calculation1.Name = "A"; + calculation1.Output = new TestPipingOutput(); + calculation1.Attach(calculation1Observer); + var calculation2 = PipingCalculationFactory.CreateCalculationWithValidInput(); + calculation2.Name = "B"; + calculation2.Output = new TestPipingOutput(); + calculation1.Attach(calculation2Observer); + + var childGroup = new PipingCalculationGroup(); + childGroup.Children.Add(calculation1); + + var emptyChildGroup = new PipingCalculationGroup(); + + var group = new PipingCalculationGroup(); + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(calculation2); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBox.Text); + Assert.AreEqual("Bevestigen", messageBox.Title); + if (confirm) + { + messageBox.ClickOk(); + } + else + { + messageBox.ClickCancel(); + } + }; + + // Precondition + Assert.IsTrue(group.HasOutput); + + var contextMenu = info.ContextMenuStrip(nodeData, node, info); + + // Call + contextMenu.Items[contextMenuClearOutputIndex].PerformClick(); + + // Assert + Assert.AreNotEqual(confirm, group.HasOutput); + Assert.AreNotEqual(confirm, calculation1.HasOutput); + Assert.AreNotEqual(confirm, calculation2.HasOutput); + mocks.VerifyAll(); + } + + [Test] + public void GetChildNodeObjects_EmptyGroup_ReturnEmpty() + { + // Setup + var group = new PipingCalculationGroup(); + var groupContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + var children = info.ChildNodeObjects(groupContext); + + // Assert + CollectionAssert.IsEmpty(children); + } + + [Test] + public void GetChildNodeObjects_GroupWithMixedContents_ReturnChildren() + { + // Setup + var calculationItem = mocks.StrictMock(); + + mocks.ReplayAll(); + + var childCalculation = new PipingCalculation(); + + var childGroup = new PipingCalculationGroup(); + + var group = new PipingCalculationGroup(); + group.Children.Add(calculationItem); + group.Children.Add(childCalculation); + group.Children.Add(childGroup); + var nodeData = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + + + // Call + var children = info.ChildNodeObjects(nodeData).ToArray(); + + // Assert + Assert.AreEqual(group.Children.Count, children.Length); + Assert.AreSame(calculationItem, children[0]); + var returnedCalculationContext = (PipingCalculationContext)children[1]; + Assert.AreSame(childCalculation, returnedCalculationContext.WrappedData); + var returnedCalculationGroupContext = (PipingCalculationGroupContext)children[2]; + Assert.AreSame(childGroup, returnedCalculationGroupContext.WrappedData); + mocks.VerifyAll(); + } + + /// + /// Creates a stub that is in the expanded state. + /// + /// The data corresponding with the created node. + /// The child nodes. + private TreeNode CreateExpandedNodeStub(object nodeData, TreeNode[] childNodes) + { + var preUpdateExpandedNode = mocks.Stub(); + preUpdateExpandedNode.Tag = nodeData; + preUpdateExpandedNode.Expect(n => n.IsExpanded).Return(true); + preUpdateExpandedNode.Nodes.AddRange(childNodes); + return preUpdateExpandedNode; + } + + /// + /// Creates an stub that is expected to be expanded. + /// + /// The data corresponding with the created node. + /// The child nodes. + /// Optional: action to be called when is being retrieved. + private TreeNode CreateNodeStubToBeExpanded(object nodeData, TreeNode[] childNodes, Action whenNodesCalledAction = null) + { + var postUpdateExpandedNode = new TreeNode(); + postUpdateExpandedNode.Tag = nodeData; + postUpdateExpandedNode.Collapse(); + postUpdateExpandedNode.Nodes.AddRange(childNodes); + return postUpdateExpandedNode; + } + + /// + /// Creates a stub that is in the collapsed state. + /// + /// The data corresponding with the created node. + /// The child nodes. + private TreeNode CreateCollapsedNodeStub(object nodeData, TreeNode[] childNodes) + { + var collapsedNode = new TreeNode(); + collapsedNode.Tag = nodeData; + collapsedNode.Collapse(); + collapsedNode.Nodes.AddRange(childNodes); + return collapsedNode; + } + + /// + /// Creates an stub that is expected to be collapsed. + /// + /// The data corresponding with the created node. + /// The child nodes. + private TreeNode CreateNodeStubToBeCollapsed(object nodeData, TreeNode[] childNodes) + { + var nodeToBeCollapsed = new TreeNode(); + nodeToBeCollapsed.Tag = nodeData; + nodeToBeCollapsed.Nodes.AddRange(childNodes); + return nodeToBeCollapsed; + } + + /// + /// Creates an stub that expects its + /// method will be called once. + /// + /// Optional: Action to be performed when + /// is being called. + private IObserver CreateObserverStubWithUpdateExpectancy(Action whenCalledAction = null) + { + var newOwnerObserver = mocks.StrictMock(); + newOwnerObserver.Expect(o => o.UpdateObserver()).WhenCalled(invocation => + { + if (whenCalledAction != null) + { + whenCalledAction(invocation); + } + }); + return newOwnerObserver; + } + + /// + /// Creates an instance of and the corresponding + /// . + /// + /// The created group without any children. + /// The context object for , without any other data. + private static void CreatePipingCalculationGroupAndContext(out PipingCalculationGroup data, out PipingCalculationGroupContext dataContext) + { + data = new PipingCalculationGroup(); + dataContext = new PipingCalculationGroupContext(data, + Enumerable.Empty(), + Enumerable.Empty()); + } + + /// + /// Creates an instance of and the corresponding context. + /// + /// Defines the implementation of to be constructed. + /// Output: The concrete create class based on . + /// Output: The corresponding with . + /// Optional: The name of . + /// + private static void CreatePipingCalculationItemAndContext(PipingCalculationItemType type, out IPipingCalculationItem data, out object dataContext, string initialName = null) + { + switch (type) + { + case PipingCalculationItemType.Calculation: + var calculation = new PipingCalculation(); + if (initialName != null) + { + calculation.Name = initialName; + } + data = calculation; + dataContext = new PipingCalculationContext(calculation, + Enumerable.Empty(), + Enumerable.Empty()); + break; + case PipingCalculationItemType.Group: + var group = new PipingCalculationGroup(); + if (initialName != null) + { + group.Name = initialName; + } + data = group; + dataContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty()); + break; + default: + throw new NotSupportedException(); + } + } + + /// + /// Use to creates a stub tree node as a simple node-tree leaf. + /// + private TreeNode CreateStubTreeNode() + { + return CreateTreeNodeLeafForData(new object()); + } + + /// + /// Creates an stub that represents a tree-node leaf. + /// + /// The data associated with the node. + private TreeNode CreateTreeNodeLeafForData(object nodeData) + { + var preUpdateDraggedItemContextNode = mocks.Stub(); + preUpdateDraggedItemContextNode.Tag = nodeData; + preUpdateDraggedItemContextNode.Stub(n => n.IsExpanded).Return(false); + return preUpdateDraggedItemContextNode; + } + + /// + /// Type indicator for testing methods on . + /// + public enum DragDropTestMethod + { + /// + /// Indicates . + /// + CanDrop, + /// + /// Indicates . + /// + CanInsert + } + + /// + /// Type indicator for implementations of to be created in a test. + /// + public enum PipingCalculationItemType + { + /// + /// Indicates . + /// + Calculation, + /// + /// Indicates . + /// + Group + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingFailureMechanismTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingFailureMechanismTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingFailureMechanismTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,486 @@ +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Piping.Calculation.TestUtil; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.Properties; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Plugin; +using RingtoetsFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using PipingFormsResources = Ringtoets.Piping.Forms.Properties.Resources; +using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + public class PipingFailureMechanismTreeNodeInfoTest : NUnitFormTest + { + private const int contextMenuAddFolderIndex = 0; + private const int contextMenuAddCalculationIndex = 1; + private const int contextMenuValidateAllIndex = 3; + private const int contextMenuCalculateAllIndex = 4; + private const int contextMenuClearIndex = 5; + + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingFailureMechanism)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PipingFailureMechanism), info.TagType); + + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var mechanism = new PipingFailureMechanism(); + + // Call + var text = info.Text(mechanism); + + // Assert + Assert.AreEqual(Resources.PipingFailureMechanism_DisplayName, text); + } + + [Test] + public void Image_Always_ReturnsPlaceHolderIcon() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(PipingFormsResources.PipingIcon, image); + } + + [Test] + public void GetChildNodeObjects_Always_ReturnChildDataNodes() + { + // Setup + var pipingFailureMechanism = new PipingFailureMechanism(); + pipingFailureMechanism.CalculationsGroup.Children.Add(new PipingCalculation()); + pipingFailureMechanism.CalculationsGroup.Children.Add(new PipingCalculation()); + + // Call + var children = info.ChildNodeObjects(pipingFailureMechanism).ToArray(); + + // Assert + Assert.AreEqual(3, children.Length); + var inputsFolder = (CategoryTreeFolder)children[0]; + Assert.AreEqual("Invoer", inputsFolder.Name); + Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category); + CollectionAssert.AreEqual(new object[] + { + pipingFailureMechanism.SectionDivisions, + pipingFailureMechanism.SurfaceLines, + pipingFailureMechanism.SoilProfiles, + pipingFailureMechanism.BoundaryConditions + }, inputsFolder.Contents); + + var calculationsFolder = (PipingCalculationGroupContext)children[1]; + Assert.AreEqual("Berekeningen", calculationsFolder.WrappedData.Name); + CollectionAssert.AreEqual(pipingFailureMechanism.CalculationsGroup.Children, calculationsFolder.WrappedData.Children); + Assert.AreSame(pipingFailureMechanism.SurfaceLines, calculationsFolder.AvailablePipingSurfaceLines); + Assert.AreSame(pipingFailureMechanism.SoilProfiles, calculationsFolder.AvailablePipingSoilProfiles); + + var outputsFolder = (CategoryTreeFolder)children[2]; + Assert.AreEqual("Uitvoer", outputsFolder.Name); + Assert.AreEqual(TreeFolderCategory.Output, outputsFolder.Category); + CollectionAssert.AreEqual(new object[] + { + pipingFailureMechanism.AssessmentResult + }, outputsFolder.Contents); + } + + [Test] + [TestCase(false)] + [TestCase(true)] + public void GivenMultiplePipingCalculationsWithOutput_WhenClearingOutputFromContextMenu_ThenPipingOutputCleared(bool confirm) + { + // Given + var gui = mocks.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var observer = mocks.StrictMock(); + var nodeMock = mocks.Stub(); + var dataMock = mocks.StrictMock(); + + if (confirm) + { + observer.Expect(o => o.UpdateObserver()).Repeat.Twice(); + } + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + dataMock.CalculationsGroup.Children.Add(new PipingCalculation + { + Output = new TestPipingOutput() + }); + dataMock.CalculationsGroup.Children.Add(new PipingCalculation + { + Output = new TestPipingOutput() + }); + dataMock.CalculationsGroup.Children.ElementAt(0).Attach(observer); + dataMock.CalculationsGroup.Children.ElementAt(1).Attach(observer); + + ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(dataMock, nodeMock, info); + + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBox.Text); + Assert.AreEqual("Bevestigen", messageBox.Title); + if (confirm) + { + messageBox.ClickOk(); + } + else + { + messageBox.ClickCancel(); + } + }; + + // When + contextMenuAdapter.Items[contextMenuClearIndex].PerformClick(); + + // Then + Assert.AreNotEqual(confirm, dataMock.CalculationsGroup.HasOutput); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_HasCalculationWithOutput_ReturnsContextMenuWithCommonItems() + { + // Setup + var gui = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.GetPipingCalculations().First().Output = new TestPipingOutput(); + + var node = new TreeNode + { + Tag = failureMechanism + }; + + var applicationFeatureCommandHandler = mocks.Stub(); + var exportImportHandler = mocks.Stub(); + var viewCommandsHandler = mocks.StrictMock(); + + var menuBuilder = new ContextMenuBuilder(applicationFeatureCommandHandler, exportImportHandler, viewCommandsHandler, node, info); + gui.Expect(cmp => cmp.Get(node, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + ContextMenuStrip menu = info.ContextMenuStrip(failureMechanism, node, info); + + // Assert + Assert.AreEqual(12, menu.Items.Count); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddFolderIndex, PipingFormsResources.PipingCalculationGroup_Add_PipingCalculationGroup, PipingFormsResources.PipingFailureMechanism_Add_PipingCalculationGroup_Tooltip, PipingFormsResources.AddFolderIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndex, PipingFormsResources.PipingCalculationGroup_Add_PipingCalculation, PipingFormsResources.PipingFailureMechanism_Add_PipingCalculation_Tooltip, PipingFormsResources.PipingIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, 3, RingtoetsFormsResources.Validate_all, RingtoetsFormsResources.Validate_all_ToolTip, RingtoetsFormsResources.ValidateAllIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, 4, RingtoetsFormsResources.Calculate_all, RingtoetsFormsResources.Calculate_all_ToolTip, RingtoetsFormsResources.CalculateAllIcon); + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIndex, RingtoetsFormsResources.Clear_all_output, RingtoetsFormsResources.Clear_all_output_ToolTip, RingtoetsFormsResources.ClearIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, 7, CoreCommonGuiResources.Import, CoreCommonGuiResources.Import_ToolTip, CoreCommonGuiResources.ImportIcon, false); + TestHelper.AssertContextMenuStripContainsItem(menu, 8, CoreCommonGuiResources.Export, CoreCommonGuiResources.Export_ToolTip, CoreCommonGuiResources.ExportIcon, false); + + TestHelper.AssertContextMenuStripContainsItem(menu, 10, CoreCommonGuiResources.Expand_all, CoreCommonGuiResources.Expand_all_ToolTip, CoreCommonGuiResources.ExpandAllIcon, false); + TestHelper.AssertContextMenuStripContainsItem(menu, 11, CoreCommonGuiResources.Collapse_all, CoreCommonGuiResources.Collapse_all_ToolTip, CoreCommonGuiResources.CollapseAllIcon, false); + + CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[2], menu.Items[6], menu.Items[9] }, typeof(ToolStripSeparator)); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_PipingFailureMechanismNoOutput_ClearAllOutputDisabled() + { + // Setup + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var nodeMock = mocks.StrictMock(); + var dataMock = mocks.StrictMock(); + + var gui = mocks.StrictMock(); + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + ContextMenuStrip contextMenu = info.ContextMenuStrip(dataMock, nodeMock, info); + + // Assert + ToolStripItem clearOutputItem = contextMenu.Items[contextMenuClearIndex]; + Assert.IsFalse(clearOutputItem.Enabled); + Assert.AreEqual("Er zijn geen berekeningen met uitvoer om te wissen.", clearOutputItem.ToolTipText); + + mocks.VerifyAll(); // Expect no calls on arguments + } + + [Test] + public void ContextMenuStrip_PipingFailureMechanismWithOutput_ClearAllOutputEnabled() + { + // Setup + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var nodeMock = mocks.StrictMock(); + var dataMock = mocks.StrictMock(); + var gui = mocks.StrictMock(); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + dataMock.CalculationsGroup.Children.Add(new PipingCalculation + { + Output = new TestPipingOutput() + }); + + // Call + ContextMenuStrip contextMenu = info.ContextMenuStrip(dataMock, nodeMock, info); + + // Assert + ToolStripItem clearOutputItem = contextMenu.Items[contextMenuClearIndex]; + Assert.IsTrue(clearOutputItem.Enabled); + Assert.AreEqual(RingtoetsFormsResources.Clear_all_output_ToolTip, clearOutputItem.ToolTipText); + + mocks.VerifyAll(); // Expect no calls on arguments + } + + [Test] + public void ContextMenuStrip_PipingFailureMechanismWithNoCalculations_ValidateAndCalculateAllDisabled() + { + // Setup + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var nodeMock = new TreeNode(null); + var dataMock = new PipingFailureMechanism(); + var gui = mocks.StrictMock(); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + dataMock.CalculationsGroup.Children.Clear(); + + // Call + ContextMenuStrip contextMenu = info.ContextMenuStrip(dataMock, nodeMock, info); + + // Assert + ToolStripItem validateItem = contextMenu.Items[contextMenuValidateAllIndex]; + ToolStripItem calculateItem = contextMenu.Items[contextMenuCalculateAllIndex]; + Assert.IsFalse(validateItem.Enabled); + Assert.IsFalse(calculateItem.Enabled); + Assert.AreEqual(PipingFormsResources.PipingFailureMechanismNodePresenter_CreateCalculateAllItem_No_calculations_to_run, calculateItem.ToolTipText); + Assert.AreEqual(PipingFormsResources.PipingFailureMechanismNodePresenter_CreateValidateAllItem_No_calculations_to_validate, validateItem.ToolTipText); + + mocks.VerifyAll(); // Expect no calls on arguments + } + + [Test] + public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + { + // Setup + var gui = mocks.StrictMock(); + var menuBuilder = mocks.StrictMock(); + var nodeMock = mocks.StrictMock(); + + menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddImportItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddExportItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.Build()).Return(null); + + gui.Expect(cmp => cmp.Get(nodeMock, info)).Return(menuBuilder); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(new PipingFailureMechanism(), nodeMock, info); + + // Assert + mocks.VerifyAll(); + } + +// [Test] +// public void ContextMenuStrip_ClickOnAddCalculationItem_NewPipingCalculationInstanceAddedToFailureMechanismAndNotifyObservers() +// { +// // Setup +// var failureMechanism = new PipingFailureMechanism(); +// failureMechanism.CalculationsGroup.Children.Clear(); +// failureMechanism.CalculationsGroup.Children.Add(new PipingCalculation()); +// +// var treeView = new Core.Common.Controls.TreeView.TreeView(); +// +// var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); +// +// var failureMechanismCalculationsNode = new TreeNode(); +// failureMechanismCalculationsNode.Collapse(); +// +// var failureMechanismNode = new TreeNode(); +// failureMechanismNode.Collapse(); +// failureMechanismNode.Nodes.AddRange(new [] +// { +// new TreeNode(), +// failureMechanismCalculationsNode, +// new TreeNode() +// }); +// +// var observerMock = mocks.StrictMock(); +// observerMock.Expect(o => o.UpdateObserver()); +// +// var gui = mocks.StrictMock(); +// gui.Expect(cmp => cmp.Get(failureMechanismNode, info)).Return(menuBuilder); +// +// mocks.ReplayAll(); +// +// plugin.Gui = gui; +// +// failureMechanism.CalculationsGroup.Attach(observerMock); +// +// // Precondition +// Assert.AreEqual(1, failureMechanism.CalculationsGroup.Children.Count); +// +// // Call +// ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanism, failureMechanismNode, info); +// ToolStripItem addCalculationItem = contextMenu.Items[contextMenuAddCalculationIndex]; +// addCalculationItem.PerformClick(); +// +// // Assert +// Assert.AreEqual(2, failureMechanism.CalculationsGroup.Children.Count); +// IPipingCalculationItem addedItem = failureMechanism.CalculationsGroup.Children.ElementAt(1); +// Assert.AreEqual("Nieuwe berekening (1)", addedItem.Name, +// "Because there is already an item with the same default name, '(1)' should be appended."); +// Assert.IsInstanceOf(addedItem); +// +//// Assert.AreSame(newCalculationContextNode, newCalculationContextNode.TreeView.SelectedNode); +// Assert.IsTrue(failureMechanismNode.IsExpanded); +// Assert.IsTrue(failureMechanismCalculationsNode.IsExpanded); +// mocks.VerifyAll(); +// } +// +// [Test] +// public void ContextMenuStrip_ClickOnAddFolderItem_NewPipingCalculationGroupInstanceAddedToFailureMechanismAndNotifyObservers() +// { +// // Setup +// var failureMechanism = new PipingFailureMechanism(); +// failureMechanism.CalculationsGroup.Children.Clear(); +// failureMechanism.CalculationsGroup.Children.Add(new PipingCalculationGroup()); +// +// var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); +// +// var newCalculationGroupContextNode = mocks.StrictMock(); +// +// var failureMechanismCalculationsNode = mocks.StrictMock(); +// failureMechanismCalculationsNode.Expect(n => n.IsExpanded).Return(false); +// failureMechanismCalculationsNode.Expect(n => n.Expand()); +// failureMechanismCalculationsNode.Expect(n => n.Nodes).WhenCalled(invocation => +// { +// if (failureMechanism.CalculationsGroup.Children.Count == 2) +// { +// invocation.ReturnValue = new List +// { +// newCalculationGroupContextNode +// }; +// } +// }).Return(null); +// +// var failureMechanismNode = new TreeNode(); +// failureMechanismNode.Collapse(); +// failureMechanismNode.Nodes.AddRange(new [] +// { +// new TreeNode(), +// failureMechanismCalculationsNode, +// new TreeNode() +// }); +// +// var observerMock = mocks.StrictMock(); +// observerMock.Expect(o => o.UpdateObserver()); +// +// var gui = mocks.StrictMock(); +// gui.Expect(cmp => cmp.Get(failureMechanismNode, info)).Return(menuBuilder); +// +// mocks.ReplayAll(); +// +// plugin.Gui = gui; +// +// failureMechanism.Attach(observerMock); +// +// // Precondition +// Assert.AreEqual(1, failureMechanism.CalculationsGroup.Children.Count); +// +// // Call +// ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanism, failureMechanismNode, info); +// ToolStripItem addCalculationItem = contextMenu.Items[contextMenuAddFolderIndex]; +// addCalculationItem.PerformClick(); +// +// // Assert +// Assert.AreEqual(2, failureMechanism.CalculationsGroup.Children.Count); +// IPipingCalculationItem addedItem = failureMechanism.CalculationsGroup.Children.ElementAt(1); +// Assert.AreEqual("Nieuwe map (1)", addedItem.Name, +// "Because there is already an item with the same default name, '(1)' should be appended."); +// Assert.IsInstanceOf(addedItem); +// +// Assert.AreSame(newCalculationGroupContextNode, newCalculationGroupContextNode.TreeView.SelectedNode); +// Assert.IsTrue(failureMechanismNode.IsExpanded); +// mocks.VerifyAll(); +// } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingInputContextTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingInputContextTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingInputContextTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,112 @@ +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Plugin; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class PipingInputContextTreeNodeInfoTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingInputContext)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PipingInputContext), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Setup + var pipingInputContext = mocks.StrictMock(new PipingInput(), Enumerable.Empty(), Enumerable.Empty()); + + mocks.ReplayAll(); + + // Call + var text = info.Text(pipingInputContext); + + // Assert + Assert.AreEqual(Resources.PipingInputContextNodePresenter_NodeDisplayName, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var pipingInputContext = mocks.StrictMock(new PipingInput(), Enumerable.Empty(), Enumerable.Empty()); + + mocks.ReplayAll(); + + // Call + var image = info.Image(pipingInputContext); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.PipingInputIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var treeNode = new TreeNode(); + var gui = mocks.StrictMultiMock(); + var menuBuilderMock = mocks.StrictMock(); + + gui.Expect(g => g.Get(treeNode, info)).Return(menuBuilderMock); + + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, treeNode, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingOutputTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingOutputTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingOutputTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,110 @@ +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Plugin; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class PipingOutputTreeNodeInfoTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingOutput)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PipingOutput), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Setup + var pipingOutput = mocks.StrictMock(0, 0, 0, 0, 0, 0); + + mocks.ReplayAll(); + + // Call + var text = info.Text(pipingOutput); + + // Assert + Assert.AreEqual(Resources.PipingOutput_DisplayName, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var pipingOutput = mocks.StrictMock(0, 0, 0, 0, 0, 0); + + mocks.ReplayAll(); + + // Call + var image = info.Image(pipingOutput); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.PipingOutputIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var treeNode = new TreeNode(); + var gui = mocks.StrictMultiMock(); + var menuBuilderMock = mocks.StrictMock(); + + gui.Expect(g => g.Get(treeNode, info)).Return(menuBuilderMock); + + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, treeNode, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingSoilProfileCollectionTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingSoilProfileCollectionTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingSoilProfileCollectionTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,173 @@ +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Plugin; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class PipingSoilProfileCollectionTreeNodeInfoTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(IEnumerable)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(IEnumerable), info.TagType); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Setup + var pipingSoilProfiles = mocks.StrictMock>(); + + mocks.ReplayAll(); + + // Call + var text = info.Text(pipingSoilProfiles); + + // Assert + Assert.AreEqual(Resources.PipingSoilProfilesCollection_DisplayName, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var pipingSoilProfiles = mocks.StrictMock>(); + + mocks.ReplayAll(); + + // Call + var image = info.Image(pipingSoilProfiles); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.FolderIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void ForeColor_CollectionWithoutSoilProfiles_ReturnsGrayText() + { + // Setup + var pipingSoilProfiles = mocks.StrictMock>(); + + pipingSoilProfiles.Expect(collection => collection.GetEnumerator()); + + mocks.ReplayAll(); + + // Call + var foreColor = info.ForeColor(pipingSoilProfiles); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), foreColor); + + mocks.VerifyAll(); + } + + [Test] + public void ForeColor_CollectionWithSoilProfiles_ReturnsControlText() + { + // Setup + IEnumerable pipingSoilProfiles = new[] + { + new PipingSoilProfile("", 0, new List { new PipingSoilLayer(10) }), + new PipingSoilProfile("", 0, new List { new PipingSoilLayer(10) }) + }; + + // Call + var foreColor = info.ForeColor(pipingSoilProfiles); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), foreColor); + + mocks.VerifyAll(); + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildsOnData() + { + // Setup + var pipingSoilProfile1 = new PipingSoilProfile("", 0, new List { new PipingSoilLayer(10) }); + var pipingSoilProfile2 = new PipingSoilProfile("", 0, new List { new PipingSoilLayer(10) }); + IEnumerable pipingSoilProfiles = new[] + { + pipingSoilProfile1, + pipingSoilProfile2 + }; + + mocks.ReplayAll(); + + // Call + var objects = info.ChildNodeObjects(pipingSoilProfiles); + + // Assert + CollectionAssert.AreEqual(new[] { pipingSoilProfile1, pipingSoilProfile2 }, objects); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var treeNode = new TreeNode(); + var gui = mocks.StrictMultiMock(); + var menuBuilderMock = mocks.StrictMock(); + + gui.Expect(g => g.Get(treeNode, info)).Return(menuBuilderMock); + + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, treeNode, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingSoilProfileTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingSoilProfileTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingSoilProfileTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,111 @@ +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Plugin; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class PipingSoilProfileTreeNodeInfoTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingSoilProfile)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PipingSoilProfile), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var testName = "ttt"; + var pipingSoilLayer = mocks.StrictMock(10); + var pipingSoilProfile = mocks.StrictMock(testName, 0, new[] { pipingSoilLayer }); + + mocks.ReplayAll(); + + // Call + var text = info.Text(pipingSoilProfile); + + // Assert + Assert.AreEqual(testName, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var pipingSoilLayer = mocks.StrictMock(10); + var pipingSoilProfile = mocks.StrictMock("", 0, new[] { pipingSoilLayer }); + + mocks.ReplayAll(); + + // Call + var image = info.Image(pipingSoilProfile); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.PipingSoilProfileIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var treeNode = new TreeNode(); + var gui = mocks.StrictMultiMock(); + var menuBuilderMock = mocks.StrictMock(); + + gui.Expect(g => g.Get(treeNode, info)).Return(menuBuilderMock); + + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, treeNode, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,173 @@ +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Plugin; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class RingtoetsPipingSurfaceLineCollectionTreeNodeInfoTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(IEnumerable)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(IEnumerable), info.TagType); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsTextFromResource() + { + // Setup + var ringtoetsPipingSurfaceLines = mocks.StrictMock>(); + + mocks.ReplayAll(); + + // Call + var text = info.Text(ringtoetsPipingSurfaceLines); + + // Assert + Assert.AreEqual(Resources.PipingSurfaceLinesCollection_DisplayName, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var ringtoetsPipingSurfaceLines = mocks.StrictMock>(); + + mocks.ReplayAll(); + + // Call + var image = info.Image(ringtoetsPipingSurfaceLines); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.FolderIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void ForeColor_CollectionWithoutSurfaceLines_ReturnsGrayText() + { + // Setup + var ringtoetsPipingSurfaceLines = mocks.StrictMock>(); + + ringtoetsPipingSurfaceLines.Expect(collection => collection.GetEnumerator()); + + mocks.ReplayAll(); + + // Call + var foreColor = info.ForeColor(ringtoetsPipingSurfaceLines); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), foreColor); + + mocks.VerifyAll(); + } + + [Test] + public void ForeColor_CollectionWithSurfaceLines_ReturnsControlText() + { + // Setup + IEnumerable ringtoetsPipingSurfaceLines = new[] + { + new RingtoetsPipingSurfaceLine(), + new RingtoetsPipingSurfaceLine() + }; + + // Call + var foreColor = info.ForeColor(ringtoetsPipingSurfaceLines); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), foreColor); + + mocks.VerifyAll(); + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildsOnData() + { + // Setup + var ringtoetsPipingSurfaceLine1 = new RingtoetsPipingSurfaceLine(); + var ringtoetsPipingSurfaceLine2 = new RingtoetsPipingSurfaceLine(); + IEnumerable ringtoetsPipingSurfaceLines = new[] + { + ringtoetsPipingSurfaceLine1, + ringtoetsPipingSurfaceLine2 + }; + + mocks.ReplayAll(); + + // Call + var objects = info.ChildNodeObjects(ringtoetsPipingSurfaceLines); + + // Assert + CollectionAssert.AreEqual(new[] { ringtoetsPipingSurfaceLine1, ringtoetsPipingSurfaceLine2 }, objects); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var treeNode = new TreeNode(); + var gui = mocks.StrictMultiMock(); + var menuBuilderMock = mocks.StrictMock(); + + gui.Expect(g => g.Get(treeNode, info)).Return(menuBuilderMock); + + menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, treeNode, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/RingtoetsPipingSurfaceLineTreeNodeInfoTest.cs (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -0,0 +1,110 @@ +using System.Linq; +using System.Windows.Forms; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Plugin; + +namespace Ringtoets.Piping.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class RingtoetsPipingSurfaceLineTreeNodeInfoTest + { + private MockRepository mocks; + private PipingGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new PipingGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(RingtoetsPipingSurfaceLine)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(RingtoetsPipingSurfaceLine), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var ringtoetsPipingSurfaceLine = mocks.StrictMock(); + var testName = "ttt"; + ringtoetsPipingSurfaceLine.Name = testName; + + mocks.ReplayAll(); + + // Call + var text = info.Text(ringtoetsPipingSurfaceLine); + + // Assert + Assert.AreEqual(testName, text); + + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var ringtoetsPipingSurfaceLine = mocks.StrictMock(); + + mocks.ReplayAll(); + + // Call + var image = info.Image(ringtoetsPipingSurfaceLine); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.PipingSurfaceLineIcon, image); + + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var treeNode = new TreeNode(); + var gui = mocks.StrictMultiMock(); + var menuBuilderMock = mocks.StrictMock(); + + gui.Expect(g => g.Get(treeNode, info)).Return(menuBuilderMock); + + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(null, treeNode, info); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs =================================================================== diff -u -r654d3a712eedbdeea718dc0448c5544f09e053cd -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision 654d3a712eedbdeea718dc0448c5544f09e053cd) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSoilProfilesImporterTest.cs (.../PipingSoilProfilesImporterTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -272,7 +272,6 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var importer = new PipingSoilProfilesImporter @@ -301,7 +300,7 @@ Assert.AreEqual(1, observableSoilProfileList.Count); Assert.AreEqual(4, progress); - mocks.VerifyAll(); + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -312,7 +311,6 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var importer = new PipingSoilProfilesImporter @@ -329,7 +327,7 @@ Assert.IsTrue(importResult); Assert.AreEqual(0, observableSoilProfileList.Count); - mocks.VerifyAll(); + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } private void IncrementProgress(string a, int b, int c) Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs =================================================================== diff -u -r654d3a712eedbdeea718dc0448c5544f09e053cd -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs (.../PipingSurfaceLineCsvImporterTest.cs) (revision 654d3a712eedbdeea718dc0448c5544f09e053cd) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs (.../PipingSurfaceLineCsvImporterTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -52,7 +52,6 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var observableSurfaceLinesList = new ObservableList(); @@ -106,7 +105,7 @@ Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); - mocks.VerifyAll(); + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -118,7 +117,6 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var observableSurfaceLinesList = new ObservableList(); @@ -154,7 +152,7 @@ Assert.IsTrue(TestHelper.CanOpenFileForWrite(validFilePath)); - mocks.VerifyAll(); + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -413,7 +411,6 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var importer = new PipingSurfaceLinesCsvImporter(); @@ -445,7 +442,7 @@ Assert.AreEqual(5, progressCallCount, "Expect 1 call for each surfaceline (3 in total) +1 for 0/N progress, and 1 for putting data in model."); - mocks.VerifyAll(); + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } [Test] @@ -457,7 +454,6 @@ var mocks = new MockRepository(); var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var observableSurfaceLinesList = new ObservableList(); @@ -487,7 +483,7 @@ Assert.IsTrue(TestHelper.CanOpenFileForWrite(path)); - mocks.VerifyAll(); + mocks.VerifyAll(); // Ensure there are no calls to UpdateObserver } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingGuiPluginTest.cs =================================================================== diff -u -r98939d3757e99732f74f6345b5eb58c90e30a4d4 -rb6d165f6edddc4271e94c5f6d70c12d4ba0c60eb --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingGuiPluginTest.cs (.../PipingGuiPluginTest.cs) (revision 98939d3757e99732f74f6345b5eb58c90e30a4d4) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/PipingGuiPluginTest.cs (.../PipingGuiPluginTest.cs) (revision b6d165f6edddc4271e94c5f6d70c12d4ba0c60eb) @@ -1,12 +1,12 @@ using System; +using System.Collections.Generic; using System.Linq; using Core.Common.Base.Plugin; using Core.Common.Controls.TreeView; using Core.Common.Gui; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Piping.Data; -using Ringtoets.Piping.Forms.NodePresenters; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.PropertyClasses; using GuiPluginResources = Ringtoets.Piping.Plugin.Properties.Resources; @@ -80,7 +80,7 @@ } [Test] - public void GetProjectTreeViewNodePresenters_ReturnsSupportedNodePresenters() + public void GetTreeNodeInfos_ReturnsSupportedTreeNodeInfos() { // setup var mocks = new MockRepository(); @@ -99,21 +99,21 @@ }) { // call - ITreeNodePresenter[] nodePresenters = guiPlugin.GetProjectTreeViewNodePresenters().ToArray(); + TreeNodeInfo[] treeNodeInfos = guiPlugin.GetTreeNodeInfos().ToArray(); // assert - Assert.AreEqual(11, nodePresenters.Length); - Assert.IsTrue(nodePresenters.Any(np => np is PipingSurfaceLineCollectionNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PipingSurfaceLineNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PipingSoilProfileCollectionNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PipingSoilProfileNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PipingCalculationContextNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PipingCalculationGroupContextNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PipingInputContextNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PipingFailureMechanismNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is PipingOutputNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is EmptyPipingOutputNodePresenter)); - Assert.IsTrue(nodePresenters.Any(np => np is EmptyPipingCalculationReportNodePresenter)); + Assert.AreEqual(11, treeNodeInfos.Length); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(IEnumerable))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(RingtoetsPipingSurfaceLine))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(IEnumerable))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(PipingSoilProfile))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(PipingCalculationContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(PipingCalculationGroupContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(PipingInputContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(PipingFailureMechanism))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(PipingOutput))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(EmptyPipingOutput))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(EmptyPipingCalculationReport))); } mocks.VerifyAll(); }