// 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.Collections.ObjectModel; using Core.Common.TestUtil; using Core.Components.Charting.Data; using Core.Components.Charting.TestUtil; using Core.Components.OxyPlot.Converter; using NUnit.Framework; using OxyPlot; using OxyPlot.Series; namespace Core.Components.OxyPlot.Test.Converter { [TestFixture] public class ChartPointDataConverterTest { [Test] public void DefaultConstructor_IsChartDataConverter() { // Call var converter = new ChartPointDataConverter(); // Assert Assert.IsInstanceOf>(converter); } [Test] public void CanConvertSeries_PointData_ReturnTrue() { // Setup var converter = new ChartPointDataConverter(); var pointData = new ChartPointData(new Collection>(), "test data"); // Call var canConvert = converter.CanConvertSeries(pointData); // Assert Assert.IsTrue(canConvert); } [Test] public void CanConvertSeries_ChartData_ReturnsFalse() { // Setup var converter = new ChartPointDataConverter(); var chartData = new TestChartData(); // Call var canConvert = converter.CanConvertSeries(chartData); // Assert Assert.IsFalse(canConvert); } [Test] public void Convert_RandomPointData_ReturnsNewSeries() { // Setup var converter = new ChartPointDataConverter(); var random = new Random(21); var randomCount = random.Next(5, 10); var points = new Collection>(); for (int i = 0; i < randomCount; i++) { points.Add(Tuple.Create(random.NextDouble(), random.NextDouble())); } var pointData = new ChartPointData(points, "test data"); // Call var series = converter.Convert(pointData); // Assert Assert.IsInstanceOf>(series); var lineSeries = ((LineSeries)series[0]); CollectionAssert.AreEqual(points, lineSeries.ItemsSource); Assert.AreNotSame(points, lineSeries.ItemsSource); Assert.AreEqual(LineStyle.None, lineSeries.LineStyle); Assert.AreEqual(MarkerType.Circle, lineSeries.MarkerType); } [Test] public void Convert_DataNull_ThrowsArgumentNullException() { // Setup var testConverter = new ChartPointDataConverter(); // Call TestDelegate test = () => testConverter.Convert(null); // Assert Assert.Throws(test); } [Test] public void Convert_DataCannotBeConverted_ThrowsArgumentException() { // Setup var testConverter = new ChartPointDataConverter(); var testChartData = new TestChartData(); var expectedMessage = string.Format("The data of type {0} cannot be converted by this converter.", testChartData.GetType()); // Precondition Assert.IsFalse(testConverter.CanConvertSeries(testChartData)); // Call TestDelegate test = () => testConverter.Convert(testChartData); // Assert TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); } } }