Index: Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs =================================================================== diff -u -rb743d495d10779d51c8f75b7cb04b5babb4b226f -r068e27ad7b5fb663d8f272d4aebbcf2d3e365abf --- Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision b743d495d10779d51c8f75b7cb04b5babb4b226f) +++ Core/Common/src/Core.Common.Gui/Forms/MainWindow/MainWindow.xaml.cs (.../MainWindow.xaml.cs) (revision 068e27ad7b5fb663d8f272d4aebbcf2d3e365abf) @@ -401,7 +401,7 @@ throw new InvalidOperationException("Must call 'SetGui(IGui)' before calling 'InitPropertiesWindowAndActivate'."); } - if ((propertyGrid == null) || (propertyGrid.IsDisposed)) + if (propertyGrid == null || propertyGrid.IsDisposed) { propertyGrid = new PropertyGridView.PropertyGridView(applicationSelection, gui.PropertyResolver); } @@ -479,11 +479,13 @@ if (e.Item == propertyGrid) { + propertyGrid.Dispose(); propertyGrid = null; } if (e.Item == MessageWindow) { + messageWindow.Dispose(); messageWindow = null; } } Index: Core/Common/test/Core.Common.TestUtil.Test/WindowsFormsTestHelperTest.cs =================================================================== diff -u -r0190b07aad429867b364655eacc3527dd813644a -r068e27ad7b5fb663d8f272d4aebbcf2d3e365abf --- Core/Common/test/Core.Common.TestUtil.Test/WindowsFormsTestHelperTest.cs (.../WindowsFormsTestHelperTest.cs) (revision 0190b07aad429867b364655eacc3527dd813644a) +++ Core/Common/test/Core.Common.TestUtil.Test/WindowsFormsTestHelperTest.cs (.../WindowsFormsTestHelperTest.cs) (revision 068e27ad7b5fb663d8f272d4aebbcf2d3e365abf) @@ -73,7 +73,7 @@ var exception = Assert.Throws(testDelegate); - Assert.IsTrue(exception.Message.Contains("my message from thread")); + Assert.IsTrue(exception.Message.Contains("Throwing this exception is intended and part of a test.")); Assert.IsTrue(exception.StackTrace.Contains("MethodWithExceptionInSeparateThread")); WindowsFormsTestHelper.CloseAll(); @@ -120,7 +120,7 @@ private void MethodWithExceptionInSeparateThread() { - throw new InvalidOperationException("my message from thread"); + throw new InvalidOperationException("Throwing this exception is intended and part of a test."); } } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.Designer.cs =================================================================== diff -u -r61de56d96afe43d6ba193795c084a07fdff78b34 -r068e27ad7b5fb663d8f272d4aebbcf2d3e365abf --- Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.Designer.cs (.../MapLegendView.Designer.cs) (revision 61de56d96afe43d6ba193795c084a07fdff78b34) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.Designer.cs (.../MapLegendView.Designer.cs) (revision 068e27ad7b5fb663d8f272d4aebbcf2d3e365abf) @@ -7,6 +7,19 @@ /// private System.ComponentModel.IContainer components = null; + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + #region Component Designer generated code /// Index: Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs =================================================================== diff -u -r7e2303a28d41c62ef43c7902817e15390671df3f -r068e27ad7b5fb663d8f272d4aebbcf2d3e365abf --- Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 7e2303a28d41c62ef43c7902817e15390671df3f) +++ Core/Plugins/src/Core.Plugins.DotSpatial/Legend/MapLegendView.cs (.../MapLegendView.cs) (revision 068e27ad7b5fb663d8f272d4aebbcf2d3e365abf) @@ -100,18 +100,6 @@ } } - protected override void Dispose(bool disposing) - { - Data = null; - - if (disposing && (components != null)) - { - components.Dispose(); - } - - base.Dispose(disposing); - } - private void RegisterTreeNodeInfos() { treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs =================================================================== diff -u -r04b631b486b742c5339deb1d5504bb13ab5e248d -r068e27ad7b5fb663d8f272d4aebbcf2d3e365abf --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 04b631b486b742c5339deb1d5504bb13ab5e248d) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLegendViewTest.cs (.../MapLegendViewTest.cs) (revision 068e27ad7b5fb663d8f272d4aebbcf2d3e365abf) @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using System.Windows.Forms; using Core.Common.Base.Geometry; @@ -45,17 +44,18 @@ public void Constructor_ContextMenuBuilderProviderAndWindowNotNull_CreatesUserControlAndTreeViewControl() { // Call - var view = new MapLegendView(contextMenuBuilderProvider, parentWindow); + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow)) + { + var treeView = TypeUtils.GetField(view, "treeViewControl"); - var treeView = TypeUtils.GetField(view, "treeViewControl"); - - // Assert - Assert.IsInstanceOf(view); - Assert.IsInstanceOf(view); - Assert.IsNull(view.Data); - Assert.AreEqual(Resources.General_Map, view.Text); - Assert.IsNotNull(treeView); - Assert.IsInstanceOf(treeView); + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNull(view.Data); + Assert.AreEqual(Resources.General_Map, view.Text); + Assert.IsNotNull(treeView); + Assert.IsInstanceOf(treeView); + } } [Test] @@ -82,94 +82,104 @@ public void Data_MapDataCollection_DataSet() { // Setup - var view = new MapLegendView(contextMenuBuilderProvider, parentWindow); - var mapData = new MapDataCollection(new List(), "test data"); + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow)) + { + var mapData = new MapDataCollection(new List(), "test data"); - // Call - view.Data = mapData; + // Call + view.Data = mapData; - // Assert - Assert.AreSame(mapData, view.Data); - Assert.IsInstanceOf(view.Data); + // Assert + Assert.AreSame(mapData, view.Data); + Assert.IsInstanceOf(view.Data); + } } [Test] public void Data_MapPointData_DataSet() { // Setup - var view = new MapLegendView(contextMenuBuilderProvider, parentWindow); - var mapData = new MapPointData(CreateFeature(), "test data"); + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow)) + { + var mapData = new MapPointData(CreateFeature(), "test data"); - // Call - view.Data = mapData; + // Call + view.Data = mapData; - // Assert - Assert.AreSame(mapData, view.Data); - Assert.IsInstanceOf(view.Data); + // Assert + Assert.AreSame(mapData, view.Data); + Assert.IsInstanceOf(view.Data); + } } [Test] public void Data_MapLineData_DataSet() { // Setup - var view = new MapLegendView(contextMenuBuilderProvider, parentWindow); - var mapData = new MapLineData(CreateFeature(), "test data"); + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow)) + { + var mapData = new MapLineData(CreateFeature(), "test data"); - // Call - view.Data = mapData; + // Call + view.Data = mapData; - // Assert - Assert.AreSame(mapData, view.Data); - Assert.IsInstanceOf(view.Data); + // Assert + Assert.AreSame(mapData, view.Data); + Assert.IsInstanceOf(view.Data); + } } [Test] public void Data_MapPolygonData_DataSet() { // Setup - var view = new MapLegendView(contextMenuBuilderProvider, parentWindow); - var mapData = new MapPolygonData(CreateFeature(), "test data"); + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow)) + { + var mapData = new MapPolygonData(CreateFeature(), "test data"); - // Call - view.Data = mapData; + // Call + view.Data = mapData; - // Assert - Assert.AreSame(mapData, view.Data); - Assert.IsInstanceOf(view.Data); + // Assert + Assert.AreSame(mapData, view.Data); + Assert.IsInstanceOf(view.Data); + } } [Test] public void Data_ForNull_NullSet() { // Setup - var view = new MapLegendView(contextMenuBuilderProvider, parentWindow); + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow)) + { + // Call + view.Data = null; - // Call - view.Data = null; - - // Assert - Assert.IsNull(view.Data); + // Assert + Assert.IsNull(view.Data); + } } [Test] public void Data_OtherObject_ThrowsInvalidCastException() { // Setup - var view = new MapLegendView(contextMenuBuilderProvider, parentWindow); + using (var view = new MapLegendView(contextMenuBuilderProvider, parentWindow)) + { + // Call + TestDelegate test = () => view.Data = new object(); - // Call - TestDelegate test = () => view.Data = new object(); - - // Assert - Assert.Throws(test); + // Assert + Assert.Throws(test); + } } - private Collection CreateFeature() + private MapFeature[] CreateFeature() { - return new Collection + return new [] { - new MapFeature(new Collection + new MapFeature(new [] { new MapGeometry(new[] { Index: Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs =================================================================== diff -u -r354027b2a36a779798852d3edadaaf339140295c -r068e27ad7b5fb663d8f272d4aebbcf2d3e365abf --- Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 354027b2a36a779798852d3edadaaf339140295c) +++ Core/Plugins/test/Core.Plugins.DotSpatial.Test/Legend/MapLineDataTreeNodeInfoTest.cs (.../MapLineDataTreeNodeInfoTest.cs) (revision 068e27ad7b5fb663d8f272d4aebbcf2d3e365abf) @@ -22,6 +22,12 @@ private MapLegendView mapLegendView; private TreeNodeInfo info; + [TearDown] + public void TearDown() + { + mapLegendView.Dispose(); + } + [Test] public void Initialized_Always_ExpectedPropertiesSet() {