Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/ChartLegendViewTest.cs =================================================================== diff -u -r62a092ac8884ea1901204fb735a469209a1ba803 -rf926bf3621c9a8d5b6e57a0b34f8b26ea3b655c4 --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/ChartLegendViewTest.cs (.../ChartLegendViewTest.cs) (revision 62a092ac8884ea1901204fb735a469209a1ba803) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/Legend/ChartLegendViewTest.cs (.../ChartLegendViewTest.cs) (revision f926bf3621c9a8d5b6e57a0b34f8b26ea3b655c4) @@ -110,21 +110,22 @@ innerCollection }, "test data"); - var chartLegendView = new ChartLegendView + using (var chartLegendView = new ChartLegendView { Data = rootCollection - }; + }) + { + TreeViewControl treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); + Dictionary treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + var info = treeNodeInfoLookup[typeof(ChartDataCollection)]; - TreeViewControl treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); - Dictionary treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); - var info = treeNodeInfoLookup[typeof(ChartDataCollection)]; + // When + info.OnDrop(chartLineData, rootCollection, innerCollection, 0, treeViewControl); - // When - info.OnDrop(chartLineData, rootCollection, innerCollection, 0, treeViewControl); - - // Then - CollectionAssert.DoesNotContain(innerCollection.List, chartLineData); - CollectionAssert.Contains(rootCollection.List, chartLineData); + // Then + CollectionAssert.DoesNotContain(innerCollection.List, chartLineData); + CollectionAssert.Contains(rootCollection.List, chartLineData); + } } [Test] @@ -143,21 +144,22 @@ innerCollection }, "test data"); - var chartLegendView = new ChartLegendView + using (var chartLegendView = new ChartLegendView { Data = rootCollection - }; + }) + { + TreeViewControl treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); + Dictionary treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + var info = treeNodeInfoLookup[typeof(ChartDataCollection)]; - TreeViewControl treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); - Dictionary treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); - var info = treeNodeInfoLookup[typeof(ChartDataCollection)]; + // When + info.OnDrop(chartLineData, innerCollection, rootCollection, 0, treeViewControl); - // When - info.OnDrop(chartLineData, innerCollection, rootCollection, 0, treeViewControl); - - // Then - CollectionAssert.DoesNotContain(rootCollection.List, chartLineData); - CollectionAssert.Contains(innerCollection.List, chartLineData); + // Then + CollectionAssert.DoesNotContain(rootCollection.List, chartLineData); + CollectionAssert.Contains(innerCollection.List, chartLineData); + } } [Test] @@ -176,20 +178,21 @@ CreateChartLineData() }, "test data"); - var chartLegendView = new ChartLegendView + using (var chartLegendView = new ChartLegendView { Data = rootCollection - }; + }) + { + TreeViewControl treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); + Dictionary treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); + var info = treeNodeInfoLookup[typeof(ChartDataCollection)]; - TreeViewControl treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); - Dictionary treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); - var info = treeNodeInfoLookup[typeof(ChartDataCollection)]; + // When + info.OnDrop(chartLineData, rootCollection, rootCollection, index, treeViewControl); - // When - info.OnDrop(chartLineData, rootCollection, rootCollection, index, treeViewControl); - - // Then - Assert.AreEqual(2 - index, rootCollection.List.IndexOf(chartLineData)); + // Then + Assert.AreEqual(2 - index, rootCollection.List.IndexOf(chartLineData)); + } } private ChartData CreateChartLineData()