Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/HydraulicBoundaryDatabaseProperties.cs =================================================================== diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -rc596452c5be18e76aea44c66f5b947e8088eacff --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/HydraulicBoundaryDatabaseProperties.cs (.../HydraulicBoundaryDatabaseProperties.cs) (revision ac96d7c315129af851634ed5a4a6800b59ede718) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/HydraulicBoundaryDatabaseProperties.cs (.../HydraulicBoundaryDatabaseProperties.cs) (revision c596452c5be18e76aea44c66f5b947e8088eacff) @@ -80,12 +80,12 @@ set { data.WrappedData.HydraulicBoundaryDatabase.UsePreprocessor = value; + data.WrappedData.NotifyObservers(); } } [PropertyOrder(3)] [DynamicVisible] - [DynamicReadOnly] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.HydraulicBoundaryDatabase_PreprocessorDirectory_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.HydraulicBoundaryDatabase_PreprocessorDirectory_Description))] @@ -102,24 +102,40 @@ } } - [DynamicVisibleValidationMethod] - public bool DynamicVisibleValidationMethod(string propertyName) + [PropertyOrder(4)] + [DynamicVisible] + [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(Resources), nameof(Resources.HydraulicBoundaryDatabase_PreprocessorDirectory_DisplayName))] + [ResourcesDescription(typeof(Resources), nameof(Resources.HydraulicBoundaryDatabase_PreprocessorDirectory_Description))] + public string PreprocessorDirectoryReadOnly { - if (propertyName.Equals(nameof(UsePreprocessor)) || propertyName.Equals(nameof(PreprocessorDirectory))) + get { - return data.WrappedData.HydraulicBoundaryDatabase?.CanUsePreprocessor ?? false; + return data.WrappedData.HydraulicBoundaryDatabase.PreprocessorDirectory; } - return true; } - [DynamicReadOnlyValidationMethod] - public bool DynamicReadOnlyValidationMethod(string propertyName) + [DynamicVisibleValidationMethod] + public bool DynamicVisibleValidationMethod(string propertyName) { - if (propertyName.Equals(nameof(PreprocessorDirectory))) + bool canUsePreprocessor = data.WrappedData.HydraulicBoundaryDatabase?.CanUsePreprocessor ?? false; + + if (propertyName.Equals(nameof(UsePreprocessor)) && !canUsePreprocessor) { - return !data.WrappedData.HydraulicBoundaryDatabase.UsePreprocessor; + return false; } - return false; + + if (propertyName.Equals(nameof(PreprocessorDirectory)) && (!canUsePreprocessor || !UsePreprocessor)) + { + return false; + } + + if (propertyName.Equals(nameof(PreprocessorDirectoryReadOnly)) && (!canUsePreprocessor || UsePreprocessor)) + { + return false; + } + + return true; } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/HydraulicBoundaryDatabasePropertiesTest.cs =================================================================== diff -u -r73162f4fb6fd9caae7e48d464eab43510c70f52b -rc596452c5be18e76aea44c66f5b947e8088eacff --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/HydraulicBoundaryDatabasePropertiesTest.cs (.../HydraulicBoundaryDatabasePropertiesTest.cs) (revision 73162f4fb6fd9caae7e48d464eab43510c70f52b) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/HydraulicBoundaryDatabasePropertiesTest.cs (.../HydraulicBoundaryDatabasePropertiesTest.cs) (revision c596452c5be18e76aea44c66f5b947e8088eacff) @@ -20,9 +20,11 @@ // All rights reserved. using System.ComponentModel; +using Core.Common.Base; using Core.Common.Gui.PropertyBag; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Integration.Data; @@ -82,6 +84,7 @@ Assert.AreEqual(filePath, properties.FilePath); Assert.AreEqual(usePreprocessor, properties.UsePreprocessor); Assert.AreEqual(preprocessorDirectory, properties.PreprocessorDirectory); + Assert.AreEqual(preprocessorDirectory, properties.PreprocessorDirectoryReadOnly); } [Test] @@ -180,16 +183,24 @@ } [Test] - public void UsePreprocessor_SetNewValue_ValueSetToHydraulicBoundaryDataBase([Values(true, false)] bool usePreprocessor) + public void UsePreprocessor_SetNewValue_ValueSetToHydraulicBoundaryDatabaseAndObserversNotified([Values(true, false)] bool usePreprocessor) { // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { CanUsePreprocessor = true, UsePreprocessor = !usePreprocessor, PreprocessorDirectory = "Preprocessor" }; - var context = new HydraulicBoundaryDatabaseContext(new AssessmentSection(AssessmentSectionComposition.Dike)) + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var context = new HydraulicBoundaryDatabaseContext(assessmentSection) { WrappedData = { @@ -198,15 +209,18 @@ }; var properties = new HydraulicBoundaryDatabaseProperties(context); + assessmentSection.Attach(observer); + // Call properties.UsePreprocessor = usePreprocessor; // Assert Assert.AreEqual(usePreprocessor, hydraulicBoundaryDatabase.UsePreprocessor); + mocks.VerifyAll(); } [Test] - public void PreprocessorDirectory_SetNewValue_ValueSetToHydraulicBoundaryDataBase() + public void PreprocessorDirectory_SetNewValue_ValueSetToHydraulicBoundaryDatabase() { // Setup const string newPreprocessorDirectory = @"C:/path"; @@ -233,17 +247,17 @@ } [Test] - [TestCase(true)] - [TestCase(false)] - public void DynamicVisibleValidationMethod_DependingOnCanUsePreprocessor_ReturnExpectedVisibility(bool canUsePreprocessor) + public void DynamicVisibleValidationMethod_DependingOnCanUsePreprocessorAndUsePreprocessor_ReturnExpectedVisibility( + [Values(true, false)] bool canUsePreprocessor, + [Values(true, false)] bool usePreprocessor) { // Setup var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); if (canUsePreprocessor) { hydraulicBoundaryDatabase.CanUsePreprocessor = true; - hydraulicBoundaryDatabase.UsePreprocessor = true; + hydraulicBoundaryDatabase.UsePreprocessor = usePreprocessor; hydraulicBoundaryDatabase.PreprocessorDirectory = "Preprocessor"; } @@ -256,9 +270,10 @@ var properties = new HydraulicBoundaryDatabaseProperties(context); // Assert - Assert.AreEqual(canUsePreprocessor, properties.DynamicVisibleValidationMethod(nameof(properties.UsePreprocessor))); - Assert.AreEqual(canUsePreprocessor, properties.DynamicVisibleValidationMethod(nameof(properties.PreprocessorDirectory))); Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.FilePath))); + Assert.AreEqual(canUsePreprocessor, properties.DynamicVisibleValidationMethod(nameof(properties.UsePreprocessor))); + Assert.AreEqual(canUsePreprocessor && usePreprocessor, properties.DynamicVisibleValidationMethod(nameof(properties.PreprocessorDirectory))); + Assert.AreEqual(canUsePreprocessor && !usePreprocessor, properties.DynamicVisibleValidationMethod(nameof(properties.PreprocessorDirectoryReadOnly))); } [Test] @@ -271,33 +286,10 @@ var properties = new HydraulicBoundaryDatabaseProperties(context); // Assert + Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.FilePath))); Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.UsePreprocessor))); Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.PreprocessorDirectory))); - Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.FilePath))); + Assert.IsFalse(properties.DynamicVisibleValidationMethod(nameof(properties.PreprocessorDirectoryReadOnly))); } - - [Test] - [TestCase(true)] - [TestCase(false)] - public void DynamicReadOnlyValidationMethod_DependingOnUsePreprocessor_ReturnExpectedValue(bool usePreprocessor) - { - // Setup - var context = new HydraulicBoundaryDatabaseContext(new AssessmentSection(AssessmentSectionComposition.Dike) - { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase - { - CanUsePreprocessor = true, - UsePreprocessor = usePreprocessor, - PreprocessorDirectory = "Preprocessor" - } - }); - - // Call - var properties = new HydraulicBoundaryDatabaseProperties(context); - - // Assert - Assert.AreEqual(!usePreprocessor, properties.DynamicReadOnlyValidationMethod(nameof(properties.PreprocessorDirectory))); - Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(properties.UsePreprocessor))); - } } } \ No newline at end of file