Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesTest.cs =================================================================== diff -u -re7b22b417acc51a88beb210ba39fef0f75e2760e -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesTest.cs (.../ClosingStructuresFailureMechanismPropertiesTest.cs) (revision e7b22b417acc51a88beb210ba39fef0f75e2760e) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesTest.cs (.../ClosingStructuresFailureMechanismPropertiesTest.cs) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -234,6 +234,7 @@ // Assert Assert.Throws(test); + Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } @@ -267,6 +268,7 @@ // Assert Assert.AreEqual(value, failureMechanism.GeneralInput.N2A); + Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/FailureMechanismSetPropertyValueAfterConfirmationParameterTesterTest.cs =================================================================== diff -u -ree0576b711ce1fabcb12903b1c56cbae0bc9414b -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/FailureMechanismSetPropertyValueAfterConfirmationParameterTesterTest.cs (.../FailureMechanismSetPropertyValueAfterConfirmationParameterTesterTest.cs) (revision ee0576b711ce1fabcb12903b1c56cbae0bc9414b) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil.Test/FailureMechanismSetPropertyValueAfterConfirmationParameterTesterTest.cs (.../FailureMechanismSetPropertyValueAfterConfirmationParameterTesterTest.cs) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -49,6 +49,7 @@ // Assert Assert.Throws(test); + Assert.IsTrue(tester.Called); } [Test] @@ -68,6 +69,7 @@ // Assert Assert.Throws(test); + Assert.IsTrue(tester.Called); } [Test] @@ -83,11 +85,12 @@ testFailureMechanism, value, returnedAffectedObjects); // Call - var affectedObjetcs = tester.SetPropertyValueAfterConfirmation(testFailureMechanism, value, (m, v) => called++); + var affectedObjects = tester.SetPropertyValueAfterConfirmation(testFailureMechanism, value, (m, v) => called++); // Assert Assert.AreEqual(1, called); - Assert.AreSame(returnedAffectedObjects, affectedObjetcs); + Assert.AreSame(returnedAffectedObjects, affectedObjects); + Assert.IsTrue(tester.Called); } [Test] @@ -108,6 +111,7 @@ // Assert var exception = Assert.Throws(test); Assert.AreSame(expectedException, exception); + Assert.IsTrue(tester.Called); } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs =================================================================== diff -u -r82d54017e93bce01e76c58537c13979c2e1af142 -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs (.../GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs) (revision 82d54017e93bce01e76c58537c13979c2e1af142) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs (.../GrassCoverErosionInwardsFailureMechanismContextPropertiesTest.cs) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -229,6 +229,7 @@ // Assert Assert.Throws(test); + Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } @@ -264,6 +265,7 @@ // Assert Assert.AreEqual(newLengthEffect, failureMechanism.GeneralInput.N); + Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } } Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs =================================================================== diff -u -re2f91813f3aae8eb2daef6ff1ffac61d197148a8 -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs) (revision e2f91813f3aae8eb2daef6ff1ffac61d197148a8) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/PropertyClasses/GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs (.../GrassCoverErosionOutwardsFailureMechanismPropertiesTest.cs) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -187,6 +187,7 @@ // Assert Assert.Throws(test); + Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } @@ -219,6 +220,7 @@ // Assert Assert.AreEqual(newLengthEffect, failureMechanism.GeneralInput.N); + Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresFailureMechanismPropertiesTest.cs =================================================================== diff -u -raac0eeeb6697f9eaab2bbe62dd80f05b38cf515c -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresFailureMechanismPropertiesTest.cs (.../HeightStructuresFailureMechanismPropertiesTest.cs) (revision aac0eeeb6697f9eaab2bbe62dd80f05b38cf515c) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresFailureMechanismPropertiesTest.cs (.../HeightStructuresFailureMechanismPropertiesTest.cs) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -203,6 +203,7 @@ // Assert Assert.Throws(test); + Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } @@ -235,6 +236,7 @@ // Assert Assert.AreEqual(value, failureMechanism.GeneralInput.N); + Assert.IsTrue(changeHandler.Called); mockRepository.VerifyAll(); } } Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailureMechanismProperties.cs =================================================================== diff -u -r8dcb8c0fa8992c488bdea7d0631c84b7b1b09e61 -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailureMechanismProperties.cs (.../StabilityPointStructuresFailureMechanismProperties.cs) (revision 8dcb8c0fa8992c488bdea7d0631c84b7b1b09e61) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Forms/PropertyClasses/StabilityPointStructuresFailureMechanismProperties.cs (.../StabilityPointStructuresFailureMechanismProperties.cs) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -19,7 +19,10 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // 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.Gui.PropertyBag; @@ -45,6 +48,30 @@ private const int modelFactorCollisionLoadPropertyIndex = 7; private const int modelFactorLoadEffectPropertyIndex = 8; + private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler; + + /// + /// Creates a new instance of . + /// + /// The instance to show the properties of. + /// Handler responsible for handling effects of a property change. + /// Thrown when any input parameter is null. + public StabilityPointStructuresFailureMechanismProperties( + StabilityPointStructuresFailureMechanism data, + IFailureMechanismPropertyChangeHandler handler) + { + if (data == null) + { + throw new ArgumentNullException(nameof(data)); + } + if (handler == null) + { + throw new ArgumentNullException(nameof(handler)); + } + Data = data; + propertyChangeHandler = handler; + } + #region Length effect parameters [PropertyOrder(lengthEffectPropertyIndex)] @@ -59,8 +86,12 @@ } set { - data.GeneralInput.N = value; - data.NotifyObservers(); + IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation( + data, + value, + (f, v) => f.GeneralInput.N = v); + + NotifyAffectedObjects(affectedObjects); } } @@ -173,5 +204,13 @@ } #endregion + + private static void NotifyAffectedObjects(IEnumerable affectedObjects) + { + foreach (var affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); + } + } } } \ No newline at end of file Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -r2a0fbe6ec22928831305671ecd4f41030b827250 -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 2a0fbe6ec22928831305671ecd4f41030b827250) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -59,10 +59,9 @@ { yield return new PropertyInfo { - CreateInstance = context => new StabilityPointStructuresFailureMechanismProperties - { - Data = context.WrappedData - } + CreateInstance = context => new StabilityPointStructuresFailureMechanismProperties( + context.WrappedData, + new FailureMechanismPropertyChangeHandler()) }; yield return new PropertyInfo(); yield return new PropertyInfo Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailureMechanismPropertiesTest.cs =================================================================== diff -u -rc238c8de03e71e09a71c68b6f28fb057ef8a1c4d -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailureMechanismPropertiesTest.cs (.../StabilityPointStructuresFailureMechanismPropertiesTest.cs) (revision c238c8de03e71e09a71c68b6f28fb057ef8a1c4d) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresFailureMechanismPropertiesTest.cs (.../StabilityPointStructuresFailureMechanismPropertiesTest.cs) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -19,12 +19,15 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.ComponentModel; using Core.Common.Base; using Core.Common.Gui.PropertyBag; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.Common.Forms.TestUtil; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.PropertyClasses; @@ -43,27 +46,54 @@ private const int modelFactorLoadEffectPropertyIndex = 7; [Test] - public void Constructor_ExpectedValues() + public void Constructor_DataIsNull_ThrowArgumentNullException() { + // Setup + var mocks = new MockRepository(); + IFailureMechanismPropertyChangeHandler changeHandler = + mocks.Stub>(); + mocks.ReplayAll(); + // Call - var properties = new StabilityPointStructuresFailureMechanismProperties(); + TestDelegate test = () => new StabilityPointStructuresFailureMechanismProperties(null, changeHandler); // Assert - Assert.IsInstanceOf>(properties); - Assert.IsNull(properties.Data); + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("data", paramName); + mocks.VerifyAll(); } [Test] - public void Data_SetNewFailureMechanismContextInstance_ReturnCorrectPropertyValues() + public void Constructor_ChangeHandlerIsNull_ThrowArgumentNullException() { + // Call + TestDelegate test = () => new StabilityPointStructuresFailureMechanismProperties( + new StabilityPointStructuresFailureMechanism(), + null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("handler", paramName); + } + + [Test] + public void Constructor_ValidValues_ExpectedValues() + { // Setup + var mocks = new MockRepository(); + IFailureMechanismPropertyChangeHandler changeHandler = + mocks.Stub>(); + mocks.ReplayAll(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var properties = new StabilityPointStructuresFailureMechanismProperties(); // Call - properties.Data = failureMechanism; + var properties = new StabilityPointStructuresFailureMechanismProperties(failureMechanism, changeHandler); // Assert + Assert.IsInstanceOf>(properties); + Assert.AreSame(failureMechanism, properties.Data); + Assert.AreEqual("Kunstwerken - Sterkte en stabiliteit puntconstructies", properties.Name); Assert.AreEqual("STKWp", properties.Code); @@ -81,43 +111,20 @@ } [Test] - public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers() + public void Constructor_Always_PropertiesHaveExpectedAttributesValues() { // Setup - var mockRepository = new MockRepository(); - var observerMock = mockRepository.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()).Repeat.Times(1); - mockRepository.ReplayAll(); + var mocks = new MockRepository(); + IFailureMechanismPropertyChangeHandler changeHandler = + mocks.Stub>(); + mocks.ReplayAll(); var failureMechanism = new StabilityPointStructuresFailureMechanism(); - failureMechanism.Attach(observerMock); - var properties = new StabilityPointStructuresFailureMechanismProperties - { - Data = failureMechanism - }; - const int newLengthEffect = 10; // Call - properties.LengthEffect = newLengthEffect; + var properties = new StabilityPointStructuresFailureMechanismProperties(failureMechanism, changeHandler); // Assert - Assert.AreEqual(newLengthEffect, failureMechanism.GeneralInput.N); - mockRepository.VerifyAll(); - } - - [Test] - public void Constructor_Always_PropertiesHaveExpectedAttributesValues() - { - // Setup - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - - // Call - var properties = new StabilityPointStructuresFailureMechanismProperties - { - Data = failureMechanism - }; - - // Assert var generalCategory = "Algemeen"; var lengthEffectCategory = "Lengte-effect parameters"; var modelSettingsCategory = "Modelinstellingen"; @@ -184,5 +191,70 @@ "Modelfactor belastingeffect.", true); } + + [Test] + [TestCase(0)] + [TestCase(-1)] + [TestCase(-20)] + public void LengthEffect_InvalidValueWithConfirmation_UpdateDataAndNotifyObservers(int value) + { + // Setup + var mockRepository = new MockRepository(); + var observableMock = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var changeHandler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + value, + new[] + { + observableMock + }); + + var properties = new StabilityPointStructuresFailureMechanismProperties(failureMechanism, changeHandler); + + // Call + TestDelegate test = () => properties.LengthEffect = value; + + // Assert + Assert.Throws(test); + Assert.IsTrue(changeHandler.Called); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(1)] + [TestCase(10)] + [TestCase(20)] + public void LengthEffect_SetValidValueWithConfirmation_UpdateDataAndNotifyObservers(int value) + { + // Setup + var mockRepository = new MockRepository(); + var observableMock = mockRepository.StrictMock(); + observableMock.Expect(o => o.NotifyObservers()); + + mockRepository.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var changeHandler = new FailureMechanismSetPropertyValueAfterConfirmationParameterTester( + failureMechanism, + value, + new[] + { + observableMock + }); + + var properties = new StabilityPointStructuresFailureMechanismProperties(failureMechanism, changeHandler); + + // Call + properties.LengthEffect = value; + + // Assert + Assert.AreEqual(value, failureMechanism.GeneralInput.N); + Assert.IsTrue(changeHandler.Called); + mockRepository.VerifyAll(); + } } } \ No newline at end of file Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/PropertyInfos/StabilityPointStructuresFailureMechanismContextPropertyInfoTest.cs =================================================================== diff -u --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/PropertyInfos/StabilityPointStructuresFailureMechanismContextPropertyInfoTest.cs (revision 0) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/PropertyInfos/StabilityPointStructuresFailureMechanismContextPropertyInfoTest.cs (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -0,0 +1,59 @@ +using System.Linq; +using Core.Common.Gui.Plugin; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; +using Ringtoets.StabilityPointStructures.Forms.PropertyClasses; +using Ringtoets.Common.Data.AssessmentSection; + +namespace Ringtoets.StabilityPointStructures.Plugin.Test.PropertyInfos +{ + public class StabilityPointStructuresFailureMechanismContextPropertyInfoTest + { + private StabilityPointStructuresPlugin plugin; + private PropertyInfo info; + + [SetUp] + public void SetUp() + { + plugin = new StabilityPointStructuresPlugin(); + info = plugin.GetPropertyInfos().First(tni => tni.PropertyObjectType == typeof(StabilityPointStructuresFailureMechanismProperties)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(StabilityPointStructuresFailureMechanismContext), info.DataType); + Assert.AreEqual(typeof(StabilityPointStructuresFailureMechanismProperties), info.PropertyObjectType); + } + + [Test] + public void CreateInstance_Always_NewPropertiesWithFailureMechanismContextAsData() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + mocks.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var context = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + var objectProperties = info.CreateInstance(context); + + // Assert + Assert.IsInstanceOf(objectProperties); + Assert.AreSame(failureMechanism, objectProperties.Data); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj =================================================================== diff -u -r0f678f97e76d90e4a7e7f0611ff22ab196b46381 -r23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj (.../Ringtoets.StabilityPointStructures.Plugin.Test.csproj) (revision 0f678f97e76d90e4a7e7f0611ff22ab196b46381) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj (.../Ringtoets.StabilityPointStructures.Plugin.Test.csproj) (revision 23d8c8de4ee091d49d86c4eadcb82c3eaeeef74d) @@ -65,6 +65,7 @@ +