Index: Core/Common/test/Core.Common.TestUtil.Test/ControlsTestHelperTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.TestUtil.Test/ControlsTestHelperTest.cs (revision 0) +++ Core/Common/test/Core.Common.TestUtil.Test/ControlsTestHelperTest.cs (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -0,0 +1,97 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.ObjectModel; +using System.Windows.Forms; +using NUnit.Framework; + +namespace Core.Common.TestUtil.Test +{ + [TestFixture] + public class ControlsTestHelperTest + { + [Test] + public void FakeUserSelectingNewValue_ValueInComboBoxDifferentFromCurrentValue_SetSelectedValueAndFireEvents() + { + // Setup + const string selectedindexchanged = "SelectedIndexChanged"; + const string selectedvaluechanged = "SelectedValueChanged"; + const string selectionchangecommitted = "SelectionChangeCommitted"; + + string value1 = "1", value2 = "2"; + + using(var form = new Form()) + using (var control = new ComboBox + { + DropDownStyle = ComboBoxStyle.DropDownList, + DataSource = new[] + { + Tuple.Create(value1, "A"), + Tuple.Create(value2, "B"), + }, + ValueMember = "Item1", + DisplayMember = "Item2" + }) + { + control.SelectedValue = value1; + + form.Controls.Add(control); + form.Show(); + + var raisedEvents = new Collection(); + control.SelectedIndexChanged += (sender, args) => + { + raisedEvents.Add(selectedindexchanged); + }; + control.SelectedValueChanged += (sender, args) => + { + raisedEvents.Add(selectedvaluechanged); + }; + control.SelectionChangeCommitted += (sender, args) => + { + raisedEvents.Add(selectionchangecommitted); + }; + control.Validating += (sender, args) => + { + Assert.Fail("Validating event should not be fired as 'FakeUserSelectingNewValue' method does not handle focus-changes."); + }; + control.Validated += (sender, args) => + { + Assert.Fail("Validated event should not be fired as 'FakeUserSelectingNewValue' method does not handle focus-changes."); + }; + + // Call + ControlsTestHelper.FakeUserSelectingNewValue(control, value2); + + // Assert + Assert.AreEqual(value2, control.SelectedValue); + var expectedRaisedEvents = new[] + { + selectedvaluechanged, + selectedindexchanged, + selectionchangecommitted + }; + CollectionAssert.AreEqual(expectedRaisedEvents, raisedEvents); + } + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.TestUtil.Test/Core.Common.TestUtil.Test.csproj =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Core/Common/test/Core.Common.TestUtil.Test/Core.Common.TestUtil.Test.csproj (.../Core.Common.TestUtil.Test.csproj) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.TestUtil.Test/Core.Common.TestUtil.Test.csproj (.../Core.Common.TestUtil.Test.csproj) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -51,13 +51,16 @@ + + Properties\GlobalAssembly.cs + Index: Core/Common/test/Core.Common.TestUtil/ControlsTestHelper.cs =================================================================== diff -u --- Core/Common/test/Core.Common.TestUtil/ControlsTestHelper.cs (revision 0) +++ Core/Common/test/Core.Common.TestUtil/ControlsTestHelper.cs (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Windows.Forms; +using NUnit.Extensions.Forms; + +namespace Core.Common.TestUtil +{ + /// + /// Class providing high level actions on winforms controls. + /// + public static class ControlsTestHelper + { + /// + /// Emulates the user selecting new value a . + /// + /// The combo box to be edited. + /// The new value to be selected. + /// Thrown when + /// isn't configured to use . + /// + /// + /// Do not use this method for instances configured + /// to use with . + /// + /// + /// The and events + /// will not be fired when calling this method, as this method does not deal with + /// focus changes. + /// + /// + public static void FakeUserSelectingNewValue(ComboBox comboBox, object newValue) + { + if (comboBox.DataSource == null || comboBox.DisplayMember == null || comboBox.ValueMember == null) + { + throw new InvalidOperationException("Call FakeUserSelectingNewValue only for ComboBox instances that are configured to use a DataSource."); + } + + comboBox.SelectedValue = newValue; + EventHelper.RaiseEvent(comboBox, "SelectionChangeCommitted"); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj (.../Core.Common.TestUtil.csproj) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj (.../Core.Common.TestUtil.csproj) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -72,6 +72,9 @@ ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True + + ..\..\..\..\lib\NUnitForms.dll + @@ -88,6 +91,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContribution.cs =================================================================== diff -u -r901339a7022b3be93778d9691b001ba085c53d43 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContribution.cs (.../FailureMechanismContribution.cs) (revision 901339a7022b3be93778d9691b001ba085c53d43) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContribution.cs (.../FailureMechanismContribution.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -35,6 +35,7 @@ { private readonly ICollection distribution = new List(); private double norm; + private readonly OtherFailureMechanism otherFailureMechanism = new OtherFailureMechanism(); /// /// Creates a new instance of . Values are taken from the @@ -139,10 +140,7 @@ /// Thrown when is not in the interval [0, 100] private void AddOtherContributionItem(double otherContribution) { - var otherFailureMechanism = new OtherFailureMechanism - { - Contribution = otherContribution - }; + otherFailureMechanism.Contribution = otherContribution; var otherContributionItem = new FailureMechanismContributionItem(otherFailureMechanism, norm, true); distribution.Add(otherContributionItem); } Index: Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContributionItem.cs =================================================================== diff -u -recf136a787efcd5d3f171f8aee8930f84a89e80a -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContributionItem.cs (.../FailureMechanismContributionItem.cs) (revision ecf136a787efcd5d3f171f8aee8930f84a89e80a) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContributionItem.cs (.../FailureMechanismContributionItem.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -26,8 +26,8 @@ namespace Ringtoets.Common.Data.Contribution { /// - /// This class represents an amount for which a failure mechanism will contribute to the - /// overall verdict of an assessment section. + /// This class represents an amount for which a will + /// contribute to the overall verdict of an assessment section. /// public class FailureMechanismContributionItem { @@ -47,7 +47,7 @@ { if (failureMechanism == null) { - throw new ArgumentNullException("failureMechanism",Resources.FailureMechanismContributionItem_Can_not_create_contribution_item_without_failure_mechanism); + throw new ArgumentNullException("failureMechanism", Resources.FailureMechanismContributionItem_Can_not_create_contribution_item_without_failure_mechanism); } this.failureMechanism = failureMechanism; @@ -124,12 +124,23 @@ } /// - /// Gets a value indicating whether the corresponding failure mechanism is always - /// relevant. When true, then cannot be set to false. + /// Gets a value indicating whether the corresponding + /// is always relevant. When true, then cannot be set to false. /// public bool IsAlwaysRelevant { get; private set; } /// + /// Gets the failure mechanism. + /// + public IFailureMechanism FailureMechanism + { + get + { + return failureMechanism; + } + } + + /// /// Notifies the observers for the wrapped . /// public void NotifyFailureMechanismObservers() Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r86b6ce2b77450d63016858e8e18796c02bdaad52 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 86b6ce2b77450d63016858e8e18796c02bdaad52) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -400,16 +400,6 @@ } /// - /// Looks up a localized string similar to Weet u zeker dat u alles binnen deze Berekeningen map wilt verwijderen?. - /// - public static string CalculationGroup_RemoveAllChildrenFromGroup_Are_you_sure_you_want_to_remove_everything_from_this_group { - get { - return ResourceManager.GetString("CalculationGroup_RemoveAllChildrenFromGroup_Are_you_sure_you_want_to_remove_every" + - "thing_from_this_group", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Valideer alle berekeningen binnen deze berekeningsmap.. /// public static string CalculationGroup_Validate_all_ToolTip { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx =================================================================== diff -u -r86b6ce2b77450d63016858e8e18796c02bdaad52 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 86b6ce2b77450d63016858e8e18796c02bdaad52) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -418,9 +418,6 @@ Voeg een nieuw traject toe aan het project. - - Weet u zeker dat u alles binnen deze Berekeningen map wilt verwijderen? - Genereer &berekeningen... Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs =================================================================== diff -u -rb6f4e414fc874653cc6ad84b80f330b28e69b823 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision b6f4e414fc874653cc6ad84b80f330b28e69b823) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -22,7 +22,6 @@ using System; using System.Linq; using System.Windows.Forms; -using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; @@ -368,21 +367,6 @@ }); } - private static void RemoveAllChildrenFromGroup(CalculationGroup calculationGroup, IViewCommands viewCommands) - { - if (MessageBox.Show(Resources.CalculationGroup_RemoveAllChildrenFromGroup_Are_you_sure_you_want_to_remove_everything_from_this_group, BaseResources.Confirm, MessageBoxButtons.OKCancel) != DialogResult.OK) - { - return; - } - foreach (var calculation in calculationGroup.GetCalculations()) - { - viewCommands.RemoveAllViewsForItem(calculation); - } - calculationGroup.Children.Clear(); - - calculationGroup.NotifyObservers(); - } - private static void SetStateWithEnableFunction(T context, Func enableFunction, StrictContextMenuItem menuItem) { var validationText = enableFunction != null ? enableFunction(context) : null; Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionItemTest.cs =================================================================== diff -u -recf136a787efcd5d3f171f8aee8930f84a89e80a -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionItemTest.cs (.../FailureMechanismContributionItemTest.cs) (revision ecf136a787efcd5d3f171f8aee8930f84a89e80a) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionItemTest.cs (.../FailureMechanismContributionItemTest.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -83,6 +83,7 @@ Assert.AreEqual(norm, result.Norm); Assert.IsFalse(result.IsAlwaysRelevant); Assert.AreEqual(isRelevant, result.IsRelevant); + Assert.AreSame(failureMechanism, result.FailureMechanism); mockRepository.VerifyAll(); } Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionTest.cs =================================================================== diff -u -r901339a7022b3be93778d9691b001ba085c53d43 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionTest.cs (.../FailureMechanismContributionTest.cs) (revision 901339a7022b3be93778d9691b001ba085c53d43) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionTest.cs (.../FailureMechanismContributionTest.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -228,6 +228,27 @@ } [Test] + public void UpdateContributions_MultipleChanges_AllFailureMechanismContributionItemsHaveLatestContribution() + { + // Given + IEnumerable failureMechanisms = Enumerable.Empty(); + var failureMechanismContribution = new FailureMechanismContribution(failureMechanisms, 12.34, 0.00001); + + const double latestContribution = 2.3; + + // When + failureMechanismContribution.UpdateContributions(failureMechanisms, 1); + var item1 = failureMechanismContribution.Distribution.Single(); + failureMechanismContribution.UpdateContributions(failureMechanisms, latestContribution); + var item2 = failureMechanismContribution.Distribution.Single(); + + // Then + Assert.AreEqual(latestContribution, item1.Contribution); + Assert.AreEqual(latestContribution, item2.Contribution); + Assert.AreEqual(item1.Assessment, item2.Assessment); + } + + [Test] [TestCase(0)] [TestCase(34.6)] [TestCase(100)] Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -97,6 +97,7 @@ DesignWaterLevelLocationsView.cs + Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionItemRow.cs =================================================================== diff -u -recf136a787efcd5d3f171f8aee8930f84a89e80a -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionItemRow.cs (.../FailureMechanismContributionItemRow.cs) (revision ecf136a787efcd5d3f171f8aee8930f84a89e80a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionItemRow.cs (.../FailureMechanismContributionItemRow.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -20,6 +20,8 @@ // All rights reserved. using System; +using Core.Common.Controls.Views; +using Core.Common.Gui.Commands; using Ringtoets.Common.Data.Contribution; namespace Ringtoets.Integration.Forms.Views @@ -30,20 +32,28 @@ internal class FailureMechanismContributionItemRow { private readonly FailureMechanismContributionItem contributionItem; + private readonly IViewCommands viewCommands; /// /// Creates a new instance of . /// /// The this row contains. - /// Thrown when is null. - internal FailureMechanismContributionItemRow(FailureMechanismContributionItem contributionItem) + /// Class responsible for exposing high level + /// related commands. + /// Thrown when any of the input arguments is null. + internal FailureMechanismContributionItemRow(FailureMechanismContributionItem contributionItem, IViewCommands viewCommands) { if (contributionItem == null) { throw new ArgumentNullException("contributionItem"); } + if (viewCommands == null) + { + throw new ArgumentNullException("viewCommands"); + } this.contributionItem = contributionItem; + this.viewCommands = viewCommands; } /// @@ -101,6 +111,11 @@ } set { + if (!value) + { + viewCommands.RemoveAllViewsForItem(contributionItem.FailureMechanism); + } + contributionItem.IsRelevant = value; contributionItem.NotifyFailureMechanismObservers(); } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs =================================================================== diff -u -r753480c9461b7b5bb10eb7abe78224f24160a536 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision 753480c9461b7b5bb10eb7abe78224f24160a536) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -29,13 +29,9 @@ using Core.Common.Controls.Views; using Core.Common.Gui.Commands; using Core.Common.Utils.Reflection; -using log4net; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; -using Ringtoets.Common.Service; -using Ringtoets.GrassCoverErosionOutwards.Data; -using Ringtoets.HydraRing.Data; using CoreCommonBaseResources = Core.Common.Base.Properties.Resources; using CommonGuiResources = Core.Common.Gui.Properties.Resources; using RingtoetsGrassCoverErosionOutwardsFormsResources = Ringtoets.GrassCoverErosionOutwards.Forms.Properties.Resources; @@ -52,31 +48,61 @@ { private const int isRelevantColumnIndex = 0; private const int probabilityPerYearColumnIndex = 4; - private static readonly ILog log = LogManager.GetLogger(typeof(FailureMechanismContributionView)); - private readonly Observer isFailureMechanismRelevantObserver; - private readonly Observer closeViewsForIrrelevantFailureMechanismObserver; - private readonly IFailureMechanismContributionNormChangeHandler changeHandler; + /// + /// This observer is listening for changes to: + /// + /// + /// + /// + /// + private readonly Observer failureMechanismObserver; + + private readonly IFailureMechanismContributionNormChangeHandler normChangeHandler; + private readonly IAssessmentSectionCompositionChangeHandler compositionChangeHandler; + private readonly IViewCommands viewCommands; private FailureMechanismContribution data; private IAssessmentSection assessmentSection; /// /// Creates a new instance of . /// - public FailureMechanismContributionView(IFailureMechanismContributionNormChangeHandler changeHandler) + /// The object responsible for handling the change + /// in the . + /// The object responsible for handling the + /// change in the . + /// Objects exposing high level related commands. + /// When any input argument is null. + public FailureMechanismContributionView(IFailureMechanismContributionNormChangeHandler normChangeHandler, + IAssessmentSectionCompositionChangeHandler compositionChangeHandler, + IViewCommands viewCommands) { + if (normChangeHandler == null) + { + throw new ArgumentNullException("normChangeHandler"); + } + if (compositionChangeHandler == null) + { + throw new ArgumentNullException("compositionChangeHandler"); + } + if (viewCommands == null) + { + throw new ArgumentNullException("viewCommands"); + } + InitializeComponent(); InitializeGridColumns(); InitializeAssessmentSectionCompositionComboBox(); BindNormChange(); BindNormInputLeave(); SubscribeEvents(); - this.changeHandler = changeHandler; + this.normChangeHandler = normChangeHandler; + this.compositionChangeHandler = compositionChangeHandler; + this.viewCommands = viewCommands; - isFailureMechanismRelevantObserver = new Observer(probabilityDistributionGrid.RefreshDataGridView); - closeViewsForIrrelevantFailureMechanismObserver = new Observer(CloseViewsForIrrelevantFailureMechanism); + failureMechanismObserver = new Observer(probabilityDistributionGrid.RefreshDataGridView); } /// @@ -94,8 +120,6 @@ } } - public IViewCommands ViewCommands { private get; set; } - public object Data { get @@ -127,8 +151,8 @@ components.Dispose(); } UnsubscribeEvents(); + UnbindAssessmentSectionCompositionChange(); DetachFromFailureMechanisms(); - ViewCommands = null; } base.Dispose(disposing); } @@ -191,11 +215,9 @@ { foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms()) { - failureMechanism.Detach(isFailureMechanismRelevantObserver); - failureMechanism.Detach(closeViewsForIrrelevantFailureMechanismObserver); + failureMechanism.Detach(failureMechanismObserver); - isFailureMechanismRelevantObserver.Dispose(); - closeViewsForIrrelevantFailureMechanismObserver.Dispose(); + failureMechanismObserver.Dispose(); } } } @@ -206,30 +228,16 @@ { foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms()) { - failureMechanism.Attach(isFailureMechanismRelevantObserver); - failureMechanism.Attach(closeViewsForIrrelevantFailureMechanismObserver); + failureMechanism.Attach(failureMechanismObserver); } } } - private void CloseViewsForIrrelevantFailureMechanism() - { - if (ViewCommands != null) - { - var irrelevantFailureMechanisms = assessmentSection.GetFailureMechanisms().Where(failureMechanism => !failureMechanism.IsRelevant); - - foreach (var failureMechanism in irrelevantFailureMechanisms) - { - ViewCommands.RemoveAllViewsForItem(failureMechanism); - } - } - } - private void SetGridDataSource() { if (data != null) { - probabilityDistributionGrid.SetDataSource(data.Distribution.Select(ci => new FailureMechanismContributionItemRow(ci)).ToArray()); + probabilityDistributionGrid.SetDataSource(data.Distribution.Select(ci => new FailureMechanismContributionItemRow(ci, viewCommands)).ToArray()); probabilityDistributionGrid.RefreshDataGridView(); } } @@ -252,12 +260,12 @@ private void BindAssessmentSectionCompositionChange() { - assessmentSectionCompositionComboBox.SelectedIndexChanged += AssessmentSectionCompositionComboBoxSelectedIndexChanged; + assessmentSectionCompositionComboBox.SelectionChangeCommitted += AssessmentSectionCompositionComboBoxSelectionChangeComitted; } private void UnbindAssessmentSectionCompositionChange() { - assessmentSectionCompositionComboBox.SelectedIndexChanged -= AssessmentSectionCompositionComboBoxSelectedIndexChanged; + assessmentSectionCompositionComboBox.SelectionChangeCommitted -= AssessmentSectionCompositionComboBoxSelectionChangeComitted; } private void BindNormChange() @@ -389,31 +397,20 @@ return rowData.IsAlwaysRelevant; } - private void AssessmentSectionCompositionComboBoxSelectedIndexChanged(object sender, EventArgs e) + private void AssessmentSectionCompositionComboBoxSelectionChangeComitted(object sender, EventArgs e) { - assessmentSection.ChangeComposition((AssessmentSectionComposition) assessmentSectionCompositionComboBox.SelectedValue); - SetGridDataSource(); - - if (assessmentSection.HydraulicBoundaryDatabase != null) + var newComposition = (AssessmentSectionComposition)assessmentSectionCompositionComboBox.SelectedValue; + if (assessmentSection.Composition != newComposition && compositionChangeHandler.ConfirmCompositionChange()) { - ClearGrassCoverErosionOutwardsHydraulicBoundaryLocations(); + IEnumerable changedObjects = compositionChangeHandler.ChangeComposition(assessmentSection, newComposition); + foreach (IObservable changedObject in changedObjects) + { + changedObject.NotifyObservers(); + } } - - assessmentSection.NotifyObservers(); - } - - private void ClearGrassCoverErosionOutwardsHydraulicBoundaryLocations() - { - var grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .First(); - ObservableList hydraulicBoundaryLocations = grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations; - bool locationsAffected = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(hydraulicBoundaryLocations) - .Any(); - if (locationsAffected) + else { - hydraulicBoundaryLocations.NotifyObservers(); - log.Info(RingtoetsGrassCoverErosionOutwardsFormsResources.GrassCoverErosionOutwards_NormValueChanged_Waveheight_and_design_water_level_results_cleared); + assessmentSectionCompositionComboBox.SelectedValue = assessmentSection.Composition; } } @@ -422,7 +419,7 @@ int returnPeriod = Convert.ToInt32(normInput.Value); if (returnPeriod != 0 && assessmentSection.FailureMechanismContribution.Norm.CompareTo(1.0/returnPeriod) != 0) { - if (!changeHandler.ConfirmNormChange()) + if (!normChangeHandler.ConfirmNormChange()) { e.Cancel = true; RevertNormInputValue(); @@ -433,7 +430,7 @@ private void NormNumericUpDown_Validated(object sender, EventArgs e) { double newNormValue = 1.0/Convert.ToInt32(normInput.Value); - IEnumerable changedObjects = changeHandler.ChangeNorm(assessmentSection, newNormValue); + IEnumerable changedObjects = normChangeHandler.ChangeNorm(assessmentSection, newNormValue); foreach (IObservable changedObject in changedObjects) { changedObject.NotifyObservers(); Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx =================================================================== diff -u -recf136a787efcd5d3f171f8aee8930f84a89e80a -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx (.../FailureMechanismContributionView.resx) (revision ecf136a787efcd5d3f171f8aee8930f84a89e80a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx (.../FailureMechanismContributionView.resx) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -289,7 +289,7 @@ probabilityDistributionGrid - Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=16.4.1.6923, Culture=neutral, PublicKeyToken=null + Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=16.4.1.6918, Culture=neutral, PublicKeyToken=null tableLayoutPanel Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IAssessmentSectionCompositionChangeHandler.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IAssessmentSectionCompositionChangeHandler.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IAssessmentSectionCompositionChangeHandler.cs (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -0,0 +1,52 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using Core.Common.Base; +using Ringtoets.Common.Data.AssessmentSection; + +namespace Ringtoets.Integration.Forms.Views +{ + /// + /// Interface for an object that can properly change the + /// of an . + /// + public interface IAssessmentSectionCompositionChangeHandler + { + /// + /// Checks to see if the replacement of the assessment section composition should occur or not. + /// + /// true if the change should occur, false otherwise. + bool ConfirmCompositionChange(); + + /// + /// Replaces the of the + /// and propagates the changes to underlying data structure. + /// + /// The section to be updated. + /// The new norm value. + /// All objects that have been affected by the change. + /// Thrown when + /// is null. + IEnumerable ChangeComposition(IAssessmentSection assessmentSection, AssessmentSectionComposition newComposition); + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -0,0 +1,79 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using log4net; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Forms.Views; +using Ringtoets.Integration.Plugin.Properties; +using Ringtoets.Integration.Service; +using CoreCommonBaseResources = Core.Common.Base.Properties.Resources; + +namespace Ringtoets.Integration.Plugin.Handlers +{ + /// + /// Class responsible for changing the + /// value clearing all data dependent on the original norm value. + /// + public class AssessmentSectionCompositionChangeHandler : IAssessmentSectionCompositionChangeHandler + { + private readonly ILog log = LogManager.GetLogger(typeof(AssessmentSectionCompositionChangeHandler)); + + public bool ConfirmCompositionChange() + { + DialogResult result = MessageBox.Show(Resources.AssessmentSectionCompositionChangeHandler_Confirm_change_composition_and_clear_dependent_data, + CoreCommonBaseResources.Confirm, + MessageBoxButtons.OKCancel); + return result == DialogResult.OK; + } + + public IEnumerable ChangeComposition(IAssessmentSection assessmentSection, AssessmentSectionComposition newComposition) + { + if (assessmentSection == null) + { + throw new ArgumentNullException("assessmentSection"); + } + + var affectedObjects = new List(); + if (assessmentSection.Composition != newComposition) + { + assessmentSection.ChangeComposition(newComposition); + + affectedObjects.Add(assessmentSection); + affectedObjects.AddRange(assessmentSection.GetFailureMechanisms()); + + IObservable[] affectedCalculations = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection).ToArray(); + if (affectedCalculations.Length > 0) + { + affectedObjects.AddRange(affectedCalculations); + log.InfoFormat(Resources.ChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared, + affectedObjects.Count); + } + } + return affectedObjects; + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs =================================================================== diff -u -r753480c9461b7b5bb10eb7abe78224f24160a536 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (.../FailureMechanismContributionNormChangeHandler.cs) (revision 753480c9461b7b5bb10eb7abe78224f24160a536) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (.../FailureMechanismContributionNormChangeHandler.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -76,7 +76,7 @@ List affectedObjects = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection).ToList(); if (affectedObjects.Count > 0) { - log.InfoFormat(Resources.FailureMechanismContributionNormChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared, + log.InfoFormat(Resources.ChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared, affectedObjects.Count); } Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -61,6 +61,27 @@ } /// + /// Looks up a localized string similar to Na het aanpassen van het trajecttype zullen alle rekenresultaten van alle toetssporen gewist worden. + /// + ///Wilt u doorgaan?. + /// + public static string AssessmentSectionCompositionChangeHandler_Confirm_change_composition_and_clear_dependent_data { + get { + return ResourceManager.GetString("AssessmentSectionCompositionChangeHandler_Confirm_change_composition_and_clear_de" + + "pendent_data", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to De resultaten van {0} berekeningen zijn verwijderd.. + /// + public static string ChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared { + get { + return ResourceManager.GetString("ChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Opmerkingen. /// public static string Comment_DisplayName { @@ -100,16 +121,6 @@ } /// - /// Looks up a localized string similar to De resultaten van {0} berekeningen zijn verwijderd.. - /// - public static string FailureMechanismContributionNormChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared { - get { - return ResourceManager.GetString("FailureMechanismContributionNormChangeHandler_Results_of_NumberOfCalculations_0_c" + - "alculations_cleared", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd.. /// public static string FailureMechanismContributionNormChangeHandler_Waveheight_and_design_water_level_results_cleared { Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx =================================================================== diff -u -r1ecce87531e75e9bf509ad7fb8bfbe05c627570d -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 1ecce87531e75e9bf509ad7fb8bfbe05c627570d) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -147,7 +147,7 @@ Wilt u doorgaan? - + De resultaten van {0} berekeningen zijn verwijderd. @@ -158,4 +158,9 @@ Wilt u doorgaan? + + Na het aanpassen van het trajecttype zullen alle rekenresultaten van alle toetssporen gewist worden. + +Wilt u doorgaan? + \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -54,6 +54,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r9fb229f4fc4fe2c11e79e344c76ceb220f2dc96a -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 9fb229f4fc4fe2c11e79e344c76ceb220f2dc96a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -298,11 +298,12 @@ GetViewData = context => context.WrappedData, Image = RingtoetsCommonFormsResources.FailureMechanismContributionIcon, CloseForData = CloseFailureMechanismContributionViewForData, - CreateInstance = () => new FailureMechanismContributionView(new FailureMechanismContributionNormChangeHandler()), + CreateInstance = () => new FailureMechanismContributionView(new FailureMechanismContributionNormChangeHandler(), + new AssessmentSectionCompositionChangeHandler(), + Gui.ViewCommands), AfterCreate = (view, context) => { view.AssessmentSection = context.Parent; - view.ViewCommands = Gui.ViewCommands; } }; Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs =================================================================== diff -u -r753480c9461b7b5bb10eb7abe78224f24160a536 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs (.../FailureMechanismContributionViewIntegrationTest.cs) (revision 753480c9461b7b5bb10eb7abe78224f24160a536) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs (.../FailureMechanismContributionViewIntegrationTest.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -20,11 +20,13 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Data; +using Core.Common.Gui.Commands; using Core.Common.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; @@ -52,11 +54,17 @@ private const string messageAllHydraulicBoundaryLocationOutputCleared = "Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd."; - private const string messageGrassCoverErosionOutwardsHydraulicBoundaryLocationOutputCleared = - "De berekende waterstanden en golfhoogtes bij doorsnede-eis voor alle hydraulische randvoorwaarden locaties zijn verwijderd."; - private const string messageCalculationsremoved = "De resultaten van {0} berekeningen zijn verwijderd."; + private const string normInputTextBoxName = "normInput"; + private const string dataGridViewControlName = "dataGridView"; + private const string assessmentSectionCompositionComboBoxName = "assessmentSectionCompositionComboBox"; + private const int isRelevantColumnIndex = 0; + private const int nameColumnIndex = 1; + private const int codeColumnIndex = 2; + private const int contributionColumnIndex = 3; + private const int probabilitySpaceColumnIndex = 4; + [Test] public void NormTextBox_ValueChanged_ClearsDependentDataAndNotifiesObserversAndLogsMessages() { @@ -135,6 +143,8 @@ hydraulicBoundaryDatabaseObserver.Expect(hbdo => hbdo.UpdateObserver()); IObserver grassCoverErosionOutwardsObserver = mockRepository.StrictMock(); grassCoverErosionOutwardsObserver.Expect(o => o.UpdateObserver()); + + var viewCommands = mockRepository.Stub(); mockRepository.ReplayAll(); failureMechanismContribution.Attach(observerMock); @@ -150,10 +160,11 @@ assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserver); - var handler = new FailureMechanismContributionNormChangeHandler(); + var handler1 = new FailureMechanismContributionNormChangeHandler(); + var handler2 = new AssessmentSectionCompositionChangeHandler(); using (var form = new Form()) - using (var distributionView = new FailureMechanismContributionView(handler) + using (var distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -162,7 +173,7 @@ form.Controls.Add(distributionView); form.Show(); - var normTester = new ControlTester("normInput"); + var normTester = new ControlTester(normInputTextBoxName); // Precondition int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); @@ -242,6 +253,8 @@ IObserver calculationObserver = mockRepository.StrictMock(); // No update observers expected. IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); hydraulicBoundaryDatabaseObserver.Expect(hbdo => hbdo.UpdateObserver()); + + var viewCommands = mockRepository.Stub(); mockRepository.ReplayAll(); failureMechanismContribution.Attach(observerMock); @@ -251,10 +264,11 @@ emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver); emptyHeightStructuresCalculation.Attach(calculationObserver); - var handler = new FailureMechanismContributionNormChangeHandler(); + var handler1 = new FailureMechanismContributionNormChangeHandler(); + var handler2 = new AssessmentSectionCompositionChangeHandler(); using (Form form = new Form()) - using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler) + using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -263,7 +277,7 @@ form.Controls.Add(distributionView); form.Show(); - ControlTester normTester = new ControlTester("normInput"); + ControlTester normTester = new ControlTester(normInputTextBoxName); HydraulicBoundaryLocation hydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations[0]; @@ -348,6 +362,8 @@ IObserver emptyHeightStructuresCalculationObserver = mockRepository.StrictMock(); IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); // No update observer expected. + + var viewCommands = mockRepository.Stub(); mockRepository.ReplayAll(); failureMechanismContribution.Attach(observerMock); @@ -361,10 +377,11 @@ grassCoverErosionInwardsCalculation.Attach(grassCoverErosionInwardsCalculationObserver); heightStructuresCalculation.Attach(heightStructuresCalculationObserver); - var handler = new FailureMechanismContributionNormChangeHandler(); + var handler1 = new FailureMechanismContributionNormChangeHandler(); + var handler2 = new AssessmentSectionCompositionChangeHandler(); using (Form form = new Form()) - using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler) + using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -373,7 +390,7 @@ form.Controls.Add(distributionView); form.Show(); - ControlTester normTester = new ControlTester("normInput"); + ControlTester normTester = new ControlTester(normInputTextBoxName); // Precondition int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); @@ -455,6 +472,7 @@ IObserver emptyGrassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock(); IObserver emptyHeightStructuresCalculationObserver = mockRepository.StrictMock(); + var viewCommands = mockRepository.Stub(); mockRepository.ReplayAll(); failureMechanismContribution.Attach(observerMock); @@ -467,10 +485,11 @@ grassCoverErosionInwardsCalculation.Attach(grassCoverErosionInwardsCalculationObserver); heightStructuresCalculation.Attach(heightStructuresCalculationObserver); - var handler = new FailureMechanismContributionNormChangeHandler(); + var handler1 = new FailureMechanismContributionNormChangeHandler(); + var handler2 = new AssessmentSectionCompositionChangeHandler(); using (Form form = new Form()) - using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler) + using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -479,7 +498,7 @@ form.Controls.Add(distributionView); form.Show(); - ControlTester normTester = new ControlTester("normInput"); + ControlTester normTester = new ControlTester(normInputTextBoxName); // Precondition int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); @@ -541,6 +560,8 @@ observerMock.Expect(o => o.UpdateObserver()); IObserver calculationObserver = mockRepository.StrictMock(); IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); + + var viewCommands = mockRepository.Stub(); mockRepository.ReplayAll(); failureMechanismContribution.Attach(observerMock); @@ -549,10 +570,11 @@ emptyHeightStructuresCalculation.Attach(calculationObserver); hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserver); - var handler = new FailureMechanismContributionNormChangeHandler(); + var handler1 = new FailureMechanismContributionNormChangeHandler(); + var handler2 = new AssessmentSectionCompositionChangeHandler(); using (Form form = new Form()) - using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler) + using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -561,7 +583,7 @@ form.Controls.Add(distributionView); form.Show(); - ControlTester normTester = new ControlTester("normInput"); + ControlTester normTester = new ControlTester(normInputTextBoxName); // Precondition int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); @@ -605,17 +627,20 @@ IObserver observerMock = mockRepository.StrictMock(); observerMock.Expect(o => o.UpdateObserver()); IObserver calculationObserver = mockRepository.StrictMock(); + + var viewCommands = mockRepository.Stub(); mockRepository.ReplayAll(); failureMechanismContribution.Attach(observerMock); emptyPipingCalculation.Attach(calculationObserver); emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver); emptyHeightStructuresCalculation.Attach(calculationObserver); - var handler = new FailureMechanismContributionNormChangeHandler(); + var handler1 = new FailureMechanismContributionNormChangeHandler(); + var handler2 = new AssessmentSectionCompositionChangeHandler(); using (Form form = new Form()) - using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler) + using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -624,7 +649,7 @@ form.Controls.Add(distributionView); form.Show(); - ControlTester normTester = new ControlTester("normInput"); + ControlTester normTester = new ControlTester(normInputTextBoxName); // Precondition int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); @@ -647,200 +672,75 @@ } [Test] - public void AssessmentSectionCompositionComboBox_ValueChanged_ClearsDependentDataAndNotifiesObserversAndLogsMessages() + [TestCase(AssessmentSectionComposition.Dike, AssessmentSectionComposition.Dune)] + [TestCase(AssessmentSectionComposition.Dike, AssessmentSectionComposition.DikeAndDune)] + [TestCase(AssessmentSectionComposition.Dune, AssessmentSectionComposition.Dike)] + [TestCase(AssessmentSectionComposition.Dune, AssessmentSectionComposition.DikeAndDune)] + [TestCase(AssessmentSectionComposition.DikeAndDune, AssessmentSectionComposition.Dike)] + [TestCase(AssessmentSectionComposition.DikeAndDune, AssessmentSectionComposition.Dune)] + public void GivenViewWithAssessmentSection_WhenChangingCompositionComboBoxAndOk_ThenUpdateAssessmentSectionContributionAndView(AssessmentSectionComposition initialComposition, AssessmentSectionComposition newComposition) { - // Setup - var waveHeight = (RoundedDouble) 3.0; - var designWaterLevel = (RoundedDouble) 4.2; + // Given + var mocks = new MockRepository(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0.0, 0.0) - { - WaveHeight = waveHeight, - DesignWaterLevel = designWaterLevel - }; - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase - { - Locations = - { - hydraulicBoundaryLocation - } - }; + var assessmentSection = new AssessmentSection(initialComposition); - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) - { - HydraulicBoundaryDatabase = hydraulicBoundaryDatabase - }; + var handler1 = new FailureMechanismContributionNormChangeHandler(); + var handler2 = new AssessmentSectionCompositionChangeHandler(); - var grassCoverErosionOutwardsHydraulicBoundaryLocation = new HydraulicBoundaryLocation(hydraulicBoundaryLocation.Id, - hydraulicBoundaryLocation.Name, - hydraulicBoundaryLocation.Location.X, - hydraulicBoundaryLocation.Location.Y) - { - WaveHeight = waveHeight, - DesignWaterLevel = designWaterLevel - }; - - assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Add(grassCoverErosionOutwardsHydraulicBoundaryLocation); - - var mockRepository = new MockRepository(); - IObserver observerMock = mockRepository.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()); - IObserver hydraulicBoundaryDatabaseObserverMock = mockRepository.StrictMock(); - IObserver grassCoverErosionOutwardsObserverMock = mockRepository.StrictMock(); - grassCoverErosionOutwardsObserverMock.Expect(o => o.UpdateObserver()); - mockRepository.ReplayAll(); - - assessmentSection.Attach(observerMock); - hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserverMock); - assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserverMock); - - var handler = new FailureMechanismContributionNormChangeHandler(); - using (var form = new Form()) - using (var distributionView = new FailureMechanismContributionView(handler) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = assessmentSection.FailureMechanismContribution, AssessmentSection = assessmentSection }) { - form.Controls.Add(distributionView); + form.Controls.Add(view); form.Show(); - var compositionTester = (ComboBox) new ControlTester("assessmentSectionCompositionComboBox").TheObject; - // Precondition - Assert.AreEqual(waveHeight, hydraulicBoundaryLocation.WaveHeight, hydraulicBoundaryLocation.WaveHeight.GetAccuracy()); - Assert.AreEqual(designWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel.GetAccuracy()); - Assert.AreEqual(waveHeight, grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight, grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight.GetAccuracy()); - Assert.AreEqual(designWaterLevel, grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel, grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel.GetAccuracy()); + Assert.AreNotEqual(assessmentSection.Composition, newComposition); - // Call - Action call = () => compositionTester.SelectedValue = AssessmentSectionComposition.DikeAndDune; + bool dataGridInvalidated = false; + var contributionGridView = (DataGridView) new ControlTester(dataGridViewControlName).TheObject; + contributionGridView.Invalidated += (sender, args) => dataGridInvalidated = true; - // Assert - TestHelper.AssertLogMessages(call, msgs => - { - string[] messages = msgs.ToArray(); - Assert.AreEqual(1, messages.Length); - Assert.AreEqual(messageGrassCoverErosionOutwardsHydraulicBoundaryLocationOutputCleared, messages[0]); - }); - Assert.AreEqual(waveHeight, hydraulicBoundaryLocation.WaveHeight, hydraulicBoundaryLocation.WaveHeight.GetAccuracy()); - Assert.AreEqual(designWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel.GetAccuracy()); - Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight); - Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel); - } - mockRepository.VerifyAll(); - } + var compositionComboBox = (ComboBox) new ControlTester(assessmentSectionCompositionComboBoxName).TheObject; - [Test] - public void AssessmentSectionCompositionComboBox_HydraulicBoundaryDatabaseAndNoLocationsWithOutputAndValueChanged_NoObserversNotified() - { - // Setup - var waveHeight = (RoundedDouble) 3.0; - var designWaterLevel = (RoundedDouble) 4.2; - - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 0.0, 0.0) - { - WaveHeight = waveHeight, - DesignWaterLevel = designWaterLevel - }; - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase - { - Locations = + // When + DialogBoxHandler = (name, wnd) => { - hydraulicBoundaryLocation - } - }; + var tester = new MessageBoxTester(wnd); + tester.ClickOk(); + }; + ControlsTestHelper.FakeUserSelectingNewValue(compositionComboBox, newComposition); - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) - { - HydraulicBoundaryDatabase = hydraulicBoundaryDatabase - }; + // Then + Assert.AreEqual(newComposition, compositionComboBox.SelectedValue); - var grassCoverErosionOutwardsHydraulicBoundaryLocation = new HydraulicBoundaryLocation(hydraulicBoundaryLocation.Id, - hydraulicBoundaryLocation.Name, - hydraulicBoundaryLocation.Location.X, - hydraulicBoundaryLocation.Location.Y); - - assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Add(grassCoverErosionOutwardsHydraulicBoundaryLocation); - - var mockRepository = new MockRepository(); - IObserver observerMock = mockRepository.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()); - IObserver hydraulicBoundaryDatabaseObserverMock = mockRepository.StrictMock(); - IObserver grassCoverErosionOutwardsObserverMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - assessmentSection.Attach(observerMock); - hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserverMock); - assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserverMock); - - var handler = new FailureMechanismContributionNormChangeHandler(); - - using (var form = new Form()) - using (var distributionView = new FailureMechanismContributionView(handler) - { - Data = assessmentSection.FailureMechanismContribution, - AssessmentSection = assessmentSection - }) - { - form.Controls.Add(distributionView); - form.Show(); - - var compositionTester = (ComboBox) new ControlTester("assessmentSectionCompositionComboBox").TheObject; - - // Precondition - Assert.AreEqual(waveHeight, hydraulicBoundaryLocation.WaveHeight, hydraulicBoundaryLocation.WaveHeight.GetAccuracy()); - Assert.AreEqual(designWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel.GetAccuracy()); - Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight); - Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel); - - // Call - compositionTester.SelectedValue = AssessmentSectionComposition.DikeAndDune; - - // Assert - Assert.AreEqual(waveHeight, hydraulicBoundaryLocation.WaveHeight, hydraulicBoundaryLocation.WaveHeight.GetAccuracy()); - Assert.AreEqual(designWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel.GetAccuracy()); - Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.WaveHeight); - Assert.IsNaN(grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevel); + Assert.IsTrue(dataGridInvalidated, + "Expect the DataGridView to be flagged for redrawing."); + AssertDataGridViewDataSource(assessmentSection.FailureMechanismContribution.Distribution, contributionGridView); } - mockRepository.VerifyAll(); + mocks.VerifyAll(); } - [Test] - public void AssessmentSectionCompositionComboBox_NoHydraulicBoundaryDatabaseAndValueChanged_NoObserversNotified() + private void AssertDataGridViewDataSource(IEnumerable expectedDistributionElements, DataGridView dataGridView) { - // Setup - var mockRepository = new MockRepository(); - IObserver observerMock = mockRepository.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()); - IObserver grassCoverErosionOutwardsObserverMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); - - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - assessmentSection.Attach(observerMock); - assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserverMock); - - var handler = new FailureMechanismContributionNormChangeHandler(); - - using (var form = new Form()) - using (var distributionView = new FailureMechanismContributionView(handler) + FailureMechanismContributionItem[] itemArray = expectedDistributionElements.ToArray(); + Assert.AreEqual(itemArray.Length, dataGridView.RowCount); + for (int i = 0; i < itemArray.Length; i++) { - Data = assessmentSection.FailureMechanismContribution, - AssessmentSection = assessmentSection - }) - { - form.Controls.Add(distributionView); - form.Show(); - - var compositionTester = (ComboBox) new ControlTester("assessmentSectionCompositionComboBox").TheObject; - - // Call - compositionTester.SelectedValue = AssessmentSectionComposition.DikeAndDune; + FailureMechanismContributionItem expectedElement = itemArray[i]; + DataGridViewRow row = dataGridView.Rows[i]; + Assert.AreEqual(expectedElement.IsRelevant, row.Cells[isRelevantColumnIndex].Value); + Assert.AreEqual(expectedElement.Assessment, row.Cells[nameColumnIndex].Value); + Assert.AreEqual(expectedElement.AssessmentCode, row.Cells[codeColumnIndex].Value); + Assert.AreEqual(expectedElement.Contribution, row.Cells[contributionColumnIndex].Value); + Assert.AreEqual(expectedElement.ProbabilitySpace, row.Cells[probabilitySpaceColumnIndex].Value); } - - // Assert - mockRepository.VerifyAll(); // Expect UpdateObserver call } private static void SimulateUserCommittingNormValue(ControlTester normTester, int normValue) Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionItemRowTest.cs =================================================================== diff -u -recf136a787efcd5d3f171f8aee8930f84a89e80a -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionItemRowTest.cs (.../FailureMechanismContributionItemRowTest.cs) (revision ecf136a787efcd5d3f171f8aee8930f84a89e80a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionItemRowTest.cs (.../FailureMechanismContributionItemRowTest.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -21,6 +21,7 @@ using System; using Core.Common.Base; +using Core.Common.Gui.Commands; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.Contribution; @@ -35,31 +36,58 @@ [Test] public void Constructor_WithoutFailureMechanismContributionItem_ThrowsArgumentNullException() { + // setup + var mocks = new MockRepository(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + // Call - TestDelegate test = () => new FailureMechanismContributionItemRow(null); + TestDelegate test = () => new FailureMechanismContributionItemRow(null, viewCommands); // Assert string paramName = Assert.Throws(test).ParamName; Assert.AreEqual("contributionItem", paramName); + mocks.VerifyAll(); } [Test] + public void Constructor_WithoutViewCommands_ThrowsArgumentNullException() + { + // Setup + var pipingFailureMechanism = new PipingFailureMechanism(); + var contributionItem = new FailureMechanismContributionItem(pipingFailureMechanism, 1000); + + // Call + TestDelegate call = () => new FailureMechanismContributionItemRow(contributionItem, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreSame("viewCommands", paramName); + } + + [Test] public void Constructor_WithFailureMechanismContributionItem_PropertiesFromFailureMechanismContributionItem() { // Setup + var mocks = new MockRepository(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + var pipingFailureMechanism = new PipingFailureMechanism(); const double norm = 0.1; var contributionItem = new FailureMechanismContributionItem(pipingFailureMechanism, norm); // Call - var row = new FailureMechanismContributionItemRow(contributionItem); + var row = new FailureMechanismContributionItemRow(contributionItem, viewCommands); // Assert Assert.AreEqual(contributionItem.Contribution, row.Contribution); Assert.AreEqual(contributionItem.Assessment, row.Assessment); Assert.AreEqual(contributionItem.AssessmentCode, row.Code); Assert.AreEqual(contributionItem.IsRelevant, row.IsRelevant); Assert.AreEqual(contributionItem.ProbabilitySpace, row.ProbabilitySpace); + + mocks.VerifyAll(); } [Test] @@ -68,18 +96,24 @@ public void IsRelevant_AlwaysOnChange_NotifyFailureMechanismObserversAndCalculationPropertyChanged(bool newValue) { // Setup + var pipingFailureMechanism = new PipingFailureMechanism(); + var mocks = new MockRepository(); + var viewCommands = mocks.StrictMock(); + if (!newValue) + { + viewCommands.Expect(c => c.RemoveAllViewsForItem(pipingFailureMechanism)); + } var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); - var pipingFailureMechanism = new PipingFailureMechanism(); pipingFailureMechanism.Attach(observer); const double norm = 0.1; var contributionItem = new FailureMechanismContributionItem(pipingFailureMechanism, norm); - var row = new FailureMechanismContributionItemRow(contributionItem); + var row = new FailureMechanismContributionItemRow(contributionItem, viewCommands); // Call row.IsRelevant = newValue; Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs =================================================================== diff -u -r901339a7022b3be93778d9691b001ba085c53d43 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs (.../FailureMechanismContributionViewTest.cs) (revision 901339a7022b3be93778d9691b001ba085c53d43) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs (.../FailureMechanismContributionViewTest.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -28,6 +28,7 @@ using Core.Common.Base; using Core.Common.Controls.DataGrid; using Core.Common.Gui.Commands; +using Core.Common.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; @@ -69,15 +70,74 @@ } [Test] - public void DefaultConstructor_SetsDefaults() + public void Constructor_NormChangeHandlerNull_ThrowArgumentNullException() { // Setup var mocks = new MockRepository(); - var handler = mocks.Stub(); + var compositionChangeHandler = mocks.Stub(); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); // Call - using (var contributionView = new FailureMechanismContributionView(handler)) + TestDelegate call = () => new FailureMechanismContributionView(null, compositionChangeHandler, viewCommands); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("normChangeHandler", paramName); + + mocks.VerifyAll(); + } + + [Test] + public void Constructor_CompositionChangeHandlerNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var normChangeHandler = mocks.Stub(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new FailureMechanismContributionView(normChangeHandler, null, viewCommands); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("compositionChangeHandler", paramName); + + mocks.VerifyAll(); + } + + [Test] + public void Constructor_ViewCommandsNull_ThrowArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var normChangeHandler = mocks.Stub(); + var compositionChangeHandler = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new FailureMechanismContributionView(normChangeHandler, compositionChangeHandler, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("viewCommands", paramName); + + mocks.VerifyAll(); + } + + [Test] + public void Constructor_SetsDefaults() + { + // Setup + var mocks = new MockRepository(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); + mocks.ReplayAll(); + + // Call + using (var contributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { ShowFormWithView(contributionView); @@ -103,14 +163,16 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; // Call - using (var contributionView = new FailureMechanismContributionView(handler) + using (var contributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -149,18 +211,19 @@ var observable2 = mockRepository.StrictMock(); observable2.Expect(o => o.NotifyObservers()); - var handler = mockRepository.StrictMock(); - handler.Expect(h => h.ConfirmNormChange()).Return(true); - handler.Expect(h => h.ChangeNorm(assessmentSection, norm)) - .Return(new[] - { - observable1, - observable2 - }); - + var handler1 = mockRepository.StrictMock(); + handler1.Expect(h => h.ConfirmNormChange()).Return(true); + handler1.Expect(h => h.ChangeNorm(assessmentSection, norm)) + .Return(new[] + { + observable1, + observable2 + }); + var handler2 = mockRepository.Stub(); + var viewCommands = mockRepository.Stub(); mockRepository.ReplayAll(); - using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler) + using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -190,15 +253,16 @@ int initialReturnPeriod = Convert.ToInt32(1.0/failureMechanismContribution.Norm); MockRepository mockRepository = new MockRepository(); - var handler = mockRepository.StrictMock(); - handler.Expect(h => h.ConfirmNormChange()).Return(false); - handler.Expect(h => h.ChangeNorm(assessmentSection, newReturnPeriod)) - .Return(Enumerable.Empty()) - .Repeat.Never(); - + var handler1 = mockRepository.StrictMock(); + handler1.Expect(h => h.ConfirmNormChange()).Return(false); + handler1.Expect(h => h.ChangeNorm(assessmentSection, newReturnPeriod)) + .Return(Enumerable.Empty()) + .Repeat.Never(); + var handler2 = mockRepository.Stub(); + var viewCommands = mockRepository.Stub(); mockRepository.ReplayAll(); - using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler) + using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -224,10 +288,12 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); - using (var distributionView = new FailureMechanismContributionView(handler)) + using (var distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { // Call ShowFormWithView(distributionView); @@ -267,7 +333,9 @@ double testContribution = 100 - otherContribution; var mockRepository = new MockRepository(); - var handler = mockRepository.Stub(); + var handler1 = mockRepository.Stub(); + var handler2 = mockRepository.Stub(); + var viewCommands = mockRepository.Stub(); var someMechanism = mockRepository.StrictMock(testName, testCode); someMechanism.Contribution = testContribution; @@ -279,7 +347,7 @@ someMechanism }, otherContribution, 0.01); - using (var distributionView = new FailureMechanismContributionView(handler) + using (var distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { AssessmentSection = assessmentSection }) @@ -318,7 +386,9 @@ var assessmentSection2 = new AssessmentSection(AssessmentSectionComposition.Dike); var mockRepository = new MockRepository(); - var handler = mockRepository.Stub(); + var handler1 = mockRepository.Stub(); + var handler2 = mockRepository.Stub(); + var viewCommands = mockRepository.Stub(); var someMechanism = mockRepository.Stub(); mockRepository.ReplayAll(); @@ -331,7 +401,7 @@ someMechanism }, random.Next(0, 100), 1.0/newReturnPeriod); - using (var distributionView = new FailureMechanismContributionView(handler) + using (var distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = initialContribution, AssessmentSection = assessmentSection1 @@ -365,7 +435,9 @@ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var mockRepository = new MockRepository(); - var handler = mockRepository.Stub(); + var handler1 = mockRepository.Stub(); + var handler2 = mockRepository.Stub(); + var viewCommands = mockRepository.Stub(); var someMechanism = mockRepository.Stub(); mockRepository.ReplayAll(); @@ -374,7 +446,7 @@ someMechanism }, random.Next(0, 100), 1.0/initialNormValue); - using (var distributionView = new FailureMechanismContributionView(handler) + using (var distributionView = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = contribution, AssessmentSection = assessmentSection @@ -406,15 +478,17 @@ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var mockRepository = new MockRepository(); - var handler = mockRepository.Stub(); + var handler1 = mockRepository.Stub(); + var handler2 = mockRepository.Stub(); + var viewCommands = mockRepository.Stub(); var failureMechanismStub = mockRepository.Stub(); failureMechanismStub.Stub(fm => fm.Name).Return("A"); failureMechanismStub.Stub(fm => fm.Code).Return("C"); failureMechanismStub.Contribution = 100; failureMechanismStub.IsRelevant = isFailureMechanismRelevant; mockRepository.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { // When var contributionData = new FailureMechanismContribution(new[] @@ -443,14 +517,16 @@ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var mockRepository = new MockRepository(); - var handler = mockRepository.Stub(); + var handler1 = mockRepository.Stub(); + var handler2 = mockRepository.Stub(); + var viewCommands = mockRepository.Stub(); var failureMechanismStub = mockRepository.Stub(); failureMechanismStub.Stub(fm => fm.Name).Return("A"); failureMechanismStub.Stub(fm => fm.Code).Return("C"); failureMechanismStub.Contribution = 0; mockRepository.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { // When var contributionData = new FailureMechanismContribution(new[] @@ -482,14 +558,16 @@ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var mockRepository = new MockRepository(); - var handler = mockRepository.Stub(); + var handler1 = mockRepository.Stub(); + var handler2 = mockRepository.Stub(); + var viewCommands = mockRepository.Stub(); var failureMechanismStub = mockRepository.Stub(); failureMechanismStub.Stub(fm => fm.Name).Return("A"); failureMechanismStub.Stub(fm => fm.Code).Return("C"); failureMechanismStub.Contribution = contribution; mockRepository.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { // When var contributionData = new FailureMechanismContribution(new[] @@ -523,10 +601,12 @@ { // Setup var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { ShowFormWithView(view); @@ -552,40 +632,48 @@ [TestCase(AssessmentSectionComposition.Dune, AssessmentSectionComposition.DikeAndDune)] [TestCase(AssessmentSectionComposition.DikeAndDune, AssessmentSectionComposition.Dike)] [TestCase(AssessmentSectionComposition.DikeAndDune, AssessmentSectionComposition.Dune)] - public void CompositionComboBox_ChangeCompositionAndOk_UpdateAssessmentSectionContributionAndView(AssessmentSectionComposition initialComposition, AssessmentSectionComposition newComposition) + public void CompositionComboBox_ChangeCompositionAndOk_ChangeCompositionAndNotifyAffectedObjects(AssessmentSectionComposition initialComposition, AssessmentSectionComposition newComposition) { // Setup + var assessmentSection = new AssessmentSection(initialComposition); + var mocks = new MockRepository(); - var handler = mocks.Stub(); + var observable1 = mocks.StrictMock(); + observable1.Expect(o => o.NotifyObservers()); + var observable2 = mocks.StrictMock(); + observable2.Expect(o => o.NotifyObservers()); + + var handler1 = mocks.Stub(); + var handler2 = mocks.StrictMock(); + handler2.Expect(h => h.ConfirmCompositionChange()) + .Return(true); + handler2.Expect(h => h.ChangeComposition(assessmentSection, newComposition)) + .Return(new[] + { + observable1, + observable2 + }); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands) { - var assessmentSection = new AssessmentSection(initialComposition); - - view.Data = assessmentSection.FailureMechanismContribution; - view.AssessmentSection = assessmentSection; + Data = assessmentSection.FailureMechanismContribution, + AssessmentSection = assessmentSection + }) + { ShowFormWithView(view); // Precondition Assert.AreNotEqual(assessmentSection.Composition, newComposition); - bool dataGridInvalidated = false; - var contributionGridView = (DataGridView) new ControlTester(dataGridViewControlName).TheObject; - contributionGridView.Invalidated += (sender, args) => dataGridInvalidated = true; - var compositionComboBox = (ComboBox) new ControlTester(assessmentSectionCompositionComboBoxName).TheObject; // Call - compositionComboBox.SelectedValue = newComposition; + ControlsTestHelper.FakeUserSelectingNewValue(compositionComboBox, newComposition); // Assert Assert.AreEqual(newComposition, compositionComboBox.SelectedValue); - Assert.AreEqual(newComposition, assessmentSection.Composition); - - Assert.IsTrue(dataGridInvalidated, - "Expect the DataGridView to be flagged for redrawing."); - AssertDataGridViewDataSource(assessmentSection.FailureMechanismContribution.Distribution, contributionGridView); } mocks.VerifyAll(); } @@ -597,22 +685,29 @@ [TestCase(AssessmentSectionComposition.Dune, AssessmentSectionComposition.DikeAndDune)] [TestCase(AssessmentSectionComposition.DikeAndDune, AssessmentSectionComposition.Dike)] [TestCase(AssessmentSectionComposition.DikeAndDune, AssessmentSectionComposition.Dune)] - public void CompositionComboBox_ChangeComposition_NotifyAssessmentSectionObservers(AssessmentSectionComposition initialComposition, AssessmentSectionComposition newComposition) + public void CompositionComboBox_ChangeCompositionAndCancel_ComboBoxStillAtOriginalValue(AssessmentSectionComposition initialComposition, AssessmentSectionComposition newComposition) { // Setup + var assessmentSection = new AssessmentSection(initialComposition); + var mocks = new MockRepository(); - var handler = mocks.Stub(); - var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); + var handler1 = mocks.Stub(); + var handler2 = mocks.StrictMock(); + handler2.Expect(h => h.ConfirmCompositionChange()) + .Return(false); + handler2.Expect(h => h.ChangeComposition(null, AssessmentSectionComposition.Dike)) + .IgnoreArguments() + .Return(new IObservable[0]) + .Repeat.Never(); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands) { - var assessmentSection = new AssessmentSection(initialComposition); - assessmentSection.Attach(observer); - - view.Data = assessmentSection.FailureMechanismContribution; - view.AssessmentSection = assessmentSection; + Data = assessmentSection.FailureMechanismContribution, + AssessmentSection = assessmentSection + }) + { ShowFormWithView(view); // Precondition @@ -621,23 +716,28 @@ var compositionComboBox = (ComboBox) new ControlTester(assessmentSectionCompositionComboBoxName).TheObject; // Call - compositionComboBox.SelectedValue = newComposition; + ControlsTestHelper.FakeUserSelectingNewValue(compositionComboBox, newComposition); + + // Assert + Assert.AreEqual(initialComposition, compositionComboBox.SelectedValue, + "The ComboBox should be reset to the original composition value, as change was not accepted by user."); } - // Assert - mocks.VerifyAll(); // Expect UpdateObserver call + mocks.VerifyAll(); } [Test] public void GivenView_WhenSettingRelevantFailureMechanism_RowIsStylesAsEnabled() { // Given var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); var failureMechanism = mocks.Stub(); failureMechanism.IsRelevant = true; mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { ShowFormWithView(view); @@ -674,12 +774,14 @@ { // Given var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); var failureMechanism = mocks.Stub(); failureMechanism.IsRelevant = false; mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { ShowFormWithView(view); @@ -719,7 +821,9 @@ // Given List failureMechanismObservers = new List(); var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); var failureMechanism = mocks.Stub(); failureMechanism.Stub(fm => fm.Name).Return("A"); failureMechanism.Stub(fm => fm.Code).Return("C"); @@ -743,7 +847,7 @@ assessmentSection.Stub(section => section.Composition).Return(AssessmentSectionComposition.Dike); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { ShowFormWithView(view); @@ -796,82 +900,42 @@ } [Test] - [TestCase(true)] - [TestCase(false)] - public void GivenViewWithViewCommands_IsRelevantPropertyChangeNotified_CloseViewsForIrrelevantFailureMechanisms(bool initialIsRelevant) + public void GivenView_WhenMakingFailureMechanismIrrelevant_UpdateFailureMechanismAndNotifyObserversAndCloseRelatedViews() { // Given - List failureMechanismObservers = new List(); var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); var failureMechanism = mocks.Stub(); failureMechanism.Stub(fm => fm.Name).Return("A"); - failureMechanism.Stub(fm => fm.Code).Return("C"); - failureMechanism.IsRelevant = initialIsRelevant; - failureMechanism.Stub(fm => fm.Attach(null)) - .IgnoreArguments() - .WhenCalled(invocation => { failureMechanismObservers.Add((IObserver) invocation.Arguments[0]); }); - failureMechanism.Stub(fm => fm.NotifyObservers()) - .WhenCalled(invocation => { failureMechanismObservers[1].UpdateObserver(); }); - failureMechanism.Stub(fm => fm.Detach(null)) - .IgnoreArguments() - .WhenCalled(invocation => { failureMechanismObservers.Remove((IObserver) invocation.Arguments[0]); }); + failureMechanism.Stub(fm => fm.Code).Return("b"); + failureMechanism.IsRelevant = true; + failureMechanism.Expect(fm => fm.NotifyObservers()); + var viewCommands = mocks.Stub(); + viewCommands.Expect(c => c.RemoveAllViewsForItem(failureMechanism)); + mocks.ReplayAll(); - var relevantFailureMechanism = mocks.Stub(); - relevantFailureMechanism.Stub(fm => fm.Name).Return("B"); - relevantFailureMechanism.Stub(fm => fm.Code).Return("C"); - relevantFailureMechanism.IsRelevant = true; - relevantFailureMechanism.Stub(fm => fm.Attach(null)) - .IgnoreArguments(); - relevantFailureMechanism.Stub(fm => fm.Detach(null)) - .IgnoreArguments(); - - var irrelevantFailureMechanism = mocks.Stub(); - irrelevantFailureMechanism.Stub(fm => fm.Name).Return("C"); - irrelevantFailureMechanism.Stub(fm => fm.Code).Return("C"); - irrelevantFailureMechanism.IsRelevant = false; - irrelevantFailureMechanism.Stub(fm => fm.Attach(null)) - .IgnoreArguments(); - irrelevantFailureMechanism.Stub(fm => fm.Detach(null)) - .IgnoreArguments(); - var failureMechanisms = new[] - { - failureMechanism, - relevantFailureMechanism, - irrelevantFailureMechanism - }; + { + failureMechanism + }; + var contribution = new FailureMechanismContribution(failureMechanisms, 50.0, 1.0 / 30000); - var assessmentSection = mocks.Stub(); - assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(failureMechanisms); - assessmentSection.Stub(section => section.Composition).Return(AssessmentSectionComposition.Dike); - - IViewCommands viewCommandsStub = mocks.Stub(); - if (initialIsRelevant) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { - viewCommandsStub.Expect(vc => vc.RemoveAllViewsForItem(failureMechanism)); - } - viewCommandsStub.Expect(vc => vc.RemoveAllViewsForItem(relevantFailureMechanism)).Repeat.Never(); - viewCommandsStub.Expect(vc => vc.RemoveAllViewsForItem(irrelevantFailureMechanism)); - mocks.ReplayAll(); - - using (var view = new FailureMechanismContributionView(handler) - { - ViewCommands = viewCommandsStub - }) - { ShowFormWithView(view); - var contribution = new FailureMechanismContribution(failureMechanisms, 50.0, 1.0/30000); - view.Data = contribution; - view.AssessmentSection = assessmentSection; + var dataGridView = (DataGridView)new ControlTester(dataGridViewControlName).TheObject; + DataGridViewRow row = dataGridView.Rows[0]; + // When - failureMechanism.IsRelevant = !initialIsRelevant; - failureMechanism.NotifyObservers(); + row.Cells[isRelevantColumnIndex].Value = false; + + // Then + Assert.IsFalse(failureMechanism.IsRelevant); } - // Then mocks.VerifyAll(); } @@ -880,10 +944,12 @@ { // Given var mocks = new MockRepository(); - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { ShowFormWithView(view); @@ -914,10 +980,12 @@ { // Given var mocks = new MockRepository(); - var handler = mocks.Stub(); - handler.Stub(h => h.ChangeNorm(null, 1)) - .IgnoreArguments() - .Return(Enumerable.Empty()); + var handler1 = mocks.Stub(); + handler1.Stub(h => h.ChangeNorm(null, 1)) + .IgnoreArguments() + .Return(Enumerable.Empty()); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -926,7 +994,7 @@ const int returnPeriod = 200; int originalReturnPeriodValue = Convert.ToInt32(1.0/failureMechanismContribution.Norm); - using (var view = new FailureMechanismContributionView(handler) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -964,14 +1032,18 @@ FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; var mocks = new MockRepository(); - var handler = mocks.StrictMock(); - handler.Expect(h => h.ConfirmNormChange()) - .Return(true); - handler.Expect(h => h.ChangeNorm(assessmentSection, norm)) - .Return(Enumerable.Empty()); + var handler1 = mocks.StrictMock(); + handler1.Expect(h => h.ConfirmNormChange()) + .Return(true); + handler1.Expect(h => h.ChangeNorm(assessmentSection, norm)) + .Return(Enumerable.Empty()); + var handler2 = mocks.Stub(); + handler2.Stub(h => h.ConfirmCompositionChange()) + .Return(false); + var viewCommands = mocks.Stub(); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = failureMechanismContribution, AssessmentSection = assessmentSection @@ -1009,22 +1081,6 @@ } } - private void AssertDataGridViewDataSource(IEnumerable expectedDistributionElements, DataGridView dataGridView) - { - FailureMechanismContributionItem[] itemArray = expectedDistributionElements.ToArray(); - Assert.AreEqual(itemArray.Length, dataGridView.RowCount); - for (int i = 0; i < itemArray.Length; i++) - { - FailureMechanismContributionItem expectedElement = itemArray[i]; - DataGridViewRow row = dataGridView.Rows[i]; - Assert.AreEqual(expectedElement.IsRelevant, row.Cells[isRelevantColumnIndex].Value); - Assert.AreEqual(expectedElement.Assessment, row.Cells[nameColumnIndex].Value); - Assert.AreEqual(expectedElement.AssessmentCode, row.Cells[codeColumnIndex].Value); - Assert.AreEqual(expectedElement.Contribution, row.Cells[contributionColumnIndex].Value); - Assert.AreEqual(expectedElement.ProbabilitySpace, row.Cells[probabilitySpaceColumnIndex].Value); - } - } - private void ShowFormWithView(FailureMechanismContributionView distributionView) { testForm.Controls.Add(distributionView); Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -0,0 +1,207 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Plugin.Handlers; +using Ringtoets.Integration.Service; +using Ringtoets.Integration.TestUtils; + +namespace Ringtoets.Integration.Plugin.Test.Handlers +{ + [TestFixture] + public class AssessmentSectionCompositionChangeHandlerTest : NUnitFormTest + { + [Test] + public void ConfirmCompositionChange_Always_ShowMessageBox() + { + // Setup + string title = "", message = ""; + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + title = tester.Title; + message = tester.Text; + + tester.ClickOk(); + }; + + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + handler.ConfirmCompositionChange(); + + // Assert + Assert.AreEqual("Bevestigen", title); + string expectedMessage = "Na het aanpassen van het trajecttype zullen alle rekenresultaten van alle toetssporen gewist worden." + Environment.NewLine + + Environment.NewLine + + "Wilt u doorgaan?"; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + public void ConfirmCompositionChange_MessageBoxOk_ReturnTrue() + { + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickOk(); + }; + + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + bool result = handler.ConfirmCompositionChange(); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void ConfirmCompositionChange_MessageBoxCancel_ReturnFalse() + { + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickCancel(); + }; + + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + bool result = handler.ConfirmCompositionChange(); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void ChangeComposition_AssessmentSectionNull_ThrowArgumentNullException() + { + // Setup + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + TestDelegate call = () => handler.ChangeComposition(null, AssessmentSectionComposition.Dike); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("assessmentSection", paramName); + } + + [Test] + public void ChangeComposition_ChangeToSameValue_DoNothing() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetFullyConfiguredAssessmentSection(); + AssessmentSectionComposition originalComposition = assessmentSection.Composition; + ICalculation[] calculationsWithOutput = assessmentSection.GetFailureMechanisms() + .SelectMany(fm => fm.Calculations) + .Where(c => c.HasOutput) + .ToArray(); + + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + IEnumerable affectedObjects = handler.ChangeComposition(assessmentSection, originalComposition); + + // Assert + Assert.True(calculationsWithOutput.All(c => c.HasOutput), + "All calculations that had output still have them."); + + CollectionAssert.IsEmpty(affectedObjects); + } + + [Test] + public void ChangeComposition_ChangeToDifferentValue_ChangeCompositionAndClearAllCalculationOutputAndReturnsAllAffectedObjects() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetFullyConfiguredAssessmentSection(); + var newComposition = AssessmentSectionComposition.DikeAndDune; + + // Precondition + Assert.AreNotEqual(assessmentSection.Composition, newComposition); + + IObservable[] expectedAffectedObjects = assessmentSection.GetFailureMechanisms().Cast() + .Concat(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)) + .Concat(new[] + { + assessmentSection + }) + .ToArray(); + + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + IEnumerable affectedObjects = null; + Action call = () => affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); + + // Assert + string expectedMessage = "De resultaten van 51 berekeningen zijn verwijderd."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + + Assert.AreEqual(newComposition, assessmentSection.Composition); + Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void ChangeComposition_ChangeToDifferentValueAndNoCalculationsWithOutput_ChangeCompositionAndReturnsAllAffectedObjects() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetFullyConfiguredAssessmentSection(); + RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection); + var newComposition = AssessmentSectionComposition.Dune; + + // Precondition + Assert.AreNotEqual(assessmentSection.Composition, newComposition); + CollectionAssert.IsEmpty(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)); + + IObservable[] expectedAffectedObjects = assessmentSection.GetFailureMechanisms().Cast() + .Concat(new[] + { + assessmentSection + }) + .ToArray(); + + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + IEnumerable affectedObjects = null; + Action call = () => affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); + + // Assert + TestHelper.AssertLogMessagesCount(call, 0); + + Assert.AreEqual(newComposition, assessmentSection.Composition); + Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs =================================================================== diff -u -r901339a7022b3be93778d9691b001ba085c53d43 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (.../FailureMechanismContributionNormChangeHandlerTest.cs) (revision 901339a7022b3be93778d9691b001ba085c53d43) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (.../FailureMechanismContributionNormChangeHandlerTest.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -31,6 +31,7 @@ using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.Views; using Ringtoets.Integration.Plugin.Handlers; +using Ringtoets.Integration.Service; using Ringtoets.Integration.TestUtils; namespace Ringtoets.Integration.Plugin.Test.Handlers @@ -158,6 +159,8 @@ IEnumerable affectedObjects = null; const double norm = 1.0/1000; + const int newNormValue = 1000; + // Call Action call = () => affectedObjects = handler.ChangeNorm(section, norm); @@ -169,6 +172,8 @@ }; TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages, 2); + Assert.AreEqual(1.0/newNormValue, section.FailureMechanismContribution.Norm); + CollectionAssert.IsEmpty(section.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput), "There should be no calculations with output."); @@ -190,5 +195,47 @@ } CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); } + + [Test] + public void ChangeNorm_FullyConfiguredAssessmentSectionWithoutCalculationOutput_NormChangedContributionsUpdatedAndReturnsAllAffectedObjects() + { + // Setup + AssessmentSection section = TestDataGenerator.GetFullyConfiguredAssessmentSection(); + RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(section); + + // Precondition + CollectionAssert.IsEmpty(section.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)); + + var handler = new FailureMechanismContributionNormChangeHandler(); + + IEnumerable affectedObjects = null; + + const double newNormValue = 0.1234; + + // Call + Action call = () => affectedObjects = handler.ChangeNorm(section, newNormValue); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, "Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd.", 1); + + Assert.AreEqual(newNormValue, section.FailureMechanismContribution.Norm); + + var expectedAffectedObjects = section.GetFailureMechanisms() + .Concat(new IObservable[] + { + section.FailureMechanismContribution, + section.GrassCoverErosionOutwards.HydraulicBoundaryLocations, + section.HydraulicBoundaryDatabase + }); + foreach (HydraulicBoundaryLocation location in section.HydraulicBoundaryDatabase.Locations + .Concat(section.GrassCoverErosionOutwards.HydraulicBoundaryLocations)) + { + Assert.IsNaN(location.DesignWaterLevel); + Assert.IsNaN(location.WaveHeight); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.WaveHeightCalculationConvergence); + } + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r3df4971064b76a8e789bed245e8851fea72ba085 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 3df4971064b76a8e789bed245e8851fea72ba085) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -67,6 +67,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismContributionViewInfoTest.cs =================================================================== diff -u -r753480c9461b7b5bb10eb7abe78224f24160a536 -r2ff2a985fe9015df6da49fe43006e5c7631434c3 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismContributionViewInfoTest.cs (.../FailureMechanismContributionViewInfoTest.cs) (revision 753480c9461b7b5bb10eb7abe78224f24160a536) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismContributionViewInfoTest.cs (.../FailureMechanismContributionViewInfoTest.cs) (revision 2ff2a985fe9015df6da49fe43006e5c7631434c3) @@ -60,11 +60,13 @@ public void GetViewName_Always_ReturnsViewName() { // Setup - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabaseOrFailureMechanisms(mocks); mocks.ReplayAll(); - var view = new FailureMechanismContributionView(handler); + var view = new FailureMechanismContributionView(handler1, handler2, viewCommands); // Call var viewName = info.GetViewName(view, assessmentSectionStub.FailureMechanismContribution); @@ -135,14 +137,16 @@ public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() { // Setup - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabaseOrFailureMechanisms(mocks); assessmentSectionStub.Stub(section => section.Composition) .Return(AssessmentSectionComposition.Dike); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = assessmentSectionStub.FailureMechanismContribution, AssessmentSection = assessmentSectionStub @@ -161,7 +165,9 @@ public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() { // Setup - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); IAssessmentSection assessmentSection1 = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabaseOrFailureMechanisms(mocks); assessmentSection1.Stub(section => section.Composition) @@ -172,7 +178,7 @@ .Return(AssessmentSectionComposition.DikeAndDune); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands) { Data = assessmentSection1.FailureMechanismContribution, AssessmentSection = assessmentSection1 @@ -192,12 +198,14 @@ public void CloseForData_ViewWithoutData_ReturnsFalse() { // Setup - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabaseOrFailureMechanisms(mocks); mocks.ReplayAll(); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) { // Call var closeForData = info.CloseForData(view, assessmentSectionStub); @@ -212,21 +220,22 @@ public void AfterCreate_WithGuiSet_SetsAssessmentSection() { // Setup - var handler = mocks.Stub(); + var handler1 = mocks.Stub(); + var handler2 = mocks.Stub(); + var viewCommands = mocks.Stub(); IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabaseOrFailureMechanisms(mocks); assessmentSectionStub.Stub(section => section.Composition).Return(AssessmentSectionComposition.Dike); IGui guiStub = mocks.Stub(); guiStub.Stub(g => g.ProjectOpened += null).IgnoreArguments(); guiStub.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); - guiStub.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); var context = new FailureMechanismContributionContext(assessmentSectionStub.FailureMechanismContribution, assessmentSectionStub); - using (var view = new FailureMechanismContributionView(handler)) + using (var view = new FailureMechanismContributionView(handler1, handler2, viewCommands)) using (var ringtoetsPlugin = new RingtoetsPlugin()) { info = ringtoetsPlugin.GetViewInfos().First(tni => tni.ViewType == typeof(FailureMechanismContributionView));