// Copyright (C) Stichting Deltares 2017. 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 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 General Public License for more details. // // You should have received a copy of the GNU 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.ComponentModel; using Core.Common.Base.Geometry; using Core.Common.Gui.Converters; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Hydraulics.IllustrationPoints; using Ringtoets.Common.Data.TestUtil.IllustrationPoints; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.PropertyClasses; namespace Ringtoets.Integration.Forms.Test.PropertyClasses { [TestFixture] public class HydraulicBoundaryLocationPropertiesTest { [Test] public void Constructor_DefaultArgumentValues_DoesNotThrowException() { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "", 0.0, 0.0); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); var context = new TestHydraulicBoundaryLocationContext(hydraulicBoundaryDatabase, hydraulicBoundaryLocation); // Call TestDelegate test = () => new TestHydraulicBoundaryLocationProperties { Data = context }; // Assert Assert.DoesNotThrow(test); } [Test] public void GetProperties_ValidData_ReturnsExpectedValues() { // Setup const long id = 1234L; const double x = 567.0; const double y = 890.0; const string name = ""; var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(id, name, x, y); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); var context = new TestHydraulicBoundaryLocationContext(hydraulicBoundaryDatabase, hydraulicBoundaryLocation); // Call HydraulicBoundaryLocationProperties hydraulicBoundaryLocationProperties = new TestHydraulicBoundaryLocationProperties { Data = context }; // Assert Assert.AreEqual(id, hydraulicBoundaryLocationProperties.Id); Assert.AreEqual(name, hydraulicBoundaryLocationProperties.Name); var coordinates = new Point2D(x, y); Assert.AreEqual(coordinates, hydraulicBoundaryLocationProperties.Location); } [Test] [TestCase("")] [TestCase("some name")] public void ToString_WithName_ReturnsName(string name) { // Setup const long id = 1234L; const double x = 567.0; const double y = 890.0; var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(id, name, x, y); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); var context = new TestHydraulicBoundaryLocationContext(hydraulicBoundaryDatabase, hydraulicBoundaryLocation); // Call HydraulicBoundaryLocationProperties hydraulicBoundaryLocationProperties = new TestHydraulicBoundaryLocationProperties { Data = context }; // Assert string expectedString = $"{name} {new Point2D(x, y)}"; Assert.AreEqual(expectedString, hydraulicBoundaryLocationProperties.ToString()); } [Test] public void Constructor_WithGeneralIllustrationPointsResult_PropertiesHaveExpectedAttributesValues() { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "", 0.0, 0.0); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); var context = new TestHydraulicBoundaryLocationContext(hydraulicBoundaryDatabase, hydraulicBoundaryLocation); // Call var hydraulicBoundaryLocationProperties = new TestHydraulicBoundaryLocationProperties { WithGeneralResult = true, Data = context }; // Assert TypeConverter classTypeConverter = TypeDescriptor.GetConverter(hydraulicBoundaryLocationProperties, true); Assert.IsInstanceOf(classTypeConverter); const string generalCategory = "Algemeen"; const string illustrationPointsCategory = "Illustratiepunten"; PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(hydraulicBoundaryLocationProperties); Assert.AreEqual(7, dynamicProperties.Count); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dynamicProperties[0], generalCategory, "ID", "ID van de hydraulische randvoorwaardenlocatie in de database.", true); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dynamicProperties[1], generalCategory, "Naam", "Naam van de hydraulische randvoorwaardenlocatie.", true); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dynamicProperties[2], generalCategory, "Coördinaten [m]", "Coördinaten van de hydraulische randvoorwaardenlocatie.", true); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dynamicProperties[3], illustrationPointsCategory, "Maatgevende windrichting", "De windrichting waarvoor de berekende betrouwbaarheidsindex het laagst is.", true); TestHelper.AssertTypeConverter(nameof(HydraulicBoundaryLocationProperties.AlphaValues)); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dynamicProperties[4], illustrationPointsCategory, "Alfa's", "Berekende invloedscoëfficiënten voor alle beschouwde stochasten.", true); TestHelper.AssertTypeConverter(nameof(HydraulicBoundaryLocationProperties.Durations)); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dynamicProperties[5], illustrationPointsCategory, "Tijdsduren", "Tijdsduren waarop de stochasten betrekking hebben.", true); TestHelper.AssertTypeConverter(nameof(HydraulicBoundaryLocationProperties.IllustrationPoints)); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(dynamicProperties[6], illustrationPointsCategory, "Illustratiepunten", "De lijst van illustratiepunten voor de berekening.", true); } [Test] public void Constructor_WithGeneralIllustrationPointsResultAndDifferentPropertyOrder_PropertiesAreInExpectedOrder() { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "", 0.0, 0.0); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); var context = new TestHydraulicBoundaryLocationContext(hydraulicBoundaryDatabase, hydraulicBoundaryLocation); // Call var hydraulicBoundaryLocationProperties = new TestHydraulicBoundaryLocationProperties(new HydraulicBoundaryLocationProperties.ConstructionProperties { IllustrationPointsIndex = 1, IdIndex = 2, NameIndex = 3, LocationIndex = 4, GoverningWindDirectionIndex = 5, StochastsIndex = 6, DurationsIndex = 7 }) { WithGeneralResult = true, Data = context }; // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(hydraulicBoundaryLocationProperties); Assert.AreEqual(7, dynamicProperties.Count); Assert.AreEqual(dynamicProperties[0].Name, nameof(HydraulicBoundaryLocationProperties.IllustrationPoints)); Assert.AreEqual(dynamicProperties[1].Name, nameof(HydraulicBoundaryLocationProperties.Id)); Assert.AreEqual(dynamicProperties[2].Name, nameof(HydraulicBoundaryLocationProperties.Name)); Assert.AreEqual(dynamicProperties[3].Name, nameof(HydraulicBoundaryLocationProperties.Location)); Assert.AreEqual(dynamicProperties[4].Name, nameof(HydraulicBoundaryLocationProperties.GoverningWindDirection)); Assert.AreEqual(dynamicProperties[5].Name, nameof(HydraulicBoundaryLocationProperties.AlphaValues)); Assert.AreEqual(dynamicProperties[6].Name, nameof(HydraulicBoundaryLocationProperties.Durations)); } [Test] public void Constructor_WithoutGeneralIllustrationPointsResult_PropertiesAreInExpectedOrder() { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, "", 0.0, 0.0); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); var context = new TestHydraulicBoundaryLocationContext(hydraulicBoundaryDatabase, hydraulicBoundaryLocation); // Call var hydraulicBoundaryLocationProperties = new TestHydraulicBoundaryLocationProperties { WithGeneralResult = false, Data = context }; // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(hydraulicBoundaryLocationProperties); Assert.AreEqual(3, dynamicProperties.Count); Assert.AreEqual(dynamicProperties[0].Name, nameof(HydraulicBoundaryLocationProperties.Id)); Assert.AreEqual(dynamicProperties[1].Name, nameof(HydraulicBoundaryLocationProperties.Name)); Assert.AreEqual(dynamicProperties[2].Name, nameof(HydraulicBoundaryLocationProperties.Location)); } private class TestHydraulicBoundaryLocationProperties : HydraulicBoundaryLocationProperties { public TestHydraulicBoundaryLocationProperties() : base(new ConstructionProperties()) {} public TestHydraulicBoundaryLocationProperties(ConstructionProperties propertyIndexes) : base(propertyIndexes) {} public bool WithGeneralResult; protected override GeneralResult GetGeneralIllustrationPointsResult() { return WithGeneralResult ? new TestGeneralResult() : null; } } private class TestHydraulicBoundaryLocationContext : HydraulicBoundaryLocationContext { public TestHydraulicBoundaryLocationContext(HydraulicBoundaryDatabase wrappedData, HydraulicBoundaryLocation hydraulicBoundaryLocation) : base(wrappedData, hydraulicBoundaryLocation) {} } } }