Index: Core/Gui/test/Core.Gui.Test/Core.Gui.Test.csproj =================================================================== diff -u -r98da4d6cd59cac814ec00c54b22db4dc74b7eed0 -rfb76368e28aac13fd082e93c2dbcce44d88a1695 --- Core/Gui/test/Core.Gui.Test/Core.Gui.Test.csproj (.../Core.Gui.Test.csproj) (revision 98da4d6cd59cac814ec00c54b22db4dc74b7eed0) +++ Core/Gui/test/Core.Gui.Test/Core.Gui.Test.csproj (.../Core.Gui.Test.csproj) (revision fb76368e28aac13fd082e93c2dbcce44d88a1695) @@ -17,6 +17,7 @@ + Index: Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartDataCollectionTreeNodeInfoTest.cs (revision 0) +++ Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartDataCollectionTreeNodeInfoTest.cs (revision fb76368e28aac13fd082e93c2dbcce44d88a1695) @@ -0,0 +1,492 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Base.Geometry; +using Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using Core.Common.Util.Reflection; +using Core.Components.Chart.Data; +using Core.Components.Chart.Forms; +using Core.Components.Chart.TestUtil; +using Core.Gui.ContextMenu; +using Core.Gui.Forms.Chart; +using Core.Gui.PresentationObjects.Chart; +using Core.Gui.Properties; +using Core.Gui.TestUtil.ContextMenu; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Gui.Test.Forms.Chart +{ + [TestFixture] + public class ChartDataCollectionTreeNodeInfoTest + { + private const int contextMenuZoomToAllIndex = 0; + private ChartLegendView chartLegendView; + private TreeNodeInfo info; + private IContextMenuBuilderProvider contextMenuBuilderProvider; + private MockRepository mocks; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + contextMenuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + chartLegendView = new ChartLegendView(contextMenuBuilderProvider); + + var treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); + var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + + info = treeNodeInfoLookup[typeof(ChartDataCollection)]; + } + + [TearDown] + public void TearDown() + { + chartLegendView.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.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.CheckedState); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNotNull(info.CanDrag); + Assert.IsNotNull(info.CanDrop); + Assert.IsNotNull(info.CanInsert); + Assert.IsNotNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsNameFromChartData() + { + // Setup + var chartDataCollection = new ChartDataCollection("test data"); + + // Call + string text = info.Text(chartDataCollection); + + // Assert + Assert.AreEqual(chartDataCollection.Name, text); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + var chartDataCollection = new ChartDataCollection("test data"); + + // Call + Image image = info.Image(chartDataCollection); + + // Assert + TestHelper.AssertImagesAreEqual(Resources.folder, image); + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildrenWithContextAndDataReversed() + { + // Setup + var chartData1 = new TestChartData(); + var chartData2 = new TestChartData(); + var chartData3 = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test data"); + + chartDataCollection.Add(chartData1); + chartDataCollection.Add(chartData2); + chartDataCollection.Add(chartData3); + + // Call + object[] objects = info.ChildNodeObjects(chartDataCollection); + + // Assert + var expectedChildren = new[] + { + new ChartDataContext(chartData3, chartDataCollection), + new ChartDataContext(chartData2, chartDataCollection), + new ChartDataContext(chartData1, chartDataCollection) + }; + CollectionAssert.AreEqual(expectedChildren, objects); + } + + [Test] + public void CanDrop_TargetParentIsSameAsSourceParent_ReturnsTrue() + { + // Setup + ChartData chartData = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test"); + + ChartDataContext context = GetContext(chartData, chartDataCollection); + + // Call + bool canDrop = info.CanDrop(context, chartDataCollection); + + // Assert + Assert.IsTrue(canDrop); + } + + [Test] + public void CanDrop_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + ChartData chartData = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test"); + + ChartDataContext context = GetContext(chartData, chartDataCollection); + + // Call + bool canDrop = info.CanDrop(context, GetContext(new ChartDataCollection("test"))); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + public void CanInsert_TargetParentIsSameAsSourceParent_ReturnsTrue() + { + // Setup + ChartData chartData = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test"); + + ChartDataContext context = GetContext(chartData, chartDataCollection); + + // Call + bool canInsert = info.CanInsert(context, chartDataCollection); + + // Assert + Assert.IsTrue(canInsert); + } + + [Test] + public void CanInsert_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + ChartData chartData = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test"); + + ChartDataContext context = GetContext(chartData, chartDataCollection); + + // Call + bool canInsert = info.CanInsert(context, GetContext(new ChartDataCollection("test"))); + + // Assert + Assert.IsFalse(canInsert); + } + + [Test] + public void CanDrag_Always_ReturnsTrue() + { + // Call + bool canInsert = info.CanDrag(null, null); + + // Assert + Assert.IsTrue(canInsert); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void OnDrop_ChartDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var chartData1 = new TestChartData(); + var chartData2 = new TestChartData(); + var chartData3 = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test data"); + + chartDataCollection.Add(chartData1); + chartDataCollection.Add(chartData2); + chartDataCollection.Add(chartData3); + + ChartDataContext context1 = GetContext(chartData1); + + chartDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + info.OnDrop(context1, chartDataCollection, chartDataCollection, position, treeViewControl); + + // Assert + int reversedIndex = 2 - position; + Assert.AreSame(context1.WrappedData, chartDataCollection.Collection.ElementAt(reversedIndex)); + + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(-50)] + [TestCase(-1)] + [TestCase(4)] + [TestCase(50)] + public void OnDrop_ChartDataMovedToPositionOutsideRange_ThrowsException(int position) + { + // Setup + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var chartData1 = new ChartLineData("line"); + var chartData2 = new ChartAreaData("area"); + var chartData3 = new ChartPointData("point"); + var chartData4 = new ChartMultipleAreaData("multiple area"); + var chartDataCollection = new ChartDataCollection("test data"); + + chartDataCollection.Add(chartData1); + chartDataCollection.Add(chartData2); + chartDataCollection.Add(chartData3); + chartDataCollection.Add(chartData4); + + chartDataCollection.Attach(observer); + chartLegendView.Data = chartDataCollection; + + ChartDataContext context1 = GetContext(chartData1); + + chartDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + TestDelegate test = () => info.OnDrop(context1, chartDataCollection, chartDataCollection, position, treeViewControl); + + // Assert + Assert.Throws(test); + + mocks.VerifyAll(); // Expect no update observer. + } + } + + [Test] + public void ContextMenuStrip_WithChartDataCollection_CallsContextMenuBuilderMethods() + { + // Setup + var chartDataCollection = new ChartDataCollection("test data"); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + var menuBuilder = mocks.StrictMock(); + using (mocks.Ordered()) + { + menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.Build()).Return(null); + } + + contextMenuBuilderProvider.Expect(cmbp => cmbp.Get(null, null)) + .IgnoreArguments() + .Return(menuBuilder); + mocks.ReplayAll(); + + // Call + info.ContextMenuStrip(chartDataCollection, null, treeViewControl); + + // Assert + // Asserts done in TearDown + } + } + + [Test] + public void ContextMenuStrip_InvisibleChartDataInChartDataCollection_ZoomToAllDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var pointData = new ChartPointData("test data") + { + IsVisible = false + }; + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(pointData); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet er minstens één gegevensreeks in deze map met gegevensreeksen zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_VisibleChartDataWithoutFeaturesInChartDataCollection_ZoomToAllDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var lineData = new ChartLineData("test line") + { + IsVisible = false, + Points = new[] + { + new Point2D(1, 5) + } + }; + var pointData = new ChartPointData("test data") + { + IsVisible = true + }; + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(pointData); + chartDataCollection.Add(lineData); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet minstens één van de zichtbare gegevensreeksen in deze map met gegevensreeksen elementen bevatten.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_ChartDataCollectionWithVisibleChartData_ZoomToAllEnabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var chartPointData = new ChartPointData("test") + { + IsVisible = true, + Points = new[] + { + new Point2D(0, 1) + } + }; + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(chartPointData); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de grafiek dusdanig dat alle zichtbare gegevensreeksen in deze map met gegevensreeksen precies in het beeld passen.", + Resources.ZoomToAllIcon); + } + } + + [Test] + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() + { + // Setup + var lineData = new ChartLineData("test line") + { + IsVisible = true, + Points = new[] + { + new Point2D(1, 5) + } + }; + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(lineData); + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + var chartControl = mocks.StrictMock(); + chartControl.Expect(c => c.Data).Return(new ChartDataCollection("name")); + chartControl.Expect(c => c.ZoomToVisibleSeries(chartDataCollection)); + + mocks.ReplayAll(); + + chartLegendView.ChartControl = chartControl; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_DisabledZoomToAllContextMenuItemClicked_DoesNotThrow() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + var lineData = new ChartLineData("test line"); + var chartDataCollection = new ChartDataCollection("test data"); + chartDataCollection.Add(lineData); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(chartDataCollection, null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + + private static ChartDataContext GetContext(ChartData chartData, ChartDataCollection chartDataCollection = null) + { + return new ChartDataContext(chartData, chartDataCollection ?? new ChartDataCollection("test")); + } + } +} \ No newline at end of file Index: Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartDataContextTreeNodeInfoTest.cs =================================================================== diff -u --- Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartDataContextTreeNodeInfoTest.cs (revision 0) +++ Core/Gui/test/Core.Gui.Test/Forms/Chart/ChartDataContextTreeNodeInfoTest.cs (revision fb76368e28aac13fd082e93c2dbcce44d88a1695) @@ -0,0 +1,680 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Base.Geometry; +using Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using Core.Common.Util.Reflection; +using Core.Components.Chart.Data; +using Core.Components.Chart.Forms; +using Core.Components.Chart.TestUtil; +using Core.Gui.ContextMenu; +using Core.Gui.Forms.Chart; +using Core.Gui.PresentationObjects.Chart; +using Core.Gui.Properties; +using Core.Gui.TestUtil.ContextMenu; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Gui.Test.Forms.Chart +{ + [TestFixture] + public class ChartDataContextTreeNodeInfoTest + { + private const int contextMenuZoomToAllIndex = 0; + + private ChartLegendView chartLegendView; + private TreeNodeInfo info; + private MockRepository mocks; + private IContextMenuBuilderProvider contextMenuBuilderProvider; + + private static IEnumerable ChartDataLegendImages + { + get + { + yield return new TestCaseData(new ChartPointData("test"), Resources.PointsIcon); + yield return new TestCaseData(new ChartLineData("test"), Resources.LineIcon); + yield return new TestCaseData(new ChartAreaData("test"), Resources.AreaIcon); + yield return new TestCaseData(new ChartMultipleAreaData("test"), Resources.AreaIcon); + yield return new TestCaseData(new ChartMultipleLineData("test"), Resources.LineIcon); + yield return new TestCaseData(new ChartDataCollection("test"), Resources.folder); + } + } + + private static IEnumerable DragChartData + { + get + { + return new ChartData[] + { + new ChartPointData("test"), + new ChartLineData("test"), + new ChartAreaData("test"), + new ChartMultipleLineData("test"), + new ChartDataCollection("test") + }; + } + } + + private static IEnumerable NoChartDataCollection + { + get + { + return new ChartData[] + { + new ChartPointData("test"), + new ChartLineData("test"), + new ChartAreaData("test"), + new ChartMultipleAreaData("test"), + new ChartMultipleLineData("test") + }; + } + } + + private static IEnumerable IsCheckedChartData + { + get + { + yield return new TestCaseData(new ChartPointData("test"), false); + yield return new TestCaseData(new ChartPointData("test"), true); + yield return new TestCaseData(new ChartLineData("test"), false); + yield return new TestCaseData(new ChartLineData("test"), true); + yield return new TestCaseData(new ChartAreaData("test"), false); + yield return new TestCaseData(new ChartAreaData("test"), true); + yield return new TestCaseData(new ChartMultipleAreaData("test"), false); + yield return new TestCaseData(new ChartMultipleAreaData("test"), true); + yield return new TestCaseData(new ChartMultipleLineData("test"), false); + yield return new TestCaseData(new ChartMultipleLineData("test"), true); + } + } + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + contextMenuBuilderProvider = mocks.StrictMock(); + mocks.ReplayAll(); + + chartLegendView = new ChartLegendView(contextMenuBuilderProvider); + + var treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); + var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + + info = treeNodeInfoLookup[typeof(ChartDataContext)]; + } + + [TearDown] + public void TearDown() + { + chartLegendView.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.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNotNull(info.CanCheck); + Assert.IsNotNull(info.CheckedState); + 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_ReturnsNameFromWrappedChartData() + { + // Setup + ChartDataContext context = GetContext(new TestChartData()); + + // Call + string text = info.Text(context); + + // Assert + Assert.AreEqual(context.WrappedData.Name, text); + } + + [Test] + [TestCaseSource(nameof(ChartDataLegendImages))] + public void Image_WrappedDataChartPointData_ReturnsExpectedImage(ChartData chartData, Image expectedImage) + { + // Setup + ChartDataContext context = GetContext(chartData); + + // Call + Image image = info.Image(context); + + // Assert + TestHelper.AssertImagesAreEqual(expectedImage, image); + } + + [Test] + public void ChildNodeObjects_ChartDataCollection_ReturnsItemsFromChartDataCollectionList() + { + // Setup + var chartData1 = new TestChartData(); + var chartData2 = new TestChartData(); + var chartData3 = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test"); + + chartDataCollection.Add(chartData1); + chartDataCollection.Add(chartData2); + chartDataCollection.Add(chartData3); + + ChartDataContext context = GetContext(chartDataCollection); + + // Call + object[] objects = info.ChildNodeObjects(context); + + // Assert + var expectedChildren = new[] + { + new ChartDataContext(chartData3, new ChartDataCollection("test")), + new ChartDataContext(chartData2, new ChartDataCollection("test")), + new ChartDataContext(chartData1, new ChartDataCollection("test")) + }; + CollectionAssert.AreEqual(expectedChildren, objects); + } + + [Test] + [TestCaseSource(nameof(NoChartDataCollection))] + public void ChildNodeObjects_OtherThanChartDataCollection_ReturnsEmptyArray(ChartData chartData) + { + // Setup + ChartDataContext context = GetContext(chartData); + + // Call + object[] objects = info.ChildNodeObjects(context); + + // Assert + CollectionAssert.IsEmpty(objects); + } + + [Test] + public void CanDrag_WrappedDataChartMultipleAreaData_ReturnsFalse() + { + // Setup + var multipleChartAreaData = new ChartMultipleAreaData("test"); + ChartDataContext context = GetContext(multipleChartAreaData); + + // Call + bool canDrag = info.CanDrag(context, null); + + // Assert + Assert.IsFalse(canDrag); + } + + [Test] + [TestCaseSource(nameof(DragChartData))] + public void CanDrag_WrappedDataOtherThanChartMultipleAreaData_ReturnsTrue(ChartData chartData) + { + // Setup + ChartDataContext context = GetContext(chartData); + + // Call + bool canDrag = info.CanDrag(context, null); + + // Assert + Assert.IsTrue(canDrag); + } + + [Test] + public void CanCheck_WrappedDataChartDataCollection_ReturnsFalse() + { + // Setup + ChartDataContext context = GetContext(new ChartDataCollection("test")); + + // Call + bool canCheck = info.CanCheck(context); + + // Assert + Assert.IsFalse(canCheck); + } + + [Test] + [TestCaseSource(nameof(NoChartDataCollection))] + public void CanCheck_WrappedDataOtherThanChartDataCollection_ReturnsTrue(ChartData chartData) + { + // Setup + ChartDataContext context = GetContext(chartData); + + // Call + bool canCheck = info.CanCheck(context); + + // Assert + Assert.IsTrue(canCheck); + } + + [Test] + [TestCaseSource(nameof(IsCheckedChartData))] + public void IsChecked_Always_ReturnsAccordingToVisibleStateOfChartData(ChartData chartData, bool isVisible) + { + // Setup + ChartDataContext context = GetContext(chartData); + context.WrappedData.IsVisible = isVisible; + + // Call + TreeNodeCheckedState checkedState = info.CheckedState(context); + + // Assert + TreeNodeCheckedState expectedCheckedState = isVisible ? TreeNodeCheckedState.Checked : TreeNodeCheckedState.Unchecked; + Assert.AreEqual(expectedCheckedState, checkedState); + } + + [Test] + [TestCaseSource(nameof(IsCheckedChartData))] + public void OnNodeChecked_Always_SetsChartDataVisibilityAndNotifiesParentObservers(ChartData chartData, bool initialVisibleState) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + ChartDataContext context = GetContext(chartData); + 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 + ChartData chartData = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test"); + + ChartDataContext context = GetContext(chartData, chartDataCollection); + ChartDataContext targetContext = GetContext(chartDataCollection); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsTrue(canDrop); + } + + [Test] + public void CanDrop_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + ChartData chartData = new TestChartData(); + ChartData chartData2 = new TestChartData(); + + ChartDataContext context = GetContext(chartData); + ChartDataContext targetContext = GetContext(chartData2); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + public void CanDrop_TargetDataIsCollection_ReturnsFalse() + { + // Setup + ChartData chartData = new TestChartData(); + var rootCollection = new ChartDataCollection("test"); + var targetCollection = new ChartDataCollection("test"); + + ChartDataContext context = GetContext(chartData, rootCollection); + ChartDataContext targetContext = GetContext(targetCollection, rootCollection); + + // Call + bool canDrop = info.CanDrop(context, targetContext); + + // Assert + Assert.IsFalse(canDrop); + } + + [Test] + public void CanInsert_TargetIsSameAsSourceParent_ReturnsTrue() + { + // Setup + ChartData chartData = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test"); + + ChartDataContext context = GetContext(chartData, chartDataCollection); + ChartDataContext targetContext = GetContext(chartDataCollection); + + // Call + bool canInsert = info.CanInsert(context, targetContext); + + // Assert + Assert.IsTrue(canInsert); + } + + [Test] + public void CanInsert_TargetParentNotSameAsSourceParent_ReturnsFalse() + { + // Setup + ChartData chartData = new TestChartData(); + ChartData chartData2 = new TestChartData(); + + ChartDataContext context = GetContext(chartData); + ChartDataContext targetContext = GetContext(chartData2); + + // Call + bool canInsert = info.CanInsert(context, targetContext); + + // Assert + Assert.IsFalse(canInsert); + } + + [Test] + public void CanInsert_TargetDataIsCollection_ReturnsFalse() + { + // Setup + ChartData chartData = new TestChartData(); + var rootCollection = new ChartDataCollection("test"); + var targetCollection = new ChartDataCollection("test"); + + ChartDataContext context = GetContext(chartData, rootCollection); + ChartDataContext 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_ChartDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var chartData1 = new TestChartData(); + var chartData2 = new TestChartData(); + var chartData3 = new TestChartData(); + var chartDataCollection = new ChartDataCollection("test"); + + chartDataCollection.Add(chartData1); + chartDataCollection.Add(chartData2); + chartDataCollection.Add(chartData3); + + ChartDataContext context1 = GetContext(chartData1); + ChartDataContext collectionContext = GetContext(chartDataCollection); + + chartDataCollection.Attach(observer); + + using (var treeViewControl = new TreeViewControl()) + { + // Call + info.OnDrop(context1, collectionContext, collectionContext, position, treeViewControl); + + // Assert + int reversedIndex = 2 - position; + var wrappedCollectionData = (ChartDataCollection) collectionContext.WrappedData; + Assert.AreSame(context1.WrappedData, wrappedCollectionData.Collection.ElementAt(reversedIndex)); + + mocks.VerifyAll(); + } + } + + [Test] + [TestCase(-50)] + [TestCase(-1)] + [TestCase(5)] + [TestCase(50)] + public void OnDrop_ChartDataMovedToPositionOutsideRange_ThrowsException(int position) + { + // Setup + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var chartData1 = new ChartLineData("line"); + var chartData2 = new ChartAreaData("area"); + var chartData3 = new ChartPointData("point"); + var chartData4 = new ChartMultipleAreaData("multiple area"); + var chartData5 = new ChartMultipleLineData("multiple line"); + var chartDataCollection = new ChartDataCollection("test"); + + chartDataCollection.Add(chartData1); + chartDataCollection.Add(chartData2); + chartDataCollection.Add(chartData3); + chartDataCollection.Add(chartData4); + chartDataCollection.Add(chartData5); + + chartDataCollection.Attach(observer); + chartLegendView.Data = chartDataCollection; + + ChartDataContext context = GetContext(chartData1); + ChartDataContext collectionContext = GetContext(chartDataCollection); + + chartDataCollection.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] + [TestCaseSource(nameof(NoChartDataCollection))] + public void ContextMenuStrip_DifferentTypesOfChartData_CallsBuilder(ChartData chartData) + { + // 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.AddPropertiesItem()).Return(builder); + builder.Expect(mb => mb.Build()).Return(null); + } + + contextMenuBuilderProvider.Expect(p => p.Get(chartData, null)).Return(builder); + + mocks.ReplayAll(); + + // Call + info.ContextMenuStrip(GetContext(chartData), 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 lineData = new ChartLineData("A") + { + IsVisible = true, + Points = new[] + { + new Point2D(0, 1) + } + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de grafiek dusdanig dat deze gegevensreeks 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 lineData = new ChartLineData("A") + { + IsVisible = false + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de gegevensreeks 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 lineData = new ChartLineData("A") + { + IsVisible = true + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de gegevensreeks elementen bevatten.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_EnabledZoomToAllContextMenuItemClicked_DoZoomToVisibleData() + { + // Setup + var lineData = new ChartLineData("A") + { + IsVisible = true, + Points = new[] + { + new Point2D(0, 1) + } + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + var chartControl = mocks.StrictMock(); + chartControl.Expect(c => c.Data).Return(new ChartDataCollection("name")); + chartControl.Expect(c => c.ZoomToVisibleSeries(lineData)); + mocks.ReplayAll(); + + chartLegendView.ChartControl = chartControl; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) + { + // Call + contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + // Assert expectancies are called in TearDown() + } + } + + [Test] + public void ContextMenuStrip_NoChartControlAndEnabledZoomToAllContextMenuItemClicked_DoesNotThrow() + { + // Setup + var lineData = new ChartLineData("A") + { + IsVisible = true, + Points = new[] + { + new Point2D(0, 1) + } + }; + + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(lineData), null, null)) + { + // Call + TestDelegate call = () => contextMenu.Items[contextMenuZoomToAllIndex].PerformClick(); + + // Assert + Assert.DoesNotThrow(call); + } + } + + private static ChartDataContext GetContext(ChartData chartData, ChartDataCollection chartDataCollection = null) + { + return new ChartDataContext(chartData, chartDataCollection ?? new ChartDataCollection("test")); + } + } +} \ No newline at end of file Fisheye: Tag fb76368e28aac13fd082e93c2dbcce44d88a1695 refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag fb76368e28aac13fd082e93c2dbcce44d88a1695 refers to a dead (removed) revision in file `Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?