// Copyright (C) Stichting Deltares 2016. 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.Linq; using System.Windows.Forms; using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; using Core.Common.Utils.Reflection; using Core.Components.Charting.Data; using Core.Plugins.OxyPlot.Legend; using Core.Plugins.OxyPlot.Properties; using NUnit.Framework; namespace Core.Plugins.OxyPlot.Test.Legend { [TestFixture] public class ChartLegendViewTest { [Test] public void DefaultConstructor_CreatesUserControl() { // Call using (var view = new ChartLegendView()) { // Assert Assert.IsInstanceOf(view); Assert.IsInstanceOf(view); Assert.IsNull(view.Data); Assert.AreEqual(Resources.General_Chart, view.Text); } } [Test] public void Data_ChartControl_DataSet() { // Setup using (var view = new ChartLegendView()) { var chartDataCollection = new ChartDataCollection(new List(), "test data"); // Call view.Data = chartDataCollection; // Assert Assert.AreSame(chartDataCollection, view.Data); } } [Test] public void Data_ForNull_NullSet() { // Setup using (var view = new ChartLegendView()) { // Call view.Data = null; // Assert Assert.IsNull(view.Data); } } [Test] public void Data_OtherObject_ThrowsInvalidCastException() { // Setup using (var view = new ChartLegendView()) { // Call TestDelegate test = () => view.Data = new object(); // Assert Assert.Throws(test); } } [Test] public void GivenChartDataContainingCollection_WhenDragDroppingFromCollectionToRoot_ThenDataMoved() { // Given var chartLineData = CreateChartLineData(); var innerCollection = new ChartDataCollection(new List { chartLineData }, "collection"); var rootCollection = new ChartDataCollection(new List { CreateChartLineData(), innerCollection }, "test data"); using (var chartLegendView = new ChartLegendView { Data = rootCollection }) { 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); // Then CollectionAssert.DoesNotContain(innerCollection.List, chartLineData); CollectionAssert.Contains(rootCollection.List, chartLineData); } } [Test] public void GivenChartDataContainingCollection_WhenDragDroppingFromRootToCollection_ThenDataMoved() { // Given var chartLineData = CreateChartLineData(); var innerCollection = new ChartDataCollection(new List { CreateChartLineData() }, "collection"); var rootCollection = new ChartDataCollection(new List { chartLineData, innerCollection }, "test data"); using (var chartLegendView = new ChartLegendView { Data = rootCollection }) { 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); // Then CollectionAssert.DoesNotContain(rootCollection.List, chartLineData); CollectionAssert.Contains(innerCollection.List, chartLineData); } } [Test] [TestCase(0)] [TestCase(1)] [TestCase(2)] public void GivenChartDataContainingCollection_WhenDragDroppingFromRootToRoot_ThenDataPositionChanged(int index) { // Given var chartLineData = CreateChartLineData(); var rootCollection = new ChartDataCollection(new List { chartLineData, CreateChartLineData(), CreateChartLineData() }, "test data"); using (var chartLegendView = new ChartLegendView { Data = rootCollection }) { 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); // Then Assert.AreEqual(2 - index, rootCollection.List.IndexOf(chartLineData)); } } private ChartData CreateChartLineData() { return new ChartLineData(Enumerable.Empty(), "some name"); } } }