Index: Core/Common/src/Core.Common.Gui/Forms/ViewHost/DocumentViewController.cs
===================================================================
diff -u -r24da3aa72ccc0776599628c9f971081694048d9a -r3df4971064b76a8e789bed245e8851fea72ba085
--- Core/Common/src/Core.Common.Gui/Forms/ViewHost/DocumentViewController.cs (.../DocumentViewController.cs) (revision 24da3aa72ccc0776599628c9f971081694048d9a)
+++ Core/Common/src/Core.Common.Gui/Forms/ViewHost/DocumentViewController.cs (.../DocumentViewController.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -179,7 +179,7 @@
private static IView CreateViewForData(object data, ViewInfo viewInfo)
{
- var view = (IView) Activator.CreateInstance(viewInfo.ViewType);
+ IView view = viewInfo.CreateInstance();
view.Data = viewInfo.GetViewData(data);
Index: Core/Common/src/Core.Common.Gui/Plugin/ViewInfo.cs
===================================================================
diff -u -rdd84dcabe5561e637e4ade45457437d9c037535b -r3df4971064b76a8e789bed245e8851fea72ba085
--- Core/Common/src/Core.Common.Gui/Plugin/ViewInfo.cs (.../ViewInfo.cs) (revision dd84dcabe5561e637e4ade45457437d9c037535b)
+++ Core/Common/src/Core.Common.Gui/Plugin/ViewInfo.cs (.../ViewInfo.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -31,6 +31,14 @@
public class ViewInfo
{
///
+ /// Initializes a new instance of the class.
+ ///
+ public ViewInfo()
+ {
+ CreateInstance = () => (IView)Activator.CreateInstance(ViewType);
+ }
+
+ ///
/// Gets or sets the data type associated with this view info.
///
public Type DataType { get; set; }
@@ -110,6 +118,13 @@
{
return DataType + " : " + ViewDataType + " : " + ViewType;
}
+
+ ///
+ /// Gets or sets the optional method that allows for the construction of the view.
+ ///
+ /// This property needs to be set if no default constructor is available
+ /// for the view type.
+ public Func CreateInstance { get; set; }
}
///
@@ -121,6 +136,14 @@
public class ViewInfo where TView : IView
{
///
+ /// Initializes a new instance of the class.
+ ///
+ public ViewInfo()
+ {
+ CreateInstance = () => (TView)Activator.CreateInstance(ViewType);
+ }
+
+ ///
/// Gets the data type associated with this view info.
///
public Type DataType
@@ -238,14 +261,22 @@
viewInfo.AfterCreate((TView) v, (TData) o);
}
},
- GetViewName = (v, o) => viewInfo.GetViewName != null ? viewInfo.GetViewName((TView) v, (TViewData) o) : null
+ GetViewName = (v, o) => viewInfo.GetViewName != null ? viewInfo.GetViewName((TView) v, (TViewData) o) : null,
+ CreateInstance = () => viewInfo.CreateInstance()
};
}
public override string ToString()
{
return DataType + " : " + ViewDataType + " : " + ViewType;
}
+
+ ///
+ /// Gets or sets the optional method that allows for the construction of the view.
+ ///
+ /// This property needs to be set if no default constructor is available
+ /// for the view type.
+ public Func CreateInstance { get; set; }
}
///
Index: Core/Common/test/Core.Common.Gui.Test/Plugin/ViewInfoTest.cs
===================================================================
diff -u -r24da3aa72ccc0776599628c9f971081694048d9a -r3df4971064b76a8e789bed245e8851fea72ba085
--- Core/Common/test/Core.Common.Gui.Test/Plugin/ViewInfoTest.cs (.../ViewInfoTest.cs) (revision 24da3aa72ccc0776599628c9f971081694048d9a)
+++ Core/Common/test/Core.Common.Gui.Test/Plugin/ViewInfoTest.cs (.../ViewInfoTest.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -25,6 +25,7 @@
using Core.Common.Gui.Plugin;
using Core.Common.Gui.Test.Properties;
using NUnit.Framework;
+using Rhino.Mocks;
namespace Core.Common.Gui.Test.Plugin
{
@@ -48,12 +49,17 @@
Assert.IsNull(viewInfo.GetViewData);
Assert.IsNull(viewInfo.AfterCreate);
Assert.IsNull(viewInfo.CloseForData);
+ Assert.IsNotNull(viewInfo.CreateInstance);
}
[Test]
public void SimpleProperties_SetNewValues_GetNewlySetValues()
{
// Setup
+ var mocks = new MockRepository();
+ var viewInstance = mocks.Stub();
+ mocks.ReplayAll();
+
var viewInfo = new ViewInfo();
var newDataType = typeof(int);
@@ -69,6 +75,7 @@
// Do something useful
};
Func closeViewForDataDelegate = (view, o) => true;
+ Func createInstanceDelegate = () => viewInstance;
// Call
viewInfo.DataType = newDataType;
@@ -81,6 +88,7 @@
viewInfo.GetViewData = getViewDataDelegate;
viewInfo.AfterCreate = afterCreateDelegate;
viewInfo.CloseForData = closeViewForDataDelegate;
+ viewInfo.CreateInstance = createInstanceDelegate;
// Assert
Assert.AreEqual(newDataType, viewInfo.DataType);
@@ -93,9 +101,28 @@
Assert.AreEqual(getViewDataDelegate, viewInfo.GetViewData);
Assert.AreEqual(afterCreateDelegate, viewInfo.AfterCreate);
Assert.AreEqual(closeViewForDataDelegate, viewInfo.CloseForData);
+ Assert.AreEqual(createInstanceDelegate, viewInfo.CreateInstance);
}
[Test]
+ public void CreateInstance_ViewtypeWithDefaultConstructor_ReturnView()
+ {
+ // Setup
+ var viewInfo = new ViewInfo
+ {
+ DataType = typeof(int),
+ ViewDataType = typeof(string),
+ ViewType = typeof(StringView)
+ };
+
+ // Call
+ IView view = viewInfo.CreateInstance();
+
+ // Assert
+ Assert.IsInstanceOf(view);
+ }
+
+ [Test]
public void ToString_WithRelevantFieldsInitialized_ReturnText()
{
// Setup
@@ -132,6 +159,7 @@
Assert.IsNull(viewInfo.GetViewData);
Assert.IsNull(viewInfo.AfterCreate);
Assert.IsNull(viewInfo.CloseForData);
+ Assert.IsNotNull(viewInfo.CreateInstance);
}
[Test]
@@ -150,6 +178,7 @@
// Do something useful
};
Func closeViewForDataDelegate = (view, o) => true;
+ Func createInstanceDelegate = () => new StringView();
// Call
viewInfo.Description = newDescription;
@@ -159,6 +188,7 @@
viewInfo.GetViewData = getViewDataDelegate;
viewInfo.AfterCreate = afterCreateDelegate;
viewInfo.CloseForData = closeViewForDataDelegate;
+ viewInfo.CreateInstance = createInstanceDelegate;
// Assert
Assert.AreEqual(newDescription, viewInfo.Description);
@@ -186,6 +216,19 @@
}
[Test]
+ public void CreateInstance_ViewTypeHasDefaultConstructor_ReturnView()
+ {
+ // Setup
+ var viewInfo = new ViewInfo();
+
+ // Call
+ StringView view = viewInfo.CreateInstance();
+
+ // Assert
+ Assert.IsNotNull(view);
+ }
+
+ [Test]
public void ImplicitOperator_WithAllMethodsSet_InfoFullyConverted()
{
// Setup
@@ -234,6 +277,10 @@
viewInfo.GetViewData = getViewDataDelegate;
viewInfo.AfterCreate = afterCreateDelegate;
viewInfo.CloseForData = closeViewForDataDelegate;
+ viewInfo.CreateInstance = () => new StringView
+ {
+ Text = "A"
+ };
// Precondition
Assert.IsInstanceOf>(viewInfo);
@@ -251,6 +298,7 @@
Assert.AreEqual(icon, info.Image);
Assert.IsTrue(viewInfo.AdditionalDataCheck(dataObject));
Assert.AreEqual(dataObject.ToString(), viewInfo.GetViewData(dataObject));
+ Assert.AreEqual("A", viewInfo.CreateInstance().Text);
viewInfo.AfterCreate(stringView, dataObject);
Assert.IsTrue(afterCreateDelegateCalled);
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs
===================================================================
diff -u -r1e9a35d13ae40069200f8b1e6c1aa91bb54ce086 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1e9a35d13ae40069200f8b1e6c1aa91bb54ce086)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -22,7 +22,7 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.42000
+// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -346,26 +346,6 @@
}
///
- /// Looks up a localized string similar to De resultaten van {0} berekeningen zijn verwijderd..
- ///
- public static string FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared {
- get {
- return ResourceManager.GetString("FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations" +
- "_0_calculations_cleared", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd..
- ///
- public static string FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_level_results_cleared {
- get {
- return ResourceManager.GetString("FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_lev" +
- "el_results_cleared", resourceCulture);
- }
- }
-
- ///
/// Looks up a localized string similar to n.v.t.
///
public static string FailureMechanismContributionView_ProbabilityPerYear_Not_applicable {
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx
===================================================================
diff -u -r1e9a35d13ae40069200f8b1e6c1aa91bb54ce086 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision 1e9a35d13ae40069200f8b1e6c1aa91bb54ce086)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -279,12 +279,6 @@
Hs [m]
-
- De resultaten van {0} berekeningen zijn verwijderd.
-
-
- Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd.
-
Is convergentie bereikt in de toetspeil berekening?
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj
===================================================================
diff -u -r673e35de0df920529e5dda63ea8b4dfb08ed65a8 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 673e35de0df920529e5dda63ea8b4dfb08ed65a8)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -97,6 +97,7 @@
DesignWaterLevelLocationsView.cs
+
@@ -220,11 +221,6 @@
Ringtoets.GrassCoverErosionOutwards.Forms
False
-
- {18E9F7C8-3170-4E9D-8D9F-1378225EED90}
- Ringtoets.GrassCoverErosionOutwards.Service
- False
-
{1C0017D8-35B5-4CA0-8FC7-A83F46DBDC99}
Ringtoets.HeightStructures.Data
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.Designer.cs
===================================================================
diff -u -r6de928689da61ccae1dc375d27b8f178d97a13f7 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.Designer.cs (.../FailureMechanismContributionView.Designer.cs) (revision 6de928689da61ccae1dc375d27b8f178d97a13f7)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.Designer.cs (.../FailureMechanismContributionView.Designer.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -78,6 +78,8 @@
0,
0,
0});
+ this.normInput.Validating += new System.ComponentModel.CancelEventHandler(this.NormNumericUpDown_Validating);
+ this.normInput.Validated += new System.EventHandler(this.NormNumericUpDown_Validated);
//
// perYearLabel
//
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs
===================================================================
diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.cs (.../FailureMechanismContributionView.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -21,13 +21,13 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
using Core.Common.Controls.Views;
using Core.Common.Gui.Commands;
-using Core.Common.Utils.Extensions;
using Core.Common.Utils.Reflection;
using log4net;
using Ringtoets.Common.Data.AssessmentSection;
@@ -36,7 +36,6 @@
using Ringtoets.Common.Service;
using Ringtoets.GrassCoverErosionOutwards.Data;
using Ringtoets.HydraRing.Data;
-using Ringtoets.Integration.Service;
using CoreCommonBaseResources = Core.Common.Base.Properties.Resources;
using CommonGuiResources = Core.Common.Gui.Properties.Resources;
using RingtoetsGrassCoverErosionOutwardsFormsResources = Ringtoets.GrassCoverErosionOutwards.Forms.Properties.Resources;
@@ -57,14 +56,15 @@
private readonly Observer isFailureMechanismRelevantObserver;
private readonly Observer closeViewsForIrrelevantFailureMechanismObserver;
+ private readonly IFailureMechanismContributionNormChangeHandler changeHandler;
private FailureMechanismContribution data;
private IAssessmentSection assessmentSection;
///
/// Creates a new instance of .
///
- public FailureMechanismContributionView()
+ public FailureMechanismContributionView(IFailureMechanismContributionNormChangeHandler changeHandler)
{
InitializeComponent();
InitializeGridColumns();
@@ -73,6 +73,8 @@
BindNormInputLeave();
SubscribeEvents();
+ this.changeHandler = changeHandler;
+
isFailureMechanismRelevantObserver = new Observer(probabilityDistributionGrid.RefreshDataGridView);
closeViewsForIrrelevantFailureMechanismObserver = new Observer(CloseViewsForIrrelevantFailureMechanism);
}
@@ -260,92 +262,23 @@
private void BindNormChange()
{
- normInput.ValueChanged += NormValueChanged;
+ // Attaching to inner TextBox instead of 'normInput' control to capture all
+ // key presses. (This prevents some unexpected unresponsive behavior):
+ var innerTextBox = normInput.Controls.OfType().First();
+ innerTextBox.KeyDown += NormNumericUpDownInnerTextBox_KeyDown;
}
private void UnbindNormChange()
{
- normInput.ValueChanged -= NormValueChanged;
+ var innerTextBox = normInput.Controls.OfType().First();
+ innerTextBox.KeyDown -= NormNumericUpDownInnerTextBox_KeyDown;
}
private void BindNormInputLeave()
{
normInput.Leave += NormInputLeave;
}
- private void NormInputLeave(object sender, EventArgs e)
- {
- ResetTextIfEmpty();
- }
-
- private void NormValueChanged(object sender, EventArgs eventArgs)
- {
- data.Norm = Convert.ToInt32(normInput.Value);
- ClearAssessmentSectionData();
-
- data.NotifyObservers();
-
- foreach (var fm in AssessmentSection.GetFailureMechanisms())
- {
- fm.NotifyObservers();
- }
- }
-
- private void ClearAssessmentSectionData()
- {
- IObservable[] affectedCalculations = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection).ToArray();
- if (affectedCalculations.Length > 0)
- {
- affectedCalculations.ForEachElementDo(ac => ac.NotifyObservers());
- log.InfoFormat(RingtoetsIntegrationFormsResources.FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared, affectedCalculations.Length);
- }
-
- if (assessmentSection.HydraulicBoundaryDatabase != null)
- {
- ClearAllHydraulicBoundaryLocationOutput();
- }
- }
-
- private void ClearAllHydraulicBoundaryLocationOutput()
- {
- GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms()
- .OfType()
- .First();
-
- IEnumerable hydraulicBoundaryLocationAffected = RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(assessmentSection.HydraulicBoundaryDatabase,
- grassCoverErosionOutwardsFailureMechanism);
- if (hydraulicBoundaryLocationAffected.Any())
- {
- grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations.NotifyObservers();
-
- assessmentSection.HydraulicBoundaryDatabase.NotifyObservers();
- log.Info(RingtoetsIntegrationFormsResources.FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_level_results_cleared);
- }
- }
-
- private void ClearGrassCoverErosionOutwardsHydraulicBoundaryLocations()
- {
- var grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms()
- .OfType()
- .First();
- ObservableList hydraulicBoundaryLocations = grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations;
- bool locationsAffected = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(hydraulicBoundaryLocations)
- .Any();
- if (locationsAffected)
- {
- hydraulicBoundaryLocations.NotifyObservers();
- log.Info(RingtoetsGrassCoverErosionOutwardsFormsResources.GrassCoverErosionOutwards_NormValueChanged_Waveheight_and_design_water_level_results_cleared);
- }
- }
-
- private void ResetTextIfEmpty()
- {
- if (string.IsNullOrEmpty(normInput.Text))
- {
- normInput.Text = normInput.Value.ToString(CultureInfo.CurrentCulture);
- }
- }
-
private void SetNormText()
{
if (data != null)
@@ -389,6 +322,19 @@
#region Event handling
+ private void NormInputLeave(object sender, EventArgs e)
+ {
+ ResetTextIfEmpty();
+ }
+
+ private void ResetTextIfEmpty()
+ {
+ if (string.IsNullOrEmpty(normInput.Text))
+ {
+ normInput.Text = normInput.Value.ToString(CultureInfo.CurrentCulture);
+ }
+ }
+
private void ProbabilityDistributionGridOnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (data == null)
@@ -455,6 +401,67 @@
assessmentSection.NotifyObservers();
}
+ private void ClearGrassCoverErosionOutwardsHydraulicBoundaryLocations()
+ {
+ var grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms()
+ .OfType()
+ .First();
+ ObservableList hydraulicBoundaryLocations = grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations;
+ bool locationsAffected = RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(hydraulicBoundaryLocations)
+ .Any();
+ if (locationsAffected)
+ {
+ hydraulicBoundaryLocations.NotifyObservers();
+ log.Info(RingtoetsGrassCoverErosionOutwardsFormsResources.GrassCoverErosionOutwards_NormValueChanged_Waveheight_and_design_water_level_results_cleared);
+ }
+ }
+
+ private void NormNumericUpDown_Validating(object sender, CancelEventArgs e)
+ {
+ if (normInput.Value != assessmentSection.FailureMechanismContribution.Norm)
+ {
+ if (!changeHandler.ConfirmNormChange())
+ {
+ e.Cancel = true;
+ RevertNormInputValue();
+ }
+ }
+ }
+
+ private void NormNumericUpDown_Validated(object sender, EventArgs e)
+ {
+ int newNormValue = Convert.ToInt32(normInput.Value);
+ IEnumerable changedObjects = changeHandler.ChangeNorm(assessmentSection, newNormValue);
+ foreach (IObservable changedObject in changedObjects)
+ {
+ changedObject.NotifyObservers();
+ }
+ }
+
+ private void NormNumericUpDownInnerTextBox_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Escape)
+ {
+ RevertNormInputValue();
+
+ e.Handled = true;
+ e.SuppressKeyPress = true;
+ }
+ else if (e.KeyCode == Keys.Enter)
+ {
+ ActiveControl = null;
+
+ e.Handled = true;
+ e.SuppressKeyPress = true;
+ }
+ }
+
+ private void RevertNormInputValue()
+ {
+ SetNormText();
+ ActiveControl = null;
+ }
+
#endregion
}
}
\ No newline at end of file
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx
===================================================================
diff -u -r6de928689da61ccae1dc375d27b8f178d97a13f7 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx (.../FailureMechanismContributionView.resx) (revision 6de928689da61ccae1dc375d27b8f178d97a13f7)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/FailureMechanismContributionView.resx (.../FailureMechanismContributionView.resx) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -289,7 +289,7 @@
probabilityDistributionGrid
- Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=16.1.1.5095, Culture=neutral, PublicKeyToken=null
+ Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=16.4.1.6761, Culture=neutral, PublicKeyToken=null
tableLayoutPanel
Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IFailureMechanismContributionNormChangeHandler.cs
===================================================================
diff -u
--- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IFailureMechanismContributionNormChangeHandler.cs (revision 0)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/IFailureMechanismContributionNormChangeHandler.cs (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -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.Collections.Generic;
+using Core.Common.Base;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Contribution;
+
+namespace Ringtoets.Integration.Forms.Views
+{
+ ///
+ /// Interface for an object that can properly change the
+ /// of an .
+ ///
+ public interface IFailureMechanismContributionNormChangeHandler
+ {
+ ///
+ /// Checks to see if the replacement of the norm variable of the assessment section
+ /// should occur or not.
+ ///
+ /// true if the change should occur, false otherwise.
+ bool ConfirmNormChange();
+
+ ///
+ /// Replaces the of the
+ /// of the given 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.
+ IEnumerable ChangeNorm(IAssessmentSection section, int newNormValue);
+ }
+}
\ No newline at end of file
Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs
===================================================================
diff -u
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (revision 0)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -0,0 +1,107 @@
+// 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.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using Core.Common.Base;
+using Core.Common.Utils.Extensions;
+using log4net;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Contribution;
+using Ringtoets.GrassCoverErosionOutwards.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 of the of an
+ /// and clearing all data dependent on the original norm value.
+ ///
+ public class FailureMechanismContributionNormChangeHandler : IFailureMechanismContributionNormChangeHandler
+ {
+ private readonly ILog log = LogManager.GetLogger(typeof(FailureMechanismContributionNormChangeHandler));
+
+ public bool ConfirmNormChange()
+ {
+ DialogResult result = MessageBox.Show(Resources.FailureMechanismContributionNormChangeHandler_Confirm_change_norm_and_clear_dependent_data,
+ CoreCommonBaseResources.Confirm,
+ MessageBoxButtons.OKCancel);
+ return result == DialogResult.OK;
+ }
+
+ public IEnumerable ChangeNorm(IAssessmentSection section, int newNormValue)
+ {
+ var changedObjects = new List();
+
+ if (section.FailureMechanismContribution.Norm != newNormValue)
+ {
+ section.FailureMechanismContribution.Norm = newNormValue;
+
+ changedObjects.AddRange(ClearAssessmentSectionData(section));
+ changedObjects.Add(section.FailureMechanismContribution);
+ changedObjects.AddRange(section.GetFailureMechanisms());
+ }
+
+ return changedObjects;
+ }
+
+ private IEnumerable ClearAssessmentSectionData(IAssessmentSection assessmentSection)
+ {
+ List affectedObjects = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection).ToList();
+ if (affectedObjects.Count > 0)
+ {
+ log.InfoFormat(Resources.FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared,
+ affectedObjects.Count);
+ }
+
+ if (assessmentSection.HydraulicBoundaryDatabase != null)
+ {
+ affectedObjects.AddRange(ClearAllHydraulicBoundaryLocationOutput(assessmentSection));
+ }
+ return affectedObjects;
+ }
+
+ private IEnumerable ClearAllHydraulicBoundaryLocationOutput(IAssessmentSection assessmentSection)
+ {
+ GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms()
+ .OfType()
+ .First();
+
+ IEnumerable hydraulicBoundaryLocationAffected = RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(assessmentSection.HydraulicBoundaryDatabase,
+ grassCoverErosionOutwardsFailureMechanism);
+ if (hydraulicBoundaryLocationAffected.Any())
+ {
+ log.Info(Resources.FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_level_results_cleared);
+ return new IObservable[]
+ {
+ grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations,
+ assessmentSection.HydraulicBoundaryDatabase
+ };
+ }
+ return Enumerable.Empty();
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs
===================================================================
diff -u -r666de532f451548d6fcf1c61f661a6715852ac5d -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 666de532f451548d6fcf1c61f661a6715852ac5d)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -88,6 +88,36 @@
}
///
+ /// Looks up a localized string similar to Na het aanpassen van de norm zullen alle rekenresultaten van hydraulische randvoorwaarden en faalmechanismen verwijderd worden. Wilt u doorgaan?.
+ ///
+ public static string FailureMechanismContributionNormChangeHandler_Confirm_change_norm_and_clear_dependent_data {
+ get {
+ return ResourceManager.GetString("FailureMechanismContributionNormChangeHandler_Confirm_change_norm_and_clear_depen" +
+ "dent_data", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to De resultaten van {0} berekeningen zijn verwijderd..
+ ///
+ public static string FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations_0_calculations_cleared {
+ get {
+ return ResourceManager.GetString("FailureMechanismContributionView_NormValueChanged_Results_of_NumberOfCalculations" +
+ "_0_calculations_cleared", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd..
+ ///
+ public static string FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_level_results_cleared {
+ get {
+ return ResourceManager.GetString("FailureMechanismContributionView_NormValueChanged_Waveheight_and_design_water_lev" +
+ "el_results_cleared", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Vakindeling komt niet overeen met de huidige referentielijn..
///
public static string FailureMechanismSectionsImporter_Import_Imported_sections_do_not_correspond_to_current_referenceline {
Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx
===================================================================
diff -u -r666de532f451548d6fcf1c61f661a6715852ac5d -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 666de532f451548d6fcf1c61f661a6715852ac5d)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -147,4 +147,13 @@
Wilt u doorgaan?
+
+ De resultaten van {0} berekeningen zijn verwijderd.
+
+
+ Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd.
+
+
+ Na het aanpassen van de norm zullen alle rekenresultaten van hydraulische randvoorwaarden en faalmechanismen verwijderd worden. Wilt u doorgaan?
+
\ No newline at end of file
Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj
===================================================================
diff -u -r666de532f451548d6fcf1c61f661a6715852ac5d -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 666de532f451548d6fcf1c61f661a6715852ac5d)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -54,6 +54,7 @@
Properties\GlobalAssembly.cs
+
Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs
===================================================================
diff -u -rd72a7a2a430e8adaaf5357c10feb66e1f715d3b6 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision d72a7a2a430e8adaaf5357c10feb66e1f715d3b6)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -298,6 +298,7 @@
GetViewData = context => context.WrappedData,
Image = RingtoetsCommonFormsResources.FailureMechanismContributionIcon,
CloseForData = CloseFailureMechanismContributionViewForData,
+ CreateInstance = () => new FailureMechanismContributionView(new FailureMechanismContributionNormChangeHandler()),
AfterCreate = (view, context) =>
{
view.AssessmentSection = context.Parent;
Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs
===================================================================
diff -u -r8723c31042f8aa4174e6d51a42f20d3665ec2da0 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs (.../FailureMechanismContributionViewIntegrationTest.cs) (revision 8723c31042f8aa4174e6d51a42f20d3665ec2da0)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/FailureMechanismContributionViewIntegrationTest.cs (.../FailureMechanismContributionViewIntegrationTest.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
@@ -38,14 +39,15 @@
using Ringtoets.HydraRing.Data;
using Ringtoets.Integration.Data;
using Ringtoets.Integration.Forms.Views;
+using Ringtoets.Integration.Plugin.Handlers;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Data.TestUtil;
using Ringtoets.Piping.KernelWrapper.TestUtil;
namespace Ringtoets.Integration.Forms.Test
{
[TestFixture]
- public class FailureMechanismContributionViewIntegrationTest
+ public class FailureMechanismContributionViewIntegrationTest : NUnitFormTest
{
private const string messageAllHydraulicBoundaryLocationOutputCleared =
"Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd.";
@@ -118,8 +120,17 @@
MockRepository mockRepository = new MockRepository();
IObserver observerMock = mockRepository.StrictMock();
observerMock.Expect(o => o.UpdateObserver());
- IObserver calculationObserver = mockRepository.StrictMock();
- calculationObserver.Expect(co => co.UpdateObserver()).Repeat.Times(numberOfCalculations);
+
+ IObserver pipingCalculationObserver = mockRepository.StrictMock();
+ pipingCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver grassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock();
+ grassCoverErosionInwardsCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver heightStructuresCalculationObserver = mockRepository.StrictMock();
+ heightStructuresCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver emptyPipingCalculationObserver = mockRepository.StrictMock();
+ IObserver emptyGrassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock();
+ IObserver emptyHeightStructuresCalculationObserver = mockRepository.StrictMock();
+
IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock();
hydraulicBoundaryDatabaseObserver.Expect(hbdo => hbdo.UpdateObserver());
IObserver grassCoverErosionOutwardsObserver = mockRepository.StrictMock();
@@ -129,18 +140,20 @@
failureMechanismContribution.Attach(observerMock);
hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserver);
- emptyPipingCalculation.Attach(calculationObserver);
- emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver);
- emptyHeightStructuresCalculation.Attach(calculationObserver);
+ emptyPipingCalculation.Attach(emptyPipingCalculationObserver);
+ emptyGrassCoverErosionInwardsCalculation.Attach(emptyGrassCoverErosionInwardsCalculationObserver);
+ emptyHeightStructuresCalculation.Attach(emptyHeightStructuresCalculationObserver);
- pipingCalculation.Attach(calculationObserver);
- grassCoverErosionInwardsCalculation.Attach(calculationObserver);
- heightStructuresCalculation.Attach(calculationObserver);
+ pipingCalculation.Attach(pipingCalculationObserver);
+ grassCoverErosionInwardsCalculation.Attach(grassCoverErosionInwardsCalculationObserver);
+ heightStructuresCalculation.Attach(heightStructuresCalculationObserver);
assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserver);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (var form = new Form())
- using (var distributionView = new FailureMechanismContributionView
+ using (var distributionView = new FailureMechanismContributionView(handler)
{
Data = failureMechanismContribution,
AssessmentSection = assessmentSection
@@ -163,8 +176,14 @@
Assert.IsNotNull(grassCoverErosionInwardsCalculation.Output);
Assert.IsNotNull(heightStructuresCalculation.Output);
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var dialogTester = new MessageBoxTester(wnd);
+ dialogTester.ClickOk();
+ };
+
// Call
- Action call = () => normTester.Properties.Text = normValue.ToString();
+ Action call = () => SimulateUserComittingNormValue(normTester, normValue);
// Assert
TestHelper.AssertLogMessages(call, msgs =>
@@ -231,8 +250,10 @@
emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver);
emptyHeightStructuresCalculation.Attach(calculationObserver);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (Form form = new Form())
- using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView
+ using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler)
{
Data = failureMechanismContribution,
AssessmentSection = assessmentSection
@@ -249,8 +270,15 @@
Assert.AreEqual(failureMechanismContribution.Norm.ToString(), normTester.Text);
Assert.AreEqual(waveHeight, hydraulicBoundaryLocation.WaveHeight, hydraulicBoundaryLocation.WaveHeight.GetAccuracy());
Assert.AreEqual(designWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel, hydraulicBoundaryLocation.DesignWaterLevel.GetAccuracy());
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var dialogTester = new MessageBoxTester(wnd);
+ dialogTester.ClickOk();
+ };
+
// Call
- Action call = () => normTester.Properties.Text = normValue.ToString();
+ Action call = () => SimulateUserComittingNormValue(normTester, normValue);
// Assert
TestHelper.AssertLogMessageIsGenerated(call, messageAllHydraulicBoundaryLocationOutputCleared, 1);
@@ -306,24 +334,35 @@
MockRepository mockRepository = new MockRepository();
IObserver observerMock = mockRepository.StrictMock();
observerMock.Expect(o => o.UpdateObserver());
- IObserver calculationObserver = mockRepository.StrictMock();
- calculationObserver.Expect(co => co.UpdateObserver()).Repeat.Times(numberOfCalculations);
+
+ IObserver pipingCalculationObserver = mockRepository.StrictMock();
+ pipingCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver grassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock();
+ grassCoverErosionInwardsCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver heightStructuresCalculationObserver = mockRepository.StrictMock();
+ heightStructuresCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver emptyPipingCalculationObserver = mockRepository.StrictMock();
+ IObserver emptyGrassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock();
+ IObserver emptyHeightStructuresCalculationObserver = mockRepository.StrictMock();
+
IObserver hydraulicBoundaryDatabaseObserver = mockRepository.StrictMock(); // No update observer expected.
mockRepository.ReplayAll();
failureMechanismContribution.Attach(observerMock);
hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserver);
- emptyPipingCalculation.Attach(calculationObserver);
- emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver);
- emptyHeightStructuresCalculation.Attach(calculationObserver);
+ emptyPipingCalculation.Attach(emptyPipingCalculationObserver);
+ emptyGrassCoverErosionInwardsCalculation.Attach(emptyGrassCoverErosionInwardsCalculationObserver);
+ emptyHeightStructuresCalculation.Attach(emptyHeightStructuresCalculationObserver);
- pipingCalculation.Attach(calculationObserver);
- grassCoverErosionInwardsCalculation.Attach(calculationObserver);
- heightStructuresCalculation.Attach(calculationObserver);
+ pipingCalculation.Attach(pipingCalculationObserver);
+ grassCoverErosionInwardsCalculation.Attach(grassCoverErosionInwardsCalculationObserver);
+ heightStructuresCalculation.Attach(heightStructuresCalculationObserver);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (Form form = new Form())
- using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView
+ using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler)
{
Data = failureMechanismContribution,
AssessmentSection = assessmentSection
@@ -341,8 +380,14 @@
Assert.IsNotNull(grassCoverErosionInwardsCalculation.Output);
Assert.IsNotNull(heightStructuresCalculation.Output);
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var dialogTester = new MessageBoxTester(wnd);
+ dialogTester.ClickOk();
+ };
+
// Call
- Action call = () => normTester.Properties.Text = normValue.ToString();
+ Action call = () => SimulateUserComittingNormValue(normTester, normValue);
// Assert
string expectedMessage = string.Format(messageCalculationsremoved,
@@ -396,22 +441,33 @@
MockRepository mockRepository = new MockRepository();
IObserver observerMock = mockRepository.StrictMock();
observerMock.Expect(o => o.UpdateObserver());
- IObserver calculationObserver = mockRepository.StrictMock();
- calculationObserver.Expect(co => co.UpdateObserver()).Repeat.Times(numberOfCalculations);
+
+ IObserver pipingCalculationObserver = mockRepository.StrictMock();
+ pipingCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver grassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock();
+ grassCoverErosionInwardsCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver heightStructuresCalculationObserver = mockRepository.StrictMock();
+ heightStructuresCalculationObserver.Expect(o => o.UpdateObserver());
+ IObserver emptyPipingCalculationObserver = mockRepository.StrictMock();
+ IObserver emptyGrassCoverErosionInwardsCalculationObserver = mockRepository.StrictMock();
+ IObserver emptyHeightStructuresCalculationObserver = mockRepository.StrictMock();
+
mockRepository.ReplayAll();
failureMechanismContribution.Attach(observerMock);
- emptyPipingCalculation.Attach(calculationObserver);
- emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver);
- emptyHeightStructuresCalculation.Attach(calculationObserver);
+ emptyPipingCalculation.Attach(emptyPipingCalculationObserver);
+ emptyGrassCoverErosionInwardsCalculation.Attach(emptyGrassCoverErosionInwardsCalculationObserver);
+ emptyHeightStructuresCalculation.Attach(emptyHeightStructuresCalculationObserver);
- pipingCalculation.Attach(calculationObserver);
- grassCoverErosionInwardsCalculation.Attach(calculationObserver);
- heightStructuresCalculation.Attach(calculationObserver);
+ pipingCalculation.Attach(pipingCalculationObserver);
+ grassCoverErosionInwardsCalculation.Attach(grassCoverErosionInwardsCalculationObserver);
+ heightStructuresCalculation.Attach(heightStructuresCalculationObserver);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (Form form = new Form())
- using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView
+ using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler)
{
Data = failureMechanismContribution,
AssessmentSection = assessmentSection
@@ -429,8 +485,14 @@
Assert.IsNotNull(grassCoverErosionInwardsCalculation.Output);
Assert.IsNotNull(heightStructuresCalculation.Output);
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var dialogTester = new MessageBoxTester(wnd);
+ dialogTester.ClickOk();
+ };
+
// Call
- Action call = () => normTester.Properties.Text = normValue.ToString();
+ Action call = () => SimulateUserComittingNormValue(normTester, normValue);
// Assert
string expectedMessage = string.Format(messageCalculationsremoved,
@@ -483,8 +545,10 @@
emptyHeightStructuresCalculation.Attach(calculationObserver);
hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserver);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (Form form = new Form())
- using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView
+ using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler)
{
Data = failureMechanismContribution,
AssessmentSection = assessmentSection
@@ -498,8 +562,14 @@
// Precondition
Assert.AreEqual(failureMechanismContribution.Norm.ToString(), normTester.Text);
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var dialogTester = new MessageBoxTester(wnd);
+ dialogTester.ClickOk();
+ };
+
// Call
- Action call = () => normTester.Properties.Text = normValue.ToString();
+ Action call = () => SimulateUserComittingNormValue(normTester, normValue);
// Assert
TestHelper.AssertLogMessagesCount(call, 0);
@@ -537,8 +607,10 @@
emptyGrassCoverErosionInwardsCalculation.Attach(calculationObserver);
emptyHeightStructuresCalculation.Attach(calculationObserver);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (Form form = new Form())
- using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView
+ using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler)
{
Data = failureMechanismContribution,
AssessmentSection = assessmentSection
@@ -552,8 +624,14 @@
// Precondition
Assert.AreEqual(failureMechanismContribution.Norm.ToString(), normTester.Text);
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var dialogTester = new MessageBoxTester(wnd);
+ dialogTester.ClickOk();
+ };
+
// Call
- Action call = () => normTester.Properties.Text = normValue.ToString();
+ Action call = () => SimulateUserComittingNormValue(normTester, normValue);
// Assert
TestHelper.AssertLogMessagesCount(call, 0);
@@ -610,8 +688,10 @@
hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserverMock);
assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserverMock);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (var form = new Form())
- using (var distributionView = new FailureMechanismContributionView
+ using (var distributionView = new FailureMechanismContributionView(handler)
{
Data = assessmentSection.FailureMechanismContribution,
AssessmentSection = assessmentSection
@@ -689,8 +769,10 @@
hydraulicBoundaryDatabase.Attach(hydraulicBoundaryDatabaseObserverMock);
assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserverMock);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (var form = new Form())
- using (var distributionView = new FailureMechanismContributionView
+ using (var distributionView = new FailureMechanismContributionView(handler)
{
Data = assessmentSection.FailureMechanismContribution,
AssessmentSection = assessmentSection
@@ -733,8 +815,10 @@
assessmentSection.Attach(observerMock);
assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Attach(grassCoverErosionOutwardsObserverMock);
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
using (var form = new Form())
- using (var distributionView = new FailureMechanismContributionView
+ using (var distributionView = new FailureMechanismContributionView(handler)
{
Data = assessmentSection.FailureMechanismContribution,
AssessmentSection = assessmentSection
@@ -752,5 +836,17 @@
// Assert
mockRepository.VerifyAll(); // Expect UpdateObserver call
}
+
+ private static void SimulateUserComittingNormValue(ControlTester normTester, int normValue)
+ {
+ var normInput = (NumericUpDown) normTester.TheObject;
+ normInput.Value = normValue;
+ var eventArgs = new CancelEventArgs();
+ EventHelper.RaiseEvent(normTester.TheObject, "Validating", eventArgs);
+ if (!eventArgs.Cancel)
+ {
+ normTester.FireEvent("Validated");
+ }
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs
===================================================================
diff -u -r6de928689da61ccae1dc375d27b8f178d97a13f7 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs (.../FailureMechanismContributionViewTest.cs) (revision 6de928689da61ccae1dc375d27b8f178d97a13f7)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/FailureMechanismContributionViewTest.cs (.../FailureMechanismContributionViewTest.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
@@ -70,7 +71,13 @@
[Test]
public void DefaultConstructor_SetsDefaults()
{
- using (var contributionView = new FailureMechanismContributionView())
+ // Setup
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ using (var contributionView = new FailureMechanismContributionView(handler))
{
ShowFormWithView(contributionView);
@@ -88,17 +95,22 @@
Assert.IsFalse(contributionView.AutoScroll);
}
+ mocks.VerifyAll();
}
[Test]
public void NormTextBox_Initialize_TextSetToData()
{
// Setup
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+
AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution;
// Call
- using (var contributionView = new FailureMechanismContributionView
+ using (var contributionView = new FailureMechanismContributionView(handler)
{
Data = failureMechanismContribution,
AssessmentSection = assessmentSection
@@ -115,10 +127,11 @@
Assert.AreEqual(1000000, normControl.Maximum);
Assert.AreEqual(100, normControl.Minimum);
}
+ mocks.VerifyAll();
}
[Test]
- public void NormTextBox_ValueChanged_UpdatesDataWithNewValue()
+ public void NormTextBox_ValueChangedAndUserConfirmsChange_UpdatesDataWithNewValue()
{
// Setup
const int normValue = 200;
@@ -127,13 +140,61 @@
FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution;
MockRepository mockRepository = new MockRepository();
- IObserver observerMock = mockRepository.StrictMock();
- observerMock.Expect(o => o.UpdateObserver());
+ var observable1 = mockRepository.StrictMock();
+ observable1.Expect(o => o.NotifyObservers());
+ 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, normValue))
+ .Return(new[]
+ {
+ observable1,
+ observable2
+ });
+
mockRepository.ReplayAll();
- failureMechanismContribution.Attach(observerMock);
+ using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler)
+ {
+ Data = failureMechanismContribution,
+ AssessmentSection = assessmentSection
+ })
+ {
+ ShowFormWithView(distributionView);
+ ControlTester normTester = new ControlTester(normInputTextBoxName);
- using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView
+ // Precondition
+ Assert.AreEqual(failureMechanismContribution.Norm.ToString(), normTester.Text);
+
+ // Call
+ SimulateUserComittingNormValue(normTester, normValue);
+ }
+ // Assert
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void NormTextBox_ValueChangedAndUserDisallowsChange_NothingHappens()
+ {
+ // Setup
+ const int normValue = 200;
+
+ AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution;
+ int originalNormValue = failureMechanismContribution.Norm;
+
+ MockRepository mockRepository = new MockRepository();
+ var handler = mockRepository.StrictMock();
+ handler.Expect(h => h.ConfirmNormChange()).Return(false);
+ handler.Expect(h => h.ChangeNorm(assessmentSection, normValue))
+ .Return(Enumerable.Empty())
+ .Repeat.Never();
+
+ mockRepository.ReplayAll();
+
+ using (FailureMechanismContributionView distributionView = new FailureMechanismContributionView(handler)
{
Data = failureMechanismContribution,
AssessmentSection = assessmentSection
@@ -146,10 +207,10 @@
Assert.AreEqual(failureMechanismContribution.Norm.ToString(), normTester.Text);
// Call
- normTester.Properties.Text = normValue.ToString();
+ SimulateUserComittingNormValue(normTester, normValue);
// Assert
- Assert.AreEqual(normValue, failureMechanismContribution.Norm);
+ Assert.AreEqual(originalNormValue.ToString(), normTester.Properties.Text);
}
mockRepository.VerifyAll();
}
@@ -158,7 +219,11 @@
public void Data_Always_CorrectHeaders()
{
// Setup
- using (var distributionView = new FailureMechanismContributionView())
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var distributionView = new FailureMechanismContributionView(handler))
{
// Call
ShowFormWithView(distributionView);
@@ -181,6 +246,7 @@
string probabilitySpaceColumnHeaderText = dataGridView.Columns[probabilitySpaceColumnIndex].HeaderText;
Assert.AreEqual("Faalkansruimte [1/jaar]", probabilitySpaceColumnHeaderText);
}
+ mocks.VerifyAll();
}
[Test]
@@ -197,6 +263,8 @@
double testContribution = 100 - otherContribution;
var mockRepository = new MockRepository();
+ var handler = mockRepository.Stub();
+
var someMechanism = mockRepository.StrictMock(testName, testCode);
someMechanism.Contribution = testContribution;
@@ -207,7 +275,7 @@
someMechanism
}, otherContribution, 100);
- using (var distributionView = new FailureMechanismContributionView
+ using (var distributionView = new FailureMechanismContributionView(handler)
{
AssessmentSection = assessmentSection
})
@@ -246,6 +314,7 @@
var assessmentSection2 = new AssessmentSection(AssessmentSectionComposition.Dike);
var mockRepository = new MockRepository();
+ var handler = mockRepository.Stub();
var someMechanism = mockRepository.Stub();
mockRepository.ReplayAll();
@@ -258,7 +327,7 @@
someMechanism
}, random.Next(0, 100), expectedValue);
- using (var distributionView = new FailureMechanismContributionView
+ using (var distributionView = new FailureMechanismContributionView(handler)
{
Data = initialContribution,
AssessmentSection = assessmentSection1
@@ -292,6 +361,7 @@
var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
var mockRepository = new MockRepository();
+ var handler = mockRepository.Stub();
var someMechanism = mockRepository.Stub();
mockRepository.ReplayAll();
@@ -300,7 +370,7 @@
someMechanism
}, random.Next(0, 100), initialValue);
- using (var distributionView = new FailureMechanismContributionView
+ using (var distributionView = new FailureMechanismContributionView(handler)
{
Data = contribution,
AssessmentSection = assessmentSection
@@ -332,14 +402,15 @@
var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
var mockRepository = new MockRepository();
+ var handler = 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())
+ using (var view = new FailureMechanismContributionView(handler))
{
// When
var contributionData = new FailureMechanismContribution(new[]
@@ -368,13 +439,14 @@
var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
var mockRepository = new MockRepository();
+ var handler = 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())
+ using (var view = new FailureMechanismContributionView(handler))
{
// When
var contributionData = new FailureMechanismContribution(new[]
@@ -406,14 +478,14 @@
var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
var mockRepository = new MockRepository();
-
+ var handler = 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())
+ using (var view = new FailureMechanismContributionView(handler))
{
// When
var contributionData = new FailureMechanismContribution(new[]
@@ -446,7 +518,11 @@
public void CompositionComboBox_WithDataSet_SelectedDisplayTextAndValueCorrect(AssessmentSectionComposition composition, string expectedDisplayText)
{
// Setup
- using (var view = new FailureMechanismContributionView())
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view = new FailureMechanismContributionView(handler))
{
ShowFormWithView(view);
@@ -462,6 +538,7 @@
Assert.AreEqual(expectedDisplayText, compositionComboBox.Text);
Assert.AreEqual(composition, compositionComboBox.SelectedValue);
}
+ mocks.VerifyAll();
}
[Test]
@@ -474,7 +551,11 @@
public void CompositionComboBox_ChangeCompositionAndOk_UpdateAssessmentSectionContributionAndView(AssessmentSectionComposition initialComposition, AssessmentSectionComposition newComposition)
{
// Setup
- using (var view = new FailureMechanismContributionView())
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view = new FailureMechanismContributionView(handler))
{
var assessmentSection = new AssessmentSection(initialComposition);
@@ -502,6 +583,7 @@
"Expect the DataGridView to be flagged for redrawing.");
AssertDataGridViewDataSource(assessmentSection.FailureMechanismContribution.Distribution, contributionGridView);
}
+ mocks.VerifyAll();
}
[Test]
@@ -514,13 +596,14 @@
public void CompositionComboBox_ChangeComposition_NotifyAssessmentSectionObservers(AssessmentSectionComposition initialComposition, AssessmentSectionComposition newComposition)
{
// Setup
- using (var view = new FailureMechanismContributionView())
- {
- var mocks = new MockRepository();
- var observer = mocks.StrictMock();
- observer.Expect(o => o.UpdateObserver());
- mocks.ReplayAll();
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ var observer = mocks.StrictMock();
+ observer.Expect(o => o.UpdateObserver());
+ mocks.ReplayAll();
+ using (var view = new FailureMechanismContributionView(handler))
+ {
var assessmentSection = new AssessmentSection(initialComposition);
assessmentSection.Attach(observer);
@@ -535,25 +618,25 @@
// Call
compositionComboBox.SelectedValue = newComposition;
-
- // Assert
- mocks.VerifyAll(); // Expect UpdateObserver call
}
+ // Assert
+ mocks.VerifyAll(); // Expect UpdateObserver call
}
[Test]
public void GivenView_WhenSettingRelevantFailureMechanism_RowIsStylesAsEnabled()
{
// Given
- using (var view = new FailureMechanismContributionView())
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ var failureMechanism = mocks.Stub();
+ failureMechanism.IsRelevant = true;
+ mocks.ReplayAll();
+
+ using (var view = new FailureMechanismContributionView(handler))
{
ShowFormWithView(view);
- var mocks = new MockRepository();
- var failureMechanism = mocks.Stub();
- failureMechanism.IsRelevant = true;
- mocks.ReplayAll();
-
var failureMechanisms = new[]
{
failureMechanism
@@ -578,23 +661,24 @@
DataGridViewCell cell = row.Cells[i];
AssertIsCellStyledAsEnabled(cell);
}
- mocks.VerifyAll();
}
+ mocks.VerifyAll();
}
[Test]
public void GivenView_WhenSettingFailureMechanismThatIsIrrelevant_RowIsStylesAsGreyedOut()
{
// Given
- using (var view = new FailureMechanismContributionView())
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ var failureMechanism = mocks.Stub();
+ failureMechanism.IsRelevant = false;
+ mocks.ReplayAll();
+
+ using (var view = new FailureMechanismContributionView(handler))
{
ShowFormWithView(view);
- var mocks = new MockRepository();
- var failureMechanism = mocks.Stub();
- failureMechanism.IsRelevant = false;
- mocks.ReplayAll();
-
var failureMechanisms = new[]
{
failureMechanism
@@ -619,8 +703,8 @@
DataGridViewCell cell = row.Cells[i];
AssertIsCellStyleGreyedOut(cell);
}
- mocks.VerifyAll();
}
+ mocks.VerifyAll();
}
[Test]
@@ -631,6 +715,7 @@
// Given
List failureMechanismObservers = new List();
var mocks = new MockRepository();
+ var handler = mocks.Stub();
var failureMechanism = mocks.Stub();
failureMechanism.Stub(fm => fm.Name).Return("A");
failureMechanism.Stub(fm => fm.Code).Return("C");
@@ -654,7 +739,7 @@
assessmentSection.Stub(section => section.Composition).Return(AssessmentSectionComposition.Dike);
mocks.ReplayAll();
- using (var view = new FailureMechanismContributionView())
+ using (var view = new FailureMechanismContributionView(handler))
{
ShowFormWithView(view);
@@ -714,6 +799,7 @@
// Given
List failureMechanismObservers = new List();
var mocks = new MockRepository();
+ var handler = mocks.Stub();
var failureMechanism = mocks.Stub();
failureMechanism.Stub(fm => fm.Name).Return("A");
failureMechanism.Stub(fm => fm.Code).Return("C");
@@ -765,7 +851,7 @@
viewCommandsStub.Expect(vc => vc.RemoveAllViewsForItem(irrelevantFailureMechanism));
mocks.ReplayAll();
- using (var view = new FailureMechanismContributionView
+ using (var view = new FailureMechanismContributionView(handler)
{
ViewCommands = viewCommandsStub
})
@@ -789,7 +875,11 @@
public void GivenView_WhenSettingFailureMechanismThatIsAlwaysRelevant_IsRelevantFlagTrueAndReadonly()
{
// Given
- using (var view = new FailureMechanismContributionView())
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view = new FailureMechanismContributionView(handler))
{
ShowFormWithView(view);
@@ -812,8 +902,107 @@
Assert.IsTrue((bool) isRelevantCell.Value);
Assert.IsTrue(isRelevantCell.ReadOnly);
}
+ mocks.VerifyAll();
}
+ [Test]
+ public void GivenView_WhenEscapeAfterEnteringDifferentNormNotCommited_RevertNormAndNoChangedToData()
+ {
+ // Given
+ var mocks = new MockRepository();
+ var handler = mocks.Stub();
+ handler.Stub(h => h.ChangeNorm(null, 1))
+ .IgnoreArguments()
+ .Return(Enumerable.Empty());
+ mocks.ReplayAll();
+
+ AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution;
+
+ const int normValue = 200;
+ int originalNorm = failureMechanismContribution.Norm;
+
+ using (var view = new FailureMechanismContributionView(handler)
+ {
+ Data = failureMechanismContribution,
+ AssessmentSection = assessmentSection
+ })
+ {
+ ShowFormWithView(view);
+ ControlTester normTester = new ControlTester(normInputTextBoxName);
+
+ // When
+ var normInput = (NumericUpDown)normTester.TheObject;
+ view.ActiveControl = normInput;
+ normInput.Value = normValue;
+ var keyEventArgs = new KeyEventArgs(Keys.Escape);
+ EventHelper.RaiseEvent(normInput.Controls.OfType().First(), "KeyDown", keyEventArgs);
+
+ // Then
+ Assert.IsTrue(keyEventArgs.Handled);
+ Assert.IsTrue(keyEventArgs.SuppressKeyPress);
+
+ Assert.AreEqual(originalNorm, normInput.Value);
+ Assert.AreNotSame(normInput, view.ActiveControl);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GivenView_WhenEnterAfterEnteringDifferentNormNotCommited_CommitValueAndChangeData()
+ {
+ // Given
+ const int normValue = 200;
+
+ AssessmentSection assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ 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, normValue))
+ .Return(Enumerable.Empty());
+ mocks.ReplayAll();
+
+ using (var view = new FailureMechanismContributionView(handler)
+ {
+ Data = failureMechanismContribution,
+ AssessmentSection = assessmentSection
+ })
+ {
+ ShowFormWithView(view);
+ ControlTester normTester = new ControlTester(normInputTextBoxName);
+
+ // When
+ var normInput = (NumericUpDown)normTester.TheObject;
+ view.ActiveControl = normInput;
+ normInput.Value = normValue;
+ var keyEventArgs = new KeyEventArgs(Keys.Enter);
+ EventHelper.RaiseEvent(normInput.Controls.OfType().First(), "KeyDown", keyEventArgs);
+
+ // Then
+ Assert.IsTrue(keyEventArgs.Handled);
+ Assert.IsTrue(keyEventArgs.SuppressKeyPress);
+
+ Assert.AreEqual(normValue, normInput.Value);
+ Assert.AreNotSame(normInput, view.ActiveControl);
+ }
+ mocks.VerifyAll();
+ }
+
+ private static void SimulateUserComittingNormValue(ControlTester normTester, int normValue)
+ {
+ var normInput = (NumericUpDown) normTester.TheObject;
+ normInput.Value = normValue;
+ var eventArgs = new CancelEventArgs();
+ EventHelper.RaiseEvent(normTester.TheObject, "Validating", eventArgs);
+ if (!eventArgs.Cancel)
+ {
+ normTester.FireEvent("Validated");
+ }
+ }
+
private void AssertDataGridViewDataSource(IEnumerable expectedDistributionElements, DataGridView dataGridView)
{
FailureMechanismContributionItem[] itemArray = expectedDistributionElements.ToArray();
Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs
===================================================================
diff -u
--- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (revision 0)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/FailureMechanismContributionNormChangeHandlerTest.cs (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -0,0 +1,41 @@
+// 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 NUnit.Framework;
+using Ringtoets.Integration.Forms.Views;
+using Ringtoets.Integration.Plugin.Handlers;
+
+namespace Ringtoets.Integration.Plugin.Test.Handlers
+{
+ [TestFixture]
+ public class FailureMechanismContributionNormChangeHandlerTest
+ {
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Call
+ var handler = new FailureMechanismContributionNormChangeHandler();
+
+ // Assert
+ Assert.IsInstanceOf(handler);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj
===================================================================
diff -u -r666de532f451548d6fcf1c61f661a6715852ac5d -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 666de532f451548d6fcf1c61f661a6715852ac5d)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -67,6 +67,7 @@
Properties\GlobalAssembly.cs
+
Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismContributionViewInfoTest.cs
===================================================================
diff -u -ra1ec5faebf7ccf8e67fa34a2b73cd1063ab48840 -r3df4971064b76a8e789bed245e8851fea72ba085
--- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismContributionViewInfoTest.cs (.../FailureMechanismContributionViewInfoTest.cs) (revision a1ec5faebf7ccf8e67fa34a2b73cd1063ab48840)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/FailureMechanismContributionViewInfoTest.cs (.../FailureMechanismContributionViewInfoTest.cs) (revision 3df4971064b76a8e789bed245e8851fea72ba085)
@@ -60,15 +60,19 @@
public void GetViewName_Always_ReturnsViewName()
{
// Setup
- var view = new FailureMechanismContributionView();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+ var view = new FailureMechanismContributionView(handler);
+
var failureMechanismContribution = new FailureMechanismContribution(Enumerable.Empty(), 30, 1000);
// Call
var viewName = info.GetViewName(view, failureMechanismContribution);
// Assert
Assert.AreEqual("Faalkansbegroting", viewName);
+ mocks.VerifyAll();
}
[Test]
@@ -133,6 +137,8 @@
public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue()
{
// Setup
+ var handler = mocks.Stub();
+
var contribution = new FailureMechanismContribution(Enumerable.Empty(), 100.0, 123456);
var assessmentSection = mocks.Stub();
@@ -145,7 +151,7 @@
mocks.ReplayAll();
- using (var view = new FailureMechanismContributionView
+ using (var view = new FailureMechanismContributionView(handler)
{
Data = contribution,
AssessmentSection = assessmentSection
@@ -164,6 +170,8 @@
public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse()
{
// Setup
+ var handler = mocks.Stub();
+
var contribution1 = new FailureMechanismContribution(Enumerable.Empty(), 100.0, 123456);
var contribution2 = new FailureMechanismContribution(Enumerable.Empty(), 100.0, 789123);
@@ -184,7 +192,7 @@
.Return(Enumerable.Empty());
mocks.ReplayAll();
- using (var view = new FailureMechanismContributionView
+ using (var view = new FailureMechanismContributionView(handler)
{
Data = contribution1,
AssessmentSection = assessmentSection1
@@ -204,27 +212,32 @@
public void CloseForData_ViewWithoutData_ReturnsFalse()
{
// Setup
+ var handler = mocks.Stub();
+
var contribution = new FailureMechanismContribution(Enumerable.Empty(), 100.0, 789123);
var assessmentSection = mocks.Stub();
assessmentSection.Stub(section => section.FailureMechanismContribution)
.Return(contribution);
mocks.ReplayAll();
- var view = new FailureMechanismContributionView();
+ using (var view = new FailureMechanismContributionView(handler))
+ {
+ // Call
+ var closeForData = info.CloseForData(view, assessmentSection);
- // Call
- var closeForData = info.CloseForData(view, assessmentSection);
-
- // Assert
- Assert.IsFalse(closeForData);
+ // Assert
+ Assert.IsFalse(closeForData);
+ }
mocks.VerifyAll();
}
[Test]
public void AfterCreate_WithGuiSet_SetsAssessmentSection()
{
// Setup
+ var handler = mocks.Stub();
+
var contribution = new FailureMechanismContribution(Enumerable.Empty(), 100.0, 789123);
var assessmentSection = mocks.Stub();
@@ -243,8 +256,8 @@
mocks.ReplayAll();
var context = new FailureMechanismContributionContext(contribution, assessmentSection);
- var view = new FailureMechanismContributionView();
+ using (var view = new FailureMechanismContributionView(handler))
using (var ringtoetsPlugin = new RingtoetsPlugin())
{
info = ringtoetsPlugin.GetViewInfos().First(tni => tni.ViewType == typeof(FailureMechanismContributionView));