Browse Source

Add tests for Outline and fix CanInsert/Insert bugs due to drag'n'drop.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6407 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Kumar Devvrat 15 years ago
parent
commit
86d1e42f90
  1. 29
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs
  2. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs
  3. 56
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/OutlineView/HierarchyTests.cs
  4. 265
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/OutlineView/InsertTests.cs
  5. 53
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/OutlineView/SelectionTests.cs
  6. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

29
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs

@ -20,6 +20,13 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView @@ -20,6 +20,13 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
{
public class OutlineNode : INotifyPropertyChanged
{
//Used to check if element can enter other containers
public static PlacementType DummyPlacementType;
static OutlineNode()
{
DummyPlacementType = PlacementType.Register("DummyPlacement");
}
public static OutlineNode Create(DesignItem designItem)
{
OutlineNode node;
@ -137,25 +144,13 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView @@ -137,25 +144,13 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
}
}
// TODO: Outline and IPlacementBehavior must use the same logic (put it inside DesignItem)
public bool CanInsert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy)
{
if (DesignItem.ContentPropertyName == null) return false;
if (DesignItem.ContentProperty.IsCollection) {
foreach (var node in nodes) {
if (!CollectionSupport.CanCollectionAdd(DesignItem.ContentProperty.ReturnType,
node.DesignItem.ComponentType)) {
return false;
}
}
return true;
}
else {
return after == null && nodes.Count() == 1 &&
DesignItem.ContentProperty.DeclaringType.IsAssignableFrom(
nodes.First().DesignItem.ComponentType);
}
var operation = PlacementOperation.Start(nodes.Select(node => node.DesignItem).ToArray(), DummyPlacementType);
var placementBehavior = DesignItem.GetBehavior<IPlacementBehavior>();
if(operation!=null)
return placementBehavior.CanEnterContainer(operation);
return false;
}
public void Insert(IEnumerable<OutlineNode> nodes, OutlineNode after, bool copy)

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs

@ -16,14 +16,26 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView @@ -16,14 +16,26 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
{
protected override bool CanInsert(DragTreeViewItem target, DragTreeViewItem[] items, DragTreeViewItem after, bool copy)
{
return (target.DataContext as OutlineNode).CanInsert(items.Select(t => t.DataContext as OutlineNode),
after == null ? null : after.DataContext as OutlineNode, copy);
UpdateCustomNodes(items);
return (target.DataContext as OutlineNode).CanInsert(_customOutlineNodes,
after == null ? null : after.DataContext as OutlineNode, copy);
}
protected override void Insert(DragTreeViewItem target, DragTreeViewItem[] items, DragTreeViewItem after, bool copy)
{
(target.DataContext as OutlineNode).Insert(items.Select(t => t.DataContext as OutlineNode),
after == null ? null : after.DataContext as OutlineNode, copy);
UpdateCustomNodes(items);
(target.DataContext as OutlineNode).Insert(_customOutlineNodes,
after == null ? null : after.DataContext as OutlineNode, copy);
}
// Need to do this through a seperate List since previously LINQ queries apparently disconnected DataContext;bug in .NET 4.0
private List<OutlineNode> _customOutlineNodes;
void UpdateCustomNodes(IEnumerable<DragTreeViewItem> items)
{
_customOutlineNodes = new List<OutlineNode>();
foreach (var item in items)
_customOutlineNodes.Add(item.DataContext as OutlineNode);
}
}
}

56
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/OutlineView/HierarchyTests.cs

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Kumar Devvrat"/>
// <version>$Revision: $</version>
// </file>
using System;
using ICSharpCode.WpfDesign.Designer.OutlineView;
using NUnit.Framework;
namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView
{
[TestFixture]
public class HierarchyTests : ModelTestHelper
{
private DesignItem _grid;
private OutlineNode _outline;
[TestFixtureSetUp]
public void Intialize()
{
_grid = CreateGridContextWithDesignSurface("<Button/><StackPanel><Button/></StackPanel>");
_outline = OutlineNode.Create(_grid);
Assert.IsNotNull(_outline);
}
[Test]
public void VerifyGridChildren()
{
Assert.AreEqual(2, _outline.Children.Count);
}
[Test]
public void VerifyStackPanelChildren()
{
Assert.AreEqual(1, _outline.Children[1].Children.Count);
}
[Test]
public void VerifyButtonInOutline()
{
var button = _grid.ContentProperty.CollectionElements[0];
Assert.AreEqual(button, _outline.Children[0].DesignItem);
}
[Test]
public void VerifyStackPanelInOutline()
{
var stackPanel = _grid.ContentProperty.CollectionElements[1];
var stackPanelButton = stackPanel.ContentProperty.CollectionElements[0];
Assert.AreEqual(stackPanel, _outline.Children[1].DesignItem);
Assert.AreEqual(stackPanelButton, _outline.Children[1].Children[0].DesignItem);
}
}
}

265
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/OutlineView/InsertTests.cs

@ -0,0 +1,265 @@ @@ -0,0 +1,265 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Kumar Devvrat"/>
// <version>$Revision: $</version>
// </file>
using System;
using NUnit.Framework;
using ICSharpCode.WpfDesign.Designer.OutlineView;
namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView
{
[TestFixture]
public class CollectionElementsInsertTests : ModelTestHelper
{
private DesignItem _grid;
private OutlineNode _outline;
private DesignItem _gridButton;
private DesignItem _stackPanel;
private DesignItem _stackPanelButton;
private OutlineNode _gridButtonNode;
private OutlineNode _stackPanelNode;
private OutlineNode _stackPanelButtonNode;
[SetUp]
public void Intialize()
{
_grid = CreateGridContextWithDesignSurface("<Button/><StackPanel><Button/></StackPanel>");
_outline = OutlineNode.Create(_grid);
Assert.IsNotNull(_outline);
_gridButton = _grid.ContentProperty.CollectionElements[0];
_stackPanel = _grid.ContentProperty.CollectionElements[1];
_stackPanelButton = _stackPanel.ContentProperty.CollectionElements[0];
_gridButtonNode = _outline.Children[0];
_stackPanelNode = _outline.Children[1];
_stackPanelButtonNode = _stackPanelNode.Children[0];
}
[Test]
public void CanInsertIntoGrid()
{
// Check if StackPanel's button can be inserted after Grid's first button.
Assert.IsTrue(_outline.CanInsert(new[] { _stackPanelButtonNode }, _gridButtonNode, false));
}
[Test]
public void CanInsertIntoStackPanel()
{
// Move parent into one of it's children, Grid into StackPanel.
Assert.IsTrue(_stackPanelNode.CanInsert(new[] { _outline }, _outline, false));
}
#region Insert by cut operation
public void InsertIntoGridByCut()
{
// Insert StackPanel's button after Grid's first button.
_outline.Insert(new[] { _outline.Children[1].Children[0] }, _outline.Children[0], false);
}
[Test]
public void CheckGridChildrenCountWhenCut()
{
InsertIntoGridByCut();
Assert.AreEqual(3, _outline.Children.Count);
Assert.AreEqual(3, _grid.ContentProperty.CollectionElements.Count);
}
[Test]
public void CheckStackPanelChildrenCountWhenCut()
{
InsertIntoGridByCut();
Assert.AreEqual(0, _outline.Children[2].Children.Count);
Assert.AreEqual(0, _stackPanel.ContentProperty.CollectionElements.Count);
}
[Test]
public void CheckElementsInOutlineWhenCut()
{
InsertIntoGridByCut();
Assert.AreEqual(_gridButtonNode, _outline.Children[0]);
Assert.AreEqual(_stackPanelButtonNode, _outline.Children[1]);
Assert.AreEqual(_stackPanelNode, _outline.Children[2]);
}
[Test]
public void CheckElementsInDesignerWhenCut()
{
InsertIntoGridByCut();
Assert.AreEqual(_gridButton, _grid.ContentProperty.CollectionElements[0]);
Assert.AreEqual(_stackPanelButton, _grid.ContentProperty.CollectionElements[1]);
Assert.AreEqual(_stackPanel, _grid.ContentProperty.CollectionElements[2]);
}
#endregion
#region Insert by copy operation
/* Cloning DesignItem is not yet supported */
public void InsertIntoGridByCopy()
{
// Insert StackPanel's button after Grid's first button.
_outline.Insert(new[] { _outline.Children[1].Children[0] }, _outline.Children[0], true);
}
[Test]
[Ignore]
public void CheckGridChildrenCountWhenCopy()
{
InsertIntoGridByCopy();
Assert.AreEqual(3, _outline.Children.Count);
Assert.AreEqual(3, _grid.ContentProperty.CollectionElements.Count);
}
[Test]
[Ignore]
public void CheckStackPanelChildrenCountWhenCopy()
{
InsertIntoGridByCopy();
Assert.AreEqual(1, _outline.Children[2].Children.Count);
Assert.AreEqual(1, _stackPanel.ContentProperty.CollectionElements.Count);
}
[Test]
[Ignore]
public void CheckElementsInOutlineWhenCopy()
{
InsertIntoGridByCopy();
Assert.AreEqual(_gridButtonNode, _outline.Children[0]);
Assert.AreEqual(_stackPanelButtonNode, _outline.Children[1]);
Assert.AreEqual(_stackPanelNode, _outline.Children[2]);
Assert.AreEqual(_stackPanelButtonNode, _stackPanelButtonNode.Children[0]);
}
[Test]
[Ignore]
public void CheckElementsInDesignerWhenCopy()
{
InsertIntoGridByCopy();
Assert.AreEqual(_gridButton, _grid.ContentProperty.CollectionElements[0]);
Assert.AreEqual(_stackPanelButton, _grid.ContentProperty.CollectionElements[1]);
Assert.AreEqual(_stackPanel, _grid.ContentProperty.CollectionElements[2]);
Assert.AreEqual(_stackPanelButton, _stackPanel.ContentProperty.CollectionElements[0]);
}
#endregion
}
public class ContentControlInsertTests : ModelTestHelper
{
private DesignItem _grid;
private OutlineNode _outline;
private DesignItem _gridButton;
private DesignItem _stackPanel;
private DesignItem _stackPanelImage;
private OutlineNode _gridButtonNode;
private OutlineNode _stackPanelNode;
private OutlineNode _stackPanelImageNode;
[SetUp]
public void Intialize()
{
_grid = CreateGridContextWithDesignSurface("<Button/><StackPanel><Image/></StackPanel>");
_outline = OutlineNode.Create(_grid);
Assert.IsNotNull(_outline);
_gridButton = _grid.ContentProperty.CollectionElements[0];
_stackPanel = _grid.ContentProperty.CollectionElements[1];
_stackPanelImage = _stackPanel.ContentProperty.CollectionElements[0];
_gridButtonNode = _outline.Children[0];
_stackPanelNode = _outline.Children[1];
_stackPanelImageNode = _stackPanelNode.Children[0];
}
[Test]
public void CanInsertIntoButton()
{
/* Insert Image into the Grid's button. This has to be false since some of the
* ContentControl are not allowed to add element's by moving elements
* See DefaultPlacementBehavior.CanContentControlAdd() */
Assert.IsFalse(_gridButtonNode.CanInsert(new[] {_stackPanelImageNode}, null, false));
}
#region Insert element by Cut operation.
public void InsertIntoButtonByCut()
{
_gridButtonNode.Insert(new[] {_stackPanelImageNode}, null, false);
}
[Test]
public void CheckStackPanelChildrenCountWhenCut()
{
InsertIntoButtonByCut();
Assert.AreEqual(0, _stackPanelNode.Children.Count);
Assert.AreEqual(0, _stackPanel.ContentProperty.CollectionElements.Count);
}
[Test]
public void CheckElementInOutlineWhenCut()
{
InsertIntoButtonByCut();
Assert.AreEqual(_gridButtonNode, _outline.Children[0]);
Assert.AreEqual(_stackPanelImageNode, _outline.Children[0].Children[0]);
Assert.AreEqual(_stackPanelNode, _outline.Children[1]);
}
[Test]
public void CheckElementInDesignerWhenCut()
{
InsertIntoButtonByCut();
Assert.AreEqual(_gridButton, _grid.ContentProperty.CollectionElements[0]);
Assert.AreEqual(_stackPanelImage, _grid.ContentProperty.CollectionElements[0].ContentProperty.Value);
Assert.AreEqual(_stackPanel, _grid.ContentProperty.CollectionElements[1]);
}
#endregion
#region Insert element by Copy operation
/* Cloning DesignItem is not yet supported */
public void InsertIntoButtonByCopy()
{
_gridButtonNode.Insert(new[] { _stackPanelImageNode }, null, true);
}
[Test]
[Ignore]
public void CheckStackPanelChildrenCountWhenCopy()
{
InsertIntoButtonByCopy();
Assert.AreEqual(1, _stackPanelNode.Children.Count);
Assert.AreEqual(1, _stackPanel.ContentProperty.CollectionElements.Count);
}
[Test]
[Ignore]
public void CheckElementInOutlineWhenCopy()
{
InsertIntoButtonByCopy();
Assert.AreEqual(_gridButtonNode, _outline.Children[0]);
Assert.AreEqual(_stackPanelImageNode, _outline.Children[0].Children[0]);
Assert.AreEqual(_stackPanelNode, _outline.Children[1]);
Assert.AreEqual(_stackPanelImageNode, _outline.Children[1].Children[0]);
}
[Test]
[Ignore]
public void CheckElementInDesignerWhenCopy()
{
InsertIntoButtonByCopy();
Assert.AreEqual(_gridButton, _grid.ContentProperty.CollectionElements[0]);
Assert.AreEqual(_stackPanelImage, _grid.ContentProperty.CollectionElements[0].ContentProperty.ValueOnInstance);
Assert.AreEqual(_stackPanel, _grid.ContentProperty.CollectionElements[1]);
Assert.AreEqual(_stackPanel, _grid.ContentProperty.CollectionElements[1].ContentProperty.CollectionElements[0]);
}
#endregion
}
}

53
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/OutlineView/SelectionTests.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Kumar Devvrat"/>
// <version>$Revision: $</version>
// </file>
using System;
using ICSharpCode.WpfDesign.Designer.OutlineView;
using NUnit.Framework;
namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView
{
[TestFixture]
public class SelectionTests : ModelTestHelper
{
private DesignItem _grid;
private OutlineNode _outline;
[SetUp]
public void Intialize()
{
_grid = CreateGridContextWithDesignSurface("<Button/><StackPanel><Button/></StackPanel>");
_outline = OutlineNode.Create(_grid);
Assert.IsNotNull(_outline);
var selection = _grid.Services.Selection;
var stackPanel = _grid.ContentProperty.CollectionElements[1];
var stackPanelButton = stackPanel.ContentProperty.CollectionElements[0];
selection.SetSelectedComponents(new[] {stackPanel, stackPanelButton});
}
[Test]
public void CheckIfInOutlineSelected()
{
Assert.IsFalse(_outline.IsSelected);
Assert.IsFalse(_outline.Children[0].IsSelected);
Assert.IsTrue(_outline.Children[1].IsSelected);
Assert.IsTrue(_outline.Children[1].Children[0].IsSelected);
}
[Test]
public void SelectNodeInOutlineAndCheckInDesignItem()
{
var selection = _grid.Services.Selection;
selection.SetSelectedComponents(null);
_outline.IsSelected = true;
_outline.Children[0].IsSelected = true;
Assert.AreEqual(_grid, selection.PrimarySelection);
Assert.IsTrue(selection.SelectedItems.Contains(_grid.ContentProperty.CollectionElements[0]));
}
}
}

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

@ -61,6 +61,9 @@ @@ -61,6 +61,9 @@
<Compile Include="Designer\MockFocusNavigator.cs" />
<Compile Include="Designer\ModelTestHelper.cs" />
<Compile Include="Designer\ModelTests.cs" />
<Compile Include="Designer\OutlineView\HierarchyTests.cs" />
<Compile Include="Designer\OutlineView\InsertTests.cs" />
<Compile Include="Designer\OutlineView\SelectionTests.cs" />
<Compile Include="Designer\PlacementTests.cs" />
<Compile Include="XamlDom\ExampleClass.cs" />
<Compile Include="XamlDom\ExampleClassContainer.cs" />
@ -92,4 +95,7 @@ @@ -92,4 +95,7 @@
<Name>WpfDesign.Designer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Designer\OutlineView" />
</ItemGroup>
</Project>
Loading…
Cancel
Save