Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresFailureMechanismProperties.cs =================================================================== diff -u -r4d77063761342b4686ef4a56c47874558a53dec7 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresFailureMechanismProperties.cs (.../ClosingStructuresFailureMechanismProperties.cs) (revision 4d77063761342b4686ef4a56c47874558a53dec7) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresFailureMechanismProperties.cs (.../ClosingStructuresFailureMechanismProperties.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.ComponentModel; using Core.Common.Base; using Core.Common.Base.Data; @@ -52,7 +53,7 @@ private const int modelFactorSubCriticalFlowPropertyIndex = 9; private const int modelFactorInflowVolumePropertyIndex = 10; - private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; + private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; /// /// Creates a new instance of . @@ -62,15 +63,15 @@ /// Thrown when any input parameter is null. public ClosingStructuresFailureMechanismProperties( ClosingStructuresFailureMechanism data, - IFailureMechanismPropertyChangeHandler handler) + IFailureMechanismPropertyChangeHandler handler) { if (data == null) { - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); } if (handler == null) { - throw new ArgumentNullException("handler"); + throw new ArgumentNullException(nameof(handler)); } Data = data; propertyChangeHandler = handler; @@ -102,11 +103,12 @@ } set { - if (propertyChangeHandler.ConfirmPropertyChange()) - { - data.GeneralInput.N2A = value; - ClearOutputAndNotifyObservers(); - } + IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation( + data, + value, + (f, v) => f.GeneralInput.N2A = v); + + NotifyAffectedObjects(affectedObjects); } } @@ -228,13 +230,12 @@ #endregion - private void ClearOutputAndNotifyObservers() + private static void NotifyAffectedObjects(IEnumerable affectedObjects) { - foreach (IObservable changedObject in propertyChangeHandler.PropertyChanged(data)) + foreach (var affectedObject in affectedObjects) { - changedObject.NotifyObservers(); + affectedObject.NotifyObservers(); } - data.NotifyObservers(); } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -r2a0fbe6ec22928831305671ecd4f41030b827250 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 2a0fbe6ec22928831305671ecd4f41030b827250) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -63,7 +63,7 @@ { CreateInstance = context => new ClosingStructuresFailureMechanismProperties( context.WrappedData, - new FailureMechanismPropertyChangeHandler()) + new FailureMechanismPropertyChangeHandler()) }; yield return new PropertyInfo(); yield return new PropertyInfo Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesTest.cs =================================================================== diff -u -r4d77063761342b4686ef4a56c47874558a53dec7 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesTest.cs (.../ClosingStructuresFailureMechanismPropertiesTest.cs) (revision 4d77063761342b4686ef4a56c47874558a53dec7) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesTest.cs (.../ClosingStructuresFailureMechanismPropertiesTest.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -21,16 +21,15 @@ using System; using System.ComponentModel; -using System.Linq; using Core.Common.Base; using Core.Common.Gui.PropertyBag; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.ClosingStructures.Data; using Ringtoets.ClosingStructures.Forms.PropertyClasses; -using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.Common.Forms.TestUtil; namespace Ringtoets.ClosingStructures.Forms.Test.PropertyClasses { @@ -42,11 +41,12 @@ { // Setup var mocks = new MockRepository(); - IFailureMechanismPropertyChangeHandler handler = CreateSimpleHandler(mocks); + IFailureMechanismPropertyChangeHandler changeHandler = + mocks.Stub>(); mocks.ReplayAll(); // Call - TestDelegate test = () => new ClosingStructuresFailureMechanismProperties(null, handler); + TestDelegate test = () => new ClosingStructuresFailureMechanismProperties(null, changeHandler); // Assert string paramName = Assert.Throws(test).ParamName; @@ -72,7 +72,8 @@ { // Setup MockRepository mocks = new MockRepository(); - IFailureMechanismPropertyChangeHandler changeHandler = CreateSimpleHandler(mocks); + IFailureMechanismPropertyChangeHandler changeHandler = + mocks.Stub>(); mocks.ReplayAll(); var failureMechanism = new ClosingStructuresFailureMechanism(); @@ -113,7 +114,8 @@ { // Setup var mocks = new MockRepository(); - var changeHandler = CreateSimpleHandler(mocks); + IFailureMechanismPropertyChangeHandler changeHandler = + mocks.Stub>(); mocks.ReplayAll(); // Call @@ -211,20 +213,22 @@ public void N2A_InvalidValueWithConfirmation_UpdateDataAndNotifyObservers(int value) { // Setup - var mockRepository = new MockRepository(); - var observerMock = mockRepository.StrictMock(); - - var handler = mockRepository.Stub>(); - handler.Expect(h => h.ConfirmPropertyChange()).Return(true); - + var observableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); var failureMechanism = new ClosingStructuresFailureMechanism(); - failureMechanism.Attach(observerMock); - var properties = new ClosingStructuresFailureMechanismProperties(failureMechanism, handler); + var changeHandler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + value, + new[] + { + observableMock + }); + var properties = new ClosingStructuresFailureMechanismProperties(failureMechanism, changeHandler); + // Call TestDelegate test = () => properties.N2A = value; @@ -244,21 +248,19 @@ var failureMechanism = new ClosingStructuresFailureMechanism(); var mockRepository = new MockRepository(); - var observerMock = mockRepository.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()); - var observableMock = mockRepository.StrictMock(); observableMock.Expect(o => o.NotifyObservers()); - - var handler = mockRepository.Stub>(); - handler.Expect(h => h.ConfirmPropertyChange()).Return(true); - handler.Expect(h => h.PropertyChanged(failureMechanism)).Return(new[] { observableMock }); - mockRepository.ReplayAll(); - failureMechanism.Attach(observerMock); + var changeHandler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + value, + new[] + { + observableMock + }); - var properties = new ClosingStructuresFailureMechanismProperties(failureMechanism, handler); + var properties = new ClosingStructuresFailureMechanismProperties(failureMechanism, changeHandler); // Call properties.N2A = value; @@ -267,49 +269,5 @@ Assert.AreEqual(value, failureMechanism.GeneralInput.N2A); mockRepository.VerifyAll(); } - - [Test] - [TestCase(-10)] - [TestCase(-1)] - [TestCase(41)] - [TestCase(141)] - [TestCase(0)] - [TestCase(5)] - [TestCase(21)] - [TestCase(40)] - public void N2A_SetValueWithoutConfirmation_NoValueChangeNoUpdates(int value) - { - // Setup - var mockRepository = new MockRepository(); - var observerMock = mockRepository.StrictMock(); - - var handler = mockRepository.Stub>(); - handler.Expect(h => h.ConfirmPropertyChange()).Return(false); - - mockRepository.ReplayAll(); - - var failureMechanism = new ClosingStructuresFailureMechanism(); - failureMechanism.Attach(observerMock); - - var properties = new ClosingStructuresFailureMechanismProperties(failureMechanism, handler); - - var oldN2A = failureMechanism.GeneralInput.N2A; - - // Call - properties.N2A = value; - - // Assert - Assert.AreEqual(oldN2A, failureMechanism.GeneralInput.N2A); - mockRepository.VerifyAll(); - } - - private IFailureMechanismPropertyChangeHandler CreateSimpleHandler(MockRepository mockRepository) - { - var handler = mockRepository.Stub>(); - handler.Stub(h => h.ConfirmPropertyChange()).Return(true); - handler.Stub(h => h.PropertyChanged(Arg.Is.NotNull)).Return(Enumerable.Empty()); - - return handler; - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/FailureMechanismPropertyChangeHandler.cs =================================================================== diff -u -rb5cdbbdb36acf94df6252568521559881b763691 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/Common/src/Ringtoets.Common.Forms/FailureMechanismPropertyChangeHandler.cs (.../FailureMechanismPropertyChangeHandler.cs) (revision b5cdbbdb36acf94df6252568521559881b763691) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/FailureMechanismPropertyChangeHandler.cs (.../FailureMechanismPropertyChangeHandler.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -16,58 +16,6 @@ /// public class FailureMechanismPropertyChangeHandler : IFailureMechanismPropertyChangeHandler where T : IFailureMechanism { - /// - /// Checks whether a call to would have any effect in the given - /// . - /// - /// The failure mechanism to check for. - /// true if would result in changes, - /// false otherwise. - /// Thrown when - /// is null. - private bool RequiresConfirmation(T failureMechanism) - { - if (failureMechanism == null) - { - throw new ArgumentNullException(nameof(failureMechanism)); - } - return failureMechanism.Calculations.Any(c => c.HasOutput); - } - - public bool ConfirmPropertyChange() - { - DialogResult result = MessageBox.Show(ConfirmationMessage, - CoreCommonBaseResources.Confirm, - MessageBoxButtons.OKCancel); - return result == DialogResult.OK; - } - - public virtual IEnumerable PropertyChanged(T failureMechanism) - { - if (failureMechanism == null) - { - throw new ArgumentNullException(nameof(failureMechanism)); - } - var affected = new List(); - foreach (var calculation in failureMechanism.Calculations.Where(c => c.HasOutput)) - { - affected.Add(calculation); - calculation.ClearOutput(); - } - return affected; - } - - /// - /// Gets the message that is shown when conformation is inquired. - /// - protected virtual string ConfirmationMessage - { - get - { - return Resources.FailureMechanismPropertyChangeHandler_Confirm_change_composition_and_clear_dependent_data; - } - } - public IEnumerable SetPropertyValueAfterConfirmation( T failureMechanism, TValue value, SetFailureMechanismPropertyValueDelegate setValue) @@ -104,5 +52,69 @@ return changedObjects; } + + /// + /// Gets the message that is shown when conformation is inquired. + /// + protected virtual string ConfirmationMessage + { + get + { + return Resources.FailureMechanismPropertyChangeHandler_Confirm_change_composition_and_clear_dependent_data; + } + } + + /// + /// Checks whether a call to would have any effect in the given + /// . + /// + /// The failure mechanism to check for. + /// true if would result in changes, + /// false otherwise. + /// Thrown when + /// is null. + protected virtual bool RequiresConfirmation(T failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + return failureMechanism.Calculations.Any(c => c.HasOutput); + } + + /// + /// Propagates the necessary changes to underlying data structure when a property has + /// been changed for a failure mechanism. + /// + /// The failure mechanism to be updated. + /// All objects that have been affected by the change. + /// Thrown when + /// is null. + protected virtual IEnumerable PropertyChanged(T failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + var affected = new List(); + foreach (var calculation in failureMechanism.Calculations.Where(c => c.HasOutput)) + { + affected.Add(calculation); + calculation.ClearOutput(); + } + return affected; + } + + /// + /// Checks to see if the change of the failure mechanism property should occur or not. + /// + /// true if the change should occur, false otherwise. + private bool ConfirmPropertyChange() + { + DialogResult result = MessageBox.Show(ConfirmationMessage, + CoreCommonBaseResources.Confirm, + MessageBoxButtons.OKCancel); + return result == DialogResult.OK; + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/IFailureMechanismPropertyChangeHandler.cs =================================================================== diff -u -rb5cdbbdb36acf94df6252568521559881b763691 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/IFailureMechanismPropertyChangeHandler.cs (.../IFailureMechanismPropertyChangeHandler.cs) (revision b5cdbbdb36acf94df6252568521559881b763691) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/IFailureMechanismPropertyChangeHandler.cs (.../IFailureMechanismPropertyChangeHandler.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -22,22 +22,6 @@ public interface IFailureMechanismPropertyChangeHandler where T : IFailureMechanism { /// - /// Checks to see if the change of the failure mechanism property should occur or not. - /// - /// true if the change should occur, false otherwise. - bool ConfirmPropertyChange(); - - /// - /// Propagates the necessary changes to underlying data structure when a property has - /// been changed for a failure mechanism. - /// - /// The failure mechanism to be updated. - /// All objects that have been affected by the change. - /// Thrown when - /// is null. - IEnumerable PropertyChanged(T failureMechanism); - - /// /// Find out whether the property can be updated with or without confirmation. If confirmation is required, /// the confirmation is obtained, after which the property is set if confirmation is given. If no confirmation /// was required, then the value will be set for the property. Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/FailureMechanismPropertyChangeHandlerTest.cs =================================================================== diff -u -rb5cdbbdb36acf94df6252568521559881b763691 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/FailureMechanismPropertyChangeHandlerTest.cs (.../FailureMechanismPropertyChangeHandlerTest.cs) (revision b5cdbbdb36acf94df6252568521559881b763691) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/FailureMechanismPropertyChangeHandlerTest.cs (.../FailureMechanismPropertyChangeHandlerTest.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -15,99 +15,6 @@ public class FailureMechanismPropertyChangeHandlerTest : NUnitFormTest { [Test] - public void ConfirmPropertyChange_Always_ShowMessageBox() - { - // Setup - string title = ""; - string message = ""; - DialogBoxHandler = (name, wnd) => - { - var tester = new MessageBoxTester(wnd); - title = tester.Title; - message = tester.Text; - - tester.ClickOk(); - }; - - var handler = new FailureMechanismPropertyChangeHandler(); - - // Call - handler.ConfirmPropertyChange(); - - // Assert - Assert.AreEqual("Bevestigen", title); - string expectedMessage = "Als u een parameter in een toetsspoor wijzigt, zal de uitvoer van alle berekeningen in dit toetsspoor verwijderd worden." + Environment.NewLine + - Environment.NewLine + - "Weet u zeker dat u wilt doorgaan?"; - Assert.AreEqual(expectedMessage, message); - } - - [Test] - public void ConfirmPropertyChange_MessageBoxOk_ReturnTrue() - { - DialogBoxHandler = (name, wnd) => - { - var tester = new MessageBoxTester(wnd); - tester.ClickOk(); - }; - - var handler = new FailureMechanismPropertyChangeHandler(); - - // Call - bool result = handler.ConfirmPropertyChange(); - - // Assert - Assert.IsTrue(result); - } - - [Test] - public void ConfirmPropertyChange_MessageBoxCancel_ReturnFalse() - { - DialogBoxHandler = (name, wnd) => - { - var tester = new MessageBoxTester(wnd); - tester.ClickCancel(); - }; - - var handler = new FailureMechanismPropertyChangeHandler(); - - // Call - bool result = handler.ConfirmPropertyChange(); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void PropertyChanged_WithoutFailureMechanism_ThrowsArgumentNullException() - { - // Setup - var handler = new FailureMechanismPropertyChangeHandler(); - - // Call - TestDelegate test = () => handler.PropertyChanged(null); - - // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("failureMechanism", paramName); - } - - [Test] - [TestCaseSource("ChangePropertyTestCases")] - public void PropertyChanged_FailureMechanismWithDifferentCalculationCollections_ReturnsCalculationsWhichHadOutput(ChangePropertyTestCase testCase) - { - // Setup - var handler = new FailureMechanismPropertyChangeHandler(); - IFailureMechanism failureMechanism = new TestFailureMechanism(testCase.Calculations); - - // Call - IEnumerable result = handler.PropertyChanged(failureMechanism); - - // Assert - CollectionAssert.AreEquivalent(testCase.ExpectedAffectedCalculations, result); - } - - [Test] public void SetPropertyValueAfterConfirmation_WithoutFailureMechanism_ThrowsArgumentNullException() { // Setup @@ -163,11 +70,18 @@ public void SetPropertyValueAfterConfirmation_IfConfirmationRequiredThenGiven_SetValueCalledAffectedObjectsReturned(ChangePropertyTestCase testCase) { // Setup - if (testCase.ExpectedAffectedCalculations.Any()) + var dialogBoxWillBeShown = testCase.ExpectedAffectedCalculations.Any(); + + string title = ""; + string message = ""; + if (dialogBoxWillBeShown) { DialogBoxHandler = (name, wnd) => { var tester = new MessageBoxTester(wnd); + title = tester.Title; + message = tester.Text; + tester.ClickOk(); }; } @@ -184,6 +98,14 @@ (f, v) => propertySet++); // Assert + if (dialogBoxWillBeShown) + { + Assert.AreEqual("Bevestigen", title); + string expectedMessage = "Als u een parameter in een toetsspoor wijzigt, zal de uitvoer van alle berekeningen in dit toetsspoor verwijderd worden." + Environment.NewLine + + Environment.NewLine + + "Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, message); + } Assert.AreEqual(1, propertySet); var expectedAffectedObjects = new List(testCase.ExpectedAffectedCalculations); expectedAffectedObjects.Add(testFailureMechanism); Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextProperties.cs =================================================================== diff -u -r4d77063761342b4686ef4a56c47874558a53dec7 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextProperties.cs (.../GrassCoverErosionInwardsFailureMechanismContextProperties.cs) (revision 4d77063761342b4686ef4a56c47874558a53dec7) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextProperties.cs (.../GrassCoverErosionInwardsFailureMechanismContextProperties.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -28,6 +28,7 @@ using Core.Common.Utils.Attributes; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Forms.Properties; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -39,7 +40,7 @@ /// public class GrassCoverErosionInwardsFailureMechanismContextProperties : ObjectProperties { - private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; + private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; private const int namePropertyIndex = 1; private const int codePropertyIndex = 2; private const int lengthEffectPropertyIndex = 3; @@ -56,15 +57,15 @@ /// Thrown when any input parameter is null. public GrassCoverErosionInwardsFailureMechanismContextProperties( GrassCoverErosionInwardsFailureMechanismContext data, - IFailureMechanismPropertyChangeHandler handler) + IFailureMechanismPropertyChangeHandler handler) { if (data == null) { - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); } if (handler == null) { - throw new ArgumentNullException("handler"); + throw new ArgumentNullException(nameof(handler)); } Data = data; propertyChangeHandler = handler; @@ -84,11 +85,12 @@ } set { - if (propertyChangeHandler.ConfirmPropertyChange()) - { - data.WrappedData.GeneralInput.N = value; - ClearOutputAndNotifyObservers(); - } + IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation( + data.WrappedData, + value, + (f, v) => f.GeneralInput.N = v); + + NotifyAffectedObjects(affectedObjects); } } @@ -190,14 +192,12 @@ #endregion - private void ClearOutputAndNotifyObservers() + private static void NotifyAffectedObjects(IEnumerable affectedObjects) { - IEnumerable changedObjects = propertyChangeHandler.PropertyChanged(data.WrappedData); - foreach (IObservable changedObject in changedObjects) + foreach (var affectedObject in affectedObjects) { - changedObject.NotifyObservers(); + affectedObject.NotifyObservers(); } - data.WrappedData.NotifyObservers(); } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs =================================================================== diff -u -r6c3b126a0a9d31abf3bada375416117f6ffb2e97 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 6c3b126a0a9d31abf3bada375416117f6ffb2e97) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -60,7 +60,9 @@ { yield return new PropertyInfo { - CreateInstance = context => new GrassCoverErosionInwardsFailureMechanismContextProperties(context, new FailureMechanismPropertyChangeHandler()) + CreateInstance = context => new GrassCoverErosionInwardsFailureMechanismContextProperties( + context, + new FailureMechanismPropertyChangeHandler()) }; yield return new PropertyInfo(); yield return new PropertyInfo(); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs =================================================================== diff -u -r4d77063761342b4686ef4a56c47874558a53dec7 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs (.../GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs) (revision 4d77063761342b4686ef4a56c47874558a53dec7) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs (.../GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -21,14 +21,13 @@ using System; using System.ComponentModel; -using System.Linq; using Core.Common.Base; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.Common.Forms.TestUtil; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Data.Properties; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; @@ -58,7 +57,8 @@ public void Constructor_DataIsNull_ThrowArgumentNullException() { // Setup - IFailureMechanismPropertyChangeHandler handler = CreateSimpleHandler(); + var handler = + mockRepository.Stub>(); mockRepository.ReplayAll(); // Call @@ -93,7 +93,7 @@ { // Setup var assessmentSectionMock = mockRepository.StrictMock(); - IFailureMechanismPropertyChangeHandler handler = CreateSimpleHandler(); + var handler = mockRepository.Stub>(); mockRepository.ReplayAll(); @@ -127,7 +127,7 @@ { // Setup var assessmentSectionMock = mockRepository.StrictMock(); - IFailureMechanismPropertyChangeHandler handler = CreateSimpleHandler(); + var handler = mockRepository.Stub>(); mockRepository.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); @@ -207,16 +207,18 @@ public void LengthEffect_SetInvalidValueWithConfirmation_ThrowsArgumentOutOfRangeException(int newLengthEffect) { // Setup - var observerMock = mockRepository.StrictMock(); - var changeHandler = mockRepository.StrictMock>(); - changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(true); - var assessmentSectionMock = mockRepository.StrictMock(); - + var observableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - failureMechanism.Attach(observerMock); + var changeHandler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + newLengthEffect, + new[] + { + observableMock + }); var properties = new GrassCoverErosionInwardsFailureMechanismContextProperties( new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSectionMock), @@ -237,23 +239,21 @@ public void LengthEffect_SetValidValueWithConfirmation_UpdateDataAndNotifyObservers(int newLengthEffect) { // Setup - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - - var observerMock = mockRepository.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()); - var observableMock = mockRepository.StrictMock(); observableMock.Expect(o => o.NotifyObservers()); - var changeHandler = mockRepository.StrictMock>(); - changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(true); - changeHandler.Expect(h => h.PropertyChanged(failureMechanism)).Return(new[] { observableMock }); - var assessmentSectionMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - failureMechanism.Attach(observerMock); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var changeHandler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + newLengthEffect, + new[] + { + observableMock + }); var properties = new GrassCoverErosionInwardsFailureMechanismContextProperties( new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSectionMock), @@ -266,49 +266,5 @@ Assert.AreEqual(newLengthEffect, failureMechanism.GeneralInput.N); mockRepository.VerifyAll(); } - - [Test] - [TestCase(-10)] - [TestCase(-1)] - [TestCase(0)] - [TestCase(1)] - [TestCase(10)] - [TestCase(20)] - public void LengthEffect_SetValueWithoutConfirmation_NoValueChangeNoUpdates(int newLengthEffect) - { - // Setup - var observerMock = mockRepository.StrictMock(); - - var changeHandler = mockRepository.StrictMock>(); - changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(false); - - var assessmentSectionMock = mockRepository.StrictMock(); - - mockRepository.ReplayAll(); - - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - failureMechanism.Attach(observerMock); - - var properties = new GrassCoverErosionInwardsFailureMechanismContextProperties( - new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSectionMock), - changeHandler); - int oldValue = properties.LengthEffect; - - // Call - properties.LengthEffect = newLengthEffect; - - // Assert - Assert.AreEqual(oldValue, failureMechanism.GeneralInput.N); - mockRepository.VerifyAll(); - } - - private IFailureMechanismPropertyChangeHandler CreateSimpleHandler() - { - var handler = mockRepository.Stub>(); - handler.Stub(h => h.ConfirmPropertyChange()).Return(true); - handler.Stub(h => h.PropertyChanged(Arg.Is.NotNull)).Return(Enumerable.Empty()); - - return handler; - } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler.cs =================================================================== diff -u -rc016f7af2a4afdc96fc19b8db86dc8d3559de023 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler.cs) (revision c016f7af2a4afdc96fc19b8db86dc8d3559de023) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -3,7 +3,6 @@ using System.Linq; using Core.Common.Base; using Ringtoets.Common.Forms; -using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Service; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Forms.Properties; @@ -16,6 +15,12 @@ /// public class GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler : FailureMechanismPropertyChangeHandler { + protected override bool RequiresConfirmation(GrassCoverErosionOutwardsFailureMechanism failureMechanism) + { + return base.RequiresConfirmation(failureMechanism) || + failureMechanism.HydraulicBoundaryLocations.Any(c => c.WaveHeightOutput != null || c.DesignWaterLevelOutput != null); + } + protected override string ConfirmationMessage { get @@ -24,11 +29,11 @@ } } - public override IEnumerable PropertyChanged(GrassCoverErosionOutwardsFailureMechanism failureMechanism) + protected override IEnumerable PropertyChanged(GrassCoverErosionOutwardsFailureMechanism failureMechanism) { if (failureMechanism == null) { - throw new ArgumentNullException("failureMechanism"); + throw new ArgumentNullException(nameof(failureMechanism)); } var affectedObjects = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput( Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismProperties.cs =================================================================== diff -u -r4d77063761342b4686ef4a56c47874558a53dec7 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismProperties.cs (.../GrassCoverErosionOutwardsFailureMechanismProperties.cs) (revision 4d77063761342b4686ef4a56c47874558a53dec7) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Forms/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismProperties.cs (.../GrassCoverErosionOutwardsFailureMechanismProperties.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -20,16 +20,15 @@ // All rights reserved. using System; +using System.Collections.Generic; +using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Gui.Attributes; using Core.Common.Gui.PropertyBag; using Core.Common.Utils.Attributes; -using log4net; using Ringtoets.Common.Forms.PropertyClasses; -using Ringtoets.Common.Service; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; -using Ringtoets.GrassCoverErosionOutwards.Forms.Properties; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsRevetmentFormsResources = Ringtoets.Revetment.Forms.Properties.Resources; @@ -40,29 +39,28 @@ /// public class GrassCoverErosionOutwardsFailureMechanismProperties : ObjectProperties { - private static readonly ILog log = LogManager.GetLogger(typeof(GrassCoverErosionOutwardsFailureMechanismProperties)); - private readonly IFailureMechanismPropertyChangeHandler changeHandler; + private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; /// /// Creates a new instance of . /// /// The failure mechanism to show the properties for. - /// Handler responsible for handling effects of a property change. + /// Handler responsible for handling effects of a property change. /// Thrown when is null. public GrassCoverErosionOutwardsFailureMechanismProperties( GrassCoverErosionOutwardsFailureMechanism failureMechanism, - IFailureMechanismPropertyChangeHandler changeHandler) + IFailureMechanismPropertyChangeHandler handler) { if (failureMechanism == null) { - throw new ArgumentNullException("failureMechanism"); + throw new ArgumentNullException(nameof(failureMechanism)); } - if (changeHandler == null) + if (handler == null) { - throw new ArgumentNullException("changeHandler"); + throw new ArgumentNullException(nameof(handler)); } Data = failureMechanism; - this.changeHandler = changeHandler; + propertyChangeHandler = handler; } #region Length effect parameters @@ -79,11 +77,12 @@ } set { - if (changeHandler.ConfirmPropertyChange()) - { - data.GeneralInput.N = value; - ClearOutputAndNotifyObservers(); - } + IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation( + data, + value, + (f, v) => f.GeneralInput.N = v); + + NotifyAffectedObjects(affectedObjects); } } @@ -157,13 +156,12 @@ #endregion - private void ClearOutputAndNotifyObservers() + private static void NotifyAffectedObjects(IEnumerable affectedObjects) { - foreach (var observable in changeHandler.PropertyChanged(data)) + foreach (var affectedObject in affectedObjects) { - observable.NotifyObservers(); + affectedObject.NotifyObservers(); } - data.NotifyObservers(); } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs =================================================================== diff -u -r545b105a213ed85564861b4bcf6d2d6425dbde50 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs) (revision 545b105a213ed85564861b4bcf6d2d6425dbde50) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -7,7 +7,6 @@ using NUnit.Framework; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Forms.TestUtil; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.Revetment.Data; @@ -17,101 +16,140 @@ public class GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandlerTest : NUnitFormTest { [Test] - public void ConfirmPropertyChange_Always_ShowMessageBox() + public void SetPropertyValueAfterConfirmation_WithoutFailureMechanism_ThrowsArgumentNullException() { // Setup - string title = ""; - string message = ""; - DialogBoxHandler = (name, wnd) => - { - var tester = new MessageBoxTester(wnd); - title = tester.Title; - message = tester.Text; + var changeHandler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); - tester.ClickOk(); - }; - - var handler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); - // Call - handler.ConfirmPropertyChange(); + TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation( + null, + 3, + (f, v) => { }); // Assert - Assert.AreEqual("Bevestigen", title); - string expectedMessage = "Als u een parameter in een toetsspoor wijzigt, zal de uitvoer van alle randvoorwaarden locaties en berekeningen in dit toetsspoor verwijderd worden." + Environment.NewLine + - Environment.NewLine + - "Weet u zeker dat u wilt doorgaan?"; - Assert.AreEqual(expectedMessage, message); + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("failureMechanism", paramName); } [Test] - public void ConfirmPropertyChange_MessageBoxOk_ReturnTrue() + public void SetPropertyValueAfterConfirmation_WithoutValue_ThrowsArgumentNullException() { - DialogBoxHandler = (name, wnd) => - { - var tester = new MessageBoxTester(wnd); - tester.ClickOk(); - }; + // Setup + var changeHandler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); - var handler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); - // Call - bool result = handler.ConfirmPropertyChange(); + TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation( + new GrassCoverErosionOutwardsFailureMechanism(), + null, + (f, v) => { }); // Assert - Assert.IsTrue(result); + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("value", paramName); } [Test] - public void ConfirmPropertyChange_MessageBoxCancel_ReturnFalse() + public void SetPropertyValueAfterConfirmation_WithoutSetProperty_ThrowsArgumentNullException() { - DialogBoxHandler = (name, wnd) => - { - var tester = new MessageBoxTester(wnd); - tester.ClickCancel(); - }; + // Setup + var changeHandler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); - var handler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); - // Call - bool result = handler.ConfirmPropertyChange(); + TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation( + new GrassCoverErosionOutwardsFailureMechanism(), + 3, + null); // Assert - Assert.IsFalse(result); + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("setValue", paramName); } [Test] - public void ChangeComposition_WithoutFailureMechanism_ThrowsArgumentNullException() + [TestCaseSource(nameof(ChangePropertyTestCases))] + public void SetPropertyValueAfterConfirmation_IfConfirmationRequiredThenGiven_MessageDialogShownSetValueCalledAffectedObjectsReturned(ChangePropertyTestCase testCase) { // Setup - var handler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); + var dialogBoxWillBeShown = testCase.ExpectedAffectedCalculations.Any() || testCase.ExpectedAffectedLocations.Any(); + string title = ""; + string message = ""; + if (dialogBoxWillBeShown) + { + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + title = tester.Title; + message = tester.Text; + + tester.ClickOk(); + }; + } + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + foreach (var calculation in testCase.Calculations) + { + failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); + } + failureMechanism.HydraulicBoundaryLocations.AddRange(testCase.Locations); + + var propertySet = 0; + + var changeHandler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); + // Call - TestDelegate test = () => handler.PropertyChanged(null); + var affectedObjects = changeHandler.SetPropertyValueAfterConfirmation( + failureMechanism, + 3, + (f, v) => propertySet++); // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("failureMechanism", paramName); + if (dialogBoxWillBeShown) + { + Assert.AreEqual("Bevestigen", title); + string expectedMessage = "Als u een parameter in een toetsspoor wijzigt, zal de uitvoer van alle randvoorwaarden locaties en berekeningen in dit toetsspoor verwijderd worden." + Environment.NewLine + + Environment.NewLine + + "Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, message); + } + Assert.AreEqual(1, propertySet); + var expectedAffectedObjects = new List(testCase.ExpectedAffectedLocations); + expectedAffectedObjects.AddRange(testCase.ExpectedAffectedCalculations); + expectedAffectedObjects.Add(failureMechanism); + CollectionAssert.AreEqual(expectedAffectedObjects, affectedObjects); } [Test] - [TestCaseSource("ChangePropertyTestCases")] - public void ChangeComposition_FailureMechanismWithDifferentCalculationCollections_ReturnsCalculationsWhichHadOutput(ChangePropertyTestCase testCase) + public void SetPropertyValueAfterConfirmation_ConfirmationRequiredButNotGiven_SetValueNotCalledNoAffectedObjectsReturned() { // Setup - var handler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - foreach (var calculation in testCase.Calculations) + DialogBoxHandler = (name, wnd) => { - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculation); - } - failureMechanism.HydraulicBoundaryLocations.AddRange(testCase.Locations); + var tester = new MessageBoxTester(wnd); + tester.ClickCancel(); + }; + var calculationWithOutput = CreateCalculationWithOutput(); + var calculationWithoutOutput = CreateCalculationWithoutOutput(); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationWithOutput); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationWithoutOutput); + + var propertySet = 0; + + var changeHandler = new GrassCoverErosionOutwardsFailureMechanismPropertyChangeHandler(); + // Call - IEnumerable result = handler.PropertyChanged(failureMechanism); + var affectedObjects = changeHandler.SetPropertyValueAfterConfirmation( + failureMechanism, + 3, + (f, v) => propertySet++); // Assert - CollectionAssert.AreEquivalent(testCase.ExpectedAffectedCalculations.Concat(testCase.ExpectedAffectedLocations), result); + Assert.AreEqual(0, propertySet); + CollectionAssert.IsEmpty(affectedObjects); } public class ChangePropertyTestCase Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs =================================================================== diff -u -r4d77063761342b4686ef4a56c47874558a53dec7 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs) (revision 4d77063761342b4686ef4a56c47874558a53dec7) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -21,12 +21,12 @@ using System; using System.ComponentModel; -using System.Linq; using Core.Common.Base; using Core.Common.Gui.PropertyBag; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.Common.Forms.TestUtil; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Data.Properties; using Ringtoets.GrassCoverErosionOutwards.Forms.PropertyClasses; @@ -48,7 +48,7 @@ { // Setup var mockRepository = new MockRepository(); - var changeHandler = CreateSimpleHandler(mockRepository); + var changeHandler = mockRepository.Stub>(); mockRepository.ReplayAll(); // Call @@ -67,15 +67,15 @@ // Assert string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("changeHandler", paramName); + Assert.AreEqual("handler", paramName); } [Test] public void Constructor_WithFailureMechanism_ExpectedValues() { // Setup var mockRepository = new MockRepository(); - var changeHandler = CreateSimpleHandler(mockRepository); + var changeHandler = mockRepository.Stub>(); mockRepository.ReplayAll(); var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); @@ -99,7 +99,7 @@ { // Setup var mockRepository = new MockRepository(); - var changeHandler = CreateSimpleHandler(mockRepository); + var changeHandler = mockRepository.Stub>(); mockRepository.ReplayAll(); // Call @@ -166,17 +166,20 @@ public void LengthEffect_SetInvalidValueWithConfirmation_ThrowsArgumentOutOfRangeException(int newLengthEffect) { // Setup - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - var mockRepository = new MockRepository(); - var observerMock = mockRepository.StrictMock(); - var changeHandler = mockRepository.StrictMock>(); - changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(true); - + var observableMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - failureMechanism.Attach(observerMock); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var changeHandler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + newLengthEffect, + new[] + { + observableMock + }); + var properties = new GrassCoverErosionOutwardsFailureMechanismProperties(failureMechanism, changeHandler); // Call @@ -194,23 +197,21 @@ public void LengthEffect_SetValidValueWithConfirmation_UpdateDataAndNotifyObservers(int newLengthEffect) { // Setup - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - var mockRepository = new MockRepository(); - var observerMock = mockRepository.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()); - var observableMock = mockRepository.StrictMock(); observableMock.Expect(o => o.NotifyObservers()); - - var changeHandler = mockRepository.StrictMock>(); - changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(true); - changeHandler.Expect(h => h.PropertyChanged(failureMechanism)).Return(new[] { observableMock }); - mockRepository.ReplayAll(); - failureMechanism.Attach(observerMock); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var changeHandler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + newLengthEffect, + new[] + { + observableMock + }); + var properties = new GrassCoverErosionOutwardsFailureMechanismProperties(failureMechanism, changeHandler); // Call @@ -220,43 +221,5 @@ Assert.AreEqual(newLengthEffect, failureMechanism.GeneralInput.N); mockRepository.VerifyAll(); } - - [Test] - [TestCase(1)] - [TestCase(10)] - [TestCase(20)] - public void LengthEffect_SetValidValueNoConfirmation_NoValueChangeNoUpdates(int newLengthEffect) - { - // Setup - var mockRepository = new MockRepository(); - var observerMock = mockRepository.StrictMock(); - - var changeHandler = mockRepository.StrictMock>(); - changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(false); - - mockRepository.ReplayAll(); - - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - failureMechanism.Attach(observerMock); - - var properties = new GrassCoverErosionOutwardsFailureMechanismProperties(failureMechanism, changeHandler); - int oldValue = properties.LengthEffect; - - // Call - properties.LengthEffect = newLengthEffect; - - // Assert - Assert.AreEqual(oldValue, failureMechanism.GeneralInput.N); - mockRepository.VerifyAll(); - } - - private IFailureMechanismPropertyChangeHandler CreateSimpleHandler(MockRepository mockRepository) - { - var handler = mockRepository.Stub>(); - handler.Stub(h => h.ConfirmPropertyChange()).Return(true); - handler.Stub(h => h.PropertyChanged(Arg.Is.NotNull)).Return(Enumerable.Empty()); - - return handler; - } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingFailureMechanismContextProperties.cs =================================================================== diff -u -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501 -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingFailureMechanismContextProperties.cs (.../PipingFailureMechanismContextProperties.cs) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingFailureMechanismContextProperties.cs (.../PipingFailureMechanismContextProperties.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) @@ -53,11 +53,11 @@ { if (data == null) { - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); } if (handler == null) { - throw new ArgumentNullException("handler"); + throw new ArgumentNullException(nameof(handler)); } Data = data; propertyChangeHandler = handler;