Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs =================================================================== diff -u -r8cd6600dd3e505a336f657b1e63362ac3b94943c -rf3c7ae4cc9069268dba97e9dd691bf449fa393db --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision 8cd6600dd3e505a336f657b1e63362ac3b94943c) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision f3c7ae4cc9069268dba97e9dd691bf449fa393db) @@ -184,12 +184,7 @@ const string hydraulicDataCategory = "Hydraulische gegevens"; const string modelSettingsCategory = "Modelinstellingen"; - var dynamicPropertyBag = new DynamicPropertyBag(properties); - PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties( - new Attribute[] - { - new BrowsableAttribute(true) - }); + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(15, dynamicProperties.Count); PropertyDescriptor structureProperty = dynamicProperties[constructionProperties.StructurePropertyIndex]; @@ -205,7 +200,7 @@ Assert.AreEqual("De coördinaten van de locatie van het kunstwerk in het Rijksdriehoeksstelsel.", structureLocationProperty.Description); PropertyDescriptor structureNormalOrientationProperty = dynamicProperties[constructionProperties.StructureNormalOrientationPropertyIndex]; - Assert.IsFalse(structureNormalOrientationProperty.IsReadOnly); + Assert.IsTrue(structureNormalOrientationProperty.IsReadOnly); Assert.AreEqual(schematizationCategory, structureNormalOrientationProperty.Category); Assert.AreEqual("Oriëntatie [°]", structureNormalOrientationProperty.DisplayName); Assert.AreEqual("Oriëntatie van de normaal van het kunstwerk ten opzichte van het noorden.", structureNormalOrientationProperty.Description); @@ -288,6 +283,52 @@ } [Test] + [TestCase(true)] + [TestCase(false)] + public void Constructor_WithOrWithoutStructure_CorrectReadOnlyForStructureDependentProperties(bool hasStructure) + { + // Setup + mockRepository.ReplayAll(); + + StructuresInputBaseProperties< + SimpleStructure, + SimpleStructureInput, + StructuresCalculation, + IFailureMechanism> + .ConstructionProperties constructionProperties = GetRandomConstructionProperties(); + var calculation = new StructuresCalculation(); + var inputContext = new SimpleInputContext(calculation.InputParameters, + calculation, + failureMechanism, + assessmentSection); + + if (hasStructure) + { + calculation.InputParameters.Structure = new SimpleStructure(); + } + + // Call + var properties = new SimpleStructuresInputProperties( + inputContext, + constructionProperties, + handler); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + + bool expectedReadOnly = !hasStructure; + + PropertyDescriptor structureNormalOrientationProperty = dynamicProperties[constructionProperties.StructureNormalOrientationPropertyIndex]; + Assert.AreEqual(expectedReadOnly, structureNormalOrientationProperty.IsReadOnly); + + AssertPropertiesInState(properties.FlowWidthAtBottomProtection, expectedReadOnly); + AssertPropertiesInState(properties.WidthFlowApertures, expectedReadOnly); + AssertPropertiesInState(properties.StorageStructureArea, expectedReadOnly); + AssertPropertiesInState(properties.AllowedLevelIncreaseStorage, expectedReadOnly); + AssertPropertiesInState(properties.CriticalOvertoppingDischarge, expectedReadOnly); + } + + [Test] public void SelectedHydraulicBoundaryLocation_InputNoLocation_ReturnsNull() { // Setup @@ -1139,6 +1180,7 @@ var calculation = new StructuresCalculation(); SimpleStructureInput input = calculation.InputParameters; input.ForeshoreProfile = new TestForeshoreProfile(); + input.Structure = new SimpleStructure(); var customHandler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester(new[] { @@ -1159,5 +1201,14 @@ mockRepository.VerifyAll(); } + + private static void AssertPropertiesInState(object properties, bool expectedReadOnly) + { + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(3, dynamicProperties.Count); + + Assert.AreEqual(expectedReadOnly, dynamicProperties[1].IsReadOnly); + Assert.AreEqual(expectedReadOnly, dynamicProperties[2].IsReadOnly); + } } } \ No newline at end of file