Index: Riskeer/Integration/src/Riskeer.Integration.Forms/PropertyClasses/NormProperties.cs =================================================================== diff -u -r861948c43a31e3781141dece51876b2543ad6e0d -r215ddb6c4d9c4c5900105604140f4c92fe7a4c95 --- Riskeer/Integration/src/Riskeer.Integration.Forms/PropertyClasses/NormProperties.cs (.../NormProperties.cs) (revision 861948c43a31e3781141dece51876b2543ad6e0d) +++ Riskeer/Integration/src/Riskeer.Integration.Forms/PropertyClasses/NormProperties.cs (.../NormProperties.cs) (revision 215ddb6c4d9c4c5900105604140f4c92fe7a4c95) @@ -26,7 +26,6 @@ using Core.Gui.Attributes; using Core.Gui.PropertyBag; using Riskeer.Common.Data.Contribution; -using Riskeer.Common.Forms.ChangeHandlers; using Riskeer.Common.Forms.PropertyClasses; using Riskeer.Common.Forms.TypeConverters; using Riskeer.Integration.Forms.Properties; @@ -39,15 +38,15 @@ /// public class NormProperties : ObjectProperties { - private readonly IObservablePropertyChangeHandler normChangeHandler; + private readonly IFailureMechanismContributionNormChangeHandler normChangeHandler; /// /// Creates a new instance of . /// /// The for which the properties are shown. /// The for when the norm changes. /// Thrown when any parameter is null. - public NormProperties(FailureMechanismContribution failureMechanismContribution, IObservablePropertyChangeHandler normChangeHandler) + public NormProperties(FailureMechanismContribution failureMechanismContribution, IFailureMechanismContributionNormChangeHandler normChangeHandler) { if (failureMechanismContribution == null) { @@ -62,21 +61,18 @@ Data = failureMechanismContribution; this.normChangeHandler = normChangeHandler; } - + [PropertyOrder(1)] [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.LowerLimitNorm_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.LowerLimitNorm_Description))] public double LowerLimitNorm { - get - { - return data.LowerLimitNorm; - } + get => data.LowerLimitNorm; set { - PropertyChangeHelper.ChangePropertyAndNotify(() => data.LowerLimitNorm = value, normChangeHandler); + ChangeNorm(() => data.LowerLimitNorm = value, NormType.LowerLimit); } } @@ -87,13 +83,10 @@ [ResourcesDescription(typeof(Resources), nameof(Resources.SignalingNorm_Description))] public double SignalingNorm { - get - { - return data.SignalingNorm; - } + get => data.SignalingNorm; set { - PropertyChangeHelper.ChangePropertyAndNotify(() => data.SignalingNorm = value, normChangeHandler); + ChangeNorm(() => data.SignalingNorm = value, NormType.Signaling); } } @@ -104,14 +97,23 @@ [TypeConverter(typeof(EnumTypeConverter))] public NormType NormativeNorm { - get + get => data.NormativeNorm; + set { - return data.NormativeNorm; + normChangeHandler.ChangeNormativeNormType(() => data.NormativeNorm = value); } - set + } + + private void ChangeNorm(Action action, NormType normType) + { + if (data.NormativeNorm == normType) { - PropertyChangeHelper.ChangePropertyAndNotify(() => data.NormativeNorm = value, normChangeHandler); + normChangeHandler.ChangeNormativeNorm(action); } + else + { + normChangeHandler.ChangeNorm(action); + } } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Forms.Test/PropertyClasses/NormPropertiesTest.cs =================================================================== diff -u -r861948c43a31e3781141dece51876b2543ad6e0d -r215ddb6c4d9c4c5900105604140f4c92fe7a4c95 --- Riskeer/Integration/test/Riskeer.Integration.Forms.Test/PropertyClasses/NormPropertiesTest.cs (.../NormPropertiesTest.cs) (revision 861948c43a31e3781141dece51876b2543ad6e0d) +++ Riskeer/Integration/test/Riskeer.Integration.Forms.Test/PropertyClasses/NormPropertiesTest.cs (.../NormPropertiesTest.cs) (revision 215ddb6c4d9c4c5900105604140f4c92fe7a4c95) @@ -21,7 +21,6 @@ using System; using System.ComponentModel; -using Core.Common.Base; using Core.Common.TestUtil; using Core.Common.Util; using Core.Gui.PropertyBag; @@ -31,8 +30,6 @@ using Rhino.Mocks; using Riskeer.Common.Data.Contribution; using Riskeer.Common.Data.TestUtil; -using Riskeer.Common.Forms.PropertyClasses; -using Riskeer.Common.Forms.TestUtil; using Riskeer.Common.Forms.TypeConverters; using Riskeer.Integration.Forms.PropertyClasses; @@ -46,15 +43,15 @@ { // Setup var mocks = new MockRepository(); - var normChangeHandler = mocks.Stub(); + var failureMechanismContributionNormChangeHandler = mocks.Stub(); mocks.ReplayAll(); // Call - TestDelegate test = () => new NormProperties(null, normChangeHandler); + void Call() => new NormProperties(null, failureMechanismContributionNormChangeHandler); // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("failureMechanismContribution", paramName); + var exception = Assert.Throws(Call); + Assert.AreEqual("failureMechanismContribution", exception.ParamName); mocks.VerifyAll(); } @@ -65,25 +62,25 @@ FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); // Call - TestDelegate test = () => new NormProperties(failureMechanismContribution, null); + void Call() => new NormProperties(failureMechanismContribution, null); // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("normChangeHandler", paramName); + var exception = Assert.Throws(Call); + Assert.AreEqual("normChangeHandler", exception.ParamName); } [Test] public void Constructor_ValidData_ExpectedValues() { // Setup var mocks = new MockRepository(); - var normChangeHandler = mocks.Stub(); + var failureMechanismContributionNormChangeHandler = mocks.Stub(); mocks.ReplayAll(); FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); // Call - var properties = new NormProperties(failureMechanismContribution, normChangeHandler); + var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); // Assert Assert.IsInstanceOf>(properties); @@ -103,13 +100,13 @@ { // Setup var mocks = new MockRepository(); - var normChangeHandler = mocks.Stub(); + var failureMechanismContributionNormChangeHandler = mocks.Stub(); mocks.ReplayAll(); FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); // Call - var properties = new NormProperties(failureMechanismContribution, normChangeHandler); + var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); @@ -129,7 +126,7 @@ expectedCategory, "Signaleringswaarde [1/jaar]", "Overstromingskans van het dijktraject waarvan overschrijding gemeld moet worden aan de Minister van I en M."); - + PropertyDescriptor normativeNormProperty = dynamicProperties[2]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(normativeNormProperty, expectedCategory, @@ -144,13 +141,13 @@ { // Setup var mocks = new MockRepository(); - var normChangeHandler = mocks.Stub(); + var failureMechanismContributionNormChangeHandler = mocks.Stub(); mocks.ReplayAll(); FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); // Call - var properties = new NormProperties(failureMechanismContribution, normChangeHandler); + var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); // Assert Assert.AreEqual(failureMechanismContribution.LowerLimitNorm, properties.LowerLimitNorm); @@ -160,45 +157,149 @@ } [Test] - public void LowerLimitNorm_Always_ContributionNotifiedAndPropertyChangedCalled() + public void GivenNormativeNormIsLowerLimitNorm_WhenChangingLowerLimitNorm_ThenHandlerCalledAndPropertySet() { - SetPropertyAndVerifyNotificationsAndOutputForCalculation(properties => properties.LowerLimitNorm = 0.001); + // Given + FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); + + var mocks = new MockRepository(); + var failureMechanismContributionNormChangeHandler = mocks.StrictMock(); + failureMechanismContributionNormChangeHandler.Expect(h => h.ChangeNormativeNorm(null)) + .IgnoreArguments() + .WhenCalled(invocation => + { + var actionToPerform = (Action) invocation.Arguments[0]; + actionToPerform(); + }); + mocks.ReplayAll(); + + var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); + + const double newValue = 0.001; + + // When + properties.LowerLimitNorm = newValue; + + // Then + Assert.AreEqual(newValue, failureMechanismContribution.LowerLimitNorm); + mocks.VerifyAll(); } [Test] - public void SignalingNorm_Always_ContributionNotifiedAndPropertyChangedCalled() + public void GivenNormativeNormIsSignalingNorm_WhenChangingLowerLimitNorm_ThenHandlerCalledAndPropertySet() { - SetPropertyAndVerifyNotificationsAndOutputForCalculation(properties => properties.SignalingNorm = 0.00001); + // Given + FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); + failureMechanismContribution.NormativeNorm = NormType.Signaling; + + var mocks = new MockRepository(); + var failureMechanismContributionNormChangeHandler = mocks.StrictMock(); + failureMechanismContributionNormChangeHandler.Expect(h => h.ChangeNorm(null)) + .IgnoreArguments() + .WhenCalled(invocation => + { + var actionToPerform = (Action) invocation.Arguments[0]; + actionToPerform(); + }); + mocks.ReplayAll(); + + var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); + + const double newValue = 0.001; + + // When + properties.LowerLimitNorm = newValue; + + // Then + Assert.AreEqual(newValue, failureMechanismContribution.LowerLimitNorm); + mocks.VerifyAll(); } [Test] - public void NormativeNorm_Always_ContributionNotifiedAndPropertyChangedCalled() + public void GivenNormativeNormIsSignalingNorm_WhenChangingSignalingNorm_ThenHandlerCalledAndPropertySet() { - SetPropertyAndVerifyNotificationsAndOutputForCalculation(properties => properties.NormativeNorm = NormType.Signaling); + // Given + FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); + failureMechanismContribution.NormativeNorm = NormType.Signaling; + + var mocks = new MockRepository(); + var failureMechanismContributionNormChangeHandler = mocks.StrictMock(); + failureMechanismContributionNormChangeHandler.Expect(h => h.ChangeNormativeNorm(null)) + .IgnoreArguments() + .WhenCalled(invocation => + { + var actionToPerform = (Action) invocation.Arguments[0]; + actionToPerform(); + }); + mocks.ReplayAll(); + + var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); + + const double newValue = 0.00001; + + // When + properties.SignalingNorm = newValue; + + // Then + Assert.AreEqual(newValue, failureMechanismContribution.SignalingNorm); + mocks.VerifyAll(); } - private static void SetPropertyAndVerifyNotificationsAndOutputForCalculation(Action setProperty) + [Test] + public void GivenNormativeNormIsLowerLimitNorm_WhenChangingSignalingNorm_ThenHandlerCalledAndPropertySet() { + // Given + FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); + + var mocks = new MockRepository(); + var failureMechanismContributionNormChangeHandler = mocks.StrictMock(); + failureMechanismContributionNormChangeHandler.Expect(h => h.ChangeNorm(null)) + .IgnoreArguments() + .WhenCalled(invocation => + { + var actionToPerform = (Action) invocation.Arguments[0]; + actionToPerform(); + }); + mocks.ReplayAll(); + + var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); + + const double newValue = 0.00001; + + // When + properties.SignalingNorm = newValue; + + // Then + Assert.AreEqual(newValue, failureMechanismContribution.SignalingNorm); + mocks.VerifyAll(); + } + + [Test] + public void NormativeNorm_Always_HandlerCalledAndPropertySet() + { // Setup FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); var mocks = new MockRepository(); - var observable = mocks.StrictMock(); - observable.Expect(o => o.NotifyObservers()); + var failureMechanismContributionNormChangeHandler = mocks.StrictMock(); + failureMechanismContributionNormChangeHandler.Expect(h => h.ChangeNormativeNormType(null)) + .IgnoreArguments() + .WhenCalled(invocation => + { + var actionToPerform = (Action) invocation.Arguments[0]; + actionToPerform(); + }); mocks.ReplayAll(); - var handler = new SetPropertyValueAfterConfirmationParameterTester(new[] - { - observable - }); + var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); - var properties = new NormProperties(failureMechanismContribution, handler); + const NormType newValue = NormType.Signaling; // Call - setProperty(properties); + properties.NormativeNorm = newValue; // Assert - Assert.IsTrue(handler.Called); + Assert.AreEqual(newValue, failureMechanismContribution.NormativeNorm); mocks.VerifyAll(); } }