Fisheye: Tag c663c013202dfc25dfff35b26a355f164e46ebfa refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingUseBreakWaterProperties.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag c663c013202dfc25dfff35b26a355f164e46ebfa refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/ConfirmingUseForeshoreProperties.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs =================================================================== diff -u -rac05989c50afd4f4b63686ff287225ad0ce0de07 -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision ac05989c50afd4f4b63686ff287225ad0ce0de07) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -522,13 +522,13 @@ [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.BreakWaterProperties_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.BreakWaterProperties_Description))] - public ConfirmingUseBreakWaterProperties UseBreakWater + public UseBreakWaterProperties UseBreakWater { get { return data.WrappedData.ForeshoreProfile == null ? - new ConfirmingUseBreakWaterProperties() : - new ConfirmingUseBreakWaterProperties(data.WrappedData, data.Calculation, PropertyChangeHandler); + new UseBreakWaterProperties() : + new UseBreakWaterProperties(data.WrappedData, data.Calculation, PropertyChangeHandler); } } @@ -537,11 +537,11 @@ [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.ForeshoreProperties_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.ForeshoreProperties_Description))] - public ConfirmingUseForeshoreProperties UseForeshore + public UseForeshoreProperties UseForeshore { get { - return new ConfirmingUseForeshoreProperties(data.WrappedData, data.Calculation, PropertyChangeHandler); + return new UseForeshoreProperties(data.WrappedData, data.Calculation, PropertyChangeHandler); } } Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/UseBreakWaterProperties.cs =================================================================== diff -u -r69eb8c7057601ce45297368b9281ea1e60980f28 -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/UseBreakWaterProperties.cs (.../UseBreakWaterProperties.cs) (revision 69eb8c7057601ce45297368b9281ea1e60980f28) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/UseBreakWaterProperties.cs (.../UseBreakWaterProperties.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -20,12 +20,14 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.ComponentModel; +using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Gui.Attributes; using Core.Common.Utils; using Core.Common.Utils.Attributes; -using Core.Common.Utils.Reflection; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Forms.Properties; using Ringtoets.Common.Forms.TypeConverters; @@ -35,34 +37,49 @@ /// /// ViewModel of . /// - public class UseBreakWaterProperties + public class UseBreakWaterProperties + where TCalculationInput : ICalculationInput, IUseBreakWater { private const int useBreakWaterPropertyIndex = 1; private const int breakWaterTypePropertyIndex = 2; private const int breakWaterHeightPropertyIndex = 3; - private readonly IUseBreakWater data; - private readonly IPropertyChangeHandler changeHandler; + private readonly TCalculationInput data; + private readonly ICalculation calculation; + private readonly ICalculationInputPropertyChangeHandler changeHandler; /// - /// Creates a new instance of , in which - /// all the properties are read only. + /// Creates a new instance of , in which + /// all the properties are read-only and empty. /// public UseBreakWaterProperties() { } /// - /// Creates a new instance of in which the + /// Creates a new instance of in which the /// properties are editable. /// /// The data to use for the properties. + /// The calculation to which the belongs. /// Optional handler that is used to handle property changes. /// Thrown when any input parameter is null. - public UseBreakWaterProperties(IUseBreakWater useBreakWaterData, IPropertyChangeHandler handler) + public UseBreakWaterProperties( + TCalculationInput useBreakWaterData, + ICalculation calculation, + ICalculationInputPropertyChangeHandler handler) { if (useBreakWaterData == null) { throw new ArgumentNullException(nameof(useBreakWaterData)); } + if (calculation == null) + { + throw new ArgumentNullException(nameof(calculation)); + } + if (handler == null) + { + throw new ArgumentNullException(nameof(handler)); + } data = useBreakWaterData; + this.calculation = calculation; changeHandler = handler; } @@ -78,8 +95,12 @@ } set { - data.UseBreakWater = value; - NotifyPropertyChanged(); + IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation( + data, + calculation, + value, + (input, d) => data.UseBreakWater = d); + NotifyAffectedObjects(affectedObjects); } } @@ -98,8 +119,12 @@ { if (value.HasValue) { - data.BreakWater.Type = value.Value; - NotifyPropertyChanged(); + IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation( + data, + calculation, + value.Value, + (input, d) => data.BreakWater.Type = d); + NotifyAffectedObjects(affectedObjects); } } } @@ -117,16 +142,20 @@ } set { - data.BreakWater.Height = value; - NotifyPropertyChanged(); + IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation( + data, + calculation, + value, + (input, d) => data.BreakWater.Height = d); + NotifyAffectedObjects(affectedObjects); } } [DynamicReadOnlyValidationMethod] public bool DynamicReadOnlyValidationMethod(string propertyName) { return data == null || - !propertyName.Equals(TypeUtils.GetMemberName(i => i.UseBreakWater)) && + !propertyName.Equals(nameof(UseBreakWater)) && !UseBreakWater; } @@ -135,10 +164,12 @@ return string.Empty; } - private void NotifyPropertyChanged() + private static void NotifyAffectedObjects(IEnumerable affectedObjects) { - changeHandler?.PropertyChanged(); - data.NotifyObservers(); + foreach (var affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); + } } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/UseForeshoreProperties.cs =================================================================== diff -u -r69eb8c7057601ce45297368b9281ea1e60980f28 -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/UseForeshoreProperties.cs (.../UseForeshoreProperties.cs) (revision 69eb8c7057601ce45297368b9281ea1e60980f28) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/UseForeshoreProperties.cs (.../UseForeshoreProperties.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -20,12 +20,15 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Gui.Attributes; using Core.Common.Gui.Converters; using Core.Common.Utils.Attributes; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Forms.Properties; @@ -34,33 +37,40 @@ /// /// ViewModel of . /// - public class UseForeshoreProperties + public class UseForeshoreProperties where TCalculationInput : ICalculationInput, IUseForeshore { private const int useForeshorePropertyIndex = 1; private const int coordinatesPropertyIndex = 2; - private readonly IUseForeshore data; - private readonly IPropertyChangeHandler changeHandler; + private readonly TCalculationInput data; + private readonly ICalculationInputPropertyChangeHandler changeHandler; + private readonly ICalculation calculation; /// - /// Creates a new instance of , in which - /// all the properties are read only. + /// Creates a new instance of . /// - public UseForeshoreProperties() { } - - /// - /// Creates a new instance of . - /// /// The data to use for the properties. + /// The calculation to which the belongs. /// Optional handler that is used to handle property changes. - /// If is null, all properties will - /// be set to . - public UseForeshoreProperties(IUseForeshore useForeshoreData, IPropertyChangeHandler handler) + /// Thrown when any input parameter is null. + public UseForeshoreProperties( + TCalculationInput useForeshoreData, + ICalculation calculation, + ICalculationInputPropertyChangeHandler handler) { if (useForeshoreData == null) { throw new ArgumentNullException(nameof(useForeshoreData)); } + if (calculation == null) + { + throw new ArgumentNullException(nameof(calculation)); + } + if (handler == null) + { + throw new ArgumentNullException(nameof(handler)); + } data = useForeshoreData; + this.calculation = calculation; changeHandler = handler; } @@ -76,8 +86,12 @@ } set { - data.UseForeshore = value; - NotifyPropertyChanged(); + IEnumerable affectedObjects = changeHandler.SetPropertyValueAfterConfirmation( + data, + calculation, + value, + (input, d) => data.UseForeshore = d); + NotifyAffectedObjects(affectedObjects); } } @@ -104,10 +118,12 @@ return string.Empty; } - private void NotifyPropertyChanged() + private static void NotifyAffectedObjects(IEnumerable affectedObjects) { - changeHandler?.PropertyChanged(); - data.NotifyObservers(); + foreach (var affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); + } } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -r0c17207d7682c740778dc3e665b5f1dfc70c37dd -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 0c17207d7682c740778dc3e665b5f1dfc70c37dd) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -92,9 +92,7 @@ - - Fisheye: Tag c663c013202dfc25dfff35b26a355f164e46ebfa refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingUseBreakWaterPropertiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag c663c013202dfc25dfff35b26a355f164e46ebfa refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/ConfirmingUseForeshorePropertiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs =================================================================== diff -u -rd4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04 -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision d4e6fdd1b3c4e1f7f39ce1707cb9ae4241ac6e04) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -159,8 +159,8 @@ Assert.AreSame(input.WidthFlowApertures, properties.WidthFlowApertures.Data); Assert.AreSame(input.CriticalOvertoppingDischarge, properties.CriticalOvertoppingDischarge.Data); Assert.IsNull(properties.ForeshoreProfile); - Assert.IsInstanceOf>(properties.UseBreakWater); - Assert.IsInstanceOf>(properties.UseForeshore); + Assert.IsInstanceOf>(properties.UseBreakWater); + Assert.IsInstanceOf>(properties.UseForeshore); Assert.AreEqual(expectedFailureProbabilityStructureWithErosion, properties.FailureProbabilityStructureWithErosion); Assert.IsNull(properties.SelectedHydraulicBoundaryLocation); Assert.AreSame(input.StormDuration, properties.StormDuration.Data); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseBreakWaterPropertiesTest.cs =================================================================== diff -u -rf18ccfb35619abc909207957f0d62cca17013e5d -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseBreakWaterPropertiesTest.cs (.../UseBreakWaterPropertiesTest.cs) (revision f18ccfb35619abc909207957f0d62cca17013e5d) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseBreakWaterPropertiesTest.cs (.../UseBreakWaterPropertiesTest.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -28,6 +28,7 @@ using Core.Common.Utils; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.PropertyClasses; @@ -43,7 +44,7 @@ public void DefaultConstructor_ExpectedValues() { // Call - var properties = new UseBreakWaterProperties(); + var properties = new UseBreakWaterProperties(); // Assert Assert.IsFalse(properties.UseBreakWater); @@ -56,7 +57,7 @@ public void DefaultConstructor_Always_ReadOnlyProperties() { // Call - var properties = new UseBreakWaterProperties(); + var properties = new UseBreakWaterProperties(); // Assert var dynamicPropertyBag = new DynamicPropertyBag(properties); @@ -91,49 +92,23 @@ } [Test] - public void Constructor_UseBreakWaterDataNull_ThrowsArgumentNullException() - { - // Call - TestDelegate test = () => new UseBreakWaterProperties(null, null); - - // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("useBreakWaterData", paramName); - } - - [Test] - public void Constructor_WithUseBreakWaterData_ExpectedValues() - { - // Setup - var useBreakWaterData = new TestUseBreakWater - { - UseBreakWater = true, - BreakWater = new BreakWater(BreakWaterType.Caisson, 10) - }; - - // Call - var properties = new UseBreakWaterProperties(useBreakWaterData, null); - - // Assert - Assert.IsTrue(properties.UseBreakWater); - Assert.AreEqual(BreakWaterType.Caisson, properties.BreakWaterType); - Assert.AreEqual(10, properties.BreakWaterHeight, properties.BreakWaterHeight.GetAccuracy()); - Assert.AreEqual(string.Empty, properties.ToString()); - } - - [Test] [TestCase(true)] [TestCase(false)] public void Constructor_WithBreakWaterAndCalculationUseBreakWater_ReturnExpectedProperties(bool useBreakWater) { // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + TestUseBreakWater testUseBreakWater = new TestUseBreakWater { UseBreakWater = useBreakWater }; // Call - var properties = new UseBreakWaterProperties(testUseBreakWater, null); + var properties = new UseBreakWaterProperties(testUseBreakWater, calculation, handler); // Assert var dynamicPropertyBag = new DynamicPropertyBag(properties); @@ -164,91 +139,157 @@ "Hoogte [m+NAP]", "De hoogte van de dam.", !useBreakWater); + mocks.VerifyAll(); } [Test] - public void SetProperties_IndividualProperties_UpdateData() + public void Constructor_UseBreakWaterDataNull_ThrowsArgumentNullException() { // Setup - var breakWater = new BreakWater(BreakWaterType.Caisson, 2.2); - var testUseBreakWater = new TestUseBreakWater + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => new UseBreakWaterProperties(null, calculation, handler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("useBreakWaterData", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_CalculationNull_ThrowsArgumentNullException() + { + // Setup + TestUseBreakWater testUseBreakWater = new TestUseBreakWater(); + + var mocks = new MockRepository(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => new UseBreakWaterProperties(testUseBreakWater, null, handler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("calculation", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_HandlerNull_ThrowsArgumentNullException() + { + // Setup + TestUseBreakWater testUseBreakWater = new TestUseBreakWater(); + + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => new UseBreakWaterProperties(testUseBreakWater, calculation, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("handler", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_WithUseBreakWaterData_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + var useBreakWaterData = new TestUseBreakWater { - BreakWater = breakWater + UseBreakWater = true, + BreakWater = new BreakWater(BreakWaterType.Caisson, 10) }; - var properties = new UseBreakWaterProperties(testUseBreakWater, null); // Call - properties.UseBreakWater = true; - properties.BreakWaterType = BreakWaterType.Dam; - properties.BreakWaterHeight = (RoundedDouble) 1.1; + var properties = new UseBreakWaterProperties(useBreakWaterData, calculation, handler); // Assert Assert.IsTrue(properties.UseBreakWater); - Assert.AreEqual(BreakWaterType.Dam, properties.BreakWaterType); - Assert.AreEqual(1.1, properties.BreakWaterHeight, properties.BreakWaterHeight.GetAccuracy()); + Assert.AreEqual(BreakWaterType.Caisson, properties.BreakWaterType); + Assert.AreEqual(10, properties.BreakWaterHeight, properties.BreakWaterHeight.GetAccuracy()); Assert.AreEqual(string.Empty, properties.ToString()); + mocks.VerifyAll(); } [Test] - [TestCase(true)] - [TestCase(false)] - public void DikeHeight_WithOrWithoutOutput_InputNotifiedAndPropertyChangedCalled(bool hasOutput) + public void DikeHeight_Always_InputNotifiedAndPropertyChangedCalled() { - SetPropertyAndVerifyNotifcationsAndHandlerCall(hasOutput, properties => properties.BreakWaterHeight = new Random(21).NextRoundedDouble()); + var breakWaterHeight = new Random(21).NextRoundedDouble(); + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.BreakWaterHeight = breakWaterHeight, + breakWaterHeight, + new TestUseBreakWater()); } [Test] - [TestCase(true)] - [TestCase(false)] - public void BreakWaterType_WithOrWithoutOutput_InputNotifiedAndPropertyChangedCalled(bool hasOutput) + public void BreakWaterType_Always_InputNotifiedAndPropertyChangedCalled() { - SetPropertyAndVerifyNotifcationsAndHandlerCall(hasOutput, properties => properties.BreakWaterType = new Random(21).NextEnumValue()); + var type = new Random(21).NextEnumValue(); + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.BreakWaterType = type, + type, + new TestUseBreakWater()); } [Test] - [TestCase(true)] - [TestCase(false)] - public void UseBreakWater_WithOrWithoutOutput_InputNotifiedAndPropertyChangedCalled(bool hasOutput) + public void UseBreakWater_Always_InputNotifiedAndPropertyChangedCalled() { - SetPropertyAndVerifyNotifcationsAndHandlerCall(hasOutput, properties => properties.UseBreakWater = new Random(21).NextBoolean()); + var useBreakWater = new Random(21).NextBoolean(); + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.UseBreakWater = useBreakWater, + useBreakWater, + new TestUseBreakWater()); } - private class TestUseBreakWater : Observable, IUseBreakWater + public class TestUseBreakWater : Observable, ICalculationInput, IUseBreakWater { + public TestUseBreakWater() + { + BreakWater = new BreakWater(BreakWaterType.Caisson, 2); + } + public bool UseBreakWater { get; set; } public BreakWater BreakWater { get; set; } } - private void SetPropertyAndVerifyNotifcationsAndHandlerCall( - bool hasOutput, - Action setProperty) + private void SetPropertyAndVerifyNotifcationsAndOutputForCalculation( + Action> setProperty, + TPropertyValue expectedValueSet, + TestUseBreakWater input) { // Setup var mocks = new MockRepository(); - var calculationObserver = mocks.StrictMock(); - var inputObserver = mocks.StrictMock(); - inputObserver.Expect(o => o.UpdateObserver()); - var handler = mocks.StrictMock(); - handler.Expect(o => o.PropertyChanged()); + var calculation = mocks.Stub(); + var observable = mocks.StrictMock(); + observable.Expect(o => o.NotifyObservers()); mocks.ReplayAll(); - var calculation = new TestCalculation(); - if (hasOutput) - { - calculation.Output = new object(); - } + var handler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester( + input, + calculation, + expectedValueSet, + new[] + { + observable + }); - calculation.Attach(calculationObserver); - var input = new TestUseBreakWater(); - input.Attach(inputObserver); - input.BreakWater = new BreakWater(BreakWaterType.Caisson, 3.2); + var properties = new UseBreakWaterProperties(input, calculation, handler); - var properties = new UseBreakWaterProperties(input, handler); - // Call setProperty(properties); // Assert + Assert.IsTrue(handler.Called); mocks.VerifyAll(); } } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseForeshorePropertiesTest.cs =================================================================== diff -u -rf18ccfb35619abc909207957f0d62cca17013e5d -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseForeshorePropertiesTest.cs (.../UseForeshorePropertiesTest.cs) (revision f18ccfb35619abc909207957f0d62cca17013e5d) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/UseForeshorePropertiesTest.cs (.../UseForeshorePropertiesTest.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -28,6 +28,7 @@ using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TestUtil; @@ -38,64 +39,57 @@ public class UseForeshorePropertiesTest { [Test] - public void DefaultConstructor_ExpectedValues() + public void Constructor_UseForeshoreDataNull_ThrowsArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + // Call - var properties = new UseForeshoreProperties(); + TestDelegate test = () => new UseForeshoreProperties(null, calculation, handler); // Assert - Assert.IsFalse(properties.UseForeshore); - Assert.IsNull(properties.Coordinates); - Assert.AreEqual(string.Empty, properties.ToString()); - - PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(2, dynamicProperties.Count); - - PropertyDescriptor useForeshoreProperty = dynamicProperties[0]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(useForeshoreProperty, - "Misc", - "Gebruik", - "Moet de voorlandgeometrie worden gebruikt tijdens de berekening?", - true); - - PropertyDescriptor coordinatesProperty = dynamicProperties[1]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(coordinatesProperty, - "Misc", - "Coördinaten [m]", - "Lijst met punten in lokale coördinaten.", - true); + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("useForeshoreData", paramName); + mocks.VerifyAll(); } [Test] - public void Constructor_WithDataWithoutForeshoreGeometryExpectedValues() + public void Constructor_CalculationNull_ThrowsArgumentNullException() { // Setup - var useForeshoreData = new TestUseForeshore(); + TestUseForeshore testUseForeshore = new TestUseForeshore(); + var mocks = new MockRepository(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + // Call - var properties = new UseForeshoreProperties(useForeshoreData, null); + TestDelegate test = () => new UseForeshoreProperties(testUseForeshore, null, handler); // Assert - Assert.IsFalse(properties.UseForeshore); - Assert.IsNull(properties.Coordinates); - Assert.AreEqual(string.Empty, properties.ToString()); + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("calculation", paramName); + } - PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(2, dynamicProperties.Count); + [Test] + public void Constructor_HandlerNull_ThrowsArgumentNullException() + { + // Setup + TestUseForeshore testUseForeshore = new TestUseForeshore(); - PropertyDescriptor useForeshoreProperty = dynamicProperties[0]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(useForeshoreProperty, - "Misc", - "Gebruik", - "Moet de voorlandgeometrie worden gebruikt tijdens de berekening?", - true); + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + mocks.ReplayAll(); - PropertyDescriptor coordinatesProperty = dynamicProperties[1]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(coordinatesProperty, - "Misc", - "Coördinaten [m]", - "Lijst met punten in lokale coördinaten.", - true); + // Call + TestDelegate test = () => new UseForeshoreProperties(testUseForeshore, calculation, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("handler", paramName); } [TestCase(0, false)] @@ -104,14 +98,19 @@ public void Constructor_WithDataWithForeshoreGeometryVariousNumberOfElements_ReturnExpectedValues(int numberOfPoint2D, bool isEnabled) { // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + var useForeshoreData = new TestUseForeshore { ForeshoreGeometry = new RoundedPoint2DCollection( 0, Enumerable.Repeat(new Point2D(0, 0), numberOfPoint2D).ToArray()) }; // Call - var properties = new UseForeshoreProperties(useForeshoreData, null); + var properties = new UseForeshoreProperties(useForeshoreData, calculation, handler); // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); @@ -131,29 +130,41 @@ "Lijst met punten in lokale coördinaten.", true); } - [Test] - public void Constructor_WithUseForeshoreDataNull_ThrowsArgumentNullException() + public void Constructor_WithDataWithoutForeshoreGeometry_CoordinatesNull() { + // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + var useForeshoreData = new TestUseForeshore(); + // Call - TestDelegate test = () => new UseForeshoreProperties(null, null); + var properties = new UseForeshoreProperties(useForeshoreData, calculation, handler); // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("useForeshoreData", paramName); + Assert.IsFalse(properties.UseForeshore); + Assert.IsNull(properties.Coordinates); } [Test] public void Constructor_ValidData_ExpectedValues() { // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + var useForeshoreData = new TestUseForeshore { UseForeshore = true }; // Call - var properties = new UseForeshoreProperties(useForeshoreData, null); + var properties = new UseForeshoreProperties(useForeshoreData, calculation, handler); // Assert Assert.IsTrue(properties.UseForeshore); @@ -165,6 +176,11 @@ public void GetProperties_ValidUseForeshore_ExpectedValues() { // Setup + var mocks = new MockRepository(); + var calculation = mocks.Stub(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + var geometry = new[] { new Point2D(1, 1) @@ -176,63 +192,54 @@ }; // Call - var properties = new UseForeshoreProperties(useForeshoreData, null); + var properties = new UseForeshoreProperties(useForeshoreData, calculation, handler); // Assert Assert.IsTrue(properties.UseForeshore); Assert.AreEqual(geometry, properties.Coordinates); } [Test] - public void SetProperties_IndividualProperties_UpdateData() + public void UseForeshore_Always_InputNotifiedAndPropertyChangedCalled() { - // Setup - var useForeshoreData = new TestUseForeshore(); - var properties = new UseForeshoreProperties(useForeshoreData, null); - - // Call - properties.UseForeshore = true; - - // Assert - Assert.IsTrue(properties.UseForeshore); - Assert.IsNull(properties.Coordinates); - Assert.AreEqual(string.Empty, properties.ToString()); + var useForeshore = new Random(21).NextBoolean(); + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(properties => properties.UseForeshore = useForeshore, + useForeshore, + new TestUseForeshore()); } - [Test] - [TestCase(true)] - [TestCase(false)] - public void UseForeshore_WithOrWithoutOutput_InputNotifiedAndPropertyChangedCalled(bool hasOutput) + private void SetPropertyAndVerifyNotifcationsAndOutputForCalculation( + Action> setProperty, + TPropertyValue expectedValueSet, + TestUseForeshore input) { // Setup var mocks = new MockRepository(); - var calculationObserver = mocks.StrictMock(); - var inputObserver = mocks.StrictMock(); - inputObserver.Expect(o => o.UpdateObserver()); - var handler = mocks.StrictMock(); - handler.Expect(o => o.PropertyChanged()); + var calculation = mocks.Stub(); + var observable = mocks.StrictMock(); + observable.Expect(o => o.NotifyObservers()); mocks.ReplayAll(); - var calculation = new TestCalculation(); - if (hasOutput) - { - calculation.Output = new object(); - } + var handler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester( + input, + calculation, + expectedValueSet, + new[] + { + observable + }); - calculation.Attach(calculationObserver); - var input = new TestUseForeshore(); - input.Attach(inputObserver); + var properties = new UseForeshoreProperties(input, calculation, handler); - var properties = new UseForeshoreProperties(input, handler); - // Call - properties.UseForeshore = true; + setProperty(properties); // Assert + Assert.IsTrue(handler.Called); mocks.VerifyAll(); } - private class TestUseForeshore : Observable, IUseForeshore + public class TestUseForeshore : Observable, ICalculationInput, IUseForeshore { public bool UseForeshore { get; set; } public RoundedPoint2DCollection ForeshoreGeometry { get; set; } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -r0c17207d7682c740778dc3e665b5f1dfc70c37dd -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 0c17207d7682c740778dc3e665b5f1dfc70c37dd) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -92,9 +92,7 @@ - - Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs (.../GrassCoverErosionInwardsInputContextProperties.cs) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs (.../GrassCoverErosionInwardsInputContextProperties.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -146,13 +146,13 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.BreakWaterProperties_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.BreakWaterProperties_Description))] - public ConfirmingUseBreakWaterProperties BreakWater + public UseBreakWaterProperties BreakWater { get { return data.WrappedData.DikeProfile == null ? - new ConfirmingUseBreakWaterProperties() : - new ConfirmingUseBreakWaterProperties( + new UseBreakWaterProperties() : + new UseBreakWaterProperties( data.WrappedData, data.Calculation, propertyChangeHandler); } } @@ -162,11 +162,11 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.ForeshoreProperties_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.ForeshoreProperties_Description))] - public ConfirmingUseForeshoreProperties Foreshore + public UseForeshoreProperties Foreshore { get { - return new ConfirmingUseForeshoreProperties( + return new UseForeshoreProperties( data.WrappedData, data.Calculation, propertyChangeHandler); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsInputContextPropertiesTest.cs =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsInputContextPropertiesTest.cs (.../GrassCoverErosionInwardsInputContextPropertiesTest.cs) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsInputContextPropertiesTest.cs (.../GrassCoverErosionInwardsInputContextPropertiesTest.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -157,9 +157,9 @@ Assert.AreEqual(2, properties.Orientation.NumberOfDecimalPlaces); Assert.IsNull(properties.DikeProfile); Assert.IsNaN(properties.Orientation.Value); - Assert.IsInstanceOf>( + Assert.IsInstanceOf>( properties.BreakWater); - Assert.IsInstanceOf>( + Assert.IsInstanceOf>( properties.Foreshore); Assert.AreSame(inputContext, properties.DikeGeometry.Data); Assert.AreEqual(2, properties.DikeHeight.NumberOfDecimalPlaces); @@ -196,9 +196,9 @@ Assert.AreEqual(2, properties.Orientation.NumberOfDecimalPlaces); Assert.AreSame(input.DikeProfile, properties.DikeProfile); Assert.AreEqual(0.0, properties.Orientation.Value); - Assert.IsInstanceOf>( + Assert.IsInstanceOf>( properties.BreakWater); - Assert.IsInstanceOf>( + Assert.IsInstanceOf>( properties.Foreshore); Assert.AreSame(inputContext, properties.DikeGeometry.Data); Assert.AreEqual(2, properties.DikeHeight.NumberOfDecimalPlaces); Index: Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/PropertyClasses/WaveConditionsInputContextProperties.cs =================================================================== diff -u -r084a9c1b1f635d7789fc1a538fbe591557e21ac1 -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/PropertyClasses/WaveConditionsInputContextProperties.cs (.../WaveConditionsInputContextProperties.cs) (revision 084a9c1b1f635d7789fc1a538fbe591557e21ac1) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.Forms/PropertyClasses/WaveConditionsInputContextProperties.cs (.../WaveConditionsInputContextProperties.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -245,13 +245,13 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.BreakWaterProperties_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.BreakWaterProperties_Description))] - public ConfirmingUseBreakWaterProperties BreakWater + public UseBreakWaterProperties BreakWater { get { return data.WrappedData.ForeshoreProfile == null ? - new ConfirmingUseBreakWaterProperties() : - new ConfirmingUseBreakWaterProperties(data.WrappedData, data.Calculation, propertyChangeHandler); + new UseBreakWaterProperties() : + new UseBreakWaterProperties(data.WrappedData, data.Calculation, propertyChangeHandler); } } @@ -260,11 +260,11 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.ForeshoreProperties_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.ForeshoreProperties_Description))] - public ConfirmingUseForeshoreProperties ForeshoreGeometry + public UseForeshoreProperties ForeshoreGeometry { get { - return new ConfirmingUseForeshoreProperties(data.WrappedData, data.Calculation, propertyChangeHandler); + return new UseForeshoreProperties(data.WrappedData, data.Calculation, propertyChangeHandler); } } Index: Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/PropertyClasses/WaveConditionsInputContextPropertiesTest.cs =================================================================== diff -u -r242268fc2adc055cc3ac4f28b14b4db26251b30e -rc663c013202dfc25dfff35b26a355f164e46ebfa --- Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/PropertyClasses/WaveConditionsInputContextPropertiesTest.cs (.../WaveConditionsInputContextPropertiesTest.cs) (revision 242268fc2adc055cc3ac4f28b14b4db26251b30e) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.Forms.Test/PropertyClasses/WaveConditionsInputContextPropertiesTest.cs (.../WaveConditionsInputContextPropertiesTest.cs) (revision c663c013202dfc25dfff35b26a355f164e46ebfa) @@ -167,8 +167,8 @@ Assert.AreEqual(2, properties.LowerBoundaryWaterLevels.NumberOfDecimalPlaces); Assert.AreEqual(0.5, properties.StepSize.AsValue()); CollectionAssert.AreEqual(input.WaterLevels, properties.WaterLevels); - Assert.IsInstanceOf>(properties.BreakWater); - Assert.IsInstanceOf>(properties.ForeshoreGeometry); + Assert.IsInstanceOf>(properties.BreakWater); + Assert.IsInstanceOf>(properties.ForeshoreGeometry); Assert.AreEqual("Test", properties.RevetmentType); Assert.AreSame(hydraulicBoundaryLocation, properties.SelectedHydraulicBoundaryLocation.HydraulicBoundaryLocation);