Index: Ringtoets/Common/src/Ringtoets.Common.Forms/FailureMechanismPropertyChangeHandler.cs
===================================================================
diff -u -rd819ea1eaeed69d333b425c911c370397a24dc0f -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501
--- Ringtoets/Common/src/Ringtoets.Common.Forms/FailureMechanismPropertyChangeHandler.cs (.../FailureMechanismPropertyChangeHandler.cs) (revision d819ea1eaeed69d333b425c911c370397a24dc0f)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/FailureMechanismPropertyChangeHandler.cs (.../FailureMechanismPropertyChangeHandler.cs) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501)
@@ -58,5 +58,55 @@
return Resources.FailureMechanismPropertyChangeHandler_Confirm_change_composition_and_clear_dependent_data;
}
}
+
+ ///
+ /// 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.
+ ///
+ /// The type of the value that is set on a property of the failure mechanism.
+ /// The failure mechanism for which the property is supposed to be set.
+ /// The new value of the failure mechanism property.
+ /// The operation which is performed to set the new property
+ /// on the .
+ /// Thrown when any input parameter is null.
+ /// Let throw an when the
+ /// should not process the results of that operation.
+ public IEnumerable SetPropertyValueAfterConfirmation(
+ T failureMechanism,
+ TValue value, SetFailureMechanismPropertyValueDelegate setValue)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+ if (value == null)
+ {
+ throw new ArgumentNullException(nameof(value));
+ }
+ if (setValue == null)
+ {
+ throw new ArgumentNullException(nameof(setValue));
+ }
+
+ var changedObjects = new List();
+
+ if (RequiresConfirmation(failureMechanism))
+ {
+ if (ConfirmPropertyChange())
+ {
+ setValue(failureMechanism, value);
+ changedObjects.AddRange(PropertyChanged(failureMechanism));
+ changedObjects.Add(failureMechanism);
+ }
+ }
+ else
+ {
+ setValue(failureMechanism, value);
+ changedObjects.Add(failureMechanism);
+ }
+
+ return changedObjects;
+ }
}
}
\ No newline at end of file
Fisheye: Tag a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/IFailureMechanismPropertyChangeHandlerExtensions.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/IFailureMechanismPropertyChangeHandler.cs
===================================================================
diff -u -rd819ea1eaeed69d333b425c911c370397a24dc0f -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501
--- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/IFailureMechanismPropertyChangeHandler.cs (.../IFailureMechanismPropertyChangeHandler.cs) (revision d819ea1eaeed69d333b425c911c370397a24dc0f)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/IFailureMechanismPropertyChangeHandler.cs (.../IFailureMechanismPropertyChangeHandler.cs) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501)
@@ -6,10 +6,20 @@
namespace Ringtoets.Common.Forms.PropertyClasses
{
///
+ /// Action in which a property of the is set to the given .
+ ///
+ /// The type of the failure mechanism that is passed as argument.
+ /// The type of the value that is set on a property of the failure mechanism.
+ /// The failure mechanism for which the property will be set.
+ /// The new value of the failure mechanism property.
+ public delegate void SetFailureMechanismPropertyValueDelegate(TFailureMechanism failureMechanism, TValue value)
+ where TFailureMechanism : IFailureMechanism;
+
+ ///
/// Interface for an object that can properly handle data model changes due to a change of a
/// failure mechanism property.
///
- public interface IFailureMechanismPropertyChangeHandler where T : IFailureMechanism
+ public interface IFailureMechanismPropertyChangeHandler where T : IFailureMechanism
{
///
/// Checks whether a call to would have any effect in the given
@@ -37,5 +47,23 @@
/// 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.
+ ///
+ /// The type of the value that is set on a property of the failure mechanism.
+ /// The failure mechanism for which the property is supposed to be set.
+ /// The new value of the failure mechanism property.
+ /// The operation which is performed to set the new property
+ /// on the .
+ /// Thrown when any input parameter is null.
+ /// Let throw an when the
+ /// should not process the results of that operation.
+ IEnumerable SetPropertyValueAfterConfirmation(
+ T failureMechanism,
+ TValue value,
+ SetFailureMechanismPropertyValueDelegate setValue);
}
}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj
===================================================================
diff -u -rdf1f3c0c408e42ef49e30ee9477f6bece0442b0b -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision df1f3c0c408e42ef49e30ee9477f6bece0442b0b)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501)
@@ -48,7 +48,6 @@
-
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/FailureMechanismPropertyChangeHandlerTest.cs
===================================================================
diff -u -rc016f7af2a4afdc96fc19b8db86dc8d3559de023 -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/FailureMechanismPropertyChangeHandlerTest.cs (.../FailureMechanismPropertyChangeHandlerTest.cs) (revision c016f7af2a4afdc96fc19b8db86dc8d3559de023)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/FailureMechanismPropertyChangeHandlerTest.cs (.../FailureMechanismPropertyChangeHandlerTest.cs) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501)
@@ -107,6 +107,194 @@
CollectionAssert.AreEquivalent(testCase.ExpectedAffectedCalculations, result);
}
+ [Test]
+ public void SetPropertyValueAfterConfirmation_WithoutFailureMechanism_ThrowsArgumentNullException()
+ {
+ // Setup
+ var changeHandler = new FailureMechanismPropertyChangeHandler();
+
+ // Call
+ TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation(
+ null,
+ 3,
+ (f, v) => { });
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("failureMechanism", paramName);
+ }
+
+ [Test]
+ public void SetPropertyValueAfterConfirmation_WithoutValue_ThrowsArgumentNullException()
+ {
+ // Setup
+ var changeHandler = new FailureMechanismPropertyChangeHandler();
+
+ // Call
+ TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation(
+ new TestFailureMechanism(),
+ null,
+ (f, v) => { });
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("value", paramName);
+ }
+
+ [Test]
+ public void SetPropertyValueAfterConfirmation_WithoutSetProperty_ThrowsArgumentNullException()
+ {
+ // Setup
+ var changeHandler = new FailureMechanismPropertyChangeHandler();
+
+ // Call
+ TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation(
+ new TestFailureMechanism(),
+ 3,
+ null);
+
+ // Assert
+ var paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("setValue", paramName);
+ }
+
+ [Test]
+ public void SetPropertyValueAfterConfirmation_ConfirmationRequiredAndGiven_SetValueCalledAffectedObjectsReturned()
+ {
+ // Setup
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var tester = new MessageBoxTester(wnd);
+ tester.ClickOk();
+ };
+
+ var calculationWithOutput = CreateCalculationWithOutput();
+ var calculationWithoutOutput = CreateCalculationWithoutOutput();
+
+ var testFailureMechanism = new TestFailureMechanism(
+ new []
+ {
+ calculationWithOutput,
+ calculationWithoutOutput
+ });
+ var propertySet = 0;
+
+ var changeHandler = new FailureMechanismPropertyChangeHandler();
+
+ // Call
+ var affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(
+ testFailureMechanism,
+ 3,
+ (f, v) => propertySet++);
+
+ // Assert
+ Assert.AreEqual(1, propertySet);
+ CollectionAssert.AreEqual(new IObservable[] { calculationWithOutput, testFailureMechanism }, affectedObjects);
+ }
+
+ [Test]
+ public void SetPropertyValueAfterConfirmation_ConfirmationNotRequired_SetValueCalledAffectedObjectsReturned()
+ {
+ // Setup
+ var testFailureMechanism = new TestFailureMechanism();
+ var propertySet = 0;
+
+ var changeHandler = new FailureMechanismPropertyChangeHandler();
+
+ // Call
+ var affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(
+ testFailureMechanism,
+ 3,
+ (f, v) => propertySet++);
+
+ // Assert
+ Assert.AreEqual(1, propertySet);
+ CollectionAssert.AreEqual(new IObservable[] { testFailureMechanism }, affectedObjects);
+ }
+
+ [Test]
+ public void SetPropertyValueAfterConfirmation_ConfirmationRequiredButNotGiven_SetValueNotCalledNoAffectedObjectsReturned()
+ {
+ // Setup
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var tester = new MessageBoxTester(wnd);
+ tester.ClickCancel();
+ };
+
+ var calculationWithOutput = CreateCalculationWithOutput();
+ var calculationWithoutOutput = CreateCalculationWithoutOutput();
+
+ var testFailureMechanism = new TestFailureMechanism(
+ new[]
+ {
+ calculationWithOutput,
+ calculationWithoutOutput
+ });
+ var propertySet = 0;
+
+ var changeHandler = new FailureMechanismPropertyChangeHandler();
+
+ // Call
+ var affectedObjects = changeHandler.SetPropertyValueAfterConfirmation(
+ testFailureMechanism,
+ 3,
+ (f, v) => propertySet++);
+
+ // Assert
+ Assert.AreEqual(0, propertySet);
+ CollectionAssert.IsEmpty(affectedObjects);
+ }
+
+ [Test]
+ public void SetPropertyValueAfterConfirmation_ExceptionInSetValueAfterConfirmation_ExceptionBubbled()
+ {
+ // Setup
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var tester = new MessageBoxTester(wnd);
+ tester.ClickOk();
+ };
+
+ var testFailureMechanism = new TestFailureMechanism(
+ new[]
+ {
+ CreateCalculationWithOutput(),
+ });
+
+ var changeHandler = new FailureMechanismPropertyChangeHandler();
+ var expectedException = new Exception();
+
+ // Call
+ TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation(
+ testFailureMechanism,
+ 3,
+ (f, v) => { throw expectedException; });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreSame(expectedException, exception);
+ }
+
+ [Test]
+ public void SetPropertyValueAfterConfirmation_ConfirmationNotRequiredExceptionInSetValue_ExceptionBubbled()
+ {
+ // Setup
+ var testFailureMechanism = new TestFailureMechanism();
+ var changeHandler = new FailureMechanismPropertyChangeHandler();
+ var expectedException = new Exception();
+
+ // Call
+ TestDelegate test = () => changeHandler.SetPropertyValueAfterConfirmation(
+ testFailureMechanism,
+ 3,
+ (f, v) => { throw expectedException; });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreSame(expectedException, exception);
+ }
+
public class ChangePropertyTestCase
{
public ChangePropertyTestCase(ICollection calculations)
Fisheye: Tag a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/IFailureMechanismPropertyChangeHandlerExtensionsTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj
===================================================================
diff -u -rdf1f3c0c408e42ef49e30ee9477f6bece0442b0b -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision df1f3c0c408e42ef49e30ee9477f6bece0442b0b)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501)
@@ -65,7 +65,6 @@
-
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingFailureMechanismContextProperties.cs
===================================================================
diff -u -rdf1f3c0c408e42ef49e30ee9477f6bece0442b0b -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingFailureMechanismContextProperties.cs (.../PipingFailureMechanismContextProperties.cs) (revision df1f3c0c408e42ef49e30ee9477f6bece0442b0b)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingFailureMechanismContextProperties.cs (.../PipingFailureMechanismContextProperties.cs) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501)
@@ -20,13 +20,12 @@
// 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 Ringtoets.Common.Data.FailureMechanism;
-using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Common.Forms.PropertyClasses;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Forms.PresentationObjects;
@@ -40,7 +39,7 @@
///
public class PipingFailureMechanismContextProperties : ObjectProperties
{
- private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler;
+ private readonly IFailureMechanismPropertyChangeHandler propertyChangeHandler;
///
/// Creates a new instance of .
@@ -50,7 +49,7 @@
/// Thrown when any input parameter is null.
public PipingFailureMechanismContextProperties(
PipingFailureMechanismContext data,
- IFailureMechanismPropertyChangeHandler handler)
+ IFailureMechanismPropertyChangeHandler handler)
{
if (data == null)
{
@@ -118,10 +117,12 @@
}
set
{
- propertyChangeHandler.SetPropertyValueAfterConfirmation(
+ IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation(
data.WrappedData,
value,
(f,v) => f.GeneralInput.WaterVolumetricWeight = v);
+
+ NotifyAffectedObjects(affectedObjects);
}
}
@@ -169,10 +170,12 @@
}
set
{
- propertyChangeHandler.SetPropertyValueAfterConfirmation(
+ IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation(
data.WrappedData,
value,
(f, v) => f.PipingProbabilityAssessmentInput.A = v);
+
+ NotifyAffectedObjects(affectedObjects);
}
}
@@ -278,5 +281,12 @@
#endregion
+ private static void NotifyAffectedObjects(IEnumerable affectedObjects)
+ {
+ foreach (var affectedObject in affectedObjects)
+ {
+ affectedObject.NotifyObservers();
+ }
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs
===================================================================
diff -u -rc016f7af2a4afdc96fc19b8db86dc8d3559de023 -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision c016f7af2a4afdc96fc19b8db86dc8d3559de023)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501)
@@ -69,7 +69,7 @@
{
yield return new PropertyInfo
{
- CreateInstance = context => new PipingFailureMechanismContextProperties(context, new FailureMechanismPropertyChangeHandler())
+ CreateInstance = context => new PipingFailureMechanismContextProperties(context, new FailureMechanismPropertyChangeHandler())
};
yield return new PropertyInfo();
yield return new PropertyInfo();
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingFailureMechanismContextPropertiesTest.cs
===================================================================
diff -u -rd819ea1eaeed69d333b425c911c370397a24dc0f -ra1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingFailureMechanismContextPropertiesTest.cs (.../PipingFailureMechanismContextPropertiesTest.cs) (revision d819ea1eaeed69d333b425c911c370397a24dc0f)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingFailureMechanismContextPropertiesTest.cs (.../PipingFailureMechanismContextPropertiesTest.cs) (revision a1f3f9aad8b2f6e3663a7ebd8915d0c4ed664501)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Core.Common.Base;
@@ -29,7 +30,6 @@
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
-using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Forms.PropertyClasses;
using Ringtoets.Piping.Data;
@@ -46,7 +46,7 @@
{
// Setup
var mocks = new MockRepository();
- var handler = mocks.Stub>();
+ var handler = mocks.Stub>();
mocks.ReplayAll();
// Call
@@ -85,7 +85,7 @@
var mockRepository = new MockRepository();
var assessmentSectionStub = mockRepository.Stub();
- var handler = mockRepository.Stub>();
+ var handler = mockRepository.Stub>();
mockRepository.ReplayAll();
// Call
@@ -128,7 +128,7 @@
var mockRepository = new MockRepository();
var assessmentSectionStub = mockRepository.Stub();
- var handler = mockRepository.Stub>();
+ var handler = mockRepository.Stub>();
mockRepository.ReplayAll();
@@ -259,27 +259,31 @@
[TestCase(-0.1)]
[TestCase(1.1)]
[TestCase(8)]
- public void A_SetInvalidValueWithConfirmation_ThrowsArgumentException(double value)
+ public void A_SetInvalidValue_ThrowsArgumentException(double value)
{
// Setup
var failureMechanism = new PipingFailureMechanism();
var mocks = new MockRepository();
- var assessmentSection = mocks.Stub();
- var observerMock = mocks.StrictMock();
+ var observableMock = mocks.StrictMock();
- var changeHandler = mocks.Stub>();
- changeHandler.Expect(h => h.RequiresConfirmation(failureMechanism)).Return(true);
- changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(true);
+ var changeHandler = CreateStubChangeHandler(
+ mocks,
+ failureMechanism,
+ value,
+ new[]
+ {
+ observableMock
+ });
+ var assessmentSection = mocks.Stub();
+
mocks.ReplayAll();
var properties = new PipingFailureMechanismContextProperties(
new PipingFailureMechanismContext(failureMechanism, assessmentSection),
changeHandler);
- failureMechanism.Attach(observerMock);
-
// Call
TestDelegate call = () => properties.A = value;
@@ -296,29 +300,28 @@
[TestCase(1)]
[TestCase(0.0000001)]
[TestCase(0.9999999)]
- public void A_SetValidValueWithConfirmation_SetsValueAndUpdatesObservers(double value)
+ public void A_SetValidValue_SetsValueAndUpdatesObservers(double value)
{
// Setup
var failureMechanism = new PipingFailureMechanism();
var mocks = new MockRepository();
- var observerMock = mocks.StrictMock();
- observerMock.Expect(o => o.UpdateObserver());
-
var observableMock = mocks.StrictMock();
observableMock.Expect(o => o.NotifyObservers());
- var changeHandler = mocks.Stub>();
- changeHandler.Expect(h => h.RequiresConfirmation(failureMechanism)).Return(true);
- changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(true);
- changeHandler.Expect(h => h.PropertyChanged(failureMechanism)).Return(new [] { observableMock });
+ var changeHandler = CreateStubChangeHandler(
+ mocks,
+ failureMechanism,
+ value,
+ new[]
+ {
+ observableMock
+ });
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
- failureMechanism.Attach(observerMock);
-
var properties = new PipingFailureMechanismContextProperties(
new PipingFailureMechanismContext(failureMechanism, assessmentSection),
changeHandler);
@@ -332,73 +335,38 @@
}
[Test]
- [TestCase(-1)]
- [TestCase(-0.1)]
- [TestCase(1.1)]
- [TestCase(8)]
- [TestCase(1)]
- [TestCase(10)]
- [TestCase(20)]
- public void A_SetValidNoConfirmation_NoValueChangeNoUpdates(double value)
- {
- // Setup
- var failureMechanism = new PipingFailureMechanism();
-
- var mockRepository = new MockRepository();
- var observerMock = mockRepository.StrictMock();
-
- var changeHandler = mockRepository.StrictMock>();
- changeHandler.Expect(h => h.RequiresConfirmation(failureMechanism)).Return(true);
- changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(false);
-
- var assessmentSection = mockRepository.Stub();
-
- mockRepository.ReplayAll();
-
- failureMechanism.Attach(observerMock);
-
- var properties = new PipingFailureMechanismContextProperties(
- new PipingFailureMechanismContext(failureMechanism, assessmentSection),
- changeHandler);
- double oldValue = properties.A;
-
- // Call
- properties.A = value;
-
- // Assert
- Assert.AreEqual(oldValue, failureMechanism.PipingProbabilityAssessmentInput.A);
- mockRepository.VerifyAll();
- }
-
- [Test]
[TestCase(double.NaN)]
[TestCase(double.NegativeInfinity)]
[TestCase(double.PositiveInfinity)]
[TestCase(-0.005)]
[TestCase(20.005)]
- public void WaterVolumetricWeight_SetInvalidValueWithConfirmation_ThrowArgumentExceptionAndDoesNotUpdateObservers(double value)
+ public void WaterVolumetricWeight_SetInvalidValue_ThrowArgumentExceptionAndDoesNotUpdateObservers(double value)
{
// Setup
var failureMechanism = new PipingFailureMechanism();
+ var roundedValue = (RoundedDouble) value;
var mocks = new MockRepository();
- var observerMock = mocks.StrictMock();
+ var observableMock = mocks.StrictMock();
var assessmentSection = mocks.Stub();
- var changeHandler = mocks.Stub>();
- changeHandler.Expect(h => h.RequiresConfirmation(failureMechanism)).Return(true);
- changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(true);
+ var changeHandler = CreateStubChangeHandler(
+ mocks,
+ failureMechanism,
+ roundedValue,
+ new[]
+ {
+ observableMock
+ });
mocks.ReplayAll();
-
- failureMechanism.Attach(observerMock);
-
+
var properties = new PipingFailureMechanismContextProperties(
new PipingFailureMechanismContext(failureMechanism, assessmentSection),
changeHandler);
// Call
- TestDelegate test = () => properties.WaterVolumetricWeight = (RoundedDouble) value;
+ TestDelegate test = () => properties.WaterVolumetricWeight = roundedValue;
// Assert
TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, "De waarde moet binnen het bereik [0, 20] liggen.");
@@ -409,78 +377,61 @@
[TestCase(5)]
[TestCase(-0.004)]
[TestCase(20.004)]
- public void WaterVolumetricWeight_SetValidValueWithConfirmation_SetsValueRoundedAndUpdatesObservers(double value)
+ public void WaterVolumetricWeight_SetValidValue_SetsValueRoundedAndUpdatesObservers(double value)
{
// Setup
var failureMechanism = new PipingFailureMechanism();
+ var roundedValue = (RoundedDouble)value;
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
- var observerMock = mocks.StrictMock();
- observerMock.Expect(o => o.UpdateObserver());
var observableMock = mocks.StrictMock();
observableMock.Expect(o => o.NotifyObservers());
- var handler = mocks.Stub>();
- handler.Expect(h => h.RequiresConfirmation(failureMechanism)).Return(true);
- handler.Expect(h => h.ConfirmPropertyChange()).Return(true);
- handler.Expect(h => h.PropertyChanged(failureMechanism)).Return(new[] { observableMock });
+ var changeHandler = CreateStubChangeHandler(
+ mocks,
+ failureMechanism,
+ roundedValue,
+ new[]
+ {
+ observableMock
+ });
mocks.ReplayAll();
- failureMechanism.Attach(observerMock);
-
var properties = new PipingFailureMechanismContextProperties(
new PipingFailureMechanismContext(failureMechanism, assessmentSection),
- handler);
+ changeHandler);
// Call
- properties.WaterVolumetricWeight = (RoundedDouble) value;
+ properties.WaterVolumetricWeight = roundedValue;
// Assert
Assert.AreEqual(value, failureMechanism.GeneralInput.WaterVolumetricWeight.Value, failureMechanism.GeneralInput.WaterVolumetricWeight.GetAccuracy());
mocks.VerifyAll();
}
-
- [Test]
- [TestCase(double.NaN)]
- [TestCase(double.NegativeInfinity)]
- [TestCase(double.PositiveInfinity)]
- [TestCase(-0.005)]
- [TestCase(20.005)]
- [TestCase(5)]
- [TestCase(-0.004)]
- [TestCase(20.004)]
- public void WaterVolumetricWeight_SetValueNoConfirmation_NoValueChangeNoUpdates(double value)
+
+ private static IFailureMechanismPropertyChangeHandler CreateStubChangeHandler(
+ MockRepository mocks,
+ PipingFailureMechanism failureMechanism,
+ T value,
+ IEnumerable affectedObjects)
{
- // Setup
- var failureMechanism = new PipingFailureMechanism();
-
- var mocks = new MockRepository();
- var observerMock = mocks.StrictMock();
- var assessmentSection = mocks.Stub();
-
- var changeHandler = mocks.StrictMock>();
- changeHandler.Expect(h => h.RequiresConfirmation(failureMechanism)).Return(true);
- changeHandler.Expect(h => h.ConfirmPropertyChange()).Return(false);
-
- mocks.ReplayAll();
-
- failureMechanism.Attach(observerMock);
-
- var properties = new PipingFailureMechanismContextProperties(
- new PipingFailureMechanismContext(failureMechanism, assessmentSection),
- changeHandler);
-
- RoundedDouble oldValue = properties.WaterVolumetricWeight;
-
- // Call
- properties.WaterVolumetricWeight = (RoundedDouble) value;
-
- // Assert
- Assert.AreEqual(oldValue, failureMechanism.GeneralInput.WaterVolumetricWeight.Value, failureMechanism.GeneralInput.WaterVolumetricWeight.GetAccuracy());
- mocks.VerifyAll();
+ var changeHandler = mocks.Stub>();
+ changeHandler.Expect(h => h.SetPropertyValueAfterConfirmation(
+ Arg.Is.Same(failureMechanism),
+ Arg.Is.Equal(value),
+ Arg>.Is.NotNull))
+ .WhenCalled(m =>
+ {
+ var action = (SetFailureMechanismPropertyValueDelegate) m.Arguments[2];
+ var fm = (PipingFailureMechanism) m.Arguments[0];
+ var v = (T) m.Arguments[1];
+ action(fm, v);
+ })
+ .Return(affectedObjects);
+ return changeHandler;
}
}
}
\ No newline at end of file