Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsDesignWaterLevelLocationContextPropertiesTest.cs =================================================================== diff -u -re182f6f394aa75e739467a77e7bcacd9a8b25429 -rb2f550432173db787e99cf93b0c1db320d129d80 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsDesignWaterLevelLocationContextPropertiesTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationContextPropertiesTest.cs) (revision e182f6f394aa75e739467a77e7bcacd9a8b25429) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsDesignWaterLevelLocationContextPropertiesTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationContextPropertiesTest.cs) (revision b2f550432173db787e99cf93b0c1db320d129d80) @@ -19,14 +19,17 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.ComponentModel; using Core.Common.Base; -using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; +using Core.Common.Utils.Reflection; using NUnit.Framework; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionOutwards.Forms.PropertyClasses; @@ -35,6 +38,16 @@ [TestFixture] public class GrassCoverErosionOutwardsDesignWaterLevelLocationContextPropertiesTest { + private const int idPropertyIndex = 0; + private const int namePropertyIndex = 1; + private const int coordinatesPropertyIndex = 2; + private const int designWaterLevelPropertyIndex = 3; + private const int targetProbabilityPropertyIndex = 4; + private const int targetReliabilityPropertyIndex = 5; + private const int calculatedProbabilityPropertyIndex = 6; + private const int calculatedReliabilityPropertyIndex = 7; + private const int convergencePropertyIndex = 8; + [Test] public void Constructor_ExpectedValues() { @@ -47,21 +60,70 @@ } [Test] + public void GetProperties_ValidData_ReturnsExpectedValues() + { + // Setup + HydraulicBoundaryLocation hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + + // Call + var properties = new GrassCoverErosionOutwardsDesignWaterLevelLocationContextProperties + { + Data = new GrassCoverErosionOutwardsDesignWaterLevelLocationContext(new ObservableList + { + hydraulicBoundaryLocation + }, hydraulicBoundaryLocation) + }; + + // Assert + Assert.AreEqual(hydraulicBoundaryLocation.Id, properties.Id); + Assert.AreEqual(hydraulicBoundaryLocation.Name, properties.Name); + Assert.AreEqual(hydraulicBoundaryLocation.Location, properties.Location); + Assert.IsNaN(properties.DesignWaterLevel); + Assert.IsTrue(TypeUtils.HasTypeConverter(p => p.DesignWaterLevel)); + Assert.AreEqual(double.NaN, properties.TargetProbability); + Assert.IsTrue(TypeUtils.HasTypeConverter( + p => p.TargetProbability)); + Assert.IsNaN(properties.TargetReliability); + Assert.IsTrue(TypeUtils.HasTypeConverter(p => p.TargetReliability)); + Assert.AreEqual(double.NaN, properties.CalculatedProbability); + Assert.IsTrue(TypeUtils.HasTypeConverter( + p => p.CalculatedProbability)); + Assert.IsNaN(properties.CalculatedReliability); + Assert.IsTrue(TypeUtils.HasTypeConverter(p => p.CalculatedReliability)); + Assert.AreEqual(string.Empty, properties.Convergence); + } + + [Test] [TestCase(CalculationConvergence.CalculatedConverged, "Ja")] [TestCase(CalculationConvergence.CalculatedNotConverged, "Nee")] [TestCase(CalculationConvergence.NotCalculated, "")] public void GetProperties_ValidData_ReturnsExpectedValues(CalculationConvergence convergenceReached, string expectedConvergenceValue) { // Setup + var random = new Random(); const long id = 1; const double x = 567.0; const double y = 890.0; const string name = "name"; - var designWaterLevel = (RoundedDouble) 1234; + + double targetProbability = random.NextDouble(); + double targetReliability = random.NextDouble(); + double calculatedProbability = random.NextDouble(); + double calculatedReliability = random.NextDouble(); + double designWaterLevel = random.NextDouble(); + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(id, name, x, y) { - DesignWaterLevel = designWaterLevel, - DesignWaterLevelCalculationConvergence = convergenceReached + DesignWaterLevelOutput = new HydraulicBoundaryLocationOutput(designWaterLevel, targetProbability, + targetReliability, + calculatedProbability, + calculatedReliability, + convergenceReached) }; var locations = new ObservableList { @@ -81,88 +143,112 @@ Point2D coordinates = new Point2D(x, y); Assert.AreEqual(coordinates, properties.Location); Assert.AreEqual(designWaterLevel, properties.DesignWaterLevel, properties.DesignWaterLevel.GetAccuracy()); + + Assert.AreEqual(targetProbability, properties.TargetProbability); + Assert.AreEqual(targetReliability, properties.TargetReliability, properties.TargetReliability.GetAccuracy()); + Assert.AreEqual(calculatedProbability, properties.CalculatedProbability); + Assert.AreEqual(calculatedReliability, properties.CalculatedReliability, properties.CalculatedReliability.GetAccuracy()); Assert.AreEqual(expectedConvergenceValue, properties.Convergence); } [Test] public void Constructor_Always_PropertiesHaveExpectedAttributesValues() { // Setup - const long id = 1; - const double x = 567.0; - const double y = 890.0; - const string name = "name"; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(id, name, x, y); - var locations = new ObservableList - { - hydraulicBoundaryLocation - }; - var context = new GrassCoverErosionOutwardsDesignWaterLevelLocationContext(locations, hydraulicBoundaryLocation); + HydraulicBoundaryLocation hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); // Call var properties = new GrassCoverErosionOutwardsDesignWaterLevelLocationContextProperties { - Data = context + Data = new GrassCoverErosionOutwardsDesignWaterLevelLocationContext(new ObservableList + { + hydraulicBoundaryLocation + }, hydraulicBoundaryLocation) }; // Assert TypeConverter classTypeConverter = TypeDescriptor.GetConverter(properties, true); - var dynamicPropertyBag = new DynamicPropertyBag(properties); - PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(); - PropertyDescriptor idProperty = dynamicProperties.Find("Id", false); - PropertyDescriptor nameProperty = dynamicProperties.Find("Name", false); - PropertyDescriptor locationProperty = dynamicProperties.Find("Location", false); - PropertyDescriptor waterLevelProperty = dynamicProperties.Find("DesignWaterLevel", false); - PropertyDescriptor convergenceProperty = dynamicProperties.Find("Convergence", false); + var propertyBag = new DynamicPropertyBag(properties); + PropertyDescriptorCollection dynamicProperties = propertyBag.GetProperties(new Attribute[] + { + new BrowsableAttribute(true) + }); + + Assert.AreEqual(9, dynamicProperties.Count); Assert.IsInstanceOf(classTypeConverter); - const string expectedCategory = "Algemeen"; - const string expectedIdDisplayName = "ID"; - const string expectedIdDescription = "ID van de hydraulische randvoorwaardenlocatie in de database."; - const string expectedNameDisplayName = "Naam"; - const string expectedNameDescription = "Naam van de hydraulische randvoorwaardenlocatie."; - const string expectedLocationDisplayName = "Coördinaten [m]"; - const string expectedLocationDescription = "Coördinaten van de hydraulische randvoorwaardenlocatie."; - const string expectedWaterLevelDisplayName = "Waterstand bij doorsnede-eis [m+NAP]"; - const string expectedWaterLevelDescription = "Berekende waterstand bij doorsnede-eis."; - const string expectedConvergenceDisplayName = "Convergentie"; - const string expectedConvergenceDescription = "Is convergentie bereikt in de berekening van de waterstand bij doorsnede-eis?"; - + PropertyDescriptor idProperty = dynamicProperties[idPropertyIndex]; Assert.IsNotNull(idProperty); - Assert.IsTrue(idProperty.IsReadOnly); - Assert.IsTrue(idProperty.IsBrowsable); - Assert.AreEqual(expectedCategory, idProperty.Category); - Assert.AreEqual(expectedIdDisplayName, idProperty.DisplayName); - Assert.AreEqual(expectedIdDescription, idProperty.Description); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(idProperty, + "Algemeen", + "ID", + "ID van de hydraulische randvoorwaardenlocatie in de database.", + true); + PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; Assert.IsNotNull(nameProperty); - Assert.IsTrue(nameProperty.IsReadOnly); - Assert.IsTrue(nameProperty.IsBrowsable); - Assert.AreEqual(expectedCategory, nameProperty.Category); - Assert.AreEqual(expectedNameDisplayName, nameProperty.DisplayName); - Assert.AreEqual(expectedNameDescription, nameProperty.Description); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, + "Algemeen", + "Naam", + "Naam van de hydraulische randvoorwaardenlocatie.", + true); - Assert.IsNotNull(locationProperty); - Assert.IsTrue(locationProperty.IsReadOnly); - Assert.IsTrue(locationProperty.IsBrowsable); - Assert.AreEqual(expectedCategory, locationProperty.Category); - Assert.AreEqual(expectedLocationDisplayName, locationProperty.DisplayName); - Assert.AreEqual(expectedLocationDescription, locationProperty.Description); + PropertyDescriptor coordinatesProperty = dynamicProperties[coordinatesPropertyIndex]; + Assert.IsNotNull(coordinatesProperty); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(coordinatesProperty, + "Algemeen", + "Coördinaten [m]", + "Coördinaten van de hydraulische randvoorwaardenlocatie.", + true); - Assert.IsNotNull(waterLevelProperty); - Assert.IsTrue(waterLevelProperty.IsReadOnly); - Assert.IsTrue(waterLevelProperty.IsBrowsable); - Assert.AreEqual(expectedCategory, waterLevelProperty.Category); - Assert.AreEqual(expectedWaterLevelDisplayName, waterLevelProperty.DisplayName); - Assert.AreEqual(expectedWaterLevelDescription, waterLevelProperty.Description); + PropertyDescriptor designWaterLevelProperty = dynamicProperties[designWaterLevelPropertyIndex]; + Assert.IsNotNull(designWaterLevelProperty); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(designWaterLevelProperty, + "Resultaat", + "Waterstand bij doorsnede-eis [m+NAP]", + "Berekende waterstand bij doorsnede-eis.", + true); + PropertyDescriptor targetProbabilityProperty = dynamicProperties[targetProbabilityPropertyIndex]; + Assert.IsNotNull(targetProbabilityProperty); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(targetProbabilityProperty, + "Resultaat", + "Doelkans [1/jaar]", + "De ingevoerde kans waarvoor het resultaat moet worden berekend.", + true); + + PropertyDescriptor targetReliabilityProperty = dynamicProperties[targetReliabilityPropertyIndex]; + Assert.IsNotNull(targetReliabilityProperty); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(targetReliabilityProperty, + "Resultaat", + "Betrouwbaarheidsindex doelkans [-]", + "Betrouwbaarheidsindex van de ingevoerde kans waarvoor het resultaat moet worden berekend.", + true); + + PropertyDescriptor calculatedProbabilityProperty = dynamicProperties[calculatedProbabilityPropertyIndex]; + Assert.IsNotNull(calculatedProbabilityProperty); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(calculatedProbabilityProperty, + "Resultaat", + "Berekende kans [1/jaar]", + "De berekende kans van voorkomen van het berekende resultaat.", + true); + + PropertyDescriptor calculatedReliabilityProperty = dynamicProperties[calculatedReliabilityPropertyIndex]; + Assert.IsNotNull(calculatedReliabilityProperty); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(calculatedReliabilityProperty, + "Resultaat", + "Betrouwbaarheidsindex berekende kans [-]", + "Betrouwbaarheidsindex van de berekende kans van voorkomen van het berekende resultaat.", + true); + + PropertyDescriptor convergenceProperty = dynamicProperties[convergencePropertyIndex]; Assert.IsNotNull(convergenceProperty); - Assert.IsTrue(convergenceProperty.IsReadOnly); - Assert.IsTrue(convergenceProperty.IsBrowsable); - Assert.AreEqual(expectedCategory, convergenceProperty.Category); - Assert.AreEqual(expectedConvergenceDisplayName, convergenceProperty.DisplayName); - Assert.AreEqual(expectedConvergenceDescription, convergenceProperty.Description); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(convergenceProperty, + "Resultaat", + "Convergentie", + "Is convergentie bereikt in de berekening van de waterstand bij doorsnede-eis?", + true); } } } \ No newline at end of file