Index: Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.cs =================================================================== diff -u -r2a81f01756e227d5ce93717b21b87e8a5cd5fcbb -r6045128a21a5e8b1c6e1e48471749eb3da39b89d --- Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.cs (.../ChartLegendView.cs) (revision 2a81f01756e227d5ce93717b21b87e8a5cd5fcbb) +++ Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.cs (.../ChartLegendView.cs) (revision 6045128a21a5e8b1c6e1e48471749eb3da39b89d) @@ -132,7 +132,7 @@ Text = collection => collection.Name, Image = collection => GuiResources.folder, ChildNodeObjects = GetCollectionChildNodeObjects, - CanDrag = (multipleAreaData, parentData) => true, + CanDrag = (collection, parentData) => true, CanDrop = ChartDataCollectionCanDropAndInsert, CanInsert = ChartDataCollectionCanDropAndInsert, OnDrop = ChartDataCollectionOnDrop, Index: Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs =================================================================== diff -u -r3098804e6dc9d7aae2733700bfb5772eab1956d7 -r6045128a21a5e8b1c6e1e48471749eb3da39b89d --- Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 3098804e6dc9d7aae2733700bfb5772eab1956d7) +++ Core/Plugins/src/Core.Plugins.Map/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 6045128a21a5e8b1c6e1e48471749eb3da39b89d) @@ -147,6 +147,7 @@ Text = mapDataCollection => mapDataCollection.Name, Image = mapDataCollection => GuiResources.folder, ChildNodeObjects = GetCollectionChildNodeObjects, + CanDrag = (collection, parentData) => true, CanDrop = MapDataCollectionCanDropAndInsert, CanInsert = MapDataCollectionCanDropAndInsert, OnDrop = MapDataCollectionOnDrop, Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -r2a81f01756e227d5ce93717b21b87e8a5cd5fcbb -r6045128a21a5e8b1c6e1e48471749eb3da39b89d --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (.../ChartDataCollectionTreeNodeInfoTest.cs) (revision 2a81f01756e227d5ce93717b21b87e8a5cd5fcbb) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (.../ChartDataCollectionTreeNodeInfoTest.cs) (revision 6045128a21a5e8b1c6e1e48471749eb3da39b89d) @@ -143,9 +143,9 @@ // Assert var expectedChildren = new[] { - new ChartDataContext(chartData3, new ChartDataCollection("test")), - new ChartDataContext(chartData2, new ChartDataCollection("test")), - new ChartDataContext(chartData1, new ChartDataCollection("test")) + new ChartDataContext(chartData3, chartDataCollection), + new ChartDataContext(chartData2, chartDataCollection), + new ChartDataContext(chartData1, chartDataCollection) }; CollectionAssert.AreEqual(expectedChildren, objects); } Index: Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj =================================================================== diff -u -red92d5353ea8138720874c61c353fd70fd12d3d0 -r6045128a21a5e8b1c6e1e48471749eb3da39b89d --- Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj (.../Core.Plugins.Map.Test.csproj) (revision ed92d5353ea8138720874c61c353fd70fd12d3d0) +++ Core/Plugins/test/Core.Plugins.Map.Test/Core.Plugins.Map.Test.csproj (.../Core.Plugins.Map.Test.csproj) (revision 6045128a21a5e8b1c6e1e48471749eb3da39b89d) @@ -49,13 +49,11 @@ + - - - Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -r2a81f01756e227d5ce93717b21b87e8a5cd5fcbb -r6045128a21a5e8b1c6e1e48471749eb3da39b89d --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision 2a81f01756e227d5ce93717b21b87e8a5cd5fcbb) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataCollectionTreeNodeInfoTest.cs (.../MapDataCollectionTreeNodeInfoTest.cs) (revision 6045128a21a5e8b1c6e1e48471749eb3da39b89d) @@ -35,7 +35,9 @@ using Core.Components.Gis.Features; using Core.Components.Gis.Forms; using Core.Components.Gis.Geometries; +using Core.Components.Gis.TestUtil; using Core.Plugins.Map.Legend; +using Core.Plugins.Map.PresentationObjects; using Core.Plugins.Map.Properties; using NUnit.Extensions.Forms; using NUnit.Framework; @@ -60,6 +62,7 @@ { mocks = new MockRepository(); contextMenuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); mapLegendView = new MapLegendView(contextMenuBuilderProvider); @@ -79,9 +82,6 @@ [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Setup - mocks.ReplayAll(); - // Assert Assert.IsNotNull(info.Text); Assert.IsNull(info.ForeColor); @@ -97,7 +97,7 @@ Assert.IsNull(info.CanCheck); Assert.IsNull(info.IsChecked); Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); + Assert.IsNotNull(info.CanDrag); Assert.IsNotNull(info.CanDrop); Assert.IsNotNull(info.CanInsert); Assert.IsNotNull(info.OnDrop); @@ -107,7 +107,6 @@ public void Text_Always_ReturnsNameFromMapData() { // Setup - mocks.ReplayAll(); var mapDataCollection = new MapDataCollection("Collectie"); // Call @@ -120,9 +119,6 @@ [Test] public void Image_Always_ReturnsImageFromResource() { - // Setup - mocks.ReplayAll(); - // Call Image image = info.Image(null); @@ -131,12 +127,12 @@ } [Test] - public void ChildNodeObjects_Always_ReturnsChildrenOfDataReversed() + public void ChildNodeObjects_Always_ReturnsChildrenWithContextAndDataReversed() { // Setup - var mapData1 = mocks.StrictMock("test data"); - var mapData2 = mocks.StrictMock("test data"); - var mapData3 = mocks.StrictMock("test data"); + var mapData1 = new TestMapData(); + var mapData2 = new TestMapData(); + var mapData3 = new TestMapData(); var mapDataCollection = new MapDataCollection("test data"); mapDataCollection.Add(mapData1); @@ -151,69 +147,83 @@ // Assert CollectionAssert.AreEqual(new[] { - mapData3, - mapData2, - mapData1 + new MapDataContext(mapData3, mapDataCollection), + new MapDataContext(mapData2, mapDataCollection), + new MapDataContext(mapData1, mapDataCollection) }, objects); } [Test] - public void CanDrop_SourceNodeTagIsNoMapData_ReturnsFalse() + public void CanDrop_TargetParentIsSameAsSourceParent_ReturnsTrue() { // Setup - mocks.ReplayAll(); - var mapDataCollection = new MapDataCollection("test data"); + MapData mapData = new TestMapData(); + var mapDataCollection = new MapDataCollection("test"); + MapDataContext context = GetContext(mapData, mapDataCollection); + // Call - bool canDrop = info.CanDrop(new object(), mapDataCollection); + bool canDrop = info.CanDrop(context, mapDataCollection); // Assert - Assert.IsFalse(canDrop); + Assert.IsTrue(canDrop); } [Test] - public void CanDrop_SourceNodeTagIsMapData_ReturnsTrue() + public void CanDrop_TargetParentNotSameAsSourceParent_ReturnsFalse() { // Setup - var mapData = mocks.StrictMock("test data"); - var mapDataCollection = new MapDataCollection("test data"); + MapData mapData = new TestMapData(); + var mapDataCollection = new MapDataCollection("test"); - mocks.ReplayAll(); + MapDataContext context = GetContext(mapData, mapDataCollection); // Call - bool canDrop = info.CanDrop(mapData, mapDataCollection); + bool canDrop = info.CanDrop(context, GetContext(new MapDataCollection("test"))); // Assert - Assert.IsTrue(canDrop); + Assert.IsFalse(canDrop); } [Test] - public void CanInsert_SourceNodeTagIsNoMapData_ReturnsFalse() + public void CanInsert_TargetParentIsSameAsSourceParent_ReturnsTrue() { // Setup - mocks.ReplayAll(); - var mapDataCollection = new MapDataCollection("test data"); + MapData mapData = new TestMapData(); + var mapDataCollection = new MapDataCollection("test"); + MapDataContext context = GetContext(mapData, mapDataCollection); + // Call - bool canInsert = info.CanInsert(new object(), mapDataCollection); + bool canInsert = info.CanInsert(context, mapDataCollection); // Assert - Assert.IsFalse(canInsert); + Assert.IsTrue(canInsert); } [Test] - public void CanInsert_SourceNodeTagIsMapData_ReturnsTrue() + public void CanInsert_TargetParentNotSameAsSourceParent_ReturnsFalse() { // Setup - var mapData = mocks.StrictMock("test data"); - var mapDataCollection = new MapDataCollection("test data"); + MapData mapData = new TestMapData(); + var mapDataCollection = new MapDataCollection("test"); - mocks.ReplayAll(); + MapDataContext context = GetContext(mapData, mapDataCollection); // Call - bool canInsert = info.CanInsert(mapData, mapDataCollection); + bool canInsert = info.CanInsert(context, GetContext(new MapDataCollection("test"))); // Assert + Assert.IsFalse(canInsert); + } + + [Test] + public void CanDrag_Always_ReturnsTrue() + { + // Call + bool canInsert = info.CanDrag(null, null); + + // Assert Assert.IsTrue(canInsert); } @@ -224,61 +234,72 @@ public void OnDrop_MapDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) { // Setup - var mapData1 = mocks.StrictMock("test data"); - var mapData2 = mocks.StrictMock("test data"); - var mapData3 = mocks.StrictMock("test data"); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var mapData1 = new TestMapData(); + var mapData2 = new TestMapData(); + var mapData3 = new TestMapData(); var mapDataCollection = new MapDataCollection("test data"); mapDataCollection.Add(mapData1); mapDataCollection.Add(mapData2); mapDataCollection.Add(mapData3); - var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); + MapDataContext context1 = GetContext(mapData1); - mocks.ReplayAll(); + mapDataCollection.Attach(observer); using (var treeViewControl = new TreeViewControl()) { - mapDataCollection.Attach(observer); - // Call - info.OnDrop(mapData1, mapDataCollection, mapDataCollection, position, treeViewControl); + info.OnDrop(context1, mapDataCollection, mapDataCollection, position, treeViewControl); // Assert int reversedIndex = 2 - position; - Assert.AreSame(mapData1, mapDataCollection.Collection.ElementAt(reversedIndex)); + Assert.AreSame(context1.WrappedData, mapDataCollection.Collection.ElementAt(reversedIndex)); + + mocks.VerifyAll(); } } [Test] [TestCase(-50)] [TestCase(-1)] - [TestCase(3)] + [TestCase(4)] [TestCase(50)] - public void OnDrop_MapDataMovedToPositionOutsideRange_SetsNewReverseOrder(int position) + public void OnDrop_MapDataMovedToPositionOutsideRange_ThrowsException(int position) { // Setup var observer = mocks.StrictMock(); - var mapData1 = mocks.StrictMock("test data"); - var mapData2 = mocks.StrictMock("test data"); - var mapData3 = mocks.StrictMock("test data"); + mocks.ReplayAll(); + + var mapData1 = new MapLineData("line"); + var mapData2 = new MapPolygonData("polygon"); + var mapData3 = new MapPointData("point"); var mapDataCollection = new MapDataCollection("test data"); mapDataCollection.Add(mapData1); mapDataCollection.Add(mapData2); mapDataCollection.Add(mapData3); mapDataCollection.Attach(observer); - mocks.ReplayAll(); + mapLegendView.Data = mapDataCollection; + MapDataContext context1 = GetContext(mapData1); + + mapDataCollection.Attach(observer); + using (var treeViewControl = new TreeViewControl()) { // Call - TestDelegate test = () => info.OnDrop(mapData1, mapDataCollection, mapDataCollection, position, treeViewControl); + TestDelegate test = () => info.OnDrop(context1, mapDataCollection, mapDataCollection, position, treeViewControl); // Assert Assert.Throws(test); + + mocks.VerifyAll(); // Expect no update observer. } } @@ -519,7 +540,7 @@ } [Test] - public void ContextMenuStrip_NoChartControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() + public void ContextMenuStrip_NoMapControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() { // Setup var builder = new CustomItemsOnlyContextMenuBuilder(); @@ -540,5 +561,10 @@ Assert.DoesNotThrow(call); } } + + private static MapDataContext GetContext(MapData mapData, MapDataCollection mapDataCollection = null) + { + return new MapDataContext(mapData, mapDataCollection ?? new MapDataCollection("test")); + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataContextTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataContextTreeNodeInfoTest.cs (revision 0) +++ Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapDataContextTreeNodeInfoTest.cs (revision 6045128a21a5e8b1c6e1e48471749eb3da39b89d) @@ -0,0 +1,772 @@ +// Copyright (C) Stichting Deltares 2018. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +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; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using Core.Common.Util.Reflection; +using Core.Components.Gis.Data; +using Core.Components.Gis.Data.Removable; +using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; +using Core.Components.Gis.Geometries; +using Core.Components.Gis.TestUtil; +using Core.Plugins.Map.Legend; +using Core.Plugins.Map.PresentationObjects; +using Core.Plugins.Map.Properties; +using NUnit.Framework; +using Rhino.Mocks; +using GuiResources = Core.Common.Gui.Properties.Resources; + +namespace Core.Plugins.Map.Test.Legend +{ + [TestFixture] + public class MapDataContextTreeNodeInfoTest + { + private const int contextMenuZoomToAllIndex = 0; + + private MapLegendView mapLegendView; + private TreeNodeInfo info; + private MockRepository mocks; + private IContextMenuBuilderProvider contextMenuBuilderProvider; + + private static IEnumerable MapDataLegendImages + { + get + { + yield return new TestCaseData(new MapPointData("test"), Resources.PointsIcon); + yield return new TestCaseData(new MapLineData("test"), Resources.LineIcon); + yield return new TestCaseData(new MapPolygonData("test"), Resources.AreaIcon); + yield return new TestCaseData(new MapDataCollection("test"), GuiResources.folder); + } + } + + private static IEnumerable DragMapData + { + get + { + return new MapData[] + { + new MapPointData("test"), + new MapLineData("test"), + new MapPolygonData("test"), + new MapDataCollection("test") + }; + } + } + + private static IEnumerable NoMapDataCollection + { + get + { + return new MapData[] + { + new MapPointData("test"), + new MapLineData("test"), + new MapPolygonData("test") + }; + } + } + + private static IEnumerable IsCheckedMapData + { + get + { + yield return new TestCaseData(new MapPointData("test"), false); + yield return new TestCaseData(new MapPointData("test"), true); + yield return new TestCaseData(new MapLineData("test"), false); + yield return new TestCaseData(new MapLineData("test"), true); + yield return new TestCaseData(new MapPolygonData("test"), false); + yield return new TestCaseData(new MapPolygonData("test"), true); + } + } + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + contextMenuBuilderProvider = mocks.StrictMock(); + mocks.ReplayAll(); + + mapLegendView = new MapLegendView(contextMenuBuilderProvider); + + var treeViewControl = TypeUtils.GetField(mapLegendView, "treeViewControl"); + var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + + info = treeNodeInfoLookup[typeof(MapDataContext)]; + } + + [TearDown] + public void TearDown() + { + mapLegendView.Dispose(); + mocks.VerifyAll(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.IsNotNull(info.Text); + Assert.IsNull(info.ForeColor); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ExpandOnCreate); + Assert.IsNotNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNotNull(info.CanRemove); + Assert.IsNotNull(info.OnNodeRemoved); + Assert.IsNotNull(info.CanCheck); + Assert.IsNotNull(info.IsChecked); + Assert.IsNotNull(info.OnNodeChecked); + Assert.IsNotNull(info.CanDrag); + Assert.IsNotNull(info.CanDrop); + Assert.IsNotNull(info.CanInsert); + Assert.IsNotNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsNameFromWrappedMapData() + { + // Setup + MapDataContext context = GetContext(new TestMapData()); + + // Call + string text = info.Text(context); + + // Assert + Assert.AreEqual(context.WrappedData.Name, text); + } + + [Test] + [TestCaseSource(nameof(MapDataLegendImages))] + public void Image_WrappedDataMapPointData_ReturnPointsIcon(MapData mapData, Image expectedImage) + { + // Setup + MapDataContext context = GetContext(mapData); + + // Call + Image image = info.Image(context); + + // Assert + TestHelper.AssertImagesAreEqual(expectedImage, image); + } + + [Test] + public void ChildNodeObjects_MapDataCollection_ReturnsItemsFromMapDataCollectionList() + { + // Setup + var mapData1 = new TestMapData(); + var mapData2 = new TestMapData(); + var mapData3 = new TestMapData(); + var mapDataCollection = new MapDataCollection("test"); + + mapDataCollection.Add(mapData1); + mapDataCollection.Add(mapData2); + mapDataCollection.Add(mapData3); + + MapDataContext context = GetContext(mapDataCollection); + + // Call + object[] objects = info.ChildNodeObjects(context); + + // Assert + var expectedChildren = new[] + { + new MapDataContext(mapData3, new MapDataCollection("test")), + new MapDataContext(mapData2, new MapDataCollection("test")), + new MapDataContext(mapData1, new MapDataCollection("test")) + }; + CollectionAssert.AreEqual(expectedChildren, objects); + } + + [Test] + [TestCaseSource(nameof(NoMapDataCollection))] + public void ChildNodeObjects_OtherThanMapDataCollection_ReturnsEmptyArray(MapData mapData) + { + // Setup + MapDataContext context = GetContext(mapData); + + // Call + object[] objects = info.ChildNodeObjects(context); + + // Assert + CollectionAssert.IsEmpty(objects); + } + + [Test] + [TestCaseSource(nameof(DragMapData))] + public void CanDrag_Always_ReturnsTrue(MapData mapData) + { + // Setup + MapDataContext context = GetContext(mapData); + + // Call + bool canDrag = info.CanDrag(context, null); + + // Assert + Assert.IsTrue(canDrag); + } + + [Test] + public void CanCheck_WrappedDataMapDataCollection_ReturnsFalse() + { + // Setup + MapDataContext context = GetContext(new MapDataCollection("test")); + + // Call + bool canCheck = info.CanCheck(context); + + // Assert + Assert.IsFalse(canCheck); + } + + [Test] + [TestCaseSource(nameof(NoMapDataCollection))] + public void CanCheck_WrappedDataOtherThanMapDataCollection_ReturnsTrue(MapData mapData) + { + // Setup + MapDataContext context = GetContext(mapData); + + // Call + bool canCheck = info.CanCheck(context); + + // Assert + Assert.IsTrue(canCheck); + } + + [Test] + [TestCaseSource(nameof(IsCheckedMapData))] + public void IsChecked_Always_ReturnsAccordingToVisibleStateOfMapData(MapData mapData, bool isVisible) + { + // Setup + MapDataContext context = GetContext(mapData); + context.WrappedData.IsVisible = isVisible; + + // Call + bool isChecked = info.IsChecked(context); + + // Assert + Assert.AreEqual(isVisible, isChecked); + } + + [Test] + [TestCaseSource(nameof(IsCheckedMapData))] + public void OnNodeChecked_Always_SetsPointDataVisibilityAndNotifiesParentObservers(MapData mapData, bool initialVisibleState) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + MapDataContext context = GetContext(mapData); + context.WrappedData.IsVisible = initialVisibleState; + + context.WrappedData.Attach(observer); + + // Call + info.OnNodeChecked(context, null); + + // Assert + Assert.AreEqual(!initialVisibleState, context.WrappedData.IsVisible); + mocks.VerifyAll(); + } + + [Test] + public void CanDrop_TargetIsSameAsSourceParent_ReturnsTrue() + { + // Setup + MapData mapData = new TestMapData(); + var mapDataCollection = new MapDataCollection("test"); + + MapDataContext context = GetContext(mapData, mapDataCollection); + MapDataContext targetContext = GetContext(mapDataCollection); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsTrue(canDrop); + } + + [Test] + public void CanDrop_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + MapData mapData = new TestMapData(); + MapData mapData2 = new TestMapData(); + + MapDataContext context = GetContext(mapData); + MapDataContext targetContext = GetContext(mapData2); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + public void CanDrop_TargetDataIsCollection_ReturnsFalse() + { + // Setup + MapData mapData = new TestMapData(); + var rootCollection = new MapDataCollection("test"); + var targetCollection = new MapDataCollection("test"); + + MapDataContext context = GetContext(mapData, rootCollection); + MapDataContext targetContext = GetContext(targetCollection, rootCollection); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + public void CanInsert_TargetIsSameAsSourceParent_ReturnsTrue() + { + // Setup + MapData mapData = new TestMapData(); + var mapDataCollection = new MapDataCollection("test"); + + MapDataContext context = GetContext(mapData, mapDataCollection); + MapDataContext targetContext = GetContext(mapDataCollection); + + // Call + bool canInsert = info.CanInsert(context, targetContext); + + // Assert + Assert.IsTrue(canInsert); + } + + [Test] + public void CanInsert_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + MapData mapData = new TestMapData(); + MapData mapData2 = new TestMapData(); + + MapDataContext context = GetContext(mapData); + MapDataContext targetContext = GetContext(mapData2); + + // Call + bool canInsert = info.CanInsert(context, targetContext); + + // Assert + Assert.IsFalse(canInsert); + } + + [Test] + public void CanInsert_TargetDataIsCollection_ReturnsFalse() + { + // Setup + MapData mapData = new TestMapData(); + var rootCollection = new MapDataCollection("test"); + var targetCollection = new MapDataCollection("test"); + + MapDataContext context = GetContext(mapData, rootCollection); + MapDataContext targetContext = GetContext(targetCollection, rootCollection); + + // Call + bool canDrop = info.CanInsert(context, targetContext); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void OnDrop_MapDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var mapData1 = new TestMapData(); + var mapData2 = new TestMapData(); + var mapData3 = new TestMapData(); + var mapDataCollection = new MapDataCollection("test"); + + mapDataCollection.Add(mapData1); + mapDataCollection.Add(mapData2); + mapDataCollection.Add(mapData3); + + MapDataContext context1 = GetContext(mapData1); + MapDataContext collectionContext = GetContext(mapDataCollection); + + mapDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + info.OnDrop(context1, collectionContext, collectionContext, position, treeViewControl); + + // Assert + int reversedIndex = 2 - position; + var wrappedCollectionData = (MapDataCollection) collectionContext.WrappedData; + Assert.AreSame(context1.WrappedData, wrappedCollectionData.Collection.ElementAt(reversedIndex)); + + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(-50)] + [TestCase(-1)] + [TestCase(5)] + [TestCase(50)] + public void OnDrop_MapDataMovedToPositionOutsideRange_ThrowsException(int position) + { + // Setup + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var mapData1 = new MapLineData("line"); + var mapData2 = new MapPolygonData("polygon"); + var mapData3 = new MapPointData("point"); + var mapDataCollection = new MapDataCollection("test"); + + mapDataCollection.Add(mapData1); + mapDataCollection.Add(mapData2); + mapDataCollection.Add(mapData3); + + mapDataCollection.Attach(observer); + mapLegendView.Data = mapDataCollection; + + MapDataContext context = GetContext(mapData1); + MapDataContext collectionContext = GetContext(mapDataCollection); + + mapDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + TestDelegate test = () => info.OnDrop(context, collectionContext, collectionContext, position, treeViewControl); + + // Assert + Assert.Throws(test); + + mocks.VerifyAll(); // Expect no update observer. + } + } + + [Test] + public void CanRemove_WithRemovableDataAndCollection_ReturnTrue() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + MapDataContext context = GetContext(removable); + + // Call + bool canRemove = info.CanRemove(context, new MapDataCollection("collection")); + + // Assert + Assert.IsTrue(canRemove); + } + + [Test] + public void CanRemove_WithoutCollection_ReturnFalse() + { + // Setup + var removable = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + mocks.ReplayAll(); + + MapDataContext context = GetContext(removable); + + // Call + bool canRemove = info.CanRemove(context, null); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void CanRemove_WithNotRemovableData_ReturnFalse() + { + // Setup + var notRemovable = mocks.StrictMock("name"); + mocks.ReplayAll(); + + MapDataContext context = GetContext(notRemovable); + + // Call + bool canRemove = info.CanRemove(context, new MapDataCollection("collection")); + + // Assert + Assert.IsFalse(canRemove); + } + + [Test] + public void OnNodeRemoved_WithRemovableDataToRemove_DataRemoved() + { + // Setup + var toRemove = mocks.StrictMultiMock(new[] + { + typeof(IRemovable) + }, "name"); + var otherData = mocks.Stub("name"); + mocks.ReplayAll(); + + var collection = new MapDataCollection("collection"); + collection.Add(toRemove); + collection.Add(otherData); + + MapDataContext context = GetContext(toRemove, collection); + + // Call + info.OnNodeRemoved(context, collection); + + // Assert + CollectionAssert.AreEqual(new[] + { + otherData + }, collection.Collection); + } + + [Test] + [TestCaseSource(nameof(NoMapDataCollection))] + public void ContextMenuStrip_DifferentTypesOfMapData_CallsBuilder(MapData mapData) + { + // Setup + var builder = mocks.StrictMock(); + using (mocks.Ordered()) + { + builder.Expect(mb => mb.AddCustomItem(Arg.Is.NotNull)).Return(builder); + builder.Expect(mb => mb.AddSeparator()).Return(builder); + builder.Expect(mb => mb.AddDeleteItem()).Return(builder); + builder.Expect(mb => mb.AddSeparator()).Return(builder); + builder.Expect(mb => mb.AddPropertiesItem()).Return(builder); + builder.Expect(mb => mb.Build()).Return(null); + } + + contextMenuBuilderProvider.Expect(p => p.Get(mapData, null)).Return(builder); + + mocks.ReplayAll(); + + // Call + info.ContextMenuStrip(GetContext(mapData), null, null); + + // Assert + // Assert expectancies are called in TearDown() + } + + [Test] + public void ContextMenuStrip_VisibleMapData_ZoomToAllItemEnabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new TestFeatureBasedMapData("A") + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de kaart dusdanig dat deze kaartlaag precies in het beeld past.", + Resources.ZoomToAllIcon); + } + } + + [Test] + public void ContextMenuStrip_InvisibleMapData_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new TestFeatureBasedMapData("A") + { + IsVisible = false + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de kaartlaag zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_MapDataWithoutFeatures_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new TestFeatureBasedMapData("A") + { + IsVisible = true + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de kaartlaag elementen bevatten.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_EnabledZoomToAllContextMenuOnMapDataItemClicked_DoZoomToVisibleData() + { + // Setup + var mapData = new TestFeatureBasedMapData("A") + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + var mapControl = mocks.StrictMock(); + mapControl.Expect(c => c.Data).Return(new MapDataCollection("name")); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); + mocks.ReplayAll(); + + mapLegendView.MapControl = mapControl; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_EnabledZoomToAllContextMenuOnMapDataCollectionItemClicked_DoZoomToVisibleData() + { + // Setup + var mapData = new MapDataCollection("A"); + var pointData = new MapPointData("B") + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + mapData.Add(pointData); + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Stub(p => p.Get(null, null)).IgnoreArguments().Return(builder); + var mapControl = mocks.StrictMock(); + mapControl.Expect(c => c.Data).Return(new MapDataCollection("name")); + mapControl.Expect(c => c.ZoomToAllVisibleLayers(mapData)); + mocks.ReplayAll(); + + mapLegendView.MapControl = mapControl; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_NoMapControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() + { + // Setup + var mapData = new TestFeatureBasedMapData("A") + { + IsVisible = true, + Features = new[] + { + new MapFeature(Enumerable.Empty()) + } + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + + private static MapDataContext GetContext(MapData mapData, MapDataCollection mapDataCollection = null) + { + return new MapDataContext(mapData, mapDataCollection ?? new MapDataCollection("test")); + } + } +} \ No newline at end of file Fisheye: Tag 6045128a21a5e8b1c6e1e48471749eb3da39b89d refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapLineDataTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 6045128a21a5e8b1c6e1e48471749eb3da39b89d refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPointDataTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 6045128a21a5e8b1c6e1e48471749eb3da39b89d refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Map.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?