Index: Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs =================================================================== diff -u -ra3c8c0cb4384de51a18d77cc7bea487f97ba21e1 -r59dfb67d1d2e9043fc4d80412bab9255aaa1fb29 --- Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision a3c8c0cb4384de51a18d77cc7bea487f97ba21e1) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 59dfb67d1d2e9043fc4d80412bab9255aaa1fb29) @@ -21,6 +21,7 @@ using System.Linq; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; using Core.Components.DotSpatial.Forms; @@ -77,19 +78,28 @@ treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = mapPointData => DotSpatialResources.MapData_Point_data_label, - Image = mapPointData => DotSpatialResources.PointsIcon + Image = mapPointData => DotSpatialResources.PointsIcon, + CanCheck = mapPointData => true, + IsChecked = mapPointData => mapPointData.IsVisible, + OnNodeChecked = MapPointDataOnNodeChecked }); treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = mapLineData => DotSpatialResources.MapData_Line_data_label, - Image = mapLineData => DotSpatialResources.LineIcon + Image = mapLineData => DotSpatialResources.LineIcon, + CanCheck = mapLineData => true, + IsChecked = mapLineData => mapLineData.IsVisible, + OnNodeChecked = MapLineDataOnNodeChecked }); treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo { Text = mapPolygonData => DotSpatialResources.MapData_Polygon_data_label, - Image = mapPolygonData => DotSpatialResources.AreaIcon + Image = mapPolygonData => DotSpatialResources.AreaIcon, + CanCheck = mapPolygonData => true, + IsChecked = mapPolygonData => mapPolygonData.IsVisible, + OnNodeChecked = MapPolygonDataOnNodeChecked }); treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo @@ -99,5 +109,36 @@ ChildNodeObjects = mapDataCollection => mapDataCollection.List.Reverse().Cast().ToArray() }); } + + #region MapData + + private void MapPointDataOnNodeChecked(MapPointData mapPointData, object parentData) + { + PointBasedMapDataOnNodeChecked(mapPointData, parentData); + } + + private void MapLineDataOnNodeChecked(MapLineData mapLineData, object parentData) + { + PointBasedMapDataOnNodeChecked(mapLineData, parentData); + } + + private void MapPolygonDataOnNodeChecked(MapPolygonData mapPolygonData, object parentData) + { + PointBasedMapDataOnNodeChecked(mapPolygonData, parentData); + } + + private void PointBasedMapDataOnNodeChecked(PointBasedMapData pointBasedMapData, object parentData) + { + pointBasedMapData.IsVisible = !pointBasedMapData.IsVisible; + pointBasedMapData.NotifyObservers(); + + var observableParent = parentData as IObservable; + if (observableParent != null) + { + observableParent.NotifyObservers(); + } + } + + #endregion } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs =================================================================== diff -u -rf02506e58ebeecd95383ae12f4df2570ae5af17c -r59dfb67d1d2e9043fc4d80412bab9255aaa1fb29 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision f02506e58ebeecd95383ae12f4df2570ae5af17c) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 59dfb67d1d2e9043fc4d80412bab9255aaa1fb29) @@ -1,11 +1,15 @@ using System; using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Plugins.DotSpatial.Legend; using NUnit.Framework; +using Rhino.Mocks; using DotSpatialResources = Core.Plugins.DotSpatial.Properties.Resources; namespace Core.Plugins.DotSpatial.Test.Legend @@ -40,9 +44,6 @@ 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); @@ -68,5 +69,89 @@ // Assert TestHelper.AssertImagesAreEqual(DotSpatialResources.LineIcon, image); } + + [Test] + public void CanCheck_Always_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + 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 IsChecked_Always_ReturnsAccordingToVisibleStateOfLineData(bool isVisible) + { + // Setup + var mocks = new MockRepository(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + lineData.IsVisible = isVisible; + + mocks.ReplayAll(); + + // Call + var canCheck = info.IsChecked(lineData); + + // Assert + Assert.AreEqual(isVisible, canCheck); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void LineDataNodeWithoutParent_SetsLineDataVisibility(bool initialVisibleState) + { + // Setup + var mocks = new MockRepository(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + mocks.ReplayAll(); + + lineData.IsVisible = initialVisibleState; + + // Call + info.OnNodeChecked(lineData, null); + + // Assert + Assert.AreEqual(!initialVisibleState, lineData.IsVisible); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void OnNodeChecked_LineDataNodeWithObservableParent_SetsLineDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.StrictMock(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + observable.Expect(o => o.NotifyObservers()); + + mocks.ReplayAll(); + + lineData.IsVisible = initialVisibleState; + + // Call + info.OnNodeChecked(lineData, observable); + + // Assert + Assert.AreEqual(!initialVisibleState, lineData.IsVisible); + + mocks.VerifyAll(); + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs =================================================================== diff -u -rf02506e58ebeecd95383ae12f4df2570ae5af17c -r59dfb67d1d2e9043fc4d80412bab9255aaa1fb29 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision f02506e58ebeecd95383ae12f4df2570ae5af17c) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPointDataTreeNodeInfoTest.cs (.../MapPointDataTreeNodeInfoTest.cs) (revision 59dfb67d1d2e9043fc4d80412bab9255aaa1fb29) @@ -1,11 +1,15 @@ using System; using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Plugins.DotSpatial.Legend; using NUnit.Framework; +using Rhino.Mocks; using DotSpatialResources = Core.Plugins.DotSpatial.Properties.Resources; namespace Core.Plugins.DotSpatial.Test.Legend @@ -40,9 +44,6 @@ 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); @@ -68,5 +69,89 @@ // Assert TestHelper.AssertImagesAreEqual(DotSpatialResources.PointsIcon, image); } + + [Test] + public void CanCheck_Always_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + 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 IsChecked_Always_ReturnsAccordingToVisibleStateOfLineData(bool isVisible) + { + // Setup + var mocks = new MockRepository(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + lineData.IsVisible = isVisible; + + mocks.ReplayAll(); + + // Call + var canCheck = info.IsChecked(lineData); + + // Assert + Assert.AreEqual(isVisible, canCheck); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void LineDataNodeWithoutParent_SetsLineDataVisibility(bool initialVisibleState) + { + // Setup + var mocks = new MockRepository(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + mocks.ReplayAll(); + + lineData.IsVisible = initialVisibleState; + + // Call + info.OnNodeChecked(lineData, null); + + // Assert + Assert.AreEqual(!initialVisibleState, lineData.IsVisible); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void OnNodeChecked_LineDataNodeWithObservableParent_SetsLineDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.StrictMock(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + observable.Expect(o => o.NotifyObservers()); + + mocks.ReplayAll(); + + lineData.IsVisible = initialVisibleState; + + // Call + info.OnNodeChecked(lineData, observable); + + // Assert + Assert.AreEqual(!initialVisibleState, lineData.IsVisible); + + mocks.VerifyAll(); + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs =================================================================== diff -u -rf02506e58ebeecd95383ae12f4df2570ae5af17c -r59dfb67d1d2e9043fc4d80412bab9255aaa1fb29 --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision f02506e58ebeecd95383ae12f4df2570ae5af17c) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapPolygonDataTreeNodeInfoTest.cs (.../MapPolygonDataTreeNodeInfoTest.cs) (revision 59dfb67d1d2e9043fc4d80412bab9255aaa1fb29) @@ -1,11 +1,15 @@ using System; using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Gis.Data; using Core.Plugins.DotSpatial.Legend; using NUnit.Framework; +using Rhino.Mocks; using DotSpatialResources = Core.Plugins.DotSpatial.Properties.Resources; namespace Core.Plugins.DotSpatial.Test.Legend @@ -40,9 +44,6 @@ 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); @@ -68,5 +69,89 @@ // Assert TestHelper.AssertImagesAreEqual(DotSpatialResources.AreaIcon, image); } + + [Test] + public void CanCheck_Always_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + 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 IsChecked_Always_ReturnsAccordingToVisibleStateOfLineData(bool isVisible) + { + // Setup + var mocks = new MockRepository(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + lineData.IsVisible = isVisible; + + mocks.ReplayAll(); + + // Call + var canCheck = info.IsChecked(lineData); + + // Assert + Assert.AreEqual(isVisible, canCheck); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void LineDataNodeWithoutParent_SetsLineDataVisibility(bool initialVisibleState) + { + // Setup + var mocks = new MockRepository(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + mocks.ReplayAll(); + + lineData.IsVisible = initialVisibleState; + + // Call + info.OnNodeChecked(lineData, null); + + // Assert + Assert.AreEqual(!initialVisibleState, lineData.IsVisible); + + mocks.VerifyAll(); + } + + [TestCase(true)] + [TestCase(false)] + public void OnNodeChecked_LineDataNodeWithObservableParent_SetsLineDataVisibilityAndNotifiesParentObservers(bool initialVisibleState) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.StrictMock(); + var lineData = mocks.StrictMock(Enumerable.Empty()); + + observable.Expect(o => o.NotifyObservers()); + + mocks.ReplayAll(); + + lineData.IsVisible = initialVisibleState; + + // Call + info.OnNodeChecked(lineData, observable); + + // Assert + Assert.AreEqual(!initialVisibleState, lineData.IsVisible); + + mocks.VerifyAll(); + } } } \ No newline at end of file