Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Ringtoets.MacroStabilityInwards.Forms.csproj =================================================================== diff -u -ra0a4e8059c0e23db4eb3525d01a264fcf38c5ddd -re25d1dff1132d88462399833e9a76b1dc6b8b785 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Ringtoets.MacroStabilityInwards.Forms.csproj (.../Ringtoets.MacroStabilityInwards.Forms.csproj) (revision a0a4e8059c0e23db4eb3525d01a264fcf38c5ddd) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Ringtoets.MacroStabilityInwards.Forms.csproj (.../Ringtoets.MacroStabilityInwards.Forms.csproj) (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -90,28 +90,28 @@ - - + + UserControl - - PipingScenariosView.cs + + MacroStabilityInwardsScenariosView.cs - + UserControl - - PipingInputView.cs + + MacroStabilityInwardsInputView.cs - - + + UserControl - - PipingCalculationsView.cs + + MacroStabilityInwardsCalculationsView.cs - + UserControl @@ -122,7 +122,7 @@ MacroStabilityInwardsFailureMechanismView.cs - + UserControl @@ -210,15 +210,15 @@ Resources.Designer.cs Designer - - PipingScenariosView.cs + + MacroStabilityInwardsScenariosView.cs Designer - - PipingInputView.cs + + MacroStabilityInwardsInputView.cs - - PipingCalculationsView.cs + + MacroStabilityInwardsCalculationsView.cs MacroStabilityInwardsFailureMechanismView.cs Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationRow.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationRow.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationRow.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,234 @@ +// Copyright (C) Stichting Deltares 2017. 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.Globalization; +using Core.Common.Base.Data; +using Core.Common.Controls.DataGrid; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Forms.ChangeHandlers; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.MacroStabilityInwards.Data; + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + /// + /// This class represents a row of in the . + /// + internal class MacroStabilityInwardsCalculationRow + { + private readonly IObservablePropertyChangeHandler propertyChangeHandler; + + /// + /// Creates a new instance of . + /// + /// The this row contains. + /// The handler responsible for handling effects of a property change. + /// Thrown when any parameter is null. + public MacroStabilityInwardsCalculationRow(MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculation, + IObservablePropertyChangeHandler handler) + { + if (macroStabilityInwardsCalculation == null) + { + throw new ArgumentNullException(nameof(macroStabilityInwardsCalculation)); + } + if (handler == null) + { + throw new ArgumentNullException(nameof(handler)); + } + + MacroStabilityInwardsCalculation = macroStabilityInwardsCalculation; + propertyChangeHandler = handler; + } + + /// + /// Gets the this row contains. + /// + public MacroStabilityInwardsCalculationScenario MacroStabilityInwardsCalculation { get; } + + /// + /// Gets or sets the name of the . + /// + public string Name + { + get + { + return MacroStabilityInwardsCalculation.Name; + } + set + { + MacroStabilityInwardsCalculation.Name = value; + + MacroStabilityInwardsCalculation.NotifyObservers(); + } + } + + /// + /// Gets or sets the stochastic soil model of the . + /// + public DataGridViewComboBoxItemWrapper StochasticSoilModel + { + get + { + return new DataGridViewComboBoxItemWrapper(MacroStabilityInwardsCalculation.InputParameters.StochasticSoilModel); + } + set + { + StochasticSoilModel valueToSet = value?.WrappedObject; + if (!ReferenceEquals(MacroStabilityInwardsCalculation.InputParameters.StochasticSoilModel, valueToSet)) + { + PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.StochasticSoilModel = valueToSet, propertyChangeHandler); + } + } + } + + /// + /// Gets or sets the stochastic soil profile of the . + /// + public DataGridViewComboBoxItemWrapper StochasticSoilProfile + { + get + { + return new DataGridViewComboBoxItemWrapper(MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile); + } + set + { + StochasticSoilProfile valueToSet = value?.WrappedObject; + if (!ReferenceEquals(MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile, valueToSet)) + { + PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile = valueToSet, propertyChangeHandler); + } + } + } + + /// + /// Gets the stochastic soil profile probability of the . + /// + public string StochasticSoilProfileProbability + { + get + { + return MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile != null + ? new RoundedDouble(3, MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile.Probability * 100).Value.ToString(CultureInfo.CurrentCulture) + : new RoundedDouble(3).Value.ToString(CultureInfo.CurrentCulture); + } + } + + /// + /// Gets or sets the hydraulic boundary location of the . + /// + public DataGridViewComboBoxItemWrapper SelectableHydraulicBoundaryLocation + { + get + { + if (MacroStabilityInwardsCalculation.InputParameters.HydraulicBoundaryLocation == null) + { + return new DataGridViewComboBoxItemWrapper(null); + } + + return new DataGridViewComboBoxItemWrapper( + new SelectableHydraulicBoundaryLocation(MacroStabilityInwardsCalculation.InputParameters.HydraulicBoundaryLocation, + MacroStabilityInwardsCalculation.InputParameters.SurfaceLine?.ReferenceLineIntersectionWorldPoint)); + } + set + { + HydraulicBoundaryLocation valueToSet = value?.WrappedObject?.HydraulicBoundaryLocation; + if (!ReferenceEquals(MacroStabilityInwardsCalculation.InputParameters.HydraulicBoundaryLocation, valueToSet)) + { + PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.HydraulicBoundaryLocation = valueToSet, propertyChangeHandler); + } + } + } + + /// + /// Gets or sets the damping factory exit mean of the . + /// + public RoundedDouble DampingFactorExitMean + { + get + { + return MacroStabilityInwardsCalculation.InputParameters.DampingFactorExit.Mean; + } + set + { + if (!MacroStabilityInwardsCalculation.InputParameters.DampingFactorExit.Mean.Equals(value)) + { + PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.DampingFactorExit.Mean = value, propertyChangeHandler); + } + } + } + + /// + /// Gets or sets the phreatic level exit mean of the . + /// + public RoundedDouble PhreaticLevelExitMean + { + get + { + return MacroStabilityInwardsCalculation.InputParameters.PhreaticLevelExit.Mean; + } + set + { + if (!MacroStabilityInwardsCalculation.InputParameters.PhreaticLevelExit.Mean.Equals(value)) + { + PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.PhreaticLevelExit.Mean = value, propertyChangeHandler); + } + } + } + + /// + /// Gets or sets the entry point l of the . + /// + public RoundedDouble EntryPointL + { + get + { + return MacroStabilityInwardsCalculation.InputParameters.EntryPointL; + } + set + { + if (!MacroStabilityInwardsCalculation.InputParameters.EntryPointL.Equals(value)) + { + PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.EntryPointL = value, propertyChangeHandler); + } + } + } + + /// + /// Gets or sets the exit point l of the . + /// + public RoundedDouble ExitPointL + { + get + { + return MacroStabilityInwardsCalculation.InputParameters.ExitPointL; + } + set + { + if (!MacroStabilityInwardsCalculation.InputParameters.ExitPointL.Equals(value)) + { + PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.ExitPointL = value, propertyChangeHandler); + } + } + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.Designer.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.Designer.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.Designer.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,155 @@ +// Copyright (C) Stichting Deltares 2017. 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. + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + partial class MacroStabilityInwardsCalculationsView + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MacroStabilityInwardsCalculationsView)); + this.tableLayoutPanelUserControl = new System.Windows.Forms.TableLayoutPanel(); + this.splitContainer = new System.Windows.Forms.SplitContainer(); + this.tableLayoutPanelListBox = new System.Windows.Forms.TableLayoutPanel(); + this.listBox = new System.Windows.Forms.ListBox(); + this.labelFailureMechanismSections = new System.Windows.Forms.Label(); + this.tableLayoutPanelDataGrid = new System.Windows.Forms.TableLayoutPanel(); + this.labelCalculations = new System.Windows.Forms.Label(); + this.dataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl(); + this.buttonGenerateScenarios = new System.Windows.Forms.Button(); + this.tableLayoutPanelUserControl.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); + this.splitContainer.Panel1.SuspendLayout(); + this.splitContainer.Panel2.SuspendLayout(); + this.splitContainer.SuspendLayout(); + this.tableLayoutPanelListBox.SuspendLayout(); + this.tableLayoutPanelDataGrid.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanelUserControl + // + resources.ApplyResources(this.tableLayoutPanelUserControl, "tableLayoutPanelUserControl"); + this.tableLayoutPanelUserControl.Controls.Add(this.splitContainer, 0, 0); + this.tableLayoutPanelUserControl.Controls.Add(this.buttonGenerateScenarios, 0, 1); + this.tableLayoutPanelUserControl.Name = "tableLayoutPanelUserControl"; + // + // splitContainer + // + resources.ApplyResources(this.splitContainer, "splitContainer"); + this.splitContainer.Name = "splitContainer"; + // + // splitContainer.Panel1 + // + this.splitContainer.Panel1.Controls.Add(this.tableLayoutPanelListBox); + // + // splitContainer.Panel2 + // + this.splitContainer.Panel2.Controls.Add(this.tableLayoutPanelDataGrid); + this.splitContainer.TabStop = false; + // + // tableLayoutPanelListBox + // + resources.ApplyResources(this.tableLayoutPanelListBox, "tableLayoutPanelListBox"); + this.tableLayoutPanelListBox.Controls.Add(this.listBox, 0, 1); + this.tableLayoutPanelListBox.Controls.Add(this.labelFailureMechanismSections, 0, 0); + this.tableLayoutPanelListBox.Name = "tableLayoutPanelListBox"; + // + // listBox + // + resources.ApplyResources(this.listBox, "listBox"); + this.listBox.FormattingEnabled = true; + this.listBox.Name = "listBox"; + // + // labelFailureMechanismSections + // + resources.ApplyResources(this.labelFailureMechanismSections, "labelFailureMechanismSections"); + this.labelFailureMechanismSections.Name = "labelFailureMechanismSections"; + // + // tableLayoutPanelDataGrid + // + resources.ApplyResources(this.tableLayoutPanelDataGrid, "tableLayoutPanelDataGrid"); + this.tableLayoutPanelDataGrid.Controls.Add(this.labelCalculations, 0, 0); + this.tableLayoutPanelDataGrid.Controls.Add(this.dataGridViewControl, 0, 1); + this.tableLayoutPanelDataGrid.Name = "tableLayoutPanelDataGrid"; + // + // labelCalculations + // + resources.ApplyResources(this.labelCalculations, "labelCalculations"); + this.labelCalculations.Name = "labelCalculations"; + // + // dataGridViewControl + // + resources.ApplyResources(this.dataGridViewControl, "dataGridViewControl"); + this.dataGridViewControl.MultiSelect = true; + this.dataGridViewControl.Name = "dataGridViewControl"; + this.dataGridViewControl.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect; + // + // buttonGenerateScenarios + // + resources.ApplyResources(this.buttonGenerateScenarios, "buttonGenerateScenarios"); + this.buttonGenerateScenarios.Name = "buttonGenerateScenarios"; + this.buttonGenerateScenarios.UseVisualStyleBackColor = true; + this.buttonGenerateScenarios.Click += new System.EventHandler(this.OnGenerateScenariosButtonClick); + // + // MacroStabilityInwardsCalculationsView + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tableLayoutPanelUserControl); + this.Name = "MacroStabilityInwardsCalculationsView"; + this.tableLayoutPanelUserControl.ResumeLayout(false); + this.tableLayoutPanelUserControl.PerformLayout(); + this.splitContainer.Panel1.ResumeLayout(false); + this.splitContainer.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); + this.splitContainer.ResumeLayout(false); + this.tableLayoutPanelListBox.ResumeLayout(false); + this.tableLayoutPanelListBox.PerformLayout(); + this.tableLayoutPanelDataGrid.ResumeLayout(false); + this.tableLayoutPanelDataGrid.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanelUserControl; + private System.Windows.Forms.SplitContainer splitContainer; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanelListBox; + private System.Windows.Forms.ListBox listBox; + private System.Windows.Forms.Label labelFailureMechanismSections; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanelDataGrid; + private System.Windows.Forms.Label labelCalculations; + private Core.Common.Controls.DataGrid.DataGridViewControl dataGridViewControl; + private System.Windows.Forms.Button buttonGenerateScenarios; + } +} Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,672 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Common.Base.Geometry; +using Core.Common.Controls.DataGrid; +using Core.Common.Controls.Views; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Forms.ChangeHandlers; +using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.Forms.Properties; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.MacroStabilityInwards.Service; + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + /// + /// This class is a view for configuring macro stability inwards calculations. + /// + public partial class MacroStabilityInwardsCalculationsView : UserControl, ISelectionProvider + { + private const int stochasticSoilModelColumnIndex = 1; + private const int stochasticSoilProfileColumnIndex = 2; + private const int selectableHydraulicBoundaryLocationColumnIndex = 4; + + private readonly Observer assessmentSectionObserver; + private readonly RecursiveObserver inputObserver; + private readonly RecursiveObserver calculationGroupObserver; + private readonly RecursiveObserver calculationObserver; + private readonly Observer failureMechanismObserver; + private readonly RecursiveObserver surfaceLineObserver; + private readonly Observer stochasticSoilModelsObserver; + private readonly RecursiveObserver stochasticSoilProfileObserver; + private IAssessmentSection assessmentSection; + private CalculationGroup calculationGroup; + private MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism; + + private bool updatingDataSource; + + public event EventHandler SelectionChanged; + + /// + /// Creates a new instance of . + /// + public MacroStabilityInwardsCalculationsView() + { + InitializeComponent(); + InitializeDataGridView(); + InitializeListBox(); + + failureMechanismObserver = new Observer(OnFailureMechanismUpdate); + assessmentSectionObserver = new Observer(UpdateSelectableHydraulicBoundaryLocationsColumn); + // The concat is needed to observe the input of calculations in child groups. + inputObserver = new RecursiveObserver(UpdateDataGridViewDataSource, pcg => pcg.Children.Concat(pcg.Children.OfType().Select(pc => pc.InputParameters))); + calculationGroupObserver = new RecursiveObserver(UpdateDataGridViewDataSource, pcg => pcg.Children); + calculationObserver = new RecursiveObserver(dataGridViewControl.RefreshDataGridView, pcg => pcg.Children); + + surfaceLineObserver = new RecursiveObserver(UpdateDataGridViewDataSource, rpslc => rpslc); + + stochasticSoilModelsObserver = new Observer(OnStochasticSoilModelsUpdate); + stochasticSoilProfileObserver = new RecursiveObserver(dataGridViewControl.RefreshDataGridView, ssmc => ssmc.SelectMany(ssm => ssm.StochasticSoilProfiles)); + } + + /// + /// Gets or sets the macro stability inwards failure mechanism. + /// + public MacroStabilityInwardsFailureMechanism MacroStabilityInwardsFailureMechanism + { + get + { + return macroStabilityInwardsFailureMechanism; + } + set + { + macroStabilityInwardsFailureMechanism = value; + stochasticSoilModelsObserver.Observable = macroStabilityInwardsFailureMechanism?.StochasticSoilModels; + failureMechanismObserver.Observable = macroStabilityInwardsFailureMechanism; + surfaceLineObserver.Observable = macroStabilityInwardsFailureMechanism?.SurfaceLines; + stochasticSoilProfileObserver.Observable = macroStabilityInwardsFailureMechanism?.StochasticSoilModels; + + UpdateStochasticSoilModelColumn(); + UpdateStochasticSoilProfileColumn(); + UpdateSelectableHydraulicBoundaryLocationsColumn(); + UpdateSectionsListBox(); + UpdateGenerateScenariosButtonState(); + } + } + + /// + /// Gets or sets the assessment section. + /// + public IAssessmentSection AssessmentSection + { + get + { + return assessmentSection; + } + set + { + assessmentSection = value; + + assessmentSectionObserver.Observable = assessmentSection; + + UpdateSelectableHydraulicBoundaryLocationsColumn(); + } + } + + public object Data + { + get + { + return calculationGroup; + } + set + { + calculationGroup = value as CalculationGroup; + + if (calculationGroup != null) + { + UpdateDataGridViewDataSource(); + inputObserver.Observable = calculationGroup; + calculationObserver.Observable = calculationGroup; + calculationGroupObserver.Observable = calculationGroup; + } + else + { + dataGridViewControl.SetDataSource(null); + inputObserver.Observable = null; + calculationObserver.Observable = null; + calculationGroupObserver.Observable = null; + } + } + } + + public object Selection + { + get + { + return CreateSelectedItemFromCurrentRow(); + } + } + + protected override void OnLoad(EventArgs e) + { + // Necessary to correctly load the content of the dropdown lists of the comboboxes... + UpdateDataGridViewDataSource(); + base.OnLoad(e); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + dataGridViewControl.RemoveCellFormattingHandler(OnCellFormatting); + + assessmentSectionObserver.Dispose(); + failureMechanismObserver.Dispose(); + inputObserver.Dispose(); + calculationObserver.Dispose(); + surfaceLineObserver.Dispose(); + calculationGroupObserver.Dispose(); + stochasticSoilProfileObserver.Dispose(); + stochasticSoilModelsObserver.Dispose(); + + components?.Dispose(); + } + + base.Dispose(disposing); + } + + private void InitializeDataGridView() + { + dataGridViewControl.AddCurrentCellChangedHandler(DataGridViewOnCurrentCellChanged); + dataGridViewControl.AddCellFormattingHandler(OnCellFormatting); + + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsCalculationRow.Name), + Resources.PipingCalculation_Name_DisplayName); + + dataGridViewControl.AddComboBoxColumn>( + nameof(MacroStabilityInwardsCalculationRow.StochasticSoilModel), + Resources.PipingInput_StochasticSoilModel_DisplayName, + null, + nameof(DataGridViewComboBoxItemWrapper.This), + nameof(DataGridViewComboBoxItemWrapper.DisplayName)); + + dataGridViewControl.AddComboBoxColumn>( + nameof(MacroStabilityInwardsCalculationRow.StochasticSoilProfile), + Resources.PipingInput_StochasticSoilProfile_DisplayName, + null, + nameof(DataGridViewComboBoxItemWrapper.This), + nameof(DataGridViewComboBoxItemWrapper.DisplayName)); + + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsCalculationRow.StochasticSoilProfileProbability), + Resources.PipingCalculationsView_InitializeDataGridView_Stochastic_soil_profile_probability); + + dataGridViewControl.AddComboBoxColumn>( + nameof(MacroStabilityInwardsCalculationRow.SelectableHydraulicBoundaryLocation), + Resources.PipingInput_HydraulicBoundaryLocation_DisplayName, + null, + nameof(DataGridViewComboBoxItemWrapper.This), + nameof(DataGridViewComboBoxItemWrapper.DisplayName)); + + string dampingFactorExitHeader = Resources.PipingInput_DampingFactorExit_DisplayName; + dampingFactorExitHeader = char.ToLowerInvariant(dampingFactorExitHeader[0]) + dampingFactorExitHeader.Substring(1); + + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsCalculationRow.DampingFactorExitMean), + $"{Resources.Probabilistics_Mean_Symbol} {dampingFactorExitHeader}"); + + string phreaticLevelExitHeader = Resources.PipingInput_PhreaticLevelExit_DisplayName; + phreaticLevelExitHeader = char.ToLowerInvariant(phreaticLevelExitHeader[0]) + phreaticLevelExitHeader.Substring(1); + + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsCalculationRow.PhreaticLevelExitMean), + $"{Resources.Probabilistics_Mean_Symbol} {phreaticLevelExitHeader}"); + + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsCalculationRow.EntryPointL), + Resources.PipingInput_EntryPointL_DisplayName); + + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsCalculationRow.ExitPointL), + Resources.PipingInput_ExitPointL_DisplayName); + + UpdateStochasticSoilModelColumn(); + UpdateStochasticSoilProfileColumn(); + UpdateSelectableHydraulicBoundaryLocationsColumn(); + } + + private void InitializeListBox() + { + listBox.DisplayMember = nameof(FailureMechanismSection.Name); + listBox.SelectedValueChanged += ListBoxOnSelectedValueChanged; + } + + private void UpdateGenerateScenariosButtonState() + { + buttonGenerateScenarios.Enabled = macroStabilityInwardsFailureMechanism != null && + macroStabilityInwardsFailureMechanism.SurfaceLines.Any() && + macroStabilityInwardsFailureMechanism.StochasticSoilModels.Any(); + } + + private static void SetItemsOnObjectCollection(DataGridViewComboBoxCell.ObjectCollection objectCollection, object[] comboBoxItems) + { + objectCollection.Clear(); + objectCollection.AddRange(comboBoxItems); + } + + private MacroStabilityInwardsInputContext CreateSelectedItemFromCurrentRow() + { + DataGridViewRow currentRow = dataGridViewControl.CurrentRow; + + var calculationRow = (MacroStabilityInwardsCalculationRow) currentRow?.DataBoundItem; + + MacroStabilityInwardsInputContext selection = null; + if (calculationRow != null) + { + selection = new MacroStabilityInwardsInputContext( + calculationRow.MacroStabilityInwardsCalculation.InputParameters, + calculationRow.MacroStabilityInwardsCalculation, + macroStabilityInwardsFailureMechanism.SurfaceLines, + macroStabilityInwardsFailureMechanism.StochasticSoilModels, + macroStabilityInwardsFailureMechanism, + assessmentSection); + } + return selection; + } + + private static IEnumerable GetSelectableHydraulicBoundaryLocations( + IEnumerable hydraulicBoundaryLocations, RingtoetsPipingSurfaceLine surfaceLine) + { + Point2D referencePoint = surfaceLine?.ReferenceLineIntersectionWorldPoint; + return SelectableHydraulicBoundaryLocationHelper.GetSortedSelectableHydraulicBoundaryLocations( + hydraulicBoundaryLocations, referencePoint); + } + + #region Data sources + + private void UpdateDataGridViewDataSource() + { + // Skip changes coming from the view itself + if (dataGridViewControl.IsCurrentCellInEditMode) + { + updatingDataSource = true; + + UpdateStochasticSoilProfileColumn(); + updatingDataSource = false; + + dataGridViewControl.AutoResizeColumns(); + + return; + } + + var failureMechanismSection = listBox.SelectedItem as FailureMechanismSection; + if (failureMechanismSection == null || calculationGroup == null) + { + dataGridViewControl.SetDataSource(null); + return; + } + + IEnumerable lineSegments = Math2D.ConvertLinePointsToLineSegments(failureMechanismSection.Points); + IEnumerable calculations = calculationGroup + .GetCalculations() + .OfType() + .Where(pc => pc.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments)); + + updatingDataSource = true; + + PrefillComboBoxListItemsAtColumnLevel(); + + List dataSource = calculations.Select(pc => new MacroStabilityInwardsCalculationRow(pc, new ObservablePropertyChangeHandler(pc, pc.InputParameters))).ToList(); + dataGridViewControl.SetDataSource(dataSource); + dataGridViewControl.ClearCurrentCell(); + + UpdateStochasticSoilModelColumn(); + UpdateStochasticSoilProfileColumn(); + UpdateSelectableHydraulicBoundaryLocationsColumn(); + + updatingDataSource = false; + } + + private static IEnumerable> GetPrefillStochasticSoilModelsDataSource(IEnumerable stochasticSoilModels) + { + yield return new DataGridViewComboBoxItemWrapper(null); + + foreach (StochasticSoilModel stochasticSoilModel in stochasticSoilModels) + { + yield return new DataGridViewComboBoxItemWrapper(stochasticSoilModel); + } + } + + private static IEnumerable> GetStochasticSoilModelsDataSource(IEnumerable stochasticSoilModels) + { + StochasticSoilModel[] stochasticSoilModelsArray = stochasticSoilModels.ToArray(); + if (stochasticSoilModelsArray.Length != 1) + { + yield return new DataGridViewComboBoxItemWrapper(null); + } + foreach (StochasticSoilModel stochasticSoilModel in stochasticSoilModelsArray) + { + yield return new DataGridViewComboBoxItemWrapper(stochasticSoilModel); + } + } + + private static IEnumerable> GetPrefillSoilProfilesDataSource(IEnumerable stochasticSoilProfiles) + { + yield return new DataGridViewComboBoxItemWrapper(null); + + foreach (StochasticSoilProfile stochasticSoilProfile in stochasticSoilProfiles) + { + yield return new DataGridViewComboBoxItemWrapper(stochasticSoilProfile); + } + } + + private static IEnumerable> GetSoilProfilesDataSource(IEnumerable stochasticSoilProfiles) + { + StochasticSoilProfile[] stochasticSoilProfilesArray = stochasticSoilProfiles.ToArray(); + if (stochasticSoilProfilesArray.Length != 1) + { + yield return new DataGridViewComboBoxItemWrapper(null); + } + foreach (StochasticSoilProfile stochasticSoilProfile in stochasticSoilProfilesArray) + { + yield return new DataGridViewComboBoxItemWrapper(stochasticSoilProfile); + } + } + + private static List> GetSelectableHydraulicBoundaryLocationsDataSource(IEnumerable selectableHydraulicBoundaryLocations = null) + { + var dataGridViewComboBoxItemWrappers = new List> + { + new DataGridViewComboBoxItemWrapper(null) + }; + + if (selectableHydraulicBoundaryLocations != null) + { + dataGridViewComboBoxItemWrappers.AddRange(selectableHydraulicBoundaryLocations.Select(hbl => new DataGridViewComboBoxItemWrapper(hbl))); + } + + return dataGridViewComboBoxItemWrappers; + } + + #endregion + + #region Update combo box list items + + #region Update Selectable Hydraulic Boundary Locations Column + + private void UpdateSelectableHydraulicBoundaryLocationsColumn() + { + var column = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableHydraulicBoundaryLocationColumnIndex); + + using (new SuspendDataGridViewColumnResizes(column)) + { + foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) + { + FillAvailableSelectableHydraulicBoundaryLocationsList(dataGridViewRow); + } + } + } + + private void FillAvailableSelectableHydraulicBoundaryLocationsList(DataGridViewRow dataGridViewRow) + { + var rowData = (MacroStabilityInwardsCalculationRow) dataGridViewRow.DataBoundItem; + IEnumerable locations = GetSelectableHydraulicBoundaryLocationsForCalculation(rowData.MacroStabilityInwardsCalculation); + + var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[selectableHydraulicBoundaryLocationColumnIndex]; + DataGridViewComboBoxItemWrapper[] dataGridViewComboBoxItemWrappers = GetSelectableHydraulicBoundaryLocationsDataSource(locations).ToArray(); + SetItemsOnObjectCollection(cell.Items, dataGridViewComboBoxItemWrappers); + } + + private IEnumerable GetSelectableHydraulicBoundaryLocationsForCalculation(MacroStabilityInwardsCalculation macroStabilityInwardsCalculation) + { + if (assessmentSection?.HydraulicBoundaryDatabase == null || macroStabilityInwardsCalculation.InputParameters.UseAssessmentLevelManualInput) + { + return Enumerable.Empty(); + } + + return GetSelectableHydraulicBoundaryLocations(assessmentSection.HydraulicBoundaryDatabase.Locations, + macroStabilityInwardsCalculation.InputParameters.SurfaceLine); + } + + #endregion + + #region Update Stochastic Soil Model Column + + private void UpdateStochasticSoilModelColumn() + { + using (new SuspendDataGridViewColumnResizes(dataGridViewControl.GetColumnFromIndex(stochasticSoilModelColumnIndex))) + { + foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) + { + FillAvailableSoilModelsList(dataGridViewRow); + } + } + } + + private void FillAvailableSoilModelsList(DataGridViewRow dataGridViewRow) + { + var rowData = (MacroStabilityInwardsCalculationRow) dataGridViewRow.DataBoundItem; + IEnumerable stochasticSoilModels = GetSoilModelsForCalculation(rowData.MacroStabilityInwardsCalculation); + + var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[stochasticSoilModelColumnIndex]; + SetItemsOnObjectCollection(cell.Items, GetStochasticSoilModelsDataSource(stochasticSoilModels).ToArray()); + } + + private IEnumerable GetSoilModelsForCalculation(MacroStabilityInwardsCalculation macroStabilityInwardsCalculation) + { + if (macroStabilityInwardsFailureMechanism == null) + { + return Enumerable.Empty(); + } + return PipingCalculationConfigurationHelper.GetStochasticSoilModelsForSurfaceLine( + macroStabilityInwardsCalculation.InputParameters.SurfaceLine, + macroStabilityInwardsFailureMechanism.StochasticSoilModels); + } + + #endregion + + #region Update Stochastic Soil Profile Column + + private void UpdateStochasticSoilProfileColumn() + { + using (new SuspendDataGridViewColumnResizes(dataGridViewControl.GetColumnFromIndex(stochasticSoilProfileColumnIndex))) + { + foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) + { + FillAvailableSoilProfilesList(dataGridViewRow); + } + } + } + + private void FillAvailableSoilProfilesList(DataGridViewRow dataGridViewRow) + { + var rowData = (MacroStabilityInwardsCalculationRow) dataGridViewRow.DataBoundItem; + PipingInputService.SyncStochasticSoilProfileWithStochasticSoilModel(rowData.MacroStabilityInwardsCalculation.InputParameters); + + IEnumerable stochasticSoilProfiles = GetSoilProfilesForCalculation(rowData.MacroStabilityInwardsCalculation); + + var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[stochasticSoilProfileColumnIndex]; + SetItemsOnObjectCollection(cell.Items, GetSoilProfilesDataSource(stochasticSoilProfiles).ToArray()); + } + + private IEnumerable GetSoilProfilesForCalculation(MacroStabilityInwardsCalculation macroStabilityInwardsCalculation) + { + if (macroStabilityInwardsCalculation.InputParameters.StochasticSoilModel == null) + { + return Enumerable.Empty(); + } + return macroStabilityInwardsCalculation.InputParameters.StochasticSoilModel.StochasticSoilProfiles; + } + + #endregion + + #endregion + + #region Prefill combo box list items + + private void PrefillComboBoxListItemsAtColumnLevel() + { + var stochasticSoilModelColumn = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(stochasticSoilModelColumnIndex); + var stochasticSoilProfileColumn = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(stochasticSoilProfileColumnIndex); + var selectableHydraulicBoundaryLocationColumn = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableHydraulicBoundaryLocationColumnIndex); + + // Need to prefill for all possible data in order to guarantee 'combo box' columns + // do not generate errors when their cell value is not present in the list of available + // items. + using (new SuspendDataGridViewColumnResizes(stochasticSoilModelColumn)) + { + StochasticSoilModelCollection stochasticSoilModels = macroStabilityInwardsFailureMechanism.StochasticSoilModels; + SetItemsOnObjectCollection(stochasticSoilModelColumn.Items, GetPrefillStochasticSoilModelsDataSource(stochasticSoilModels).ToArray()); + } + using (new SuspendDataGridViewColumnResizes(stochasticSoilProfileColumn)) + { + StochasticSoilProfile[] soilProfiles = GetStochasticSoilProfilesFromStochasticSoilModels(); + SetItemsOnObjectCollection(stochasticSoilProfileColumn.Items, GetPrefillSoilProfilesDataSource(soilProfiles).ToArray()); + } + using (new SuspendDataGridViewColumnResizes(selectableHydraulicBoundaryLocationColumn)) + { + SetItemsOnObjectCollection(selectableHydraulicBoundaryLocationColumn.Items, + GetSelectableHydraulicBoundaryLocationsDataSource(GetSelectableHydraulicBoundaryLocationsFromFailureMechanism()).ToArray()); + } + } + + private IEnumerable GetSelectableHydraulicBoundaryLocationsFromFailureMechanism() + { + if (assessmentSection?.HydraulicBoundaryDatabase == null) + { + return null; + } + + List hydraulicBoundaryLocations = assessmentSection.HydraulicBoundaryDatabase.Locations; + + List selectableHydraulicBoundaryLocations = hydraulicBoundaryLocations.Select(hbl => new SelectableHydraulicBoundaryLocation(hbl, null)).ToList(); + if (MacroStabilityInwardsFailureMechanism == null || !MacroStabilityInwardsFailureMechanism.SurfaceLines.Any()) + { + return selectableHydraulicBoundaryLocations; + } + + foreach (RingtoetsPipingSurfaceLine surfaceLine in MacroStabilityInwardsFailureMechanism.SurfaceLines) + { + selectableHydraulicBoundaryLocations.AddRange(GetSelectableHydraulicBoundaryLocations(hydraulicBoundaryLocations, surfaceLine)); + } + return selectableHydraulicBoundaryLocations; + } + + private StochasticSoilProfile[] GetStochasticSoilProfilesFromStochasticSoilModels() + { + return macroStabilityInwardsFailureMechanism?.StochasticSoilModels + .SelectMany(ssm => ssm.StochasticSoilProfiles) + .Distinct() + .ToArray(); + } + + #endregion + + #region Event handling + + private void DataGridViewOnCurrentCellChanged(object sender, EventArgs e) + { + if (!updatingDataSource) + { + OnSelectionChanged(); + } + } + + private void ListBoxOnSelectedValueChanged(object sender, EventArgs e) + { + UpdateDataGridViewDataSource(); + OnSelectionChanged(); + } + + private void OnGenerateScenariosButtonClick(object sender, EventArgs e) + { + if (calculationGroup == null) + { + return; + } + var dialog = new PipingSurfaceLineSelectionDialog(Parent, macroStabilityInwardsFailureMechanism.SurfaceLines); + dialog.ShowDialog(); + IEnumerable calculationsStructure = PipingCalculationConfigurationHelper.GenerateCalculationItemsStructure( + dialog.SelectedItems, + macroStabilityInwardsFailureMechanism.StochasticSoilModels, + macroStabilityInwardsFailureMechanism.GeneralInput); + foreach (ICalculationBase item in calculationsStructure) + { + calculationGroup.Children.Add(item); + } + + calculationGroup.NotifyObservers(); + } + + private void OnFailureMechanismUpdate() + { + UpdateGenerateScenariosButtonState(); + UpdateSectionsListBox(); + } + + private void OnStochasticSoilModelsUpdate() + { + UpdateGenerateScenariosButtonState(); + UpdateStochasticSoilModelColumn(); + UpdateStochasticSoilProfileColumn(); + } + + private void UpdateSectionsListBox() + { + listBox.Items.Clear(); + + if (macroStabilityInwardsFailureMechanism != null && macroStabilityInwardsFailureMechanism.Sections.Any()) + { + listBox.Items.AddRange(macroStabilityInwardsFailureMechanism.Sections.Cast().ToArray()); + listBox.SelectedItem = macroStabilityInwardsFailureMechanism.Sections.First(); + } + } + + private void OnSelectionChanged() + { + SelectionChanged?.Invoke(this, new EventArgs()); + } + + private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) + { + if (eventArgs.ColumnIndex == selectableHydraulicBoundaryLocationColumnIndex) + { + DataGridViewRow dataGridViewRow = dataGridViewControl.GetRowFromIndex(eventArgs.RowIndex); + var dataItem = dataGridViewRow.DataBoundItem as MacroStabilityInwardsCalculationRow; + + if (dataItem != null && dataItem.MacroStabilityInwardsCalculation.InputParameters.UseAssessmentLevelManualInput) + { + dataGridViewRow.ReadOnly = true; + } + else if (dataGridViewRow.ReadOnly) + { + dataGridViewRow.ReadOnly = false; + } + } + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.resx =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.resx (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.resx (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,444 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 1 + + + + Fill + + + + 3, 3 + + + 1 + + + Top, Bottom, Left, Right + + + False + + + 3, 20 + + + 3, 0, 3, 0 + + + 153, 195 + + + 1 + + + listBox + + + System.Windows.Forms.ListBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelListBox + + + 0 + + + True + + + 3, 0 + + + 26, 13 + + + 0 + + + Vak + + + labelFailureMechanismSections + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelListBox + + + 1 + + + Fill + + + 0, 0 + + + 2 + + + 159, 215 + + + 0 + + + tableLayoutPanelListBox + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer.Panel1 + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="listBox" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelFailureMechanismSections" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="Absolute,20,Percent,100" /></TableLayoutSettings> + + + splitContainer.Panel1 + + + System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer + + + 0 + + + 100 + + + 1 + + + True + + + 3, 0 + + + 182, 13 + + + 0 + + + Berekeningen voor geselecteerd vak + + + labelCalculations + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelDataGrid + + + 0 + + + Top, Bottom, Left, Right + + + 3, 23 + + + 325, 189 + + + 1 + + + dataGridViewControl + + + Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=16.1.1.4340, Culture=neutral, PublicKeyToken=null + + + tableLayoutPanelDataGrid + + + 1 + + + Fill + + + 0, 0 + + + 2 + + + 331, 215 + + + 1 + + + tableLayoutPanelDataGrid + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer.Panel2 + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="labelCalculations" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="dataGridViewControl" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="Absolute,20,Percent,100" /></TableLayoutSettings> + + + splitContainer.Panel2 + + + System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer + + + 1 + + + 0 + + + 494, 215 + + + 159 + + + 0 + + + splitContainer + + + System.Windows.Forms.SplitContainer, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelUserControl + + + 0 + + + True + + + Left + + + False + + + NoControl + + + 3, 224 + + + 137, 23 + + + 0 + + + Genereer &scenario's... + + + buttonGenerateScenarios + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelUserControl + + + 1 + + + Fill + + + 0, 0 + + + 2 + + + 500, 250 + + + 0 + + + tableLayoutPanelUserControl + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="splitContainer" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="buttonGenerateScenarios" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="Percent,100,AutoSize,0,Absolute,20" /></TableLayoutSettings> + + + True + + + 6, 13 + + + True + + + 500, 250 + + + 500, 250 + + + MacroStabilityInwardsCalculationsView + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismResultView.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismResultView.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismResultView.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,183 @@ +// Copyright (C) Stichting Deltares 2017. 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.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Forms.Views; +using Ringtoets.MacroStabilityInwards.Data; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + /// + /// The view for the . + /// + public class MacroStabilityInwardsFailureMechanismResultView : FailureMechanismResultView + { + private const int assessmentLayerTwoAIndex = 2; + private const double tolerance = 1e-6; + private readonly RecursiveObserver calculationInputObserver; + private readonly RecursiveObserver calculationOutputObserver; + private readonly RecursiveObserver calculationGroupObserver; + + /// + /// Creates a new instance of . + /// + public MacroStabilityInwardsFailureMechanismResultView() + { + DataGridViewControl.AddCellFormattingHandler(ShowAssessmentLayerTwoAErrors); + DataGridViewControl.AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); + + // The concat is needed to observe the input of calculations in child groups. + calculationInputObserver = new RecursiveObserver( + UpdateDataGridViewDataSource, + cg => cg.Children.Concat(cg.Children + .OfType() + .Select(c => c.InputParameters))); + calculationOutputObserver = new RecursiveObserver( + UpdateDataGridViewDataSource, + cg => cg.Children.Concat(cg.Children + .OfType() + .Select(c => c.Output))); + calculationGroupObserver = new RecursiveObserver( + UpdateDataGridViewDataSource, + c => c.Children); + } + + public override IFailureMechanism FailureMechanism + { + set + { + base.FailureMechanism = value; + + var calculatableFailureMechanism = value as ICalculatableFailureMechanism; + CalculationGroup observableGroup = calculatableFailureMechanism?.CalculationsGroup; + + calculationInputObserver.Observable = observableGroup; + calculationOutputObserver.Observable = observableGroup; + calculationGroupObserver.Observable = observableGroup; + } + } + + protected override void Dispose(bool disposing) + { + DataGridViewControl.RemoveCellFormattingHandler(ShowAssessmentLayerTwoAErrors); + DataGridViewControl.RemoveCellFormattingHandler(DisableIrrelevantFieldsFormatting); + + calculationInputObserver.Dispose(); + calculationOutputObserver.Dispose(); + calculationGroupObserver.Dispose(); + + base.Dispose(disposing); + } + + protected override object CreateFailureMechanismSectionResultRow(MacroStabilityInwardsFailureMechanismSectionResult sectionResult) + { + if (FailureMechanism == null) + { + return null; + } + return new MacroStabilityInwardsFailureMechanismSectionResultRow(sectionResult, FailureMechanism.Calculations.OfType()); + } + + protected override void AddDataGridColumns() + { + base.AddDataGridColumns(); + + DataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.AssessmentLayerTwoA), + RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, + true); + DataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsFailureMechanismSectionResultRow.AssessmentLayerThree), + RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); + } + + #region Event handling + + private void DisableIrrelevantFieldsFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) + { + if (eventArgs.ColumnIndex > AssessmentLayerOneColumnIndex) + { + if (HasPassedLevelOne(eventArgs.RowIndex)) + { + DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + } + else + { + DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + } + } + } + + private void ShowAssessmentLayerTwoAErrors(object sender, DataGridViewCellFormattingEventArgs e) + { + if (e.ColumnIndex != assessmentLayerTwoAIndex) + { + return; + } + + DataGridViewCell currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); + + var resultRow = (MacroStabilityInwardsFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex); + MacroStabilityInwardsFailureMechanismSectionResult rowObject = resultRow.GetSectionResult; + if (rowObject.AssessmentLayerOne == AssessmentLayerOneState.Sufficient) + { + currentDataGridViewCell.ErrorText = string.Empty; + return; + } + + MacroStabilityInwardsCalculationScenario[] relevantScenarios = rowObject.GetCalculationScenarios(FailureMechanism.Calculations.OfType()).ToArray(); + bool relevantScenarioAvailable = relevantScenarios.Length != 0; + + if (!relevantScenarioAvailable) + { + currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_any_calculation_set; + return; + } + + if (Math.Abs(rowObject.GetTotalContribution(relevantScenarios) - 1.0) > tolerance) + { + currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Scenario_contribution_for_this_section_not_100; + return; + } + + CalculationScenarioStatus calculationScenarioStatus = rowObject.GetCalculationScenarioStatus(relevantScenarios); + if (calculationScenarioStatus == CalculationScenarioStatus.NotCalculated) + { + currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_been_executed; + return; + } + if (calculationScenarioStatus == CalculationScenarioStatus.Failed) + { + currentDataGridViewCell.ErrorText = RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_All_calculations_must_have_valid_output; + return; + } + currentDataGridViewCell.ErrorText = string.Empty; + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.Designer.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.Designer.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.Designer.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,89 @@ +// Copyright (C) Stichting Deltares 2017. 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 RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + partial class MacroStabilityInwardsInputView + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.chartControl = new Core.Components.OxyPlot.Forms.ChartControl(); + this.soilLayerTable = new MacroStabilityInwardsSoilLayerTable(); + this.SuspendLayout(); + // + // chartControl + // + this.chartControl.BottomAxisTitle = RingtoetsCommonFormsResources.InputView_Distance_DisplayName; + this.chartControl.ChartTitle = null; + this.chartControl.Data = null; + this.chartControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.chartControl.LeftAxisTitle = RingtoetsCommonFormsResources.InputView_Height_DisplayName; + this.chartControl.Location = new System.Drawing.Point(0, 0); + this.chartControl.MinimumSize = new System.Drawing.Size(100, 100); + this.chartControl.Name = "chartControl"; + this.chartControl.Size = new System.Drawing.Size(333, 202); + this.chartControl.TabIndex = 0; + this.chartControl.Text = "chartControl"; + // + // soilLayerTable + // + this.soilLayerTable.Dock = System.Windows.Forms.DockStyle.Bottom; + this.soilLayerTable.Location = new System.Drawing.Point(0, 202); + this.soilLayerTable.MinimumSize = new System.Drawing.Size(300, 150); + this.soilLayerTable.MultiSelect = true; + this.soilLayerTable.Name = "soilLayerTable"; + this.soilLayerTable.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect; + this.soilLayerTable.Size = new System.Drawing.Size(333, 156); + this.soilLayerTable.TabIndex = 1; + // + // MacroStabilityInwardsInputView + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.Controls.Add(this.chartControl); + this.Controls.Add(this.soilLayerTable); + this.MinimumSize = new System.Drawing.Size(200, 300); + this.Name = "MacroStabilityInwardsInputView"; + this.Size = new System.Drawing.Size(333, 358); + this.ResumeLayout(false); + + } + + #endregion + + private Core.Components.OxyPlot.Forms.ChartControl chartControl; + private MacroStabilityInwardsSoilLayerTable soilLayerTable; + } +} Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,237 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Components.Charting.Data; +using Core.Components.Charting.Forms; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.Factories; +using Ringtoets.MacroStabilityInwards.Primitives; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + /// + /// This class is a view to show the macro stability inwards input. + /// + public partial class MacroStabilityInwardsInputView : UserControl, IChartView + { + private readonly Observer calculationObserver; + private readonly Observer calculationInputObserver; + + private readonly ChartDataCollection soilProfileChartData; + private readonly ChartLineData surfaceLineChartData; + private readonly ChartPointData ditchPolderSideChartData; + private readonly ChartPointData bottomDitchPolderSideChartData; + private readonly ChartPointData bottomDitchDikeSideChartData; + private readonly ChartPointData ditchDikeSideChartData; + private readonly ChartPointData dikeToeAtPolderChartData; + private readonly ChartPointData dikeToeAtRiverChartData; + private readonly ChartPointData exitPointChartData; + private readonly ChartPointData entryPointChartData; + private readonly ChartDataCollection chartDataCollection; + + private readonly List soilLayerChartDataLookup; + + private MacroStabilityInwardsCalculationScenario data; + + private PipingSoilProfile currentSoilProfile; + + /// + /// Creates a new instance of . + /// + public MacroStabilityInwardsInputView() + { + InitializeComponent(); + + calculationObserver = new Observer(UpdateChartTitle); + calculationInputObserver = new Observer(UpdateViewData); + + chartDataCollection = new ChartDataCollection(RingtoetsCommonFormsResources.Calculation_Input); + soilProfileChartData = PipingChartDataFactory.CreateSoilProfileChartData(); + surfaceLineChartData = PipingChartDataFactory.CreateSurfaceLineChartData(); + ditchPolderSideChartData = PipingChartDataFactory.CreateDitchPolderSideChartData(); + bottomDitchPolderSideChartData = PipingChartDataFactory.CreateBottomDitchPolderSideChartData(); + bottomDitchDikeSideChartData = PipingChartDataFactory.CreateBottomDitchDikeSideChartData(); + ditchDikeSideChartData = PipingChartDataFactory.CreateDitchDikeSideChartData(); + dikeToeAtPolderChartData = PipingChartDataFactory.CreateDikeToeAtPolderChartData(); + dikeToeAtRiverChartData = PipingChartDataFactory.CreateDikeToeAtRiverChartData(); + exitPointChartData = PipingChartDataFactory.CreateExitPointChartData(); + entryPointChartData = PipingChartDataFactory.CreateEntryPointChartData(); + + chartDataCollection.Add(soilProfileChartData); + chartDataCollection.Add(surfaceLineChartData); + chartDataCollection.Add(ditchPolderSideChartData); + chartDataCollection.Add(bottomDitchPolderSideChartData); + chartDataCollection.Add(bottomDitchDikeSideChartData); + chartDataCollection.Add(ditchDikeSideChartData); + chartDataCollection.Add(dikeToeAtPolderChartData); + chartDataCollection.Add(dikeToeAtRiverChartData); + chartDataCollection.Add(exitPointChartData); + chartDataCollection.Add(entryPointChartData); + + soilLayerChartDataLookup = new List(); // Use lookup because the ordering in the chart data collection might change + } + + public object Data + { + get + { + return data; + } + set + { + data = value as MacroStabilityInwardsCalculationScenario; + + calculationObserver.Observable = data; + calculationInputObserver.Observable = data?.InputParameters; + + if (data == null) + { + chartControl.Data = null; + chartControl.ChartTitle = string.Empty; + } + else + { + SetChartData(); + + chartControl.Data = chartDataCollection; + UpdateChartTitle(); + } + UpdateTableData(); + } + } + + public IChartControl Chart + { + get + { + return chartControl; + } + } + + protected override void Dispose(bool disposing) + { + calculationObserver.Dispose(); + calculationInputObserver.Dispose(); + + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + private void UpdateChartTitle() + { + chartControl.ChartTitle = data.Name; + } + + private void UpdateViewData() + { + UpdateChartData(); + UpdateTableData(); + } + + private void UpdateChartData() + { + SetChartData(); + + surfaceLineChartData.NotifyObservers(); + ditchPolderSideChartData.NotifyObservers(); + bottomDitchPolderSideChartData.NotifyObservers(); + bottomDitchDikeSideChartData.NotifyObservers(); + ditchDikeSideChartData.NotifyObservers(); + dikeToeAtPolderChartData.NotifyObservers(); + dikeToeAtRiverChartData.NotifyObservers(); + exitPointChartData.NotifyObservers(); + entryPointChartData.NotifyObservers(); + soilProfileChartData.NotifyObservers(); + soilProfileChartData.Collection.ForEachElementDo(md => md.NotifyObservers()); + } + + private void UpdateTableData() + { + soilLayerTable.SetData(data?.InputParameters.StochasticSoilProfile?.SoilProfile?.Layers); + } + + private void SetChartData() + { + MacroStabilityInwardsInput macroStabilityInwardsInput = data.InputParameters; + RingtoetsPipingSurfaceLine surfaceLine = data.InputParameters.SurfaceLine; + + PipingChartDataFactory.UpdateSurfaceLineChartDataName(surfaceLineChartData, surfaceLine); + + surfaceLineChartData.Points = PipingChartDataPointsFactory.CreateSurfaceLinePoints(surfaceLine); + ditchPolderSideChartData.Points = PipingChartDataPointsFactory.CreateDitchPolderSidePoint(surfaceLine); + bottomDitchPolderSideChartData.Points = PipingChartDataPointsFactory.CreateBottomDitchPolderSidePoint(surfaceLine); + bottomDitchDikeSideChartData.Points = PipingChartDataPointsFactory.CreateBottomDitchDikeSidePoint(surfaceLine); + ditchDikeSideChartData.Points = PipingChartDataPointsFactory.CreateDitchDikeSidePoint(surfaceLine); + dikeToeAtPolderChartData.Points = PipingChartDataPointsFactory.CreateDikeToeAtPolderPoint(surfaceLine); + dikeToeAtRiverChartData.Points = PipingChartDataPointsFactory.CreateDikeToeAtRiverPoint(surfaceLine); + exitPointChartData.Points = PipingChartDataPointsFactory.CreateExitPointPoint(macroStabilityInwardsInput); + entryPointChartData.Points = PipingChartDataPointsFactory.CreateEntryPointPoint(macroStabilityInwardsInput); + + SetSoilProfileChartData(); + } + + private void SetSoilProfileChartData() + { + PipingSoilProfile soilProfile = data.InputParameters.StochasticSoilProfile?.SoilProfile; + + // If necessary, regenerate all soil layer chart data + if (!ReferenceEquals(currentSoilProfile, soilProfile)) + { + currentSoilProfile = soilProfile; + + soilProfileChartData.Clear(); + soilLayerChartDataLookup.Clear(); + GetSoilLayers().Select((layer, layerIndex) => PipingChartDataFactory.CreateSoilLayerChartData(layerIndex, currentSoilProfile)) + .ForEachElementDo(sl => + { + soilProfileChartData.Insert(0, sl); + soilLayerChartDataLookup.Add(sl); + }); + + PipingChartDataFactory.UpdateSoilProfileChartDataName(soilProfileChartData, currentSoilProfile); + } + + // Update the areas of all soil layer chart data + IList soilLayers = GetSoilLayers(); + + for (var i = 0; i < soilLayers.Count; i++) + { + ChartMultipleAreaData soilLayerData = soilLayerChartDataLookup[i]; + + soilLayerData.Areas = PipingChartDataPointsFactory.CreateSoilLayerAreas(soilLayers[i], currentSoilProfile, data.InputParameters.SurfaceLine); + } + } + + private IList GetSoilLayers() + { + return data?.InputParameters.StochasticSoilProfile?.SoilProfile?.Layers.ToList() ?? new List(); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.resx =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.resx (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsInputView.resx (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenarioRow.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenarioRow.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenarioRow.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,164 @@ +// Copyright (C) Stichting Deltares 2017. 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.ComponentModel; +using Core.Common.Base.Data; +using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.Forms.TypeConverters; +using Ringtoets.MacroStabilityInwards.Data; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + /// + /// This class represents a row of in the . + /// + internal class MacroStabilityInwardsScenarioRow + { + /// + /// Creates a new instance of . + /// + /// The this row contains. + /// Thrown when is null. + public MacroStabilityInwardsScenarioRow(MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculation) + { + if (macroStabilityInwardsCalculation == null) + { + throw new ArgumentNullException(nameof(macroStabilityInwardsCalculation)); + } + + MacroStabilityInwardsCalculation = macroStabilityInwardsCalculation; + } + + /// + /// Gets the this row contains. + /// + public MacroStabilityInwardsCalculationScenario MacroStabilityInwardsCalculation { get; } + + /// + /// Gets or sets the is relevant. + /// + public bool IsRelevant + { + get + { + return MacroStabilityInwardsCalculation.IsRelevant; + } + set + { + MacroStabilityInwardsCalculation.IsRelevant = value; + MacroStabilityInwardsCalculation.NotifyObservers(); + } + } + + /// + /// Gets or sets the contribution of the . + /// + public RoundedDouble Contribution + { + get + { + return new RoundedDouble(0, MacroStabilityInwardsCalculation.Contribution * 100); + } + set + { + MacroStabilityInwardsCalculation.Contribution = (RoundedDouble) (value / 100); + MacroStabilityInwardsCalculation.NotifyObservers(); + } + } + + /// + /// Gets the name of the . + /// + public string Name + { + get + { + return MacroStabilityInwardsCalculation.Name; + } + } + + /// + /// Gets the failure probability of piping of the . + /// + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] + public string FailureProbabilityPiping + { + get + { + if (MacroStabilityInwardsCalculation.SemiProbabilisticOutput == null) + { + return RingtoetsCommonFormsResources.RoundedRouble_No_result_dash; + } + return ProbabilityFormattingHelper.Format(MacroStabilityInwardsCalculation.SemiProbabilisticOutput.PipingProbability); + } + } + + /// + /// Gets the failure probability of uplift sub failure mechanism of the . + /// + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] + public string FailureProbabilityUplift + { + get + { + if (MacroStabilityInwardsCalculation.SemiProbabilisticOutput == null) + { + return RingtoetsCommonFormsResources.RoundedRouble_No_result_dash; + } + return ProbabilityFormattingHelper.Format(MacroStabilityInwardsCalculation.SemiProbabilisticOutput.UpliftProbability); + } + } + + /// + /// Gets the failure probability of heave sub failure mechanism of the . + /// + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] + public string FailureProbabilityHeave + { + get + { + if (MacroStabilityInwardsCalculation.SemiProbabilisticOutput == null) + { + return RingtoetsCommonFormsResources.RoundedRouble_No_result_dash; + } + return ProbabilityFormattingHelper.Format(MacroStabilityInwardsCalculation.SemiProbabilisticOutput.HeaveProbability); + } + } + + /// + /// Gets the failure probability of sellmeijer sub failure mechanism of the . + /// + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] + public string FailureProbabilitySellmeijer + { + get + { + if (MacroStabilityInwardsCalculation.SemiProbabilisticOutput == null) + { + return RingtoetsCommonFormsResources.RoundedRouble_No_result_dash; + } + return ProbabilityFormattingHelper.Format(MacroStabilityInwardsCalculation.SemiProbabilisticOutput.SellmeijerProbability); + } + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,134 @@ +// Copyright (C) Stichting Deltares 2017. 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. + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + partial class MacroStabilityInwardsScenariosView + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MacroStabilityInwardsScenariosView)); + this.splitContainer = new System.Windows.Forms.SplitContainer(); + this.tableLayoutPanelListBox = new System.Windows.Forms.TableLayoutPanel(); + this.listBox = new System.Windows.Forms.ListBox(); + this.labelFailureMechanismSections = new System.Windows.Forms.Label(); + this.tableLayoutPanelDataGrid = new System.Windows.Forms.TableLayoutPanel(); + this.labelCalculations = new System.Windows.Forms.Label(); + this.dataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); + this.splitContainer.Panel1.SuspendLayout(); + this.splitContainer.Panel2.SuspendLayout(); + this.splitContainer.SuspendLayout(); + this.tableLayoutPanelListBox.SuspendLayout(); + this.tableLayoutPanelDataGrid.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer + // + resources.ApplyResources(this.splitContainer, "splitContainer"); + this.splitContainer.Name = "splitContainer"; + // + // splitContainer.Panel1 + // + this.splitContainer.Panel1.Controls.Add(this.tableLayoutPanelListBox); + // + // splitContainer.Panel2 + // + this.splitContainer.Panel2.Controls.Add(this.tableLayoutPanelDataGrid); + this.splitContainer.TabStop = false; + // + // tableLayoutPanelListBox + // + resources.ApplyResources(this.tableLayoutPanelListBox, "tableLayoutPanelListBox"); + this.tableLayoutPanelListBox.Controls.Add(this.listBox, 0, 1); + this.tableLayoutPanelListBox.Controls.Add(this.labelFailureMechanismSections, 0, 0); + this.tableLayoutPanelListBox.Name = "tableLayoutPanelListBox"; + // + // listBox + // + resources.ApplyResources(this.listBox, "listBox"); + this.listBox.FormattingEnabled = true; + this.listBox.Name = "listBox"; + // + // labelFailureMechanismSections + // + resources.ApplyResources(this.labelFailureMechanismSections, "labelFailureMechanismSections"); + this.labelFailureMechanismSections.Name = "labelFailureMechanismSections"; + // + // tableLayoutPanelDataGrid + // + resources.ApplyResources(this.tableLayoutPanelDataGrid, "tableLayoutPanelDataGrid"); + this.tableLayoutPanelDataGrid.Controls.Add(this.labelCalculations, 0, 0); + this.tableLayoutPanelDataGrid.Controls.Add(this.dataGridViewControl, 0, 1); + this.tableLayoutPanelDataGrid.Name = "tableLayoutPanelDataGrid"; + // + // labelCalculations + // + resources.ApplyResources(this.labelCalculations, "labelCalculations"); + this.labelCalculations.Name = "labelCalculations"; + // + // dataGridViewControl + // + resources.ApplyResources(this.dataGridViewControl, "dataGridViewControl"); + this.dataGridViewControl.MultiSelect = true; + this.dataGridViewControl.Name = "dataGridViewControl"; + this.dataGridViewControl.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect; + // + // MacroStabilityInwardsScenariosView + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.splitContainer); + this.Name = "MacroStabilityInwardsScenariosView"; + this.splitContainer.Panel1.ResumeLayout(false); + this.splitContainer.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); + this.splitContainer.ResumeLayout(false); + this.tableLayoutPanelListBox.ResumeLayout(false); + this.tableLayoutPanelListBox.PerformLayout(); + this.tableLayoutPanelDataGrid.ResumeLayout(false); + this.tableLayoutPanelDataGrid.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanelListBox; + private System.Windows.Forms.ListBox listBox; + private System.Windows.Forms.Label labelFailureMechanismSections; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanelDataGrid; + private System.Windows.Forms.Label labelCalculations; + private Core.Common.Controls.DataGrid.DataGridViewControl dataGridViewControl; + } +} Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,207 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Common.Base.Geometry; +using Core.Common.Controls.Views; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.Properties; + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + /// + /// This class is a view for configuring macro stability inwards calculations. + /// + public partial class MacroStabilityInwardsScenariosView : UserControl, IView + { + private readonly RecursiveObserver inputObserver; + private readonly RecursiveObserver calculationGroupObserver; + private readonly RecursiveObserver calculationObserver; + private readonly Observer failureMechanismObserver; + private CalculationGroup calculationGroup; + private MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism; + + /// + /// Creates a new instance of the class. + /// + public MacroStabilityInwardsScenariosView() + { + InitializeComponent(); + InitializeDataGridView(); + InitializeListBox(); + + failureMechanismObserver = new Observer(OnFailureMechanismUpdate); + + // The concat is needed to observe the input of calculations in child groups. + inputObserver = new RecursiveObserver(UpdateDataGridViewDataSource, pcg => pcg.Children.Concat(pcg.Children.OfType().Select(pc => pc.InputParameters))); + calculationGroupObserver = new RecursiveObserver(UpdateDataGridViewDataSource, pcg => pcg.Children); + calculationObserver = new RecursiveObserver(dataGridViewControl.RefreshDataGridView, pcg => pcg.Children); + } + + /// + /// Gets or sets the macro stability inwards failure mechanism. + /// + public MacroStabilityInwardsFailureMechanism MacroStabilityInwardsFailureMechanism + { + get + { + return macroStabilityInwardsFailureMechanism; + } + set + { + macroStabilityInwardsFailureMechanism = value; + failureMechanismObserver.Observable = macroStabilityInwardsFailureMechanism; + + UpdateSectionsListBox(); + } + } + + public object Data + { + get + { + return calculationGroup; + } + set + { + calculationGroup = value as CalculationGroup; + + if (calculationGroup != null) + { + UpdateDataGridViewDataSource(); + inputObserver.Observable = calculationGroup; + calculationObserver.Observable = calculationGroup; + calculationGroupObserver.Observable = calculationGroup; + } + else + { + dataGridViewControl.SetDataSource(null); + inputObserver.Observable = null; + calculationObserver.Observable = null; + calculationGroupObserver.Observable = null; + } + } + } + + protected override void Dispose(bool disposing) + { + failureMechanismObserver.Dispose(); + inputObserver.Dispose(); + calculationObserver.Dispose(); + calculationGroupObserver.Dispose(); + + if (disposing) + { + components?.Dispose(); + } + + base.Dispose(disposing); + } + + private void InitializeDataGridView() + { + dataGridViewControl.AddCheckBoxColumn( + nameof(MacroStabilityInwardsScenarioRow.IsRelevant), + Resources.PipingCalculationsView_InitializeDataGridView_In_final_rating + ); + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsScenarioRow.Contribution), + Resources.PipingCalculationsView_InitializeDataGridView_Contribution + ); + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsScenarioRow.Name), + Resources.PipingCalculation_Name_DisplayName + ); + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsScenarioRow.FailureProbabilityPiping), + Resources.PipingScenarioView_PipingScenarioRow_FailureProbabilityPiping + ); + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsScenarioRow.FailureProbabilityUplift), + Resources.PipingScenarioView_PipingScenarioRow_FailureProbabilityUplift + ); + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsScenarioRow.FailureProbabilityHeave), + Resources.PipingScenarioView_PipingScenarioRow_FailureProbabilityHeave + ); + dataGridViewControl.AddTextBoxColumn( + nameof(MacroStabilityInwardsScenarioRow.FailureProbabilitySellmeijer), + Resources.PipingScenarioView_PipingScenarioRow_FailureProbabilitySellmeijer + ); + } + + private void InitializeListBox() + { + listBox.DisplayMember = nameof(FailureMechanismSection.Name); + listBox.SelectedValueChanged += ListBoxOnSelectedValueChanged; + } + + private void UpdateDataGridViewDataSource() + { + var failureMechanismSection = listBox.SelectedItem as FailureMechanismSection; + if (failureMechanismSection == null || calculationGroup == null) + { + dataGridViewControl.SetDataSource(null); + return; + } + + IEnumerable lineSegments = Math2D.ConvertLinePointsToLineSegments(failureMechanismSection.Points); + IEnumerable calculations = calculationGroup + .GetCalculations() + .OfType() + .Where(pc => pc.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments)); + + List dataSource = calculations.Select(pc => new MacroStabilityInwardsScenarioRow(pc)).ToList(); + dataGridViewControl.SetDataSource(dataSource); + } + + #region Event handling + + private void ListBoxOnSelectedValueChanged(object sender, EventArgs e) + { + UpdateDataGridViewDataSource(); + } + + private void OnFailureMechanismUpdate() + { + UpdateSectionsListBox(); + } + + private void UpdateSectionsListBox() + { + listBox.Items.Clear(); + + if (macroStabilityInwardsFailureMechanism != null && macroStabilityInwardsFailureMechanism.Sections.Any()) + { + listBox.Items.AddRange(macroStabilityInwardsFailureMechanism.Sections.Cast().ToArray()); + listBox.SelectedItem = macroStabilityInwardsFailureMechanism.Sections.First(); + } + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.resx =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.resx (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.resx (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,384 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Fill + + + + 0, 0 + + + + 1 + + + Top, Bottom, Left, Right + + + False + + + 3, 20 + + + 3, 0, 3, 0 + + + 141, 230 + + + 1 + + + listBox + + + System.Windows.Forms.ListBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelListBox + + + 0 + + + True + + + NoControl + + + 3, 0 + + + 26, 13 + + + 0 + + + Vak + + + labelFailureMechanismSections + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelListBox + + + 1 + + + Fill + + + 0, 0 + + + 2 + + + 147, 250 + + + 0 + + + tableLayoutPanelListBox + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer.Panel1 + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="listBox" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelFailureMechanismSections" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="Absolute,20,Percent,100" /></TableLayoutSettings> + + + splitContainer.Panel1 + + + System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer + + + 0 + + + 100 + + + 1 + + + True + + + NoControl + + + 3, 0 + + + 182, 13 + + + 0 + + + Berekeningen voor geselecteerd vak + + + labelCalculations + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelDataGrid + + + 0 + + + Top, Bottom, Left, Right + + + 3, 23 + + + 343, 224 + + + 1 + + + dataGridViewControl + + + Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=16.1.1.4340, Culture=neutral, PublicKeyToken=null + + + tableLayoutPanelDataGrid + + + 1 + + + Fill + + + 0, 0 + + + 2 + + + 349, 250 + + + 1 + + + tableLayoutPanelDataGrid + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer.Panel2 + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="labelCalculations" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="dataGridViewControl" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="Absolute,20,Percent,100" /></TableLayoutSettings> + + + splitContainer.Panel2 + + + System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer + + + 1 + + + 0 + + + 500, 250 + + + 147 + + + 0 + + + splitContainer + + + System.Windows.Forms.SplitContainer, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + True + + + 6, 13 + + + True + + + 500, 250 + + + True + + + 500, 250 + + + MacroStabilityInwardsScenariosView + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsSoilLayerTable.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsSoilLayerTable.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsSoilLayerTable.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.Controls.DataGrid; +using Ringtoets.MacroStabilityInwards.Forms.Properties; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.Forms.Views +{ + /// + /// This class defines a table in which properties of instances + /// are shown as rows. + /// + public class MacroStabilityInwardsSoilLayerTable : DataGridViewControl + { + /// + /// Creates a new instance of . + /// + public MacroStabilityInwardsSoilLayerTable() + { + AddColumns(); + } + + /// + /// Sets the given for which the properties + /// are shown in the table. + /// + /// The collection of layers to show. + public void SetData(IEnumerable layers) + { + SetDataSource(layers?.Select(l => new FormattedMacroStabilityInwardsSoilLayerRow(l)).ToArray()); + } + + private void AddColumns() + { + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.MaterialName), Resources.PipingSoilLayerTable_ColumnHeader_MaterialName, true); + AddColorColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.Color), Resources.PipingSoilLayerTable_ColumnHeader_Color); + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.Top), Resources.PipingSoilLayerTable_ColumnHeader_Top, true); + AddCheckBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.IsAquifer), Resources.PipingSoilLayerTable_ColumnHeader_IsAquifer, true); + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.PermeabilityMean), Resources.PipingSoilLayerTable_ColumnHeader_PermeabilityMean, true); + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.PermeabilityCoefficientOfVariation), Resources.PipingSoilLayerTable_ColumnHeader_PermeabilityCoefficientOfVariation, true); + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.DiameterD70Mean), Resources.PipingSoilLayerTable_ColumnHeader_DiameterD70Mean, true); + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.DiameterD70CoefficientOfVariation), Resources.PipingSoilLayerTable_ColumnHeader_DiameterD70CoefficientOfVariation, true); + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.BelowPhreaticLevelMean), Resources.PipingSoilLayerTable_ColumnHeader_BelowPhreaticLevelMean, true); + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.BelowPhreaticLevelDeviation), Resources.PipingSoilLayerTable_ColumnHeader_BelowPhreaticLevelDeviation, true); + AddTextBoxColumn(nameof(FormattedMacroStabilityInwardsSoilLayerRow.BelowPhreaticLevelShift), Resources.PipingSoilLayerTable_ColumnHeader_BelowPhreaticLevelShift, true); + } + + private class FormattedMacroStabilityInwardsSoilLayerRow + { + public FormattedMacroStabilityInwardsSoilLayerRow(PipingSoilLayer layer) + { + MaterialName = layer.MaterialName; + Color = layer.Color; + Top = new RoundedDouble(2, layer.Top); + IsAquifer = layer.IsAquifer; + PermeabilityMean = new RoundedDouble(6, layer.PermeabilityMean); + PermeabilityCoefficientOfVariation = new RoundedDouble(6, layer.PermeabilityCoefficientOfVariation); + DiameterD70Mean = new RoundedDouble(6, layer.DiameterD70Mean); + DiameterD70CoefficientOfVariation = new RoundedDouble(6, layer.DiameterD70CoefficientOfVariation); + BelowPhreaticLevelMean = new RoundedDouble(2, layer.BelowPhreaticLevelMean); + BelowPhreaticLevelDeviation = new RoundedDouble(2, layer.BelowPhreaticLevelDeviation); + BelowPhreaticLevelShift = new RoundedDouble(2, layer.BelowPhreaticLevelShift); + } + + /// + /// Gets the top level of the . + /// + public RoundedDouble Top { get; } + + /// + /// Gets a value indicating whether or not the is an aquifer. + /// + public bool IsAquifer { get; } + + /// + /// Gets the mean of the distrubtion for the volumic weight of the below the phreatic level. + /// [kN/m³] + /// + public RoundedDouble BelowPhreaticLevelMean { get; } + + /// + /// Gets the deviation of the distrubtion for the volumic weight of the below the phreatic level. + /// [kN/m³] + /// + public RoundedDouble BelowPhreaticLevelDeviation { get; } + + /// + /// Gets the shift of the distrubtion for the volumic weight of the below the phreatic level. + /// [kN/m³] + /// + public RoundedDouble BelowPhreaticLevelShift { get; } + + /// + /// Gets the mean of the distribution for the mean diameter of small scale tests applied to different kinds of sand, + /// on which the formula of Sellmeijer has been fit. + /// [m] + /// + public RoundedDouble DiameterD70Mean { get; } + + /// + /// Gets the coefficient of variation of the distribution for the mean diameter of small scale tests applied to different kinds of sand, + /// on which the formula of Sellmeijer has been fit. + /// [m] + /// + public RoundedDouble DiameterD70CoefficientOfVariation { get; } + + /// + /// Gets the mean of the distribution for the the Darcy-speed with which water flows through the aquifer layer. + /// [m/s] + /// + public RoundedDouble PermeabilityMean { get; } + + /// + /// Gets the coefficient of variation of the distribution for the Darcy-speed with which water flows through the aquifer layer. + /// [m/s] + /// + public RoundedDouble PermeabilityCoefficientOfVariation { get; } + + /// + /// Gets the name of the material that was assigned to the . + /// + public string MaterialName { get; } + + /// + /// Gets the that was used to represent the . + /// + public Color Color { get; } + } + } +} \ No newline at end of file Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingCalculationRow.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingCalculationsView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingCalculationsView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingCalculationsView.resx'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingFailureMechanismResultView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingInputView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingInputView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingInputView.resx'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingScenarioRow.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingScenariosView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingScenariosView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingScenariosView.resx'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/PipingSoilLayerTable.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs =================================================================== diff -u -ra0a4e8059c0e23db4eb3525d01a264fcf38c5ddd -re25d1dff1132d88462399833e9a76b1dc6b8b785 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision a0a4e8059c0e23db4eb3525d01a264fcf38c5ddd) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -184,7 +184,7 @@ yield return new ViewInfo< FailureMechanismSectionResultContext, IEnumerable, - PipingFailureMechanismResultView> + MacroStabilityInwardsFailureMechanismResultView> { GetViewName = (view, results) => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName, Image = RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon, @@ -193,7 +193,7 @@ AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism }; - yield return new ViewInfo + yield return new ViewInfo { GetViewData = context => context.WrappedData, GetViewName = (view, calculationGroup) => calculationGroup.Name, @@ -207,15 +207,15 @@ } }; - yield return new ViewInfo + yield return new ViewInfo { GetViewData = context => context.MacroStabilityInwardsCalculation, GetViewName = (view, input) => RingtoetsCommonFormsResources.Calculation_Input, Image = MacroStabilityInwardsFormsResources.PipingInputIcon, CloseForData = ClosePipingInputViewForData }; - yield return new ViewInfo + yield return new ViewInfo { GetViewData = context => context.WrappedData, GetViewName = (view, calculationGroup) => RingtoetsCommonFormsResources.Scenarios_DisplayName, @@ -388,7 +388,7 @@ #region FailureMechanismResultsView ViewInfo - private static bool CloseFailureMechanismResultViewForData(PipingFailureMechanismResultView view, object o) + private static bool CloseFailureMechanismResultViewForData(MacroStabilityInwardsFailureMechanismResultView view, object o) { var assessmentSection = o as IAssessmentSection; var failureMechanism = o as MacroStabilityInwardsFailureMechanism; @@ -409,9 +409,9 @@ #endregion - #region PipingCalculationsView ViewInfo + #region MacroStabilityInwardsCalculationsView ViewInfo - private static bool ClosePipingCalculationsViewForData(PipingCalculationsView view, object o) + private static bool ClosePipingCalculationsViewForData(MacroStabilityInwardsCalculationsView view, object o) { var assessmentSection = o as IAssessmentSection; var pipingFailureMechanism = o as MacroStabilityInwardsFailureMechanism; @@ -433,9 +433,9 @@ #endregion endregion - #region PipingScenariosView ViewInfo + #region MacroStabilityInwardsScenariosView ViewInfo - private static bool ClosePipingScenariosViewForData(PipingScenariosView view, object o) + private static bool ClosePipingScenariosViewForData(MacroStabilityInwardsScenariosView view, object o) { var assessmentSection = o as IAssessmentSection; var pipingFailureMechanism = o as MacroStabilityInwardsFailureMechanism; @@ -457,9 +457,9 @@ #endregion endregion - #region PipingInputView ViewInfo + #region MacroStabilityInwardsInputView ViewInfo - private static bool ClosePipingInputViewForData(PipingInputView view, object o) + private static bool ClosePipingInputViewForData(MacroStabilityInwardsInputView view, object o) { var pipingCalculationScenarioContext = o as MacroStabilityInwardsCalculationScenarioContext; if (pipingCalculationScenarioContext != null) Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Ringtoets.MacroStabilityInwards.Forms.Test.csproj =================================================================== diff -u -ra0a4e8059c0e23db4eb3525d01a264fcf38c5ddd -re25d1dff1132d88462399833e9a76b1dc6b8b785 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Ringtoets.MacroStabilityInwards.Forms.Test.csproj (.../Ringtoets.MacroStabilityInwards.Forms.Test.csproj) (revision a0a4e8059c0e23db4eb3525d01a264fcf38c5ddd) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Ringtoets.MacroStabilityInwards.Forms.Test.csproj (.../Ringtoets.MacroStabilityInwards.Forms.Test.csproj) (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -90,19 +90,19 @@ - + - + - - - - + + + + - + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationRowTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationRowTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationRowTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,556 @@ +// Copyright (C) Stichting Deltares 2017. 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.Globalization; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.Controls.DataGrid; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Forms.PropertyClasses; +using Ringtoets.Common.Forms.TestUtil; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil; + +namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views +{ + [TestFixture] + public class MacroStabilityInwardsCalculationRowTest + { + [Test] + public void Constructor_WithoutCalculation_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => new MacroStabilityInwardsCalculationRow(null, handler); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("macroStabilityInwardsCalculation", paramName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_WithoutHandler_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new MacroStabilityInwardsCalculationRow(new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("handler", paramName); + } + + [Test] + public void Constructor_WithCalculation_PropertiesFromCalculation() + { + // Setup + var mocks = new MockRepository(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + + // Call + var row = new MacroStabilityInwardsCalculationRow(calculation, handler); + + // Assert + Assert.AreSame(calculation, row.MacroStabilityInwardsCalculation); + Assert.AreEqual(calculation.Name, row.Name); + Assert.AreSame(calculation.InputParameters.StochasticSoilModel, row.StochasticSoilModel.WrappedObject); + Assert.AreSame(calculation.InputParameters.StochasticSoilProfile, row.StochasticSoilProfile.WrappedObject); + Assert.AreEqual(calculation.InputParameters.StochasticSoilProfile.Probability.ToString(CultureInfo.CurrentCulture), row.StochasticSoilProfileProbability); + Assert.AreSame(calculation.InputParameters.HydraulicBoundaryLocation, row.SelectableHydraulicBoundaryLocation.WrappedObject.HydraulicBoundaryLocation); + Assert.AreEqual(calculation.InputParameters.DampingFactorExit.Mean, row.DampingFactorExitMean); + Assert.AreEqual(calculation.InputParameters.PhreaticLevelExit.Mean, row.PhreaticLevelExitMean); + Assert.AreEqual(calculation.InputParameters.EntryPointL, row.EntryPointL); + Assert.AreEqual(calculation.InputParameters.ExitPointL, row.ExitPointL); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_WithCalculationWithInvalidInput_PropertiesFromCalculation() + { + // Setup + var mocks = new MockRepository(); + var handler = mocks.Stub(); + mocks.ReplayAll(); + + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithInvalidInput(); + + // Call + var row = new MacroStabilityInwardsCalculationRow(calculation, handler); + + // Assert + Assert.AreSame(calculation, row.MacroStabilityInwardsCalculation); + Assert.IsNull(row.StochasticSoilModel.WrappedObject); + Assert.IsNull(row.StochasticSoilProfile.WrappedObject); + Assert.AreEqual("0", row.StochasticSoilProfileProbability); + Assert.IsNull(row.SelectableHydraulicBoundaryLocation.WrappedObject); + mocks.VerifyAll(); + } + + [Test] + public void Name_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() + { + // Setup + var mockRepository = new MockRepository(); + var observer = mockRepository.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + var handler = mockRepository.Stub(); + mockRepository.ReplayAll(); + + const string newValue = "Test new name"; + + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + var row = new MacroStabilityInwardsCalculationRow(calculation, handler); + + calculation.Attach(observer); + + // Call + row.Name = newValue; + + // Assert + Assert.AreEqual(newValue, calculation.Name); + mockRepository.VerifyAll(); + } + + [Test] + public void StochasticSoilModel_AlwaysOnChange_NotifyObserverCalculationPropertyChangedOutputCleared() + { + // Setup + var newModel = new StochasticSoilModel(0, "test", "test"); + var newValue = new DataGridViewComboBoxItemWrapper(newModel); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + // Call & Assert + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(row => row.StochasticSoilModel = newValue, calculation); + } + + [Test] + public void StochasticSoilModel_ChangeToEqualValue_NoNotificationsOutputNotCleared() + { + // Setup + DataGridViewComboBoxItemWrapper oldValue = null; + + // Call + AssertPropertyNotChanged( + row => + { + oldValue = row.StochasticSoilModel; + row.StochasticSoilModel = row.StochasticSoilModel; + }, + calculation => + { + // Assert + Assert.NotNull(oldValue); + Assert.AreEqual(oldValue.WrappedObject, calculation.InputParameters.StochasticSoilModel); + }); + } + + [Test] + public void StochasticSoilProfile_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() + { + // Setup + var newProfile = new StochasticSoilProfile(0, 0, 0); + var newValue = new DataGridViewComboBoxItemWrapper(newProfile); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + // Call & Assert + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(row => row.StochasticSoilProfile = newValue, calculation); + } + + [Test] + public void StochasticSoilProfile_ChangeToEqualValue_NoNotificationsOutputNotCleared() + { + // Setup + DataGridViewComboBoxItemWrapper oldValue = null; + + // Call + AssertPropertyNotChanged( + row => + { + oldValue = row.StochasticSoilProfile; + row.StochasticSoilProfile = row.StochasticSoilProfile; + }, + calculation => + { + // Assert + Assert.NotNull(oldValue); + Assert.AreEqual(oldValue.WrappedObject, calculation.InputParameters.StochasticSoilProfile); + }); + } + + [Test] + public void SelectableHydraulicBoundaryLocation_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() + { + // Setup + var newLocation = new TestHydraulicBoundaryLocation(); + var selectableHydraulicBoundaryLocation = new SelectableHydraulicBoundaryLocation(newLocation, new Point2D(0, 0)); + var newValue = new DataGridViewComboBoxItemWrapper(selectableHydraulicBoundaryLocation); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + // Call & Assert + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(row => row.SelectableHydraulicBoundaryLocation = newValue, calculation); + } + + [Test] + public void SelectableHydraulicBoundaryLocation_ChangeToEqualValue_NoNotificationsOutputNotCleared() + { + // Setup + DataGridViewComboBoxItemWrapper oldValue = null; + + // Call + AssertPropertyNotChanged( + row => + { + oldValue = row.SelectableHydraulicBoundaryLocation; + row.SelectableHydraulicBoundaryLocation = row.SelectableHydraulicBoundaryLocation; + }, + calculation => + { + // Assert + Assert.NotNull(oldValue); + Assert.AreEqual(oldValue.WrappedObject.HydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation); + }); + } + + [Test] + public void DampingFactorExitMean_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var dampingFactorExitMean = (RoundedDouble) 2.3; + + // Call & Assert + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(row => row.DampingFactorExitMean = dampingFactorExitMean, calculation); + } + + [Test] + public void DampingFactorExitMean_ChangeToEqualValue_NoNotificationsOutputNotCleared() + { + // Setup + RoundedDouble oldValue = RoundedDouble.NaN; + + // Call + AssertPropertyNotChanged( + row => + { + oldValue = row.DampingFactorExitMean; + row.DampingFactorExitMean = row.DampingFactorExitMean; + }, + calculation => + { + // Assert + Assert.False(double.IsNaN(oldValue)); + Assert.AreEqual(oldValue, calculation.InputParameters.DampingFactorExit.Mean); + }); + } + + [Test] + public void PhreaticLevelExitMean_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var phreaticLevelExitMean = (RoundedDouble) 5.1; + + // Call & Assert + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(row => row.PhreaticLevelExitMean = phreaticLevelExitMean, calculation); + } + + [Test] + public void PhreaticLevelExitMean_ChangeToEqualValue_NoNotificationsOutputNotCleared() + { + // Setup + RoundedDouble oldValue = RoundedDouble.NaN; + + // Call + AssertPropertyNotChanged( + row => + { + oldValue = row.PhreaticLevelExitMean; + row.PhreaticLevelExitMean = row.PhreaticLevelExitMean; + }, + calculation => + { + // Assert + Assert.False(double.IsNaN(oldValue)); + Assert.AreEqual(oldValue, calculation.InputParameters.PhreaticLevelExit.Mean); + }); + } + + [Test] + public void EntryPointL_OnValidChange_NotifyObserverAndCalculationPropertyChanged() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var entryPointL = (RoundedDouble) 0.1; + + // Call & Assert + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(row => row.EntryPointL = entryPointL, calculation); + } + + [Test] + public void EntryPointL_ChangeToEqualValue_NoNotificationsOutputNotCleared() + { + // Setup + RoundedDouble oldValue = RoundedDouble.NaN; + + // Call + AssertPropertyNotChanged( + row => + { + oldValue = row.EntryPointL; + row.EntryPointL = row.EntryPointL; + }, + calculation => + { + // Assert + Assert.False(double.IsNaN(oldValue)); + Assert.AreEqual(oldValue, calculation.InputParameters.EntryPointL); + }); + } + + [Test] + [TestCase(0.2)] + [TestCase(1.0)] + public void EntryPointL_EntryPointNotBeforeExitPoint_ThrowsArgumentOutOfRangeExceptionDoesNotNotifyObservers(double newValue) + { + // Setup + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + var entryPointL = (RoundedDouble) newValue; + + // Call & Assert + const string expectedMessage = "Het uittredepunt moet landwaarts van het intredepunt liggen."; + SetPropertyToInvalidValueAndVerifyException(row => row.EntryPointL = entryPointL, calculation, + expectedMessage); + } + + [Test] + [SetCulture("nl-NL")] + public void EntryPointL_NotOnSurfaceLine_ThrowsArgumentOutOfRangeExceptionAndDoesNotNotifyObservers() + { + // Setup + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + var entryPointL = (RoundedDouble) (-3.0); + + // Call & Assert + const string expectedMessage = "Het gespecificeerde punt moet op het profiel liggen (bereik [0,0, 1,0])."; + SetPropertyToInvalidValueAndVerifyException(row => row.EntryPointL = entryPointL, calculation, + expectedMessage); + } + + [Test] + public void ExitPointL_OnValidChange_NotifyObserverAndCalculationPropertyChanged() + { + // Setup + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + var exitPointL = (RoundedDouble) 0.3; + + // Call & Assert + SetPropertyAndVerifyNotifcationsAndOutputForCalculation(row => row.ExitPointL = exitPointL, calculation); + } + + [Test] + public void ExitPointL_ChangeToEqualValue_NoNotificationsOutputNotCleared() + { + // Setup + RoundedDouble oldValue = RoundedDouble.NaN; + + // Call + AssertPropertyNotChanged( + row => + { + oldValue = row.ExitPointL; + row.ExitPointL = row.ExitPointL; + }, + calculation => + { + // Assert + Assert.False(double.IsNaN(oldValue)); + Assert.AreEqual(oldValue, calculation.InputParameters.ExitPointL); + }); + } + + [Test] + [TestCase(0.0)] + [TestCase(-0.2)] + public void ExitPointL_ExitPointNotBeyondEntryPoint_ThrowsArgumentOutOfRangeExceptionDoesNotNotifyObservers(double newValue) + { + // Setup + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + var exitPointL = (RoundedDouble) newValue; + + // Call & Assert + const string expectedMessage = "Het uittredepunt moet landwaarts van het intredepunt liggen."; + SetPropertyToInvalidValueAndVerifyException(row => row.ExitPointL = exitPointL, calculation, + expectedMessage); + } + + [Test] + [SetCulture("nl-NL")] + public void ExitPointL_NotOnSurfaceLine_ThrowsArgumentOutOfRangeExceptionAndDoesNotNotifyObservers() + { + // Setup + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + var exitPointL = (RoundedDouble) 3.0; + + // Call & Assert + const string expectedMessage = "Het gespecificeerde punt moet op het profiel liggen (bereik [0,0, 1,0])."; + SetPropertyToInvalidValueAndVerifyException(row => row.ExitPointL = exitPointL, calculation, + expectedMessage); + } + + /// + /// Asserts that the output of a remains + /// unaffected (and therefore no change notification occurring) when the input for + /// that calculation has been changed using an instance of . + /// + /// The function that changes a property of the + /// instance. This function should not throw exceptions. + /// The additional assertions to be performed on the + /// whose input has been changed. + private static void AssertPropertyNotChanged( + Action setProperty, + Action assertions) + { + AssertPropertyChangeWithOrWithoutCalculationOutput(setProperty, assertions, true, false); + AssertPropertyChangeWithOrWithoutCalculationOutput(setProperty, assertions, false, false); + } + + private static void AssertPropertyChangeWithOrWithoutCalculationOutput( + Action setProperty, + Action assertions, + bool hasOutput, + bool expectUpdates) + { + // Setup + var mockRepository = new MockRepository(); + var inputObserver = mockRepository.StrictMock(); + if (expectUpdates) + { + inputObserver.Expect(o => o.UpdateObserver()); + } + var calculationObserver = mockRepository.StrictMock(); + if (expectUpdates && hasOutput) + { + calculationObserver.Expect(o => o.UpdateObserver()); + } + var handler = mockRepository.Stub(); + mockRepository.ReplayAll(); + + TestPipingOutput assignedOutput = null; + + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + if (hasOutput) + { + assignedOutput = new TestPipingOutput(); + } + calculation.Output = assignedOutput; + + var row = new MacroStabilityInwardsCalculationRow(calculation, handler); + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(inputObserver); + + // Call + setProperty(row); + + // Assert + assertions(calculation); + if (expectUpdates) + { + Assert.IsNull(calculation.Output); + } + else + { + Assert.AreSame(assignedOutput, calculation.Output); + } + mockRepository.VerifyAll(); + } + + private static void SetPropertyToInvalidValueAndVerifyException( + Action setProperty, + MacroStabilityInwardsCalculationScenario calculation, + string expectedMessage) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.StrictMock(); + mocks.ReplayAll(); + + var handler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester( + new[] + { + observable + }); + + var row = new MacroStabilityInwardsCalculationRow(calculation, handler); + + // Call + TestDelegate test = () => setProperty(row); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + Assert.IsTrue(handler.Called); + mocks.VerifyAll(); + } + + private static void SetPropertyAndVerifyNotifcationsAndOutputForCalculation( + Action setProperty, + MacroStabilityInwardsCalculationScenario calculation) + { + // Setup + var mocks = new MockRepository(); + var observable = mocks.StrictMock(); + observable.Expect(o => o.NotifyObservers()); + mocks.ReplayAll(); + + var handler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester( + new[] + { + observable + }); + + var row = new MacroStabilityInwardsCalculationRow(calculation, handler); + + // Call + setProperty(row); + + // Assert + Assert.IsTrue(handler.Called); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,1731 @@ +// Copyright (C) Stichting Deltares 2017. 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.Globalization; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.Controls.DataGrid; +using Core.Common.Controls.Views; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views +{ + [TestFixture] + public class MacroStabilityInwardsCalculationsViewTest : NUnitFormTest + { + private const int nameColumnIndex = 0; + private const int stochasticSoilModelsColumnIndex = 1; + private const int stochasticSoilProfilesColumnIndex = 2; + private const int stochasticSoilProfilesProbabilityColumnIndex = 3; + private const int selectableHydraulicBoundaryLocationsColumnIndex = 4; + private const int dampingFactorExitMeanColumnIndex = 5; + private const int phreaticLevelExitMeanColumnIndex = 6; + private const int entryPointLColumnIndex = 7; + private const int exitPointLColumnIndex = 8; + private Form testForm; + + [SetUp] + public override void Setup() + { + base.Setup(); + + testForm = new Form(); + } + + [TearDown] + public override void TearDown() + { + base.TearDown(); + + testForm.Dispose(); + } + + [Test] + public void Constructor_DefaultValues() + { + // Call + using (var calculationsView = new MacroStabilityInwardsCalculationsView()) + { + // Assert + Assert.IsInstanceOf(calculationsView); + Assert.IsInstanceOf(calculationsView); + Assert.IsNull(calculationsView.Data); + Assert.IsNull(calculationsView.MacroStabilityInwardsFailureMechanism); + Assert.IsNull(calculationsView.AssessmentSection); + } + } + + [Test] + public void Constructor_DataGridViewCorrectlyInitialized() + { + // Call + using (ShowMacroStabilityInwardsCalculationsView()) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Assert + Assert.IsFalse(dataGridView.AutoGenerateColumns); + Assert.AreEqual(9, dataGridView.ColumnCount); + + foreach (DataGridViewComboBoxColumn column in dataGridView.Columns.OfType()) + { + Assert.AreEqual("This", column.ValueMember); + Assert.AreEqual("DisplayName", column.DisplayMember); + } + + var soilProfilesCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[stochasticSoilProfilesColumnIndex]; + DataGridViewComboBoxCell.ObjectCollection soilProfilesComboboxItems = soilProfilesCombobox.Items; + Assert.AreEqual(0, soilProfilesComboboxItems.Count); // Row dependent + + var hydraulicBoundaryLocationCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex]; + DataGridViewComboBoxCell.ObjectCollection hydraulicBoundaryLocationComboboxItems = hydraulicBoundaryLocationCombobox.Items; + Assert.AreEqual(0, hydraulicBoundaryLocationComboboxItems.Count); // Row dependent + } + } + + [Test] + public void Constructor_ListBoxCorrectlyInitialized() + { + // Call + using (ShowMacroStabilityInwardsCalculationsView()) + { + var listBox = (ListBox) new ControlTester("listBox").TheObject; + + // Assert + Assert.AreEqual(0, listBox.Items.Count); + } + } + + [Test] + public void Data_SetToNull_DoesNotThrow() + { + // Setup + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + // Call + var testDelegate = new TestDelegate(() => macroStabilityInwardsCalculationsView.Data = null); + + // Assert + Assert.DoesNotThrow(testDelegate); + } + } + + [Test] + public void AssessmentSection_WithHydraulicBoundaryDatabaseSurfaceLinesNull_SelectableHydraulicBoundaryLocationsComboboxCorrectlyInitialized() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowSimpleMacroStabilityInwardsCalculationsViewWithoutSurfaceLines( + assessmentSection, new HydraulicBoundaryDatabase())) + { + // Call + macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; + + // Assert + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var hydraulicBoundaryLocationCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex]; + DataGridViewComboBoxCell.ObjectCollection hydraulicBoundaryLocationComboboxItems = hydraulicBoundaryLocationCombobox.Items; + Assert.AreEqual(3, hydraulicBoundaryLocationComboboxItems.Count); + Assert.AreEqual("", hydraulicBoundaryLocationComboboxItems[0].ToString()); + Assert.AreEqual("Location 1", hydraulicBoundaryLocationComboboxItems[1].ToString()); + Assert.AreEqual("Location 2", hydraulicBoundaryLocationComboboxItems[2].ToString()); + } + mocks.VerifyAll(); + } + + [Test] + public void AssessmentSection_WithSurfaceLinesHydraulicBoundaryDatabaseNull_SelectableHydraulicBoundaryLocationsComboboxCorrectlyInitialized() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowSimpleMacroStabilityInwardsCalculationsViewWithSurfaceLines( + assessmentSection)) + { + // Call + macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; + + // Assert + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var hydraulicBoundaryLocationCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex]; + DataGridViewComboBoxCell.ObjectCollection hydraulicBoundaryLocationComboboxItems = hydraulicBoundaryLocationCombobox.Items; + Assert.AreEqual(1, hydraulicBoundaryLocationComboboxItems.Count); + Assert.AreEqual("", hydraulicBoundaryLocationComboboxItems[0].ToString()); + } + mocks.VerifyAll(); + } + + [Test] + public void AssessmentSection_HydraulicBoundaryDatabaseWithLocationsAndSurfaceLines_SelectableHydraulicBoundaryLocationsComboboxCorrectlyInitialized() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection)) + { + // Call + macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; + + // Assert + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var hydraulicBoundaryLocationCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex]; + DataGridViewComboBoxCell.ObjectCollection hydraulicBoundaryLocationComboboxItems = hydraulicBoundaryLocationCombobox.Items; + Assert.AreEqual(7, hydraulicBoundaryLocationComboboxItems.Count); + Assert.AreEqual("", hydraulicBoundaryLocationComboboxItems[0].ToString()); + Assert.AreEqual("Location 1", hydraulicBoundaryLocationComboboxItems[1].ToString()); + Assert.AreEqual("Location 2", hydraulicBoundaryLocationComboboxItems[2].ToString()); + Assert.AreEqual("Location 1 (2 m)", hydraulicBoundaryLocationComboboxItems[3].ToString()); + Assert.AreEqual("Location 2 (6 m)", hydraulicBoundaryLocationComboboxItems[4].ToString()); + Assert.AreEqual("Location 1 (4 m)", hydraulicBoundaryLocationComboboxItems[5].ToString()); + Assert.AreEqual("Location 2 (5 m)", hydraulicBoundaryLocationComboboxItems[6].ToString()); + } + mocks.VerifyAll(); + } + + [Test] + public void MacroStabilityInwardsFailureMechanism_FailureMechanismWithSections_SectionsListBoxCorrectlyInitialized() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismSection1 = new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + }); + var failureMechanismSection2 = new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + }); + var failureMechanismSection3 = new FailureMechanismSection("Section 3", new List + { + new Point2D(10.0, 0.0), + new Point2D(15.0, 0.0) + }); + + failureMechanism.AddSection(failureMechanismSection1); + failureMechanism.AddSection(failureMechanismSection2); + failureMechanism.AddSection(failureMechanismSection3); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + // Call + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + // Assert + var listBox = (ListBox) new ControlTester("listBox").TheObject; + Assert.AreEqual(3, listBox.Items.Count); + Assert.AreSame(failureMechanismSection1, listBox.Items[0]); + Assert.AreSame(failureMechanismSection2, listBox.Items[1]); + Assert.AreSame(failureMechanismSection3, listBox.Items[2]); + } + } + + [Test] + public void MacroStabilityInwardsCalculationsView_CalculationsWithCorrespondingStochasticSoilModel_StochasticSoilModelsComboboxCorrectlyInitialized() + { + // Setup & Call + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (ShowFullyConfiguredMacroStabilityInwardsCalculationsView(assessmentSection)) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Assert + DataGridViewComboBoxCell.ObjectCollection stochasticSoilModelsComboboxItems = ((DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex]).Items; + Assert.AreEqual(1, stochasticSoilModelsComboboxItems.Count); + Assert.AreEqual("Model A", stochasticSoilModelsComboboxItems[0].ToString()); + + stochasticSoilModelsComboboxItems = ((DataGridViewComboBoxCell) dataGridView.Rows[1].Cells[stochasticSoilModelsColumnIndex]).Items; + Assert.AreEqual(3, stochasticSoilModelsComboboxItems.Count); + Assert.AreEqual("", stochasticSoilModelsComboboxItems[0].ToString()); + Assert.AreEqual("Model A", stochasticSoilModelsComboboxItems[1].ToString()); + Assert.AreEqual("Model E", stochasticSoilModelsComboboxItems[2].ToString()); + } + mocks.VerifyAll(); + } + + [Test] + public void MacroStabilityInwardsCalculationsView_CalculationsWithCorrespondingSoilProfiles_SoilProfilesComboboxCorrectlyInitialized() + { + // Setup & Call + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (ShowFullyConfiguredMacroStabilityInwardsCalculationsView(assessmentSection)) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Assert + DataGridViewComboBoxCell.ObjectCollection soilProfilesComboboxItems = ((DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex]).Items; + Assert.AreEqual(3, soilProfilesComboboxItems.Count); + Assert.AreEqual("", soilProfilesComboboxItems[0].ToString()); + Assert.AreEqual("Profile 1", soilProfilesComboboxItems[1].ToString()); + Assert.AreEqual("Profile 2", soilProfilesComboboxItems[2].ToString()); + + soilProfilesComboboxItems = ((DataGridViewComboBoxCell) dataGridView.Rows[1].Cells[stochasticSoilProfilesColumnIndex]).Items; + Assert.AreEqual(1, soilProfilesComboboxItems.Count); + Assert.AreEqual("Profile 5", soilProfilesComboboxItems[0].ToString()); + } + mocks.VerifyAll(); + } + + [Test] + public void MacroStabilityInwardsCalculationsView_CalculationsWithAllDataSet_DataGridViewCorrectlyInitialized() + { + // Setup & Call + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (ShowFullyConfiguredMacroStabilityInwardsCalculationsView(assessmentSection)) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Assert + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(2, rows.Count); + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(9, cells.Count); + Assert.AreEqual("Calculation 1", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("Model A", cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("", cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("0", cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + Assert.AreEqual("Location 1 (2 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); + Assert.AreEqual(1.111.ToString(CultureInfo.CurrentCulture), cells[dampingFactorExitMeanColumnIndex].FormattedValue); + Assert.AreEqual(2.222.ToString(CultureInfo.CurrentCulture), cells[phreaticLevelExitMeanColumnIndex].FormattedValue); + Assert.AreEqual(3.33.ToString(CultureInfo.CurrentCulture), cells[entryPointLColumnIndex].FormattedValue); + Assert.AreEqual(4.44.ToString(CultureInfo.CurrentCulture), cells[exitPointLColumnIndex].FormattedValue); + + cells = rows[1].Cells; + Assert.AreEqual(9, cells.Count); + Assert.AreEqual("Calculation 2", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("Model E", cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("Profile 5", cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("30", cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + Assert.AreEqual("Location 2 (5 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); + Assert.AreEqual(5.556.ToString(CultureInfo.CurrentCulture), cells[dampingFactorExitMeanColumnIndex].FormattedValue); + Assert.AreEqual(6.667.ToString(CultureInfo.CurrentCulture), cells[phreaticLevelExitMeanColumnIndex].FormattedValue); + Assert.AreEqual(7.78.ToString(CultureInfo.CurrentCulture), cells[entryPointLColumnIndex].FormattedValue); + Assert.AreEqual(8.89.ToString(CultureInfo.CurrentCulture), cells[exitPointLColumnIndex].FormattedValue); + } + mocks.VerifyAll(); + } + + [Test] + public void MacroStabilityInwardsCalculationsView_SelectingCellInRow_SelectionChangedFired() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection); + + var selectionChangedCount = 0; + macroStabilityInwardsCalculationsView.SelectionChanged += (sender, args) => selectionChangedCount++; + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0]; + + // Call + EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(1, 0)); + + // Assert + Assert.AreEqual(1, selectionChangedCount); + + mocks.VerifyAll(); + } + + [Test] + public void MacroStabilityInwardsCalculationsView_ChangingListBoxSelection_DataGridViewCorrectlySyncedAndSelectionChangedFired() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection)) + { + var selectionChangedCount = 0; + macroStabilityInwardsCalculationsView.SelectionChanged += (sender, args) => selectionChangedCount++; + + var listBox = (ListBox) new ControlTester("listBox").TheObject; + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Precondition + Assert.AreEqual(2, dataGridView.Rows.Count); + Assert.AreEqual("Calculation 1", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("Calculation 2", dataGridView.Rows[1].Cells[nameColumnIndex].FormattedValue); + + // Call + listBox.SelectedIndex = 1; + + // Assert + Assert.AreEqual(1, dataGridView.Rows.Count); + Assert.AreEqual("Calculation 2", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(1, selectionChangedCount); + } + mocks.VerifyAll(); + } + + [Test] + [TestCase("test", dampingFactorExitMeanColumnIndex)] + [TestCase("test", phreaticLevelExitMeanColumnIndex)] + [TestCase("test", entryPointLColumnIndex)] + [TestCase("test", exitPointLColumnIndex)] + [TestCase(";/[].,~!@#$%^&*()_-+={}|?", dampingFactorExitMeanColumnIndex)] + [TestCase(";/[].,~!@#$%^&*()_-+={}|?", phreaticLevelExitMeanColumnIndex)] + [TestCase(";/[].,~!@#$%^&*()_-+={}|?", entryPointLColumnIndex)] + [TestCase(";/[].,~!@#$%^&*()_-+={}|?", exitPointLColumnIndex)] + public void MacroStabilityInwardsCalculationsView_EditValueInvalid_ShowsErrorTooltip(string newValue, int cellIndex) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (ShowFullyConfiguredMacroStabilityInwardsCalculationsView(assessmentSection)) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[cellIndex].Value = newValue; + + // Assert + Assert.AreEqual("De tekst moet een getal zijn.", dataGridView.Rows[0].ErrorText); + } + mocks.VerifyAll(); + } + + [Test] + [TestCase(1, dampingFactorExitMeanColumnIndex)] + [TestCase(1e-2, dampingFactorExitMeanColumnIndex)] + [TestCase(1e+6, dampingFactorExitMeanColumnIndex)] + [TestCase(14.3, dampingFactorExitMeanColumnIndex)] + [TestCase(1, phreaticLevelExitMeanColumnIndex)] + [TestCase(1e-6, phreaticLevelExitMeanColumnIndex)] + [TestCase(1e+6, phreaticLevelExitMeanColumnIndex)] + [TestCase(14.3, phreaticLevelExitMeanColumnIndex)] + [TestCase(2.2, entryPointLColumnIndex, TestName = "FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(2.2)")] + [TestCase(0.022e+2, entryPointLColumnIndex, TestName = "FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(0.022e+2)")] + [TestCase(220e-2, entryPointLColumnIndex, TestName = "FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(220e-2)")] + [TestCase(5.5, exitPointLColumnIndex, TestName = "FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(5.5)")] + [TestCase(0.055e+2, exitPointLColumnIndex, TestName = "FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(0.055e+2)")] + [TestCase(550e-2, exitPointLColumnIndex, TestName = "FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(550e-2)")] + public void FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(double newValue, int cellIndex) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + ConfigureHydraulicBoundaryDatabase(assessmentSection); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailuremechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); + + var newRoundedvalue = (RoundedDouble) newValue; + + using (ShowFullyConfiguredMacroStabilityInwardsCalculationsView(assessmentSection, failureMechanism, calculationGroup)) + { + mocks.ReplayAll(); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[cellIndex].Value = newRoundedvalue; + + // Assert + Assert.IsEmpty(dataGridView.Rows[0].ErrorText); + } + mocks.VerifyAll(); + } + + [Test] + public void ButtonGenerateScenarios_WithoutSurfaceLines_ButtonDisabled() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, "path"); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + + // Call + bool state = button.Enabled; + + // Assert + Assert.IsFalse(state); + } + } + + [Test] + public void ButtonGenerateScenarios_WithoutSoilModels_ButtonDisabled() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine() + }, "path"); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + + // Call + bool state = button.Enabled; + + // Assert + Assert.IsFalse(state); + } + } + + [Test] + public void ButtonGenerateScenarios_WithSurfaceLinesAndSoilModels_ButtonEnabled() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + const string arbitrarySourcePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine() + }, arbitrarySourcePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, arbitrarySourcePath); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + + // Call + bool state = button.Enabled; + + // Assert + Assert.IsTrue(state); + } + } + + [Test] + public void GivenMacroStabilityInwardsCalculationsViewWithFailureMechanism_WhenSectionsAddedAndFailureMechanismNotified_ThenSectionsListBoxCorrectlyUpdated() + { + // Given + var failureMechanismWithSections = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismSection1 = new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + }); + var failureMechanismSection2 = new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + }); + var failureMechanismSection3 = new FailureMechanismSection("Section 3", new List + { + new Point2D(10.0, 0.0), + new Point2D(15.0, 0.0) + }); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanismWithSections; + + var listBox = (ListBox) new ControlTester("listBox").TheObject; + + // Precondition + Assert.AreEqual(0, listBox.Items.Count); + + failureMechanismWithSections.AddSection(failureMechanismSection1); + failureMechanismWithSections.AddSection(failureMechanismSection2); + failureMechanismWithSections.AddSection(failureMechanismSection3); + + // When + failureMechanismWithSections.NotifyObservers(); + + // Then + Assert.AreEqual(3, listBox.Items.Count); + Assert.AreSame(failureMechanismSection1, listBox.Items[0]); + Assert.AreSame(failureMechanismSection2, listBox.Items[1]); + Assert.AreSame(failureMechanismSection3, listBox.Items[2]); + } + } + + [Test] + public void GivenMacroStabilityInwardsCalculationsView_WhenGenerateScenariosButtonClicked_ThenShowViewWithSurfaceLines() + { + // Given + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + const string arbitraryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine + { + Name = "Line A" + }, + new RingtoetsPipingSurfaceLine + { + Name = "Line B" + } + }, arbitraryFilePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, arbitraryFilePath); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + macroStabilityInwardsCalculationsView.Data = failureMechanism.CalculationsGroup; + var button = new ButtonTester("buttonGenerateScenarios", testForm); + + PipingSurfaceLineSelectionDialog selectionDialog = null; + DataGridViewControl grid = null; + DialogBoxHandler = (name, wnd) => + { + selectionDialog = (PipingSurfaceLineSelectionDialog) new FormTester(name).TheObject; + grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + + new ButtonTester("CustomCancelButton", selectionDialog).Click(); + }; + + // When + button.Click(); + + // Then + Assert.NotNull(selectionDialog); + Assert.NotNull(grid); + Assert.AreEqual(2, grid.Rows.Count); + } + } + + [Test] + public void GivenMacroStabilityInwardsCalculationsViewGenerateScenariosButtonClicked_WhenNoCalculationGroupDefined_ThenCalculationGroupNotUpdated() + { + // Given + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + const string arbitraryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine + { + Name = "Line A" + }, + new RingtoetsPipingSurfaceLine + { + Name = "Line B" + } + }, arbitraryFilePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, arbitraryFilePath); + failureMechanism.CalculationsGroup.Attach(observer); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + var button = new ButtonTester("buttonGenerateScenarios", testForm); + + // When + button.Click(); + + // Then + mocks.VerifyAll(); + } + } + + [Test] + [TestCase("DoForSelectedButton")] + [TestCase("CustomCancelButton")] + public void GivenMacroStabilityInwardsCalculationsViewGenerateScenariosButtonClicked_WhenDialogClosed_ThenNotifyCalculationGroup(string buttonName) + { + // Given + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + const string arbitryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine + { + Name = "Line A" + }, + new RingtoetsPipingSurfaceLine + { + Name = "Line B" + } + }, arbitryFilePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, arbitryFilePath); + failureMechanism.CalculationsGroup.Attach(observer); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + macroStabilityInwardsCalculationsView.Data = failureMechanism.CalculationsGroup; + var button = new ButtonTester("buttonGenerateScenarios", testForm); + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (PipingSurfaceLineSelectionDialog) new FormTester(name).TheObject; + var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + selectionView.Rows[0].Cells[0].Value = true; + + // When + new ButtonTester(buttonName, selectionDialog).Click(); + }; + + button.Click(); + + // Then + mocks.VerifyAll(); + } + } + + [Test] + public void GivenMacroStabilityInwardsCalculationsViewGenerateScenariosButtonClicked_WhenSurfaceLineSelectedAndDialogClosed_ThenUpdateSectionResultScenarios() + { + // Given + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism = ConfigureSimpleFailureMechanism(); + + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = macroStabilityInwardsFailureMechanism; + macroStabilityInwardsCalculationsView.Data = macroStabilityInwardsFailureMechanism.CalculationsGroup; + + // Precondition + var button = new ButtonTester("buttonGenerateScenarios", testForm); + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (PipingSurfaceLineSelectionDialog) new FormTester(name).TheObject; + var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + selectionView.Rows[0].Cells[0].Value = true; + + // When + new ButtonTester("DoForSelectedButton", selectionDialog).Click(); + }; + + button.Click(); + + // Then + MacroStabilityInwardsCalculationScenario[] macroStabilityInwardsCalculationScenarios = macroStabilityInwardsFailureMechanism.Calculations.OfType().ToArray(); + MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult1 = macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.SectionResults.First(); + MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult2 = macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.SectionResults.ElementAt(1); + + Assert.AreEqual(2, failureMechanismSectionResult1.GetCalculationScenarios(macroStabilityInwardsCalculationScenarios).Count()); + + foreach (MacroStabilityInwardsCalculationScenario calculationScenario in failureMechanismSectionResult1.GetCalculationScenarios(macroStabilityInwardsCalculationScenarios)) + { + Assert.IsInstanceOf(calculationScenario); + } + + CollectionAssert.IsEmpty(failureMechanismSectionResult2.GetCalculationScenarios(macroStabilityInwardsCalculationScenarios)); + } + } + + [Test] + public void GivenMacroStabilityInwardsCalculationsViewGenerateScenariosCancelButtonClicked_WhenDialogClosed_CalculationsNotUpdated() + { + // Given + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism = ConfigureSimpleFailureMechanism(); + + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = macroStabilityInwardsFailureMechanism; + macroStabilityInwardsCalculationsView.Data = macroStabilityInwardsFailureMechanism.CalculationsGroup; + + var button = new ButtonTester("buttonGenerateScenarios", testForm); + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (PipingSurfaceLineSelectionDialog) new FormTester(name).TheObject; + var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; + selectionView.Rows[0].Cells[0].Value = true; + + // When + new ButtonTester("CustomCancelButton", selectionDialog).Click(); + }; + + button.Click(); + + // Then + Assert.IsEmpty(macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.Calculations); + } + } + + [Test] + public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSoilModelAndNotify_ThenButtonDisabled() + { + // Given + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + // When + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, "path"); + failureMechanism.NotifyObservers(); + + // Then + var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + Assert.IsFalse(button.Enabled); + } + } + + [Test] + public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSurfaceLineAndNotify_ThenButtonDisabled() + { + // Given + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + // When + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine() + }, "path"); + failureMechanism.NotifyObservers(); + + // Then + var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + Assert.IsFalse(button.Enabled); + } + } + + [Test] + public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSurfaceLineAndSoilModelAndDoNotNotifyObservers_ThenButtonDisabled() + { + // Given + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + // When + const string arbitraryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine() + }, arbitraryFilePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, arbitraryFilePath); + + // Then + var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + Assert.IsFalse(button.Enabled); + } + } + + [Test] + public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSurfaceLineAndSoilModelAndNotifyObservers_ThenButtonEnabled() + { + // Given + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + // When + const string arbitraryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine() + }, arbitraryFilePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, arbitraryFilePath); + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.NotifyObservers(); + + // Then + var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + Assert.IsTrue(button.Enabled); + } + } + + [Test] + public void GivenFailureMechanismWithSurfaceLinesAndSoilModels_WhenSurfaceLinesAndSoilModelsClearedAndNotifyObservers_ThenButtonDisabled() + { + // Given + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + { + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + const string arbitraryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + new RingtoetsPipingSurfaceLine() + }, arbitraryFilePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel() + }, arbitraryFilePath); + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + // When + failureMechanism.SurfaceLines.Clear(); + failureMechanism.StochasticSoilModels.Clear(); + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.NotifyObservers(); + + // Then + var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + Assert.IsFalse(button.Enabled); + } + } + + [Test] + [TestCase(entryPointLColumnIndex, 6.6)] + [TestCase(entryPointLColumnIndex, 4.44)] + [TestCase(exitPointLColumnIndex, 2.22)] + [TestCase(exitPointLColumnIndex, 1.1)] + public void MacroStabilityInwardsCalculationsView_InvalidEntryOrExitPoint_ShowsErrorTooltip(int cellIndex, double newValue) + { + // Setup + var mocks = new MockRepository(); + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + ConfigureHydraulicBoundaryDatabase(assessmentSection); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailuremechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); + + var value = (RoundedDouble) newValue; + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection, failureMechanism, calculationGroup)) + { + var data = (CalculationGroup) macroStabilityInwardsCalculationView.Data; + var calculation = (MacroStabilityInwardsCalculationScenario) data.Children.First(); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[cellIndex].Value = value; + + // Assert + Assert.AreEqual("Het uittredepunt moet landwaarts van het intredepunt liggen.", dataGridView.Rows[0].ErrorText); + } + mocks.VerifyAll(); // No observer notified + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(entryPointLColumnIndex, -0.1)] + [TestCase(entryPointLColumnIndex, -1.0)] + [TestCase(exitPointLColumnIndex, 10.1)] + [TestCase(exitPointLColumnIndex, 11.0)] + public void MacroStabilityInwardsCalculationsView_EntryOrExitPointNotOnSurfaceLine_ShowsErrorToolTip(int cellIndex, double newValue) + { + // Setup + var mocks = new MockRepository(); + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + ConfigureHydraulicBoundaryDatabase(assessmentSection); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailuremechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection, failureMechanism, calculationGroup)) + { + var data = (CalculationGroup) macroStabilityInwardsCalculationView.Data; + var calculation = (MacroStabilityInwardsCalculationScenario) data.Children.First(); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[cellIndex].Value = (RoundedDouble) newValue; + + // Assert + const string expectedMessage = "Het gespecificeerde punt moet op het profiel liggen (bereik [0,0, 10,0])."; + Assert.AreEqual(expectedMessage, dataGridView.Rows[0].ErrorText); + } + mocks.VerifyAll(); // No observer notified + } + + [Test] + [TestCase(0)] + [TestCase(1)] + public void Selection_Always_ReturnsTheSelectedRowObject(int selectedRow) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection)) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + dataGridView.CurrentCell = dataGridView.Rows[selectedRow].Cells[0]; + + // Call + object selection = macroStabilityInwardsCalculationView.Selection; + + // Assert + Assert.IsInstanceOf(selection); + var dataRow = (MacroStabilityInwardsCalculationRow) dataGridView.Rows[selectedRow].DataBoundItem; + Assert.AreSame(dataRow.MacroStabilityInwardsCalculation, ((MacroStabilityInwardsInputContext) selection).MacroStabilityInwardsCalculation); + } + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void MacroStabilityInwardsCalculationsView_EditingNameViaDataGridView_ObserversCorrectlyNotified(bool useCalculationWithOutput) + { + // Setup + var mocks = new MockRepository(); + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + + calculationObserver.Expect(o => o.UpdateObserver()); + + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection)) + { + var data = (CalculationGroup) macroStabilityInwardsCalculationView.Data; + var calculation = (MacroStabilityInwardsCalculationScenario) data.Children.First(); + + if (useCalculationWithOutput) + { + calculation.Output = new TestPipingOutput(); + } + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[nameColumnIndex].Value = "New name"; + + // Assert + calculation.Output = null; + } + mocks.VerifyAll(); + } + + [Test] + [TestCase(stochasticSoilProfilesColumnIndex, null, true)] + [TestCase(stochasticSoilProfilesColumnIndex, null, false)] + [TestCase(selectableHydraulicBoundaryLocationsColumnIndex, null, true)] + [TestCase(selectableHydraulicBoundaryLocationsColumnIndex, null, false)] + [TestCase(dampingFactorExitMeanColumnIndex, 1.1, true)] + [TestCase(dampingFactorExitMeanColumnIndex, 1.1, false)] + [TestCase(phreaticLevelExitMeanColumnIndex, 1.1, true)] + [TestCase(phreaticLevelExitMeanColumnIndex, 1.1, false)] + [TestCase(entryPointLColumnIndex, 1.1, true)] + [TestCase(entryPointLColumnIndex, 1.1, false)] + [TestCase(exitPointLColumnIndex, 8.0, true)] + [TestCase(exitPointLColumnIndex, 8.0, false)] + public void MacroStabilityInwardsCalculationsView_EditingPropertyViaDataGridView_ObserversCorrectlyNotified( + int cellIndex, + object newValue, + bool useCalculationWithOutput) + { + // Setup + var mocks = new MockRepository(); + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + + if (useCalculationWithOutput) + { + DialogBoxHandler = (name, wnd) => + { + var tester = new MessageBoxTester(wnd); + tester.ClickOk(); + }; + + calculationObserver.Expect(o => o.UpdateObserver()); + } + + calculationInputObserver.Expect(o => o.UpdateObserver()); + + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailuremechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection, failureMechanism, calculationGroup)) + { + mocks.ReplayAll(); + + var data = (CalculationGroup) macroStabilityInwardsCalculationView.Data; + var calculation = (MacroStabilityInwardsCalculationScenario) data.Children[1]; + + if (useCalculationWithOutput) + { + calculation.Output = new TestPipingOutput(); + } + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[1].Cells[cellIndex].Value = newValue is double ? (RoundedDouble) (double) newValue : newValue; + + // Assert + calculation.Output = null; + } + mocks.VerifyAll(); + } + + [Test] + public void GivenMacroStabilityInwardsCalculationWithHydraulicLocation_WhenLocationManualDesignWaterLevel_SelectableHydraulicLocationReadonly() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection)) + { + var data = (CalculationGroup) macroStabilityInwardsCalculationView.Data; + var calculation = (MacroStabilityInwardsCalculationScenario) data.Children.First(); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Precondition + var currentCell = (DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[selectableHydraulicBoundaryLocationsColumnIndex]; + Assert.IsFalse(currentCell.ReadOnly); + + // When + calculation.InputParameters.UseAssessmentLevelManualInput = true; + calculation.InputParameters.NotifyObservers(); + + // Then + var currentCellUpdated = (DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[selectableHydraulicBoundaryLocationsColumnIndex]; + Assert.IsTrue(currentCellUpdated.ReadOnly); + + DataGridViewComboBoxCell.ObjectCollection hydraulicBoundaryLocationComboboxItems = currentCellUpdated.Items; + Assert.AreEqual(1, hydraulicBoundaryLocationComboboxItems.Count); + Assert.AreEqual("", hydraulicBoundaryLocationComboboxItems[0].ToString()); + } + mocks.VerifyAll(); + } + + [Test] + public void GivenMacroStabilityInwardsCalculationWithStochasticSoilProfile_WhenProbabilityChangesAndNotified_ThenNewProbabilityVisible() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection)) + { + var data = (CalculationGroup) macroStabilityInwardsCalculationView.Data; + var calculation = (MacroStabilityInwardsCalculationScenario) data.Children[1]; + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + var refreshed = 0; + + // Precondition + var currentCell = (DataGridViewTextBoxCell) dataGridView.Rows[1].Cells[stochasticSoilProfilesProbabilityColumnIndex]; + Assert.AreEqual("30", currentCell.FormattedValue); + + StochasticSoilProfile stochasticSoilProfileToChange = calculation.InputParameters.StochasticSoilProfile; + var updatedProfile = new StochasticSoilProfile( + 0.5, + stochasticSoilProfileToChange.SoilProfileType, + stochasticSoilProfileToChange.SoilProfileId) + { + SoilProfile = stochasticSoilProfileToChange.SoilProfile + }; + dataGridView.Invalidated += (sender, args) => refreshed++; + + // When + stochasticSoilProfileToChange.Update(updatedProfile); + stochasticSoilProfileToChange.NotifyObservers(); + + // Then + Assert.AreEqual(1, refreshed); + var cell = (DataGridViewTextBoxCell) dataGridView.Rows[1].Cells[stochasticSoilProfilesProbabilityColumnIndex]; + Assert.AreEqual("50", cell.FormattedValue); + } + mocks.VerifyAll(); + } + + [Test] + public void GivenMacroStabilityInwardsCalculationViewWithCalculations_WhenSurfaceLineLocatedOutsideSectionAfterUpdateAndObserversNotified_ThenDataGridViewUpdated() + { + // Given + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + assessmentSection)) + { + var data = (CalculationGroup) macroStabilityInwardsCalculationView.Data; + var calculation = (MacroStabilityInwardsCalculationScenario) data.Children[0]; + + DataGridViewControl dataGridView = macroStabilityInwardsCalculationView.Controls.Find("dataGridViewControl", true).OfType().First(); + ListBox listBox = macroStabilityInwardsCalculationView.Controls.Find("listBox", true).OfType().First(); + + // Precondition + listBox.SelectedIndex = 0; + Assert.AreEqual(2, dataGridView.Rows.Count); + Assert.AreEqual("Calculation 1", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("Calculation 2", dataGridView.Rows[1].Cells[nameColumnIndex].FormattedValue); + + listBox.SelectedIndex = 1; + Assert.AreEqual(1, dataGridView.Rows.Count); + Assert.AreEqual("Calculation 2", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + + RingtoetsPipingSurfaceLine surfaceLineToChange = calculation.InputParameters.SurfaceLine; + var updatedSurfaceLine = new RingtoetsPipingSurfaceLine + { + Name = surfaceLineToChange.Name, + ReferenceLineIntersectionWorldPoint = new Point2D(9.0, 0.0) + }; + updatedSurfaceLine.SetGeometry(new[] + { + new Point3D(9.0, 5.0, 0.0), + new Point3D(9.0, 0.0, 1.0), + new Point3D(9.0, -5.0, 0.0) + }); + + // When + surfaceLineToChange.CopyProperties(updatedSurfaceLine); + surfaceLineToChange.NotifyObservers(); + + // Then + listBox.SelectedIndex = 0; + Assert.AreEqual(1, dataGridView.Rows.Count); + Assert.AreEqual("Calculation 2", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + + listBox.SelectedIndex = 1; + Assert.AreEqual(2, dataGridView.Rows.Count); + Assert.AreEqual("Calculation 1", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("Calculation 2", dataGridView.Rows[1].Cells[nameColumnIndex].FormattedValue); + } + mocks.VerifyAll(); + } + + private MacroStabilityInwardsCalculationsView ShowFullyConfiguredMacroStabilityInwardsCalculationsView( + IAssessmentSection assessmentSection) + { + ConfigureHydraulicBoundaryDatabase(assessmentSection); + + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailuremechanism(); + + return ShowFullyConfiguredMacroStabilityInwardsCalculationsView(assessmentSection, + failureMechanism, + ConfigureCalculationGroup(assessmentSection, failureMechanism)); + } + + private MacroStabilityInwardsCalculationsView ShowFullyConfiguredMacroStabilityInwardsCalculationsView(IAssessmentSection assessmentSection, + MacroStabilityInwardsFailureMechanism failureMechanism, + CalculationGroup calculationGroup) + { + MacroStabilityInwardsCalculationsView view = ShowMacroStabilityInwardsCalculationsView(); + view.Data = calculationGroup; + view.AssessmentSection = assessmentSection; + view.MacroStabilityInwardsFailureMechanism = failureMechanism; + + return view; + } + + private static void ConfigureHydraulicBoundaryDatabase(IAssessmentSection assessmentSection) + { + var hydraulicBoundaryLocation1 = new HydraulicBoundaryLocation(1, "Location 1", 1.1, 2.2); + var hydraulicBoundaryLocation2 = new HydraulicBoundaryLocation(2, "Location 2", 3.3, 4.4); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation1); + hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation2); + assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + } + + private MacroStabilityInwardsCalculationsView ShowSimpleMacroStabilityInwardsCalculationsViewWithSurfaceLines(IAssessmentSection assessmentSection) + { + var surfaceLine1 = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 1", + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + + surfaceLine1.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + + var surfaceLine2 = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 2", + ReferenceLineIntersectionWorldPoint = new Point2D(5.0, 0.0) + }; + + surfaceLine2.SetGeometry(new[] + { + new Point3D(5.0, 5.0, 0.0), + new Point3D(5.0, 0.0, 1.0), + new Point3D(5.0, -5.0, 0.0) + }); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine1, + surfaceLine2 + }, "path"); + + failureMechanism.AddSection(new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + })); + + failureMechanism.AddSection(new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + })); + + MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView(); + + macroStabilityInwardsCalculationsView.Data = new CalculationGroup("Group", true) + { + Children = + { + new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation 1", + InputParameters = + { + SurfaceLine = surfaceLine1 + } + }, + new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation 2", + InputParameters = + { + SurfaceLine = surfaceLine2 + } + } + } + }; + + macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + return macroStabilityInwardsCalculationsView; + } + + private MacroStabilityInwardsCalculationsView ShowSimpleMacroStabilityInwardsCalculationsViewWithoutSurfaceLines(IAssessmentSection assessmentSection, + HydraulicBoundaryDatabase hydraulicBoundaryDatabase) + { + var hydraulicBoundaryLocation1 = new HydraulicBoundaryLocation(1, "Location 1", 1.1, 2.2); + var hydraulicBoundaryLocation2 = new HydraulicBoundaryLocation(2, "Location 2", 3.3, 4.4); + + assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation1); + hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation2); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + })); + + failureMechanism.AddSection(new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + })); + + MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView(); + + macroStabilityInwardsCalculationsView.Data = new CalculationGroup("Group", true) + { + Children = + { + new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation 1", + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation1 + } + }, + new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation 2", + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation2 + } + } + } + }; + + macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; + macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + return macroStabilityInwardsCalculationsView; + } + + private static MacroStabilityInwardsFailureMechanism ConfigureSimpleFailureMechanism() + { + var surfaceLine1 = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 1", + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + + surfaceLine1.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + + var surfaceLine2 = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 2", + ReferenceLineIntersectionWorldPoint = new Point2D(5.0, 0.0) + }; + + surfaceLine2.SetGeometry(new[] + { + new Point3D(5.0, 5.0, 0.0), + new Point3D(5.0, 0.0, 1.0), + new Point3D(5.0, -5.0, 0.0) + }); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + const string arbirtraryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine1, + surfaceLine2 + }, arbirtraryFilePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + new TestStochasticSoilModel + { + Geometry = + { + new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) + } + } + }, arbirtraryFilePath); + + failureMechanism.AddSection(new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + })); + + failureMechanism.AddSection(new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + })); + + return failureMechanism; + } + + private static CalculationGroup ConfigureCalculationGroup(IAssessmentSection assessmentSection, MacroStabilityInwardsFailureMechanism failureMechanism) + { + StochasticSoilModel stochasticSoilModelForCalculation2 = failureMechanism.StochasticSoilModels.Last(); + return new CalculationGroup("Group", true) + { + Children = + { + new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation 1", + InputParameters = + { + SurfaceLine = failureMechanism.SurfaceLines.First(), + StochasticSoilModel = failureMechanism.StochasticSoilModels.First(), + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(), + DampingFactorExit = + { + Mean = (RoundedDouble) 1.1111 + }, + PhreaticLevelExit = + { + Mean = (RoundedDouble) 2.2222 + }, + EntryPointL = (RoundedDouble) 3.3333, + ExitPointL = (RoundedDouble) 4.4444 + } + }, + new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation 2", + InputParameters = + { + SurfaceLine = failureMechanism.SurfaceLines.Last(), + StochasticSoilModel = stochasticSoilModelForCalculation2, + StochasticSoilProfile = stochasticSoilModelForCalculation2.StochasticSoilProfiles.First(), + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.Last(), + DampingFactorExit = + { + Mean = (RoundedDouble) 5.5555 + }, + PhreaticLevelExit = + { + Mean = (RoundedDouble) 6.6666 + }, + EntryPointL = (RoundedDouble) 7.7777, + ExitPointL = (RoundedDouble) 8.8888 + } + } + } + }; + } + + private static MacroStabilityInwardsFailureMechanism ConfigureFailuremechanism() + { + var surfaceLine1 = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 1", + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + + surfaceLine1.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + + var surfaceLine2 = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 2", + ReferenceLineIntersectionWorldPoint = new Point2D(5.0, 0.0) + }; + + surfaceLine2.SetGeometry(new[] + { + new Point3D(5.0, 5.0, 0.0), + new Point3D(5.0, 0.0, 1.0), + new Point3D(5.0, -5.0, 0.0) + }); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + const string arbitraryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine1, + surfaceLine2 + }, arbitraryFilePath); + + failureMechanism.AddSection(new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + })); + + failureMechanism.AddSection(new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + })); + + var stochasticSoilProfile1 = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }; + + var stochasticSoilModelA = new StochasticSoilModel(1, "Model A", "Model B") + { + Geometry = + { + new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) + }, + StochasticSoilProfiles = + { + stochasticSoilProfile1, + new StochasticSoilProfile(0.7, SoilProfileType.SoilProfile1D, 2) + { + SoilProfile = new PipingSoilProfile("Profile 2", -8.0, new[] + { + new PipingSoilLayer(-4.0), + new PipingSoilLayer(0.0), + new PipingSoilLayer(4.0) + }, SoilProfileType.SoilProfile1D, 2) + } + } + }; + + var stochasticSoilProfile5 = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 5", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }; + + var stochasticSoilModelE = new StochasticSoilModel(1, "Model E", "Model F") + { + Geometry = + { + new Point2D(1.0, 0.0), new Point2D(6.0, 0.0) + }, + StochasticSoilProfiles = + { + stochasticSoilProfile5 + } + }; + + failureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModelA, + new StochasticSoilModel(1, "Model C", "Model D") + { + Geometry = + { + new Point2D(1.0, 0.0), new Point2D(4.0, 0.0) + }, + StochasticSoilProfiles = + { + new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 3", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }, + new StochasticSoilProfile(0.7, SoilProfileType.SoilProfile1D, 2) + { + SoilProfile = new PipingSoilProfile("Profile 4", -8.0, new[] + { + new PipingSoilLayer(-4.0), + new PipingSoilLayer(0.0), + new PipingSoilLayer(4.0) + }, SoilProfileType.SoilProfile1D, 2) + } + } + }, + stochasticSoilModelE + }, arbitraryFilePath); + return failureMechanism; + } + + private MacroStabilityInwardsCalculationsView ShowMacroStabilityInwardsCalculationsView() + { + var calculationsView = new MacroStabilityInwardsCalculationsView(); + + testForm.Controls.Add(calculationsView); + testForm.Show(); + + return calculationsView; + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismResultViewTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismResultViewTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsFailureMechanismResultViewTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,517 @@ +// Copyright (C) Stichting Deltares 2017. 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.Data; +using Core.Common.Base.Geometry; +using Core.Common.Controls.Views; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Forms.Views; + +namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views +{ + [TestFixture] + public class MacroStabilityInwardsFailureMechanismResultViewTest + { + private const int nameColumnIndex = 0; + private const int assessmentLayerOneIndex = 1; + private const int assessmentLayerTwoAIndex = 2; + private const int assessmentLayerThreeIndex = 3; + private Form testForm; + + [SetUp] + public void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + + [Test] + public void DefaultConstructor_DefaultValues() + { + // Call + using (var view = new MacroStabilityInwardsFailureMechanismResultView()) + { + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNull(view.Data); + } + } + + [Test] + public void Constructor_DataGridViewCorrectlyInitialized() + { + // Call + using (ShowFailureMechanismResultsView()) + { + // Assert + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + Assert.AreEqual(4, dataGridView.ColumnCount); + Assert.IsTrue(dataGridView.Columns[assessmentLayerTwoAIndex].ReadOnly); + Assert.IsInstanceOf(dataGridView.Columns[assessmentLayerOneIndex]); + Assert.IsInstanceOf(dataGridView.Columns[assessmentLayerTwoAIndex]); + Assert.IsInstanceOf(dataGridView.Columns[assessmentLayerThreeIndex]); + + Assert.AreEqual("Toetslaag 1", dataGridView.Columns[assessmentLayerOneIndex].HeaderText); + Assert.AreEqual("Toetslaag 2a", dataGridView.Columns[assessmentLayerTwoAIndex].HeaderText); + Assert.AreEqual("Toetslaag 3", dataGridView.Columns[assessmentLayerThreeIndex].HeaderText); + + Assert.AreEqual(DataGridViewAutoSizeColumnsMode.AllCells, dataGridView.AutoSizeColumnsMode); + Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, dataGridView.ColumnHeadersDefaultCellStyle.Alignment); + } + } + + [Test] + public void Data_DataAlreadySetNewDataSet_DataSetAndDataGridViewUpdated() + { + // Setup + using (MacroStabilityInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView(new MacroStabilityInwardsFailureMechanism())) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + var points = new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }; + + var section = new FailureMechanismSection("test", points); + var sectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + var testData = new List + { + sectionResult + }; + + // Precondition + Assert.AreEqual(2, dataGridView.RowCount); + + // Call + view.Data = testData; + + // Assert + Assert.AreSame(testData, view.Data); + + Assert.AreEqual(testData.Count, dataGridView.RowCount); + Assert.AreEqual(sectionResult.Section.Name, dataGridView.Rows[0].Cells[0].Value); + } + } + + [Test] + public void Data_SetOtherThanFailureMechanismSectionResultListData_DataNullAndEmptyGrid() + { + // Setup + var testData = new object(); + using (MacroStabilityInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView(new MacroStabilityInwardsFailureMechanism())) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + view.Data = testData; + + // Assert + Assert.IsNull(view.Data); + + Assert.AreEqual(0, dataGridView.RowCount); + } + } + + [Test] + public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized() + { + // Setup & Call + using (ShowFullyConfiguredFailureMechanismResultsView(new MacroStabilityInwardsFailureMechanism())) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Assert + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(2, rows.Count); + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(AssessmentLayerOneState.NotAssessed, cells[assessmentLayerOneIndex].Value); + Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("-", cells[assessmentLayerThreeIndex].FormattedValue); + + cells = rows[1].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("Section 2", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(AssessmentLayerOneState.NotAssessed, cells[assessmentLayerOneIndex].Value); + Assert.AreEqual("-", cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("-", cells[assessmentLayerThreeIndex].FormattedValue); + } + } + + [Test] + [TestCase(AssessmentLayerOneState.NotAssessed)] + [TestCase(AssessmentLayerOneState.NoVerdict)] + [TestCase(AssessmentLayerOneState.Sufficient)] + public void FailureMechanismResultsView_ChangeCheckBox_DataGridViewCorrectlySyncedAndStylingSet( + AssessmentLayerOneState assessmentLayerOneState) + { + // Setup + using (ShowFullyConfiguredFailureMechanismResultsView(new MacroStabilityInwardsFailureMechanism())) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + dataGridView.Rows[0].Cells[assessmentLayerOneIndex].Value = assessmentLayerOneState; + + // Assert + DataGridViewRowCollection rows = dataGridView.Rows; + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); + DataGridViewCell cellAssessmentLayerTwoA = cells[assessmentLayerTwoAIndex]; + DataGridViewCell cellAssessmentLayerThree = cells[assessmentLayerThreeIndex]; + + Assert.AreEqual(assessmentLayerOneState, cells[assessmentLayerOneIndex].Value); + Assert.AreEqual("-", cellAssessmentLayerTwoA.FormattedValue); + Assert.AreEqual("-", cellAssessmentLayerThree.FormattedValue); + + if (assessmentLayerOneState == AssessmentLayerOneState.Sufficient) + { + DataGridViewTestHelper.AssertCellIsDisabled(cellAssessmentLayerTwoA); + DataGridViewTestHelper.AssertCellIsDisabled(cellAssessmentLayerThree); + + Assert.IsTrue(cellAssessmentLayerThree.ReadOnly); + } + else + { + DataGridViewTestHelper.AssertCellIsEnabled(cellAssessmentLayerTwoA, true); + DataGridViewTestHelper.AssertCellIsEnabled(cellAssessmentLayerThree); + + Assert.IsFalse(cellAssessmentLayerThree.ReadOnly); + } + } + } + + [Test] + [TestCase("test", assessmentLayerThreeIndex)] + [TestCase(";/[].,~!@#$%^&*()_-+={}|?", assessmentLayerThreeIndex)] + public void FailureMechanismResultView_EditValueInvalid_ShowsErrorTooltip(string newValue, int cellIndex) + { + // Setup + using (ShowFullyConfiguredFailureMechanismResultsView(new MacroStabilityInwardsFailureMechanism())) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[cellIndex].Value = newValue; + + // Assert + Assert.AreEqual("De tekst moet een getal zijn.", dataGridView.Rows[0].ErrorText); + } + } + + [Test] + [TestCase("1")] + [TestCase("1e-6")] + [TestCase("1e+6")] + [TestCase("14.3")] + public void FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(string newValue) + { + // Setup + using (MacroStabilityInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView(new MacroStabilityInwardsFailureMechanism())) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[assessmentLayerThreeIndex].Value = newValue; + + // Assert + Assert.IsEmpty(dataGridView.Rows[0].ErrorText); + + var dataObject = view.Data as List; + Assert.IsNotNull(dataObject); + MacroStabilityInwardsFailureMechanismSectionResult row = dataObject.First(); + + const string propertyName = "AssessmentLayerThree"; + object propertyValue = row.GetType().GetProperty(propertyName).GetValue(row, null); + + Assert.AreEqual((RoundedDouble) double.Parse(newValue), propertyValue); + } + } + + [Test] + [TestCase(AssessmentLayerOneState.NotAssessed)] + [TestCase(AssessmentLayerOneState.NoVerdict)] + public void FailureMechanismResultView_TotalContributionNotHundred_ShowsErrorTooltip( + AssessmentLayerOneState assessmentLayerOneState) + { + // Setup + const int rowIndex = 0; + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (MacroStabilityInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView(failureMechanism)) + { + MacroStabilityInwardsCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreatePipingCalculationScenario( + 1.0 / 1000.0, + failureMechanism.Sections.First()); + calculationScenario.Contribution = (RoundedDouble) 0.3; + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + view.Data = failureMechanism.SectionResults; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[assessmentLayerTwoAIndex]; + dataGridView.Rows[rowIndex].Cells[assessmentLayerOneIndex].Value = assessmentLayerOneState; + + // Call + object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("Bijdrage van de geselecteerde scenario's voor dit vak moet opgeteld gelijk zijn aan 100%.", + dataGridViewCell.ErrorText); + Assert.AreEqual("-", formattedValue); + } + } + + [Test] + [TestCase(AssessmentLayerOneState.NotAssessed)] + [TestCase(AssessmentLayerOneState.NoVerdict)] + public void FailureMechanismResultView_AssessmentLayerTwoAHasValue_DoesNotShowsErrorTooltip( + AssessmentLayerOneState assessmentLayerOneState) + { + // Setup + const int rowIndex = 0; + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (MacroStabilityInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView(failureMechanism)) + { + MacroStabilityInwardsCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreatePipingCalculationScenario( + (RoundedDouble) 1e-3, + failureMechanism.Sections.First()); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + view.Data = failureMechanism.SectionResults; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[assessmentLayerTwoAIndex]; + dataGridView.Rows[rowIndex].Cells[assessmentLayerOneIndex].Value = assessmentLayerOneState; + + // Call + object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.IsEmpty(dataGridViewCell.ErrorText); + Assert.AreEqual(string.Format("1/{0:N0}", 1 / calculationScenario.Probability), + formattedValue); + } + } + + [Test] + [TestCase(AssessmentLayerOneState.NotAssessed)] + [TestCase(AssessmentLayerOneState.NoVerdict)] + public void FailureMechanismResultView_AssessmentLayerTwoANull_ShowsErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) + { + // Setup + const int rowIndex = 0; + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (ShowFullyConfiguredFailureMechanismResultsView(failureMechanism)) + { + MacroStabilityInwardsCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreateNotCalculatedPipingCalculationScenario( + failureMechanism.Sections.First()); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[assessmentLayerTwoAIndex]; + dataGridView.Rows[rowIndex].Cells[assessmentLayerOneIndex].Value = assessmentLayerOneState; + + // Call + object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", + dataGridViewCell.ErrorText); + Assert.AreEqual("-", formattedValue); + } + } + + [Test] + [TestCase(AssessmentLayerOneState.NotAssessed)] + [TestCase(AssessmentLayerOneState.NoVerdict)] + public void FailureMechanismResultView_AssessmentLayerTwoANaN_ShowsErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) + { + // Setup + const int rowIndex = 0; + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (MacroStabilityInwardsFailureMechanismResultView view = ShowFullyConfiguredFailureMechanismResultsView(failureMechanism)) + { + MacroStabilityInwardsCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreateFailedPipingCalculationScenario( + failureMechanism.Sections.First()); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + view.Data = failureMechanism.SectionResults; + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[assessmentLayerTwoAIndex]; + dataGridView.Rows[rowIndex].Cells[assessmentLayerOneIndex].Value = assessmentLayerOneState; + + // Call + object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("Alle berekeningen voor dit vak moeten een geldige uitkomst hebben.", + dataGridViewCell.ErrorText); + Assert.AreEqual("-", formattedValue); + } + } + + [Test] + [TestCase(AssessmentLayerOneState.NotAssessed)] + [TestCase(AssessmentLayerOneState.NoVerdict)] + public void FailureMechanismResultView_NoCalculationScenarios_ShowsErrorTooltip(AssessmentLayerOneState assessmentLayerOneState) + { + // Setup + const int rowIndex = 0; + + using (ShowFullyConfiguredFailureMechanismResultsView(new MacroStabilityInwardsFailureMechanism())) + { + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[assessmentLayerTwoAIndex]; + dataGridView.Rows[rowIndex].Cells[assessmentLayerOneIndex].Value = assessmentLayerOneState; + + // Call + object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("Er moet minimaal één maatgevende berekening voor dit vak worden geselecteerd.", + dataGridViewCell.ErrorText); + Assert.AreEqual("-", formattedValue); + } + } + + [Test] + [TestCase(AssessmentLayerOneState.NotAssessed)] + [TestCase(AssessmentLayerOneState.NoVerdict)] + public void FailureMechanismResultView_NoCalculationScenariosRelevant_ShowsErrorTooltip( + AssessmentLayerOneState assessmentLayerOneState) + { + // Setup + const int rowIndex = 0; + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (ShowFullyConfiguredFailureMechanismResultsView(failureMechanism)) + { + MacroStabilityInwardsCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreateIrrelevantPipingCalculationScenario( + failureMechanism.Sections.First()); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[assessmentLayerTwoAIndex]; + dataGridView.Rows[rowIndex].Cells[assessmentLayerOneIndex].Value = assessmentLayerOneState; + + // Call + object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual("Er moet minimaal één maatgevende berekening voor dit vak worden geselecteerd.", + dataGridViewCell.ErrorText); + Assert.AreEqual("-", formattedValue); + } + } + + [Test] + public void FailureMechanismResultView_AssessmentLayerOneStateSufficientAndAssessmentLayerTwoAHasError_DoesNotShowError() + { + // Setup + const int rowIndex = 0; + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (ShowFullyConfiguredFailureMechanismResultsView(failureMechanism)) + { + MacroStabilityInwardsCalculationScenario calculationScenario = PipingCalculationScenarioFactory.CreateFailedPipingCalculationScenario( + failureMechanism.Sections.First()); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView) gridTester.TheObject; + + DataGridViewCell dataGridViewCell = dataGridView.Rows[rowIndex].Cells[assessmentLayerTwoAIndex]; + + // Call + dataGridView.Rows[rowIndex].Cells[assessmentLayerOneIndex].Value = AssessmentLayerOneState.Sufficient; + object formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.IsEmpty(dataGridViewCell.ErrorText); + Assert.AreEqual("-", formattedValue); + } + } + + private MacroStabilityInwardsFailureMechanismResultView ShowFullyConfiguredFailureMechanismResultsView(MacroStabilityInwardsFailureMechanism failureMechanism) + { + failureMechanism.AddSection(new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + })); + + failureMechanism.AddSection(new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + })); + + MacroStabilityInwardsFailureMechanismResultView failureMechanismResultView = ShowFailureMechanismResultsView(); + failureMechanismResultView.Data = failureMechanism.SectionResults; + failureMechanismResultView.FailureMechanism = failureMechanism; + + return failureMechanismResultView; + } + + private MacroStabilityInwardsFailureMechanismResultView ShowFailureMechanismResultsView() + { + var failureMechanismResultView = new MacroStabilityInwardsFailureMechanismResultView(); + testForm.Controls.Add(failureMechanismResultView); + testForm.Show(); + + return failureMechanismResultView; + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsInputViewTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsInputViewTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsInputViewTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,927 @@ +// Copyright (C) Stichting Deltares 2017. 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.Base.Geometry; +using Core.Components.Charting.Data; +using Core.Components.Charting.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views +{ + [TestFixture] + public class MacroStabilityInwardsInputViewTest + { + private const int soilProfileIndex = 0; + private const int surfaceLineIndex = 1; + private const int ditchPolderSideIndex = 2; + private const int bottomDitchPolderSideIndex = 3; + private const int bottomDitchDikeSideIndex = 4; + private const int ditchDikeSideIndex = 5; + private const int dikeToeAtPolderIndex = 6; + private const int dikeToeAtRiverIndex = 7; + private const int exitPointIndex = 8; + private const int entryPointIndex = 9; + + [Test] + public void DefaultConstructor_DefaultValues() + { + // Call + using (var view = new MacroStabilityInwardsInputView()) + { + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNotNull(view.Chart); + Assert.IsNull(view.Data); + Assert.AreEqual(2, view.Controls.Count); + } + } + + [Test] + public void DefaultConstructor_Always_AddEmptyChartControl() + { + // Call + using (var view = new MacroStabilityInwardsInputView()) + { + // Assert + var chartControl = (IChartControl) view.Controls.Find("chartControl", true).First(); + Assert.IsInstanceOf(chartControl); + Assert.AreSame(chartControl, chartControl); + Assert.AreEqual(DockStyle.Fill, ((Control) chartControl).Dock); + Assert.AreEqual("Afstand [m]", chartControl.BottomAxisTitle); + Assert.AreEqual("Hoogte [m+NAP]", chartControl.LeftAxisTitle); + Assert.IsNull(chartControl.Data); + } + } + + [Test] + public void DefaultConstructor_Always_AddEmptyTableControl() + { + // Call + using (var view = new MacroStabilityInwardsInputView()) + { + // Assert + var tableControl = (MacroStabilityInwardsSoilLayerTable) view.Controls.Find("soilLayerTable", true).First(); + Assert.NotNull(tableControl); + Assert.AreEqual(DockStyle.Bottom, tableControl.Dock); + CollectionAssert.IsEmpty(tableControl.Rows); + } + } + + [Test] + public void Data_CalculationScenario_DataSet() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + // Call + view.Data = calculation; + + // Assert + Assert.AreSame(calculation, view.Data); + } + } + + [Test] + public void Data_OtherThanCalculationScenario_DataNull() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + var data = new object(); + + // Call + view.Data = data; + + // Assert + Assert.IsNull(view.Data); + } + } + + [Test] + public void Data_SetToNull_ChartDataCleared() + { + // Setup + using (var view = new MacroStabilityInwardsInputView + { + Data = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + }) + { + // Precondition + Assert.AreEqual(10, view.Chart.Data.Collection.Count()); + Assert.AreEqual("Nieuwe berekening", view.Chart.ChartTitle); + + // Call + view.Data = null; + + // Assert + Assert.IsNull(view.Data); + Assert.IsNull(view.Chart.Data); + Assert.AreEqual(string.Empty, view.Chart.ChartTitle); + } + } + + [Test] + public void Data_SetToNull_TableDataCleared() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + StochasticSoilProfile = new StochasticSoilProfile(0.1, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile( + "profile", + -1, + new[] + { + new PipingSoilLayer(3.0), + new PipingSoilLayer(2.0), + new PipingSoilLayer(0) + }, + SoilProfileType.SoilProfile1D, + 1) + } + } + }; + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + var tableControl = view.Controls.Find("soilLayerTable", true).First() as MacroStabilityInwardsSoilLayerTable; + + // Precondition + Assert.NotNull(tableControl); + Assert.AreEqual(3, tableControl.Rows.Count); + + // Call + view.Data = null; + + // Assert + Assert.IsNull(view.Data); + CollectionAssert.IsEmpty(tableControl.Rows); + } + } + + [Test] + public void Data_WithSurfaceLineAndSoilProfile_DataUpdatedToCollectionOfFilledChartData() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + RingtoetsPipingSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); + surfaceLine.SetDitchDikeSideAt(new Point3D(1.2, 2.3, 4.0)); + surfaceLine.SetBottomDitchDikeSideAt(new Point3D(1.2, 2.3, 4.0)); + surfaceLine.SetDitchPolderSideAt(new Point3D(1.2, 2.3, 4.0)); + surfaceLine.SetBottomDitchPolderSideAt(new Point3D(1.2, 2.3, 4.0)); + surfaceLine.SetDikeToeAtPolderAt(new Point3D(1.2, 2.3, 4.0)); + surfaceLine.SetDikeToeAtRiverAt(new Point3D(1.2, 2.3, 4.0)); + + StochasticSoilProfile stochasticSoilProfile = GetStochasticSoilProfile(); + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + StochasticSoilProfile = stochasticSoilProfile + } + }; + + // Call + view.Data = calculation; + + // Assert + Assert.AreSame(calculation, view.Data); + ChartDataCollection chartData = view.Chart.Data; + Assert.IsInstanceOf(chartData); + Assert.AreEqual(10, chartData.Collection.Count()); + AssertSoilProfileChartData(stochasticSoilProfile, chartData.Collection.ElementAt(soilProfileIndex), true); + AssertSurfaceLineChartData(surfaceLine, chartData.Collection.ElementAt(surfaceLineIndex)); + AssertEntryPointLPointchartData(calculation.InputParameters, surfaceLine, chartData.Collection.ElementAt(entryPointIndex)); + AssertExitPointLPointchartData(calculation.InputParameters, surfaceLine, chartData.Collection.ElementAt(exitPointIndex)); + AssertCharacteristicPoints(surfaceLine, chartData.Collection.ToList()); + } + } + + [Test] + public void Data_WithoutSurfaceLine_NoChartDataSet() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + // Call + view.Data = calculation; + + // Assert + AssertEmptyChartData(view.Chart.Data); + } + } + + [Test] + public void Data_WithSurfaceLineWithoutStochasticSoilProfile_CollectionOfEmptyChartDataSetForSoilProfile() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + RingtoetsPipingSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + // Call + view.Data = calculation; + + // Assert + Assert.AreSame(calculation, view.Data); + ChartDataCollection chartData = view.Chart.Data; + Assert.IsInstanceOf(chartData); + Assert.AreEqual(10, chartData.Collection.Count()); + var soilProfileData = (ChartDataCollection) chartData.Collection.ElementAt(soilProfileIndex); + CollectionAssert.IsEmpty(soilProfileData.Collection); + Assert.AreEqual("Ondergrondschematisatie", soilProfileData.Name); + } + } + + [Test] + public void Data_WithSurfaceLineWithoutSoilProfile_CollectionOfEmptyChartDataSetForSoilProfile() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + RingtoetsPipingSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + StochasticSoilProfile = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 1) + } + }; + + // Call + view.Data = calculation; + + // Assert + Assert.AreSame(calculation, view.Data); + ChartDataCollection chartData = view.Chart.Data; + Assert.IsInstanceOf(chartData); + Assert.AreEqual(10, chartData.Collection.Count()); + var soilProfileData = (ChartDataCollection) chartData.Collection.ElementAt(soilProfileIndex); + CollectionAssert.IsEmpty(soilProfileData.Collection); + Assert.AreEqual("Ondergrondschematisatie", soilProfileData.Name); + } + } + + [Test] + public void Data_WithoutStochasticSoilProfile_SoilLayerTableEmpty() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + // Call + view.Data = calculation; + + // Assert + AssertEmtpySoilLayerTable(view); + } + } + + [Test] + public void Data_WithoutSoilProfile_SoilLayerTableEmpty() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + StochasticSoilProfile = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 1) + } + }; + + // Call + view.Data = calculation; + + // Assert + AssertEmtpySoilLayerTable(view); + } + } + + [Test] + public void UpdateObserver_CalculationNameUpdated_ChartTitleUpdated() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + const string initialName = "Initial name"; + const string updatedName = "Updated name"; + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = initialName + }; + + view.Data = calculation; + + // Precondition + Assert.AreEqual(initialName, view.Chart.ChartTitle); + + calculation.Name = updatedName; + + // Call + calculation.NotifyObservers(); + + // Assert + Assert.AreEqual(updatedName, view.Chart.ChartTitle); + } + } + + [Test] + public void UpdateObserver_OtherCalculationUpdated_ChartTitleNotUpdated() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + const string initialName = "Initial name"; + const string updatedName = "Updated name"; + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = initialName + }; + + view.Data = calculation; + + // Precondition + Assert.AreEqual(initialName, view.Chart.ChartTitle); + + var calculation2 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = initialName + }; + + view.Data = calculation2; + + calculation.Name = updatedName; + + // Call + calculation.NotifyObservers(); + + // Assert + Assert.AreEqual(initialName, view.Chart.ChartTitle); + } + } + + [Test] + public void UpdateObserver_CalculationSurfaceLineUpdated_ChartDataUpdated() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()).Repeat.Times(9); + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsInputView()) + { + var characteristicPoint = new Point3D(1.2, 2.3, 4.0); + RingtoetsPipingSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); + + surfaceLine.SetDitchDikeSideAt(characteristicPoint); + surfaceLine.SetBottomDitchDikeSideAt(characteristicPoint); + surfaceLine.SetDitchPolderSideAt(characteristicPoint); + surfaceLine.SetBottomDitchPolderSideAt(characteristicPoint); + surfaceLine.SetDikeToeAtPolderAt(characteristicPoint); + surfaceLine.SetDikeToeAtRiverAt(characteristicPoint); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + view.Data = calculation; + + List chartDataList = view.Chart.Data.Collection.ToList(); + var surfaceLineChartData = (ChartLineData) chartDataList[surfaceLineIndex]; + var entryPointChartData = (ChartPointData) chartDataList[entryPointIndex]; + var exitPointChartData = (ChartPointData) chartDataList[exitPointIndex]; + var ditchDikeSideData = (ChartPointData) chartDataList[ditchDikeSideIndex]; + var bottomDitchDikeSideData = (ChartPointData) chartDataList[bottomDitchDikeSideIndex]; + var ditchPolderSideData = (ChartPointData) chartDataList[ditchPolderSideIndex]; + var bottomDitchPolderSideData = (ChartPointData) chartDataList[bottomDitchPolderSideIndex]; + var dikeToeAtPolderData = (ChartPointData) chartDataList[dikeToeAtPolderIndex]; + var dikeToeAtRiverData = (ChartPointData) chartDataList[dikeToeAtRiverIndex]; + + surfaceLineChartData.Attach(observer); + entryPointChartData.Attach(observer); + exitPointChartData.Attach(observer); + ditchDikeSideData.Attach(observer); + bottomDitchDikeSideData.Attach(observer); + ditchPolderSideData.Attach(observer); + bottomDitchPolderSideData.Attach(observer); + dikeToeAtPolderData.Attach(observer); + dikeToeAtRiverData.Attach(observer); + + var characteristicPoint2 = new Point3D(3.5, 2.3, 8.0); + RingtoetsPipingSurfaceLine surfaceLine2 = GetSecondSurfaceLineWithGeometry(); + + surfaceLine2.SetDitchDikeSideAt(characteristicPoint2); + surfaceLine2.SetBottomDitchDikeSideAt(characteristicPoint2); + surfaceLine2.SetDitchPolderSideAt(characteristicPoint2); + surfaceLine2.SetBottomDitchPolderSideAt(characteristicPoint2); + surfaceLine2.SetDikeToeAtPolderAt(characteristicPoint2); + surfaceLine2.SetDikeToeAtRiverAt(characteristicPoint2); + + calculation.InputParameters.SurfaceLine = surfaceLine2; + + // Call + calculation.InputParameters.NotifyObservers(); + + // Assert + chartDataList = view.Chart.Data.Collection.ToList(); + + Assert.AreSame(surfaceLineChartData, (ChartLineData) chartDataList[surfaceLineIndex]); + Assert.AreSame(entryPointChartData, (ChartPointData) chartDataList[entryPointIndex]); + Assert.AreSame(exitPointChartData, (ChartPointData) chartDataList[exitPointIndex]); + Assert.AreSame(ditchDikeSideData, (ChartPointData) chartDataList[ditchDikeSideIndex]); + Assert.AreSame(bottomDitchDikeSideData, (ChartPointData) chartDataList[bottomDitchDikeSideIndex]); + Assert.AreSame(ditchPolderSideData, (ChartPointData) chartDataList[ditchPolderSideIndex]); + Assert.AreSame(bottomDitchPolderSideData, (ChartPointData) chartDataList[bottomDitchPolderSideIndex]); + Assert.AreSame(dikeToeAtPolderData, (ChartPointData) chartDataList[dikeToeAtPolderIndex]); + Assert.AreSame(dikeToeAtRiverData, (ChartPointData) chartDataList[dikeToeAtRiverIndex]); + + AssertSurfaceLineChartData(surfaceLine2, surfaceLineChartData); + AssertEntryPointLPointchartData(calculation.InputParameters, surfaceLine2, entryPointChartData); + AssertExitPointLPointchartData(calculation.InputParameters, surfaceLine2, exitPointChartData); + AssertCharacteristicPoints(surfaceLine2, chartDataList); + mocks.VerifyAll(); + } + } + + [Test] + public void UpdateObserver_StochasticSoilProfileUpdated_ChartDataUpdated() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsInputView()) + { + RingtoetsPipingSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); + StochasticSoilProfile soilProfile = GetStochasticSoilProfile(); + var soilProfile2 = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("profile", -2, new[] + { + new PipingSoilLayer(0), + new PipingSoilLayer(2), + new PipingSoilLayer(3) + }, SoilProfileType.SoilProfile1D, 1) + }; + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + StochasticSoilProfile = soilProfile + } + }; + + view.Data = calculation; + + var soilProfileData = (ChartDataCollection) view.Chart.Data.Collection.ElementAt(soilProfileIndex); + soilProfileData.Attach(observer); + + calculation.InputParameters.StochasticSoilProfile = soilProfile2; + + // Call + calculation.InputParameters.NotifyObservers(); + + // Assert + Assert.AreSame(soilProfileData, (ChartDataCollection) view.Chart.Data.Collection.ElementAt(soilProfileIndex)); + AssertSoilProfileChartData(soilProfile2, soilProfileData, true); + mocks.VerifyAll(); + } + } + + [Test] + public void UpdateObserver_DataUpdated_ChartSeriesSameOrder() + { + // Setup + const int updatedSoilProfileIndex = soilProfileIndex; + const int updatedSurfaceLineIndex = surfaceLineIndex + 8; + const int updatedDitchPolderSideIndex = ditchPolderSideIndex - 1; + const int updatedBottomDitchPolderSideIndex = bottomDitchPolderSideIndex - 1; + const int updatedBottomDitchDikeSideIndex = bottomDitchDikeSideIndex - 1; + const int updatedDitchDikeSideIndex = ditchDikeSideIndex - 1; + const int updatedDikeToeAtPolderIndex = dikeToeAtPolderIndex - 1; + const int updatedDikeToeAtRiverIndex = dikeToeAtRiverIndex - 1; + const int updatedExitPointIndex = exitPointIndex - 1; + const int updatedEntryPointIndex = entryPointIndex - 1; + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + ChartDataCollection chartData = view.Chart.Data; + + ChartData dataToMove = chartData.Collection.ElementAt(surfaceLineIndex); + chartData.Remove(dataToMove); + chartData.Add(dataToMove); + + List chartDataList = chartData.Collection.ToList(); + + var soilProfileData = (ChartDataCollection) chartDataList[updatedSoilProfileIndex]; + var surfaceLineData = (ChartLineData) chartDataList[updatedSurfaceLineIndex]; + var entryPointData = (ChartPointData) chartDataList[updatedEntryPointIndex]; + var exitPointData = (ChartPointData) chartDataList[updatedExitPointIndex]; + var ditchDikeSideData = (ChartPointData) chartDataList[updatedDitchDikeSideIndex]; + var bottomDitchDikeSideData = (ChartPointData) chartDataList[updatedBottomDitchDikeSideIndex]; + var ditchPolderSideData = (ChartPointData) chartDataList[updatedDitchPolderSideIndex]; + var bottomDitchPolderSideData = (ChartPointData) chartDataList[updatedBottomDitchPolderSideIndex]; + var dikeToeAtPolderData = (ChartPointData) chartDataList[updatedDikeToeAtPolderIndex]; + var dikeToeAtRiverData = (ChartPointData) chartDataList[updatedDikeToeAtRiverIndex]; + + Assert.AreEqual("Ondergrondschematisatie", soilProfileData.Name); + Assert.AreEqual("Profielschematisatie", surfaceLineData.Name); + Assert.AreEqual("Intredepunt", entryPointData.Name); + Assert.AreEqual("Uittredepunt", exitPointData.Name); + Assert.AreEqual("Insteek sloot dijkzijde", ditchDikeSideData.Name); + Assert.AreEqual("Slootbodem dijkzijde", bottomDitchDikeSideData.Name); + Assert.AreEqual("Insteek sloot polderzijde", ditchPolderSideData.Name); + Assert.AreEqual("Slootbodem polderzijde", bottomDitchPolderSideData.Name); + Assert.AreEqual("Teen dijk binnenwaarts", dikeToeAtPolderData.Name); + Assert.AreEqual("Teen dijk buitenwaarts", dikeToeAtRiverData.Name); + + RingtoetsPipingSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); + calculation.InputParameters.SurfaceLine = surfaceLine; + + // Call + calculation.InputParameters.NotifyObservers(); + + // Assert + chartDataList = chartData.Collection.ToList(); + + var actualSoilProfileData = (ChartDataCollection) chartDataList[updatedSoilProfileIndex]; + var actualSurfaceLineData = (ChartLineData) chartDataList[updatedSurfaceLineIndex]; + var actualEntryPointData = (ChartPointData) chartDataList[updatedEntryPointIndex]; + var actualExitPointData = (ChartPointData) chartDataList[updatedExitPointIndex]; + var actualDitchDikeSideData = (ChartPointData) chartDataList[updatedDitchDikeSideIndex]; + var actualBottomDitchDikeSideData = (ChartPointData) chartDataList[updatedBottomDitchDikeSideIndex]; + var actualDitchPolderSideData = (ChartPointData) chartDataList[updatedDitchPolderSideIndex]; + var actualBottomDitchPolderSideData = (ChartPointData) chartDataList[updatedBottomDitchPolderSideIndex]; + var actualDikeToeAtPolderData = (ChartPointData) chartDataList[updatedDikeToeAtPolderIndex]; + var actualDikeToeAtRiverData = (ChartPointData) chartDataList[updatedDikeToeAtRiverIndex]; + + Assert.AreEqual("Ondergrondschematisatie", actualSoilProfileData.Name); + Assert.AreEqual(surfaceLine.Name, actualSurfaceLineData.Name); + Assert.AreEqual("Intredepunt", actualEntryPointData.Name); + Assert.AreEqual("Uittredepunt", actualExitPointData.Name); + Assert.AreEqual("Insteek sloot dijkzijde", actualDitchDikeSideData.Name); + Assert.AreEqual("Slootbodem dijkzijde", actualBottomDitchDikeSideData.Name); + Assert.AreEqual("Insteek sloot polderzijde", actualDitchPolderSideData.Name); + Assert.AreEqual("Slootbodem polderzijde", actualBottomDitchPolderSideData.Name); + Assert.AreEqual("Teen dijk binnenwaarts", actualDikeToeAtPolderData.Name); + Assert.AreEqual("Teen dijk buitenwaarts", actualDikeToeAtRiverData.Name); + } + } + + [Test] + public void UpdateObserver_OtherCalculationUpdated_ChartDataNotUpdated() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsInputView()) + { + RingtoetsPipingSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); + var calculation1 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine + } + }; + + var calculation2 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + view.Data = calculation1; + ChartDataCollection dataBeforeUpdate = view.Chart.Data; + + foreach (ChartData chartData in dataBeforeUpdate.Collection) + { + chartData.Attach(observer); + } + + view.Data = calculation2; + + RingtoetsPipingSurfaceLine surfaceLine2 = GetSecondSurfaceLineWithGeometry(); + + calculation1.InputParameters.SurfaceLine = surfaceLine2; + + // Call + calculation1.InputParameters.NotifyObservers(); + + // Assert + Assert.AreEqual(dataBeforeUpdate, view.Chart.Data); + mocks.VerifyAll(); // no update observer expected + } + } + + [Test] + public void GivenInputViewWithSoilProfileSeries_WhenSurfaceLineSetToNull_ThenCollectionOfEmptyChartDataSetForSoilProfiles() + { + // Given + using (var view = new MacroStabilityInwardsInputView()) + { + RingtoetsPipingSurfaceLine surfaceLine = GetSurfaceLineWithGeometry(); + StochasticSoilProfile stochasticSoilProfile = GetStochasticSoilProfile(); + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = surfaceLine, + StochasticSoilProfile = stochasticSoilProfile + } + }; + + view.Data = calculation; + + ChartDataCollection chartData = view.Chart.Data; + + // Precondition + Assert.IsNotNull(chartData); + Assert.AreEqual(10, chartData.Collection.Count()); + AssertSoilProfileChartData(stochasticSoilProfile, chartData.Collection.ElementAt(soilProfileIndex), true); + + // When + calculation.InputParameters.SurfaceLine = null; + calculation.InputParameters.NotifyObservers(); + + // Then + AssertSoilProfileChartData(stochasticSoilProfile, chartData.Collection.ElementAt(soilProfileIndex), false); + } + } + + private static StochasticSoilProfile GetStochasticSoilProfile() + { + return new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("profile", -1, new[] + { + new PipingSoilLayer(1), + new PipingSoilLayer(3), + new PipingSoilLayer(5) + }, SoilProfileType.SoilProfile1D, 1) + }; + } + + private static RingtoetsPipingSurfaceLine GetSurfaceLineWithGeometry() + { + var points = new[] + { + new Point3D(1.2, 2.3, 4.0), + new Point3D(2.7, 2.8, 6.0) + }; + + return GetSurfaceLine(points); + } + + private static RingtoetsPipingSurfaceLine GetSecondSurfaceLineWithGeometry() + { + var points = new[] + { + new Point3D(3.5, 2.3, 8.0), + new Point3D(6.9, 2.0, 2.0) + }; + + return GetSurfaceLine(points); + } + + private static RingtoetsPipingSurfaceLine GetSurfaceLine(Point3D[] points) + { + var surfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Surface line name" + }; + surfaceLine.SetGeometry(points); + return surfaceLine; + } + + private static void AssertEmtpySoilLayerTable(MacroStabilityInwardsInputView view) + { + var tableControl = view.Controls.Find("soilLayerTable", true).First() as MacroStabilityInwardsSoilLayerTable; + + // Precondition + Assert.NotNull(tableControl); + CollectionAssert.IsEmpty(tableControl.Rows); + } + + private static void AssertEmptyChartData(ChartDataCollection chartDataCollection) + { + Assert.AreEqual("Invoer", chartDataCollection.Name); + + List chartDatasList = chartDataCollection.Collection.ToList(); + + Assert.AreEqual(10, chartDatasList.Count); + + var soilProfileData = (ChartDataCollection) chartDatasList[soilProfileIndex]; + var surfaceLineData = (ChartLineData) chartDatasList[surfaceLineIndex]; + var entryPointData = (ChartPointData) chartDatasList[entryPointIndex]; + var exitPointData = (ChartPointData) chartDatasList[exitPointIndex]; + var ditchDikeSideData = (ChartPointData) chartDatasList[ditchDikeSideIndex]; + var bottomDitchDikeSideData = (ChartPointData) chartDatasList[bottomDitchDikeSideIndex]; + var ditchPolderSideData = (ChartPointData) chartDatasList[ditchPolderSideIndex]; + var bottomDitchPolderSideData = (ChartPointData) chartDatasList[bottomDitchPolderSideIndex]; + var dikeToeAtPolderData = (ChartPointData) chartDatasList[dikeToeAtPolderIndex]; + var dikeToeAtRiverData = (ChartPointData) chartDatasList[dikeToeAtRiverIndex]; + + CollectionAssert.IsEmpty(soilProfileData.Collection); + CollectionAssert.IsEmpty(surfaceLineData.Points); + CollectionAssert.IsEmpty(entryPointData.Points); + CollectionAssert.IsEmpty(exitPointData.Points); + CollectionAssert.IsEmpty(ditchDikeSideData.Points); + CollectionAssert.IsEmpty(bottomDitchDikeSideData.Points); + CollectionAssert.IsEmpty(ditchPolderSideData.Points); + CollectionAssert.IsEmpty(bottomDitchPolderSideData.Points); + CollectionAssert.IsEmpty(dikeToeAtPolderData.Points); + CollectionAssert.IsEmpty(dikeToeAtRiverData.Points); + + Assert.AreEqual("Ondergrondschematisatie", soilProfileData.Name); + Assert.AreEqual("Profielschematisatie", surfaceLineData.Name); + Assert.AreEqual("Intredepunt", entryPointData.Name); + Assert.AreEqual("Uittredepunt", exitPointData.Name); + Assert.AreEqual("Insteek sloot dijkzijde", ditchDikeSideData.Name); + Assert.AreEqual("Slootbodem dijkzijde", bottomDitchDikeSideData.Name); + Assert.AreEqual("Insteek sloot polderzijde", ditchPolderSideData.Name); + Assert.AreEqual("Slootbodem polderzijde", bottomDitchPolderSideData.Name); + Assert.AreEqual("Teen dijk binnenwaarts", dikeToeAtPolderData.Name); + Assert.AreEqual("Teen dijk buitenwaarts", dikeToeAtRiverData.Name); + } + + private static void AssertSoilProfileChartData(StochasticSoilProfile soilProfile, ChartData chartData, bool mapDataShouldContainAreas) + { + Assert.IsInstanceOf(chartData); + var soilProfileChartData = (ChartDataCollection) chartData; + + int expectedLayerCount = soilProfile.SoilProfile.Layers.Count(); + Assert.AreEqual(expectedLayerCount, soilProfileChartData.Collection.Count()); + Assert.AreEqual(soilProfile.SoilProfile.Name, soilProfileChartData.Name); + + string[] soilLayers = soilProfile.SoilProfile.Layers.Select((l, i) => string.Format("{0} {1}", i + 1, l.MaterialName)).Reverse().ToArray(); + + for (var i = 0; i < expectedLayerCount; i++) + { + var chartMultipleAreaData = soilProfileChartData.Collection.ElementAt(i) as ChartMultipleAreaData; + + Assert.IsNotNull(chartMultipleAreaData); + Assert.AreEqual(soilLayers[i], chartMultipleAreaData.Name); + Assert.AreEqual(mapDataShouldContainAreas, chartMultipleAreaData.Areas.Any()); + } + } + + private static void AssertSurfaceLineChartData(RingtoetsPipingSurfaceLine surfaceLine, ChartData chartData) + { + Assert.IsInstanceOf(chartData); + var surfaceLineChartData = (ChartLineData) chartData; + + Assert.AreEqual(surfaceLine.Points.Length, surfaceLineChartData.Points.Length); + CollectionAssert.AreEqual(surfaceLine.ProjectGeometryToLZ(), surfaceLineChartData.Points); + Assert.AreEqual(surfaceLine.Name, chartData.Name); + } + + private static void AssertEntryPointLPointchartData(MacroStabilityInwardsInput macroStabilityInwardsInput, RingtoetsPipingSurfaceLine surfaceLine, ChartData chartData) + { + Assert.IsInstanceOf(chartData); + var entryPointChartData = (ChartPointData) chartData; + + Assert.AreEqual(1, entryPointChartData.Points.Length); + var entryPoint = new Point2D(macroStabilityInwardsInput.EntryPointL, surfaceLine.GetZAtL(macroStabilityInwardsInput.EntryPointL)); + CollectionAssert.AreEqual(new[] + { + entryPoint + }, entryPointChartData.Points); + Assert.AreEqual("Intredepunt", entryPointChartData.Name); + } + + private static void AssertExitPointLPointchartData(MacroStabilityInwardsInput macroStabilityInwardsInput, RingtoetsPipingSurfaceLine surfaceLine, ChartData chartData) + { + Assert.IsInstanceOf(chartData); + var exitPointChartData = (ChartPointData) chartData; + + Assert.AreEqual(1, exitPointChartData.Points.Length); + var exitPoint = new Point2D(macroStabilityInwardsInput.ExitPointL, surfaceLine.GetZAtL(macroStabilityInwardsInput.ExitPointL)); + CollectionAssert.AreEqual(new[] + { + exitPoint + }, exitPointChartData.Points); + Assert.AreEqual("Uittredepunt", exitPointChartData.Name); + } + + private static void AssertCharacteristicPoints(RingtoetsPipingSurfaceLine surfaceLine, IList characteristicPoints) + { + Point3D first = surfaceLine.Points.First(); + Point3D last = surfaceLine.Points.Last(); + var firstPoint = new Point2D(first.X, first.Y); + var lastPoint = new Point2D(last.X, last.Y); + + var ditchDikeSideData = (ChartPointData) characteristicPoints[ditchDikeSideIndex]; + Assert.AreEqual(1, ditchDikeSideData.Points.Length); + CollectionAssert.AreEqual(new[] + { + surfaceLine.DitchDikeSide.ProjectIntoLocalCoordinates(firstPoint, lastPoint) + }, ditchDikeSideData.Points); + Assert.AreEqual("Insteek sloot dijkzijde", ditchDikeSideData.Name); + + var bottomDitchDikeSideData = (ChartPointData) characteristicPoints[bottomDitchDikeSideIndex]; + Assert.AreEqual(1, bottomDitchDikeSideData.Points.Length); + CollectionAssert.AreEqual(new[] + { + surfaceLine.BottomDitchDikeSide.ProjectIntoLocalCoordinates(firstPoint, lastPoint) + }, bottomDitchDikeSideData.Points); + Assert.AreEqual("Slootbodem dijkzijde", bottomDitchDikeSideData.Name); + + var ditchPolderSideData = (ChartPointData) characteristicPoints[ditchPolderSideIndex]; + Assert.AreEqual(1, ditchPolderSideData.Points.Length); + CollectionAssert.AreEqual(new[] + { + surfaceLine.DitchPolderSide.ProjectIntoLocalCoordinates(firstPoint, lastPoint) + }, ditchPolderSideData.Points); + Assert.AreEqual("Insteek sloot polderzijde", ditchPolderSideData.Name); + + var bottomDitchPolderSideData = (ChartPointData) characteristicPoints[bottomDitchPolderSideIndex]; + Assert.AreEqual(1, bottomDitchPolderSideData.Points.Length); + CollectionAssert.AreEqual(new[] + { + surfaceLine.BottomDitchPolderSide.ProjectIntoLocalCoordinates(firstPoint, lastPoint) + }, bottomDitchPolderSideData.Points); + Assert.AreEqual("Slootbodem polderzijde", bottomDitchPolderSideData.Name); + + var dikeToeAtPolderData = (ChartPointData) characteristicPoints[dikeToeAtPolderIndex]; + Assert.AreEqual(1, dikeToeAtPolderData.Points.Length); + CollectionAssert.AreEqual(new[] + { + surfaceLine.DikeToeAtPolder.ProjectIntoLocalCoordinates(firstPoint, lastPoint) + }, dikeToeAtPolderData.Points); + Assert.AreEqual("Teen dijk binnenwaarts", dikeToeAtPolderData.Name); + + var dikeToeAtRiverData = (ChartPointData) characteristicPoints[dikeToeAtRiverIndex]; + Assert.AreEqual(1, dikeToeAtRiverData.Points.Length); + CollectionAssert.AreEqual(new[] + { + surfaceLine.DikeToeAtRiver.ProjectIntoLocalCoordinates(firstPoint, lastPoint) + }, dikeToeAtRiverData.Points); + Assert.AreEqual("Teen dijk buitenwaarts", dikeToeAtRiverData.Name); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenarioRowTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenarioRowTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenarioRowTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,153 @@ +// Copyright (C) Stichting Deltares 2017. 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 Core.Common.Base; +using Core.Common.Base.Data; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Forms.Helpers; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Forms.Views; + +namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views +{ + [TestFixture] + public class MacroStabilityInwardsScenarioRowTest + { + [Test] + public void Constructor_WithoutCalculation_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => new MacroStabilityInwardsScenarioRow(null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("macroStabilityInwardsCalculation", paramName); + } + + [Test] + public void Constructor_WithCalculationWithSemiProbabilisticOutput_PropertiesFromCalculation() + { + // Setup + var random = new Random(21); + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + calculation.SemiProbabilisticOutput = new PipingSemiProbabilisticOutput( + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble(), + random.NextDouble()); + + // Call + var row = new MacroStabilityInwardsScenarioRow(calculation); + + // Assert + Assert.AreSame(calculation, row.MacroStabilityInwardsCalculation); + Assert.AreEqual(calculation.Name, row.Name); + Assert.AreEqual(calculation.IsRelevant, row.IsRelevant); + Assert.AreEqual(calculation.Contribution * 100, row.Contribution); + Assert.AreEqual(ProbabilityFormattingHelper.Format(calculation.SemiProbabilisticOutput.PipingProbability), row.FailureProbabilityPiping); + Assert.AreEqual(ProbabilityFormattingHelper.Format(calculation.SemiProbabilisticOutput.UpliftProbability), row.FailureProbabilityUplift); + Assert.AreEqual(ProbabilityFormattingHelper.Format(calculation.SemiProbabilisticOutput.HeaveProbability), row.FailureProbabilityHeave); + Assert.AreEqual(ProbabilityFormattingHelper.Format(calculation.SemiProbabilisticOutput.SellmeijerProbability), row.FailureProbabilitySellmeijer); + } + + [Test] + public void Constructor_WithCalculationWithoutSemiProbabilisticOutput_PropertiesFromCalculation() + { + // Setup + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + + // Call + var row = new MacroStabilityInwardsScenarioRow(calculation); + + // Assert + Assert.AreSame(calculation, row.MacroStabilityInwardsCalculation); + Assert.AreEqual(calculation.Name, row.Name); + Assert.AreEqual(calculation.IsRelevant, row.IsRelevant); + Assert.AreEqual(calculation.Contribution * 100, row.Contribution); + Assert.AreEqual("-", row.FailureProbabilityPiping); + Assert.AreEqual("-", row.FailureProbabilityUplift); + Assert.AreEqual("-", row.FailureProbabilityHeave); + Assert.AreEqual("-", row.FailureProbabilitySellmeijer); + } + + [Test] + [TestCase(false)] + [TestCase(true)] + public void IsRelevant_AlwaysOnChange_NotifyObserversAndCalculationPropertyChanged(bool newValue) + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + calculation.Attach(observer); + + var row = new MacroStabilityInwardsScenarioRow(calculation); + + // Call + row.IsRelevant = newValue; + + // Assert + Assert.AreEqual(newValue, calculation.IsRelevant); + + mocks.VerifyAll(); + } + + [Test] + public void Contribution_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() + { + // Setup + int newValue = new Random().Next(0, 100); + + MacroStabilityInwardsCalculationScenario calculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); + var row = new MacroStabilityInwardsScenarioRow(calculation); + + var counter = 0; + using (new Observer(() => counter++) + { + Observable = calculation + }) + { + // Call + row.Contribution = (RoundedDouble) newValue; + + // Assert + Assert.AreEqual(1, counter); + Assert.AreEqual(new RoundedDouble(2, newValue), calculation.Contribution * 100); + } + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenariosViewTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenariosViewTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenariosViewTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,423 @@ +// Copyright (C) Stichting Deltares 2017. 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.Globalization; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Core.Common.Controls.Views; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Forms.Helpers; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views +{ + [TestFixture] + public class MacroStabilityInwardsScenariosViewTest : NUnitFormTest + { + private const int isRelevantColumnIndex = 0; + private const int contributionColumnIndex = 1; + private const int nameColumnIndex = 2; + private const int failureProbabilityColumnIndex = 3; + private const int failureProbabilityUpliftColumnIndex = 4; + private const int failureProbabilityHeaveColumnIndex = 5; + private const int failureProbabilitySellmeijerColumnIndex = 6; + private Form testForm; + + [SetUp] + public override void Setup() + { + base.Setup(); + + testForm = new Form(); + } + + [TearDown] + public override void TearDown() + { + base.TearDown(); + + testForm.Dispose(); + } + + [Test] + public void Constructor_DefaultValues() + { + // Call + using (var scenarioView = new MacroStabilityInwardsScenariosView()) + { + // Assert + Assert.IsInstanceOf(scenarioView); + Assert.IsInstanceOf(scenarioView); + Assert.IsNull(scenarioView.Data); + Assert.IsNull(scenarioView.MacroStabilityInwardsFailureMechanism); + } + } + + [Test] + public void Constructor_DataGridViewCorrectlyInitialized() + { + // Setup & Call + ShowMacroStabilityInwardsScenarioView(); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Assert + Assert.IsFalse(dataGridView.AutoGenerateColumns); + Assert.AreEqual(7, dataGridView.ColumnCount); + + foreach (DataGridViewComboBoxColumn column in dataGridView.Columns.OfType()) + { + Assert.AreEqual("This", column.ValueMember); + Assert.AreEqual("DisplayName", column.DisplayMember); + } + } + + [Test] + public void Constructor_ListBoxCorrectlyInitialized() + { + // Setup & Call + ShowMacroStabilityInwardsScenarioView(); + + var listBox = (ListBox) new ControlTester("listBox").TheObject; + + // Assert + Assert.AreEqual(0, listBox.Items.Count); + } + + [Test] + public void Data_SetToNull_DoesNotThrow() + { + // Setup + MacroStabilityInwardsScenariosView macroStabilityInwardsScenarioView = ShowMacroStabilityInwardsScenarioView(); + + // Call + var testDelegate = new TestDelegate(() => macroStabilityInwardsScenarioView.Data = null); + + // Assert + Assert.DoesNotThrow(testDelegate); + } + + [Test] + public void MacroStabilityInwardsFailureMechanism_FailureMechanismWithSections_SectionsListBoxCorrectlyInitialized() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismSection1 = new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + }); + var failureMechanismSection2 = new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + }); + var failureMechanismSection3 = new FailureMechanismSection("Section 3", new List + { + new Point2D(10.0, 0.0), + new Point2D(15.0, 0.0) + }); + + failureMechanism.AddSection(failureMechanismSection1); + failureMechanism.AddSection(failureMechanismSection2); + failureMechanism.AddSection(failureMechanismSection3); + + MacroStabilityInwardsScenariosView macroStabilityInwardsScenarioView = ShowMacroStabilityInwardsScenarioView(); + + // Call + macroStabilityInwardsScenarioView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + // Assert + var listBox = (ListBox) new ControlTester("listBox").TheObject; + Assert.AreEqual(3, listBox.Items.Count); + Assert.AreSame(failureMechanismSection1, listBox.Items[0]); + Assert.AreSame(failureMechanismSection2, listBox.Items[1]); + Assert.AreSame(failureMechanismSection3, listBox.Items[2]); + } + + [Test] + public void GivenScenariosViewWithFailureMechanism_WhenSectionsAddedAndFailureMechanismNotified_ThenSectionsListBoxCorrectlyUpdated() + { + // Given + var failureMechanismWithSections = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismSection1 = new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + }); + var failureMechanismSection2 = new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + }); + var failureMechanismSection3 = new FailureMechanismSection("Section 3", new List + { + new Point2D(10.0, 0.0), + new Point2D(15.0, 0.0) + }); + + MacroStabilityInwardsScenariosView macroStabilityInwardsScenarioView = ShowMacroStabilityInwardsScenarioView(); + macroStabilityInwardsScenarioView.MacroStabilityInwardsFailureMechanism = failureMechanismWithSections; + + var listBox = (ListBox) new ControlTester("listBox").TheObject; + + // Precondition + Assert.AreEqual(0, listBox.Items.Count); + + failureMechanismWithSections.AddSection(failureMechanismSection1); + failureMechanismWithSections.AddSection(failureMechanismSection2); + failureMechanismWithSections.AddSection(failureMechanismSection3); + + // When + failureMechanismWithSections.NotifyObservers(); + + // Then + Assert.AreEqual(3, listBox.Items.Count); + Assert.AreSame(failureMechanismSection1, listBox.Items[0]); + Assert.AreSame(failureMechanismSection2, listBox.Items[1]); + Assert.AreSame(failureMechanismSection3, listBox.Items[2]); + } + + [Test] + public void MacroStabilityInwardsScenarioView_CalculationsWithAllDataSet_DataGridViewCorrectlyInitialized() + { + // Setup & Call + ShowFullyConfiguredMacroStabilityInwardsScenarioView(); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Assert + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(2, rows.Count); + + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(7, cells.Count); + Assert.IsTrue(Convert.ToBoolean(cells[isRelevantColumnIndex].FormattedValue)); + Assert.AreEqual(100.ToString(CultureInfo.CurrentCulture), cells[contributionColumnIndex].FormattedValue); + Assert.AreEqual("Calculation 1", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("-", cells[failureProbabilityColumnIndex].FormattedValue); + Assert.AreEqual("-".ToString(CultureInfo.CurrentCulture), cells[failureProbabilityUpliftColumnIndex].FormattedValue); + Assert.AreEqual("-".ToString(CultureInfo.CurrentCulture), cells[failureProbabilityHeaveColumnIndex].FormattedValue); + Assert.AreEqual("-".ToString(CultureInfo.CurrentCulture), cells[failureProbabilitySellmeijerColumnIndex].FormattedValue); + + cells = rows[1].Cells; + Assert.AreEqual(7, cells.Count); + Assert.IsTrue(Convert.ToBoolean(cells[isRelevantColumnIndex].FormattedValue)); + Assert.AreEqual(100.ToString(CultureInfo.CurrentCulture), cells[contributionColumnIndex].FormattedValue); + Assert.AreEqual("Calculation 2", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(1.5e-3), cells[failureProbabilityColumnIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(double.NaN), cells[failureProbabilityUpliftColumnIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(0.0005), cells[failureProbabilityHeaveColumnIndex].FormattedValue); + Assert.AreEqual(ProbabilityFormattingHelper.Format(1.5e-3), cells[failureProbabilitySellmeijerColumnIndex].FormattedValue); + } + + [Test] + public void MacroStabilityInwardsScenarioView_ContributionValueInvalid_ShowsErrorTooltip() + { + // Setup + ShowFullyConfiguredMacroStabilityInwardsScenarioView(); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[contributionColumnIndex].Value = "test"; + + // Assert + Assert.AreEqual("De tekst moet een getal zijn.", dataGridView.Rows[0].ErrorText); + } + + [Test] + [TestCase(1)] + [TestCase(1e-6)] + [TestCase(1e+6)] + [TestCase(14.3)] + public void FailureMechanismResultView_EditValueValid_DoNotShowErrorToolTipAndEditValue(double newValue) + { + // Setup + ShowFullyConfiguredMacroStabilityInwardsScenarioView(); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[contributionColumnIndex].Value = (RoundedDouble) newValue; + + // Assert + Assert.IsEmpty(dataGridView.Rows[0].ErrorText); + } + + [TestCase(isRelevantColumnIndex, true)] + [TestCase(contributionColumnIndex, 30.0)] + public void MacroStabilityInwardsScenarioView_EditingPropertyViaDataGridView_ObserversCorrectlyNotified(int cellIndex, object newValue) + { + // Setup + var mocks = new MockRepository(); + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + calculationObserver.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + MacroStabilityInwardsScenariosView macroStabilityInwardsCalculationView = ShowFullyConfiguredMacroStabilityInwardsScenarioView(); + + var data = (CalculationGroup) macroStabilityInwardsCalculationView.Data; + var calculation = (MacroStabilityInwardsCalculationScenario) data.Children.First(); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Call + dataGridView.Rows[0].Cells[cellIndex].Value = newValue is double ? (RoundedDouble) (double) newValue : newValue; + + // Assert + mocks.VerifyAll(); + } + + private MacroStabilityInwardsScenariosView ShowFullyConfiguredMacroStabilityInwardsScenarioView() + { + var surfaceLine1 = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 1", + ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) + }; + + surfaceLine1.SetGeometry(new[] + { + new Point3D(0.0, 5.0, 0.0), + new Point3D(0.0, 0.0, 1.0), + new Point3D(0.0, -5.0, 0.0) + }); + + var surfaceLine2 = new RingtoetsPipingSurfaceLine + { + Name = "Surface line 2", + ReferenceLineIntersectionWorldPoint = new Point2D(5.0, 0.0) + }; + + surfaceLine2.SetGeometry(new[] + { + new Point3D(5.0, 5.0, 0.0), + new Point3D(5.0, 0.0, 1.0), + new Point3D(5.0, -5.0, 0.0) + }); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + failureMechanism.AddSection(new FailureMechanismSection("Section 1", new List + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + })); + + failureMechanism.AddSection(new FailureMechanismSection("Section 2", new List + { + new Point2D(5.0, 0.0), + new Point2D(10.0, 0.0) + })); + + MacroStabilityInwardsScenariosView macroStabilityInwardsScenarioView = ShowMacroStabilityInwardsScenarioView(); + + macroStabilityInwardsScenarioView.Data = new CalculationGroup("Group", true) + { + Children = + { + new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation 1", + InputParameters = + { + SurfaceLine = surfaceLine1, + DampingFactorExit = + { + Mean = (RoundedDouble) 1.1111 + }, + PhreaticLevelExit = + { + Mean = (RoundedDouble) 2.2222 + }, + EntryPointL = (RoundedDouble) 3.3333, + ExitPointL = (RoundedDouble) 4.4444 + } + }, + new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + Name = "Calculation 2", + InputParameters = + { + SurfaceLine = surfaceLine2, + DampingFactorExit = + { + Mean = (RoundedDouble) 5.5555 + }, + PhreaticLevelExit = + { + Mean = (RoundedDouble) 6.6666 + }, + EntryPointL = (RoundedDouble) 7.7777, + ExitPointL = (RoundedDouble) 8.8888 + }, + SemiProbabilisticOutput = new PipingSemiProbabilisticOutput( + double.NaN, + double.NaN, + double.NaN, + double.NaN, + double.NaN, + 0.0005, + double.NaN, + double.NaN, + 1.5e-3, + double.NaN, + double.NaN, + 1.5e-3, + double.NaN, + double.NaN) + } + } + }; + + macroStabilityInwardsScenarioView.MacroStabilityInwardsFailureMechanism = failureMechanism; + + return macroStabilityInwardsScenarioView; + } + + private MacroStabilityInwardsScenariosView ShowMacroStabilityInwardsScenarioView() + { + var scenarioView = new MacroStabilityInwardsScenariosView(); + + testForm.Controls.Add(scenarioView); + testForm.Show(); + + return scenarioView; + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsSoilLayerTableTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsSoilLayerTableTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsSoilLayerTableTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,227 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using System.Windows.Forms; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using Ringtoets.MacroStabilityInwards.Primitives; + +namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views +{ + [TestFixture] + public class MacroStabilityInwardsSoilLayerTableTest + { + private const int nameColumnIndex = 0; + private const int colorColumnIndex = 1; + private const int topColumnIndex = 2; + private const int isAquiferColumnIndex = 3; + private const int permeabilityMeanColumnIndex = 4; + private const int permeabilityCoefficientOfVariationColumnIndex = 5; + private const int d70MeanColumnIndex = 6; + private const int d70CoefficientOfVariationColumnIndex = 7; + private const int belowPhreaticLevelWeightMeanColumnIndex = 8; + private const int belowPhreaticLevelWeightDeviationColumnIndex = 9; + private const int belowPhreaticLevelWeightShiftColumnIndex = 10; + + [Test] + public void Constructor_InitializesWithColumns() + { + // Call + using (var table = new MacroStabilityInwardsSoilLayerTable()) + { + // Assert + DataGridViewColumn nameColumn = table.GetColumnFromIndex(nameColumnIndex); + Assert.AreEqual("Naam", nameColumn.HeaderText); + DataGridViewColumn colorColumn = table.GetColumnFromIndex(colorColumnIndex); + Assert.AreEqual("Kleur", colorColumn.HeaderText); + DataGridViewColumn topColumn = table.GetColumnFromIndex(topColumnIndex); + Assert.AreEqual("Topniveau [m+NAP]", topColumn.HeaderText); + DataGridViewColumn isAquiferColumn = table.GetColumnFromIndex(isAquiferColumnIndex); + Assert.AreEqual("Is aquifer", isAquiferColumn.HeaderText); + DataGridViewColumn permeabilityMeanColumn = table.GetColumnFromIndex(permeabilityMeanColumnIndex); + Assert.AreEqual("Doorlatendheid (verwachtingswaarde) [m/s]", permeabilityMeanColumn.HeaderText); + DataGridViewColumn permeabilityCoefficientOfVariationColumn = table.GetColumnFromIndex(permeabilityCoefficientOfVariationColumnIndex); + Assert.AreEqual("Doorlatendheid (variatiecoëfficiënt) [-]", permeabilityCoefficientOfVariationColumn.HeaderText); + DataGridViewColumn d70MeanColumn = table.GetColumnFromIndex(d70MeanColumnIndex); + Assert.AreEqual("d70 (verwachtingswaarde) [m]", d70MeanColumn.HeaderText); + DataGridViewColumn d70DeviationColumn = table.GetColumnFromIndex(d70CoefficientOfVariationColumnIndex); + Assert.AreEqual("d70 (variatiecoëfficiënt) [-]", d70DeviationColumn.HeaderText); + DataGridViewColumn belowPhreaticLevelWeightMeanColumn = table.GetColumnFromIndex(belowPhreaticLevelWeightMeanColumnIndex); + Assert.AreEqual("Verzadigd gewicht (verwachtingswaarde) [kN/m³]", belowPhreaticLevelWeightMeanColumn.HeaderText); + DataGridViewColumn belowPhreaticLevelWeightDeviationColumn = table.GetColumnFromIndex(belowPhreaticLevelWeightDeviationColumnIndex); + Assert.AreEqual("Verzadigd gewicht (standaardafwijking) [kN/m³]", belowPhreaticLevelWeightDeviationColumn.HeaderText); + DataGridViewColumn belowPhreaticLevelWeightShiftColumn = table.GetColumnFromIndex(belowPhreaticLevelWeightShiftColumnIndex); + Assert.AreEqual("Verzadigd gewicht (verschuiving) [kN/m³]", belowPhreaticLevelWeightShiftColumn.HeaderText); + + Assert.Throws(() => table.GetColumnFromIndex(belowPhreaticLevelWeightShiftColumnIndex + 1)); + + Assert.IsEmpty(table.Rows); + } + } + + [Test] + public void SetData_NoDataAlreadySet_SetNewData() + { + // Setup + using (var table = new MacroStabilityInwardsSoilLayerTable()) + { + var layers = new[] + { + new PipingSoilLayer(2.5), + new PipingSoilLayer(2.3), + new PipingSoilLayer(1.1) + }; + + // Call + table.SetData(layers); + + // Assert + Assert.AreEqual(3, table.Rows.Count); + } + } + + [Test] + public void SetData_SetNullDataAfterDataAlreadySet_ClearsData() + { + // Setup + using (var table = new MacroStabilityInwardsSoilLayerTable()) + { + var layers = new[] + { + new PipingSoilLayer(2.5), + new PipingSoilLayer(2.3), + new PipingSoilLayer(1.1) + }; + table.SetData(layers); + + // Call + table.SetData(null); + + // Assert + Assert.AreEqual(0, table.Rows.Count); + } + } + + [Test] + public void SetData_SetNewDataAfterDataAlreadySet_ClearDataAndAddNewData() + { + // Setup + using (var table = new MacroStabilityInwardsSoilLayerTable()) + { + var layers = new[] + { + new PipingSoilLayer(2.5), + new PipingSoilLayer(2.3), + new PipingSoilLayer(1.1) + }; + table.SetData(new[] + { + new PipingSoilLayer(1.0) + }); + + // Call + table.SetData(layers); + + // Assert + Assert.AreEqual(3, table.Rows.Count); + } + } + + [Test] + public void SetData_WithData_ExpectedValuesInTable() + { + // Setup + using (var table = new MacroStabilityInwardsSoilLayerTable()) + { + var layers = new[] + { + CreateMacroStabilityInwardsSoilLayer(), + CreateMacroStabilityInwardsSoilLayer(), + CreateMacroStabilityInwardsSoilLayer() + }; + table.SetData(new[] + { + new PipingSoilLayer(1.0) + }); + + // Call + table.SetData(layers); + + // Assert + Assert.AreEqual(3, table.Rows.Count); + for (var i = 0; i < table.Rows.Count; i++) + { + PipingSoilLayer soilLayer = layers[i]; + DataGridViewCellCollection rowCells = table.Rows[i].Cells; + AssertColumnValueEqual(soilLayer.MaterialName, rowCells[nameColumnIndex].Value); + AssertColumnValueEqual(soilLayer.Color, rowCells[colorColumnIndex].Value); + AssertColumnValueEqual(soilLayer.Top, rowCells[topColumnIndex].Value); + AssertColumnValueEqual(soilLayer.IsAquifer, rowCells[isAquiferColumnIndex].Value); + AssertColumnValueEqual(soilLayer.PermeabilityMean, rowCells[permeabilityMeanColumnIndex].Value); + AssertColumnValueEqual(soilLayer.PermeabilityCoefficientOfVariation, rowCells[permeabilityCoefficientOfVariationColumnIndex].Value); + AssertColumnValueEqual(soilLayer.DiameterD70Mean, rowCells[d70MeanColumnIndex].Value); + AssertColumnValueEqual(soilLayer.DiameterD70CoefficientOfVariation, rowCells[d70CoefficientOfVariationColumnIndex].Value); + AssertColumnValueEqual(soilLayer.BelowPhreaticLevelMean, rowCells[belowPhreaticLevelWeightMeanColumnIndex].Value); + AssertColumnValueEqual(soilLayer.BelowPhreaticLevelDeviation, rowCells[belowPhreaticLevelWeightDeviationColumnIndex].Value); + AssertColumnValueEqual(soilLayer.BelowPhreaticLevelShift, rowCells[belowPhreaticLevelWeightShiftColumnIndex].Value); + } + } + } + + private void AssertColumnValueEqual(object expectedValue, object actualValue) + { + if (expectedValue is string || expectedValue is Color) + { + Assert.AreEqual(expectedValue, actualValue); + } + if (expectedValue is RoundedDouble) + { + Assert.IsInstanceOf(actualValue); + var expectedRoundedDouble = (RoundedDouble) expectedValue; + Assert.AreEqual(expectedRoundedDouble, (RoundedDouble) actualValue, expectedRoundedDouble.GetAccuracy()); + } + } + + private PipingSoilLayer CreateMacroStabilityInwardsSoilLayer() + { + var random = new Random(); + + return new PipingSoilLayer(random.NextDouble()) + { + MaterialName = $"{random.NextDouble()}", + Color = Color.FromKnownColor(random.NextEnumValue()), + IsAquifer = random.NextBoolean(), + PermeabilityMean = random.NextRoundedDouble(), + PermeabilityCoefficientOfVariation = random.NextRoundedDouble(), + DiameterD70Mean = random.NextRoundedDouble(), + DiameterD70CoefficientOfVariation = random.NextRoundedDouble(), + BelowPhreaticLevelMean = random.NextRoundedDouble(), + BelowPhreaticLevelDeviation = random.NextRoundedDouble(), + BelowPhreaticLevelShift = random.NextRoundedDouble() + }; + } + } +} \ No newline at end of file Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/PipingCalculationRowTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/PipingCalculationsViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/PipingFailureMechanismResultViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/PipingInputViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/PipingScenarioRowTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/PipingScenariosViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/PipingSoilLayerTableTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsCalculationsViewIntegrationTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsCalculationsViewIntegrationTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsCalculationsViewIntegrationTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,211 @@ +// Copyright (C) Stichting Deltares 2017. 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.Globalization; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base.Data; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.TestUtils; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.Views; + +namespace Ringtoets.MacroStabilityInwards.Integration.Test +{ + [TestFixture] + public class MacroStabilityInwardsCalculationsViewIntegrationTest + { + private const int nameColumnIndex = 0; + private const int stochasticSoilModelsColumnIndex = 1; + private const int stochasticSoilProfilesColumnIndex = 2; + private const int stochasticSoilProfilesProbabilityColumnIndex = 3; + private const int hydraulicBoundaryLocationsColumnIndex = 4; + private const int exitPointLColumnIndex = 8; + + [Test] + public void MacroStabilityInwardsCalculationsView_DataImportedOrChanged_ChangesCorrectlyObservedAndSynced() + { + // Setup + using (var form = new Form()) + { + // Show the view + var calculationsView = new MacroStabilityInwardsCalculationsView(); + form.Controls.Add(calculationsView); + form.Show(); + + // Obtain some relevant controls + var listBox = (ListBox) new ControlTester("listBox").TheObject; + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Set all necessary data to the view + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + calculationsView.Data = assessmentSection.MacroStabilityInwards.CalculationsGroup; + calculationsView.AssessmentSection = assessmentSection; + calculationsView.MacroStabilityInwardsFailureMechanism = assessmentSection.MacroStabilityInwards; + + // Import failure mechanism sections and ensure the listbox is updated + DataImportHelper.ImportReferenceLine(assessmentSection); + IFailureMechanism failureMechanism = assessmentSection.MacroStabilityInwards; + DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); + Assert.AreEqual(283, listBox.Items.Count); + + // Import surface lines + DataImportHelper.ImportPipingSurfaceLines(assessmentSection); + + // Setup some calculations + var calculation1 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First(sl => sl.Name == "PK001_0001") + } + }; + var calculation2 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First(sl => sl.Name == "PK001_0001") + } + }; + + // Add a calculation and ensure it is shown in the data grid view after selecting the corresponding dike section + assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(calculation1); + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_22"); + Assert.AreEqual(1, dataGridView.Rows.Count); + + // Import soil models and profiles and ensure the corresponding combobox items are updated + DataImportHelper.ImportPipingStochasticSoilModels(assessmentSection); + StochasticSoilModelCollection stochasticSoilModelCollection = assessmentSection.MacroStabilityInwards.StochasticSoilModels; + calculation1.InputParameters.StochasticSoilModel = stochasticSoilModelCollection.First(sl => sl.Name == "PK001_0001_Piping"); + Assert.AreEqual(1, ((DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex]).Items.Count); + Assert.AreEqual("PK001_0001_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual(1, ((DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex]).Items.Count); + Assert.AreEqual("", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + + // Import hydraulic boundary locations and ensure the corresponding combobox items are updated + DataImportHelper.ImportHydraulicBoundaryDatabase(assessmentSection); + Assert.AreEqual(19, ((DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[hydraulicBoundaryLocationsColumnIndex]).Items.Count); + + // Add group and ensure the data grid view is not changed + var nestedCalculationGroup = new CalculationGroup("New group", false); + assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(nestedCalculationGroup); + assessmentSection.MacroStabilityInwards.CalculationsGroup.NotifyObservers(); + Assert.AreEqual(1, dataGridView.Rows.Count); + + // Add another, nested calculation and ensure the data grid view is updated + nestedCalculationGroup.Children.Add(calculation2); + nestedCalculationGroup.NotifyObservers(); + Assert.AreEqual(2, dataGridView.Rows.Count); + + // Add another, nested calculation without surface line and ensure the data grid view is updated when the surface line is set. + var calculation3 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + nestedCalculationGroup.Children.Add(calculation3); + nestedCalculationGroup.NotifyObservers(); + Assert.AreEqual(2, dataGridView.Rows.Count); + + calculation3.InputParameters.SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First(sl => sl.Name == "PK001_0001"); + calculation3.InputParameters.NotifyObservers(); + Assert.AreEqual(3, dataGridView.Rows.Count); + + // Change the name of the first calculation and ensure the data grid view is updated + calculation1.Name = "New name"; + calculation1.NotifyObservers(); + Assert.AreEqual("New name", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + + // Change an input parameter of the second calculation and ensure the data grid view is updated + calculation2.InputParameters.ExitPointL = (RoundedDouble) 111.11; + calculation2.InputParameters.NotifyObservers(); + Assert.AreEqual(111.11.ToString(CultureInfo.CurrentCulture), dataGridView.Rows[1].Cells[exitPointLColumnIndex].FormattedValue); + + // Add another calculation and assign all soil models + var calculation4 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(calculation4); + assessmentSection.MacroStabilityInwards.CalculationsGroup.NotifyObservers(); + calculation4.InputParameters.SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First(sl => sl.Name == "PK001_0001"); + calculation4.InputParameters.NotifyObservers(); + Assert.AreEqual(4, dataGridView.Rows.Count); + + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_22"); + calculation1.InputParameters.StochasticSoilModel = stochasticSoilModelCollection[0]; + calculation1.InputParameters.StochasticSoilProfile = stochasticSoilModelCollection[0].StochasticSoilProfiles[0]; + calculation1.InputParameters.NotifyObservers(); + Assert.AreEqual("PK001_0001_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("W1-6_0_1D1", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("100", dataGridView.Rows[0].Cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_19"); + calculation2.InputParameters.SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First(sl => sl.Name == "PK001_0002"); + calculation2.InputParameters.StochasticSoilModel = stochasticSoilModelCollection[1]; + calculation2.InputParameters.StochasticSoilProfile = stochasticSoilModelCollection[1].StochasticSoilProfiles[0]; + calculation2.InputParameters.NotifyObservers(); + Assert.AreEqual("PK001_0002_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("W1-6_4_1D1", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("100", dataGridView.Rows[0].Cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_16"); + calculation3.InputParameters.SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First(sl => sl.Name == "PK001_0003"); + calculation3.InputParameters.StochasticSoilModel = stochasticSoilModelCollection[2]; + calculation3.InputParameters.StochasticSoilProfile = stochasticSoilModelCollection[2].StochasticSoilProfiles[0]; + calculation3.InputParameters.NotifyObservers(); + Assert.AreEqual("PK001_0003_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("W1-7_0_1D1", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("100", dataGridView.Rows[0].Cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_8"); + calculation4.InputParameters.SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First(sl => sl.Name == "PK001_0004"); + calculation4.InputParameters.StochasticSoilModel = stochasticSoilModelCollection[3]; + calculation4.InputParameters.StochasticSoilProfile = stochasticSoilModelCollection[3].StochasticSoilProfiles[0]; + calculation4.InputParameters.NotifyObservers(); + Assert.AreEqual("PK001_0004_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("W1-8_6_1D1", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("100", dataGridView.Rows[0].Cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + + // Update stochastic soil models + DataUpdateHelper.UpdatePipingStochasticSoilModels(assessmentSection); + + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_22"); + Assert.AreEqual("PK001_0001_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("W1-6_0_1D1", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("50", dataGridView.Rows[0].Cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_19"); + Assert.AreEqual("PK001_0002_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("0", dataGridView.Rows[0].Cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_16"); + Assert.AreEqual("PK001_0003_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("W1-7_0_1D1", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("100", dataGridView.Rows[0].Cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + + listBox.SelectedItem = assessmentSection.MacroStabilityInwards.Sections.First(s => s.Name == "6-3_8"); + Assert.AreEqual("", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("0", dataGridView.Rows[0].Cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); + } + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsFailureMechanismResultViewIntegrationTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsFailureMechanismResultViewIntegrationTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsFailureMechanismResultViewIntegrationTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,182 @@ +// Copyright (C) Stichting Deltares 2017. 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.Linq; +using System.Windows.Forms; +using Core.Common.Base.Data; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.TestUtils; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil; +using Ringtoets.MacroStabilityInwards.Service; + +namespace Ringtoets.MacroStabilityInwards.Integration.Test +{ + [TestFixture] + public class MacroStabilityInwardsFailureMechanismResultViewIntegrationTest + { + private const int assessmentLayerTwoAIndex = 2; + + [Test] + public void FailureMechanismResultView_DataImportedOrChanged_ChangesCorrectlyObservedAndSynced() + { + using (var form = new Form()) + { + // Show the view + var failureMechanismResultView = new MacroStabilityInwardsFailureMechanismResultView(); + form.Controls.Add(failureMechanismResultView); + form.Show(); + + // Obtain the data grid view + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + + // Set all necessary data to the view + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + failureMechanismResultView.Data = assessmentSection.MacroStabilityInwards.SectionResults; + failureMechanismResultView.FailureMechanism = assessmentSection.MacroStabilityInwards; + + // Import failure mechanism sections and ensure the data grid view is updated + DataImportHelper.ImportReferenceLine(assessmentSection); + IFailureMechanism failureMechanism = assessmentSection.MacroStabilityInwards; + DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); + Assert.AreEqual(283, dataGridView.Rows.Count); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Er moet minimaal één maatgevende berekening voor dit vak worden geselecteerd.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Import surface lines + DataImportHelper.ImportPipingSurfaceLines(assessmentSection); + + // Setup some calculations + var calculation1 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First( + sl => sl.Name == "PK001_0001") + } + }; + var calculation2 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + { + InputParameters = + { + SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First( + sl => sl.Name == "PK001_0001") + } + }; + + // Add a calculation and ensure it is shown in the data grid view + assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(calculation1); + assessmentSection.MacroStabilityInwards.CalculationsGroup.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Add group and ensure the data grid view is not changed + var nestedCalculationGroup = new CalculationGroup("New group", false); + assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(nestedCalculationGroup); + assessmentSection.MacroStabilityInwards.CalculationsGroup.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Add another, nested calculation and ensure the data grid view is updated + nestedCalculationGroup.Children.Add(calculation2); + nestedCalculationGroup.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Bijdrage van de geselecteerde scenario's voor dit vak moet opgeteld gelijk zijn aan 100%.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Set the second calculation to not relevant and ensure the data grid view is updated + calculation2.IsRelevant = false; + calculation2.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Execute the first calculation and ensure the data grid view is updated + const double probability = 1.0 / 31846382.0; + calculation1.Output = new TestPipingOutput(); + calculation1.SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput(probability); + calculation1.NotifyObservers(); + Assert.AreEqual(string.Format("1/{0:N0}", 1.0 / calculation1.Probability), + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual(string.Empty, dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Add another, nested calculation without surface line and ensure the data grid view is updated when the surface line is set + var calculation3 = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + nestedCalculationGroup.Children.Add(calculation3); + nestedCalculationGroup.NotifyObservers(); + Assert.AreEqual(string.Format("1/{0:N0}", 1.0 / calculation1.Probability), + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual(string.Empty, dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + calculation3.InputParameters.SurfaceLine = assessmentSection.MacroStabilityInwards.SurfaceLines.First( + sl => sl.Name == "PK001_0001"); + calculation3.InputParameters.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Bijdrage van de geselecteerde scenario's voor dit vak moet opgeteld gelijk zijn aan 100%.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Change the contribution of the calculation and make sure the data grid view is updated + calculation3.Contribution = (RoundedDouble) 0.3; + calculation3.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Bijdrage van de geselecteerde scenario's voor dit vak moet opgeteld gelijk zijn aan 100%.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + calculation1.Contribution = (RoundedDouble) 0.7; + calculation1.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Remove a calculation and make sure the data grid view is updated + nestedCalculationGroup.Children.Remove(calculation3); + nestedCalculationGroup.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Bijdrage van de geselecteerde scenario's voor dit vak moet opgeteld gelijk zijn aan 100%.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Set contribution again so we have a probability. + calculation1.Contribution = (RoundedDouble) 1.0; + calculation1.NotifyObservers(); + Assert.AreEqual(string.Format("1/{0:N0}", 1.0 / calculation1.Probability), + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual(string.Empty, dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + + // Clear the output of the calculation and make sure the data grid view is updated + PipingDataSynchronizationService.ClearCalculationOutput(calculation1); + calculation1.NotifyObservers(); + Assert.AreEqual("-", dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].FormattedValue); + Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", + dataGridView.Rows[22].Cells[assessmentLayerTwoAIndex].ErrorText); + } + } + } +} \ No newline at end of file Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/PipingCalculationsViewIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/PipingFailureMechanismResultViewIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/Ringtoets.MacroStabilityInwards.Integration.Test.csproj =================================================================== diff -u -r4a27dfb1033419dd325dee88fd4abe3cb56e452d -re25d1dff1132d88462399833e9a76b1dc6b8b785 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/Ringtoets.MacroStabilityInwards.Integration.Test.csproj (.../Ringtoets.MacroStabilityInwards.Integration.Test.csproj) (revision 4a27dfb1033419dd325dee88fd4abe3cb56e452d) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Integration.Test/Ringtoets.MacroStabilityInwards.Integration.Test.csproj (.../Ringtoets.MacroStabilityInwards.Integration.Test.csproj) (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -63,8 +63,8 @@ Properties\GlobalAssembly.cs - - + + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/MacroStabilityInwardsPluginTest.cs =================================================================== diff -u -ra0a4e8059c0e23db4eb3525d01a264fcf38c5ddd -re25d1dff1132d88462399833e9a76b1dc6b8b785 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/MacroStabilityInwardsPluginTest.cs (.../MacroStabilityInwardsPluginTest.cs) (revision a0a4e8059c0e23db4eb3525d01a264fcf38c5ddd) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/MacroStabilityInwardsPluginTest.cs (.../MacroStabilityInwardsPluginTest.cs) (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -144,10 +144,10 @@ Assert.AreEqual(5, viewInfos.Length); Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(MacroStabilityInwardsFailureMechanismView))); - Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(PipingCalculationsView))); - Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(PipingFailureMechanismResultView))); - Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(PipingInputView))); - Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(PipingScenariosView))); + Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(MacroStabilityInwardsCalculationsView))); + Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(MacroStabilityInwardsFailureMechanismResultView))); + Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(MacroStabilityInwardsInputView))); + Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(MacroStabilityInwardsScenariosView))); } } Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/Ringtoets.MacroStabilityInwards.Plugin.Test.csproj =================================================================== diff -u -r4c16454e3b11df918816195e24fa56dc4e352eee -re25d1dff1132d88462399833e9a76b1dc6b8b785 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/Ringtoets.MacroStabilityInwards.Plugin.Test.csproj (.../Ringtoets.MacroStabilityInwards.Plugin.Test.csproj) (revision 4c16454e3b11df918816195e24fa56dc4e352eee) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/Ringtoets.MacroStabilityInwards.Plugin.Test.csproj (.../Ringtoets.MacroStabilityInwards.Plugin.Test.csproj) (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -98,11 +98,11 @@ - - - + + + - + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsCalculationsViewInfoTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsCalculationsViewInfoTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsCalculationsViewInfoTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,326 @@ +// Copyright (C) Stichting Deltares 2017. 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.Linq; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using Ringtoets.MacroStabilityInwards.Primitives; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.MacroStabilityInwards.Plugin.Test.ViewInfos +{ + [TestFixture] + public class MacroStabilityInwardsCalculationsViewInfoTest + { + private MockRepository mocks; + private MacroStabilityInwardsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new MacroStabilityInwardsPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(MacroStabilityInwardsCalculationsView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PipingCalculationGroupContext), info.DataType); + Assert.AreEqual(typeof(CalculationGroup), info.ViewDataType); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GeneralFolderIcon, info.Image); + } + + [Test] + public void GetViewData_Always_ReturnsWrappedCalculationGroup() + { + // Setup + var assessmentSection = mocks.Stub(); + + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var calculationGroup = new CalculationGroup(); + var calculationGroupContext = new PipingCalculationGroupContext(calculationGroup, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); + + // Call & Assert + Assert.AreEqual(calculationGroup, info.GetViewData(calculationGroupContext)); + mocks.VerifyAll(); + } + + [Test] + public void GetViewName_Always_ReturnsCalculationGroupName() + { + // Setup + mocks.ReplayAll(); + + var calculationsView = new MacroStabilityInwardsCalculationsView(); + var calculationGroup = new CalculationGroup + { + Name = "Test" + }; + + // Call + string name = info.GetViewName(calculationsView, calculationGroup); + + // Assert + Assert.AreEqual("Test", name); + mocks.VerifyAll(); + } + + [Test] + public void AdditionalDataCheck_CalculationGroupContextWithFailureMechanismParent_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var calculationGroupContext = new PipingCalculationGroupContext(failureMechanism.CalculationsGroup, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); + + // Call + bool additionalDataCheck = info.AdditionalDataCheck(calculationGroupContext); + + // Assert + Assert.IsTrue(additionalDataCheck); + mocks.VerifyAll(); + } + + [Test] + public void AdditionalDataCheck_CalculationGroupContextWithoutFailureMechanismParent_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var calculationGroup = new CalculationGroup(); + var calculationGroupContext = new PipingCalculationGroupContext(calculationGroup, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); + + // Call + bool additionalDataCheck = info.AdditionalDataCheck(calculationGroupContext); + + // Assert + Assert.IsFalse(additionalDataCheck); + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_AssessmentSectionRemovedWithoutFailureMechanism_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[0]); + mocks.ReplayAll(); + + var view = new MacroStabilityInwardsCalculationsView + { + Data = new CalculationGroup() + }; + + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] + { + new MacroStabilityInwardsFailureMechanism() + }); + mocks.ReplayAll(); + + var view = new MacroStabilityInwardsCalculationsView + { + Data = new CalculationGroup() + }; + + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + mocks.ReplayAll(); + + var view = new MacroStabilityInwardsCalculationsView + { + Data = failureMechanism.CalculationsGroup + }; + + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + mocks.ReplayAll(); + + var view = new MacroStabilityInwardsCalculationsView(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + view.Data = new CalculationGroup(); + + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + mocks.ReplayAll(); + + var view = new MacroStabilityInwardsCalculationsView(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + view.Data = failureMechanism.CalculationsGroup; + + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var view = new MacroStabilityInwardsCalculationsView(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(new MacroStabilityInwardsFailureMechanism(), assessmentSection); + + view.Data = failureMechanism.CalculationsGroup; + + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var view = new MacroStabilityInwardsCalculationsView(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + view.Data = failureMechanism.CalculationsGroup; + + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + + [Test] + public void AfterCreate_Always_SetsSpecificPropertiesToView() + { + // Setup + var viewMock = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + var failureMechanismMock = mocks.StrictMock(); + var calculationsGroupMock = mocks.StrictMock(); + var calculationGroupContext = new PipingCalculationGroupContext(calculationsGroupMock, Enumerable.Empty(), Enumerable.Empty(), failureMechanismMock, assessmentSection); + + viewMock.Expect(v => v.AssessmentSection = assessmentSection); + viewMock.Expect(v => v.MacroStabilityInwardsFailureMechanism = failureMechanismMock); + + mocks.ReplayAll(); + + // Call + info.AfterCreate(viewMock, calculationGroupContext); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsFailureMechanismResultViewInfoTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsFailureMechanismResultViewInfoTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsFailureMechanismResultViewInfoTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,326 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using System.Linq; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.MacroStabilityInwards.Plugin.Test.ViewInfos +{ + [TestFixture] + public class MacroStabilityInwardsFailureMechanismResultViewInfoTest + { + private MockRepository mocks; + private MacroStabilityInwardsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new MacroStabilityInwardsPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(MacroStabilityInwardsFailureMechanismResultView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(FailureMechanismSectionResultContext), info.DataType); + Assert.AreEqual(typeof(IEnumerable), info.ViewDataType); + } + + [Test] + public void GetViewData_Always_ReturnsWrappedFailureMechanismResult() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var context = new FailureMechanismSectionResultContext(failureMechanism.SectionResults, failureMechanism); + + // Call + object viewData = info.GetViewData(context); + + // Assert + Assert.AreSame(failureMechanism.SectionResults, viewData); + } + + [Test] + public void GetViewName_Always_ReturnsViewName() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (var view = new MacroStabilityInwardsFailureMechanismResultView()) + { + // Call + string viewName = info.GetViewName(view, failureMechanism.SectionResults); + + // Assert + Assert.AreEqual("Resultaat", viewName); + } + } + + [Test] + public void ViewType_Always_ReturnsViewType() + { + // Call + Type viewType = info.ViewType; + + // Assert + Assert.AreEqual(typeof(MacroStabilityInwardsFailureMechanismResultView), viewType); + } + + [Test] + public void DataType_Always_ReturnsDataType() + { + // Call + Type dataType = info.DataType; + + // Assert + Assert.AreEqual(typeof(FailureMechanismSectionResultContext), dataType); + } + + [Test] + public void ViewDataType_Always_ReturnsViewDataType() + { + // Call + Type viewDataType = info.ViewDataType; + + // Assert + Assert.AreEqual(typeof(IEnumerable), viewDataType); + } + + [Test] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon, image); + } + + [Test] + public void CloseForData_AssessmentSectionRemovedWithoutFailureMechanism_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[0]); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + using (var view = new MacroStabilityInwardsFailureMechanismResultView + { + Data = failureMechanism.SectionResults + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var otherFailureMechanism = mocks.Stub("N", "C"); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] + { + otherFailureMechanism + }); + + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + using (var view = new MacroStabilityInwardsFailureMechanismResultView + { + Data = failureMechanism.SectionResults + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[] + { + new TestFailureMechanism(), + failureMechanism + }); + + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsFailureMechanismResultView + { + Data = failureMechanism.SectionResults + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + using (var view = new MacroStabilityInwardsFailureMechanismResultView + { + Data = failureMechanism.SectionResults + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (var view = new MacroStabilityInwardsFailureMechanismResultView + { + Data = failureMechanism.SectionResults + }) + { + // Call + bool closeForData = info.CloseForData(view, new MacroStabilityInwardsFailureMechanism()); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); + using (var view = new MacroStabilityInwardsFailureMechanismResultView + { + Data = failureMechanism.SectionResults + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (var view = new MacroStabilityInwardsFailureMechanismResultView + { + Data = failureMechanism.SectionResults + }) + { + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext( + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void AfterCreate_Always_SetsSpecificPropertiesToView() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var context = new FailureMechanismSectionResultContext(failureMechanism.SectionResults, failureMechanism); + var viewMock = mocks.StrictMock(); + viewMock.Expect(v => v.FailureMechanism = failureMechanism); + + mocks.ReplayAll(); + + // Call + info.AfterCreate(viewMock, context); + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsInputViewInfoTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsInputViewInfoTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsInputViewInfoTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,618 @@ +// Copyright (C) Stichting Deltares 2017. 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.Linq; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using Ringtoets.MacroStabilityInwards.Primitives; +using FormsResources = Ringtoets.MacroStabilityInwards.Forms.Properties.Resources; + +namespace Ringtoets.MacroStabilityInwards.Plugin.Test.ViewInfos +{ + [TestFixture] + public class MacroStabilityInwardsInputViewInfoTest + { + private MockRepository mocks; + private MacroStabilityInwardsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new MacroStabilityInwardsPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(MacroStabilityInwardsInputView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(MacroStabilityInwardsInputContext), info.DataType); + Assert.AreEqual(typeof(MacroStabilityInwardsCalculationScenario), info.ViewDataType); + TestHelper.AssertImagesAreEqual(FormsResources.PipingInputIcon, info.Image); + } + + [Test] + public void GetViewName_Always_ReturnsInputResourceName() + { + // Setup + using (var view = new MacroStabilityInwardsInputView()) + { + var calculationScenario = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + // Call + string viewName = info.GetViewName(view, calculationScenario); + + // Assert + Assert.AreEqual("Invoer", viewName); + } + } + + [Test] + public void GetViewData_Always_ReturnsWrappedCalculation() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var input = new MacroStabilityInwardsInput(new GeneralMacroStabilityInwardsInput()); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationInputContext = new MacroStabilityInwardsInputContext(input, calculation, Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + + // Call + object viewData = info.GetViewData(calculationInputContext); + + // Assert + Assert.AreEqual(calculation, viewData); + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedCalculationScenarioContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationScenarioContext = new MacroStabilityInwardsCalculationScenarioContext(calculation, + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, calculationScenarioContext); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedCalculationScenarioContext_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationToRemove = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + + var calculationScenarioContext = new MacroStabilityInwardsCalculationScenarioContext(calculationToRemove, + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, calculationScenarioContext); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_ViewCorrespondingWithRemovedCalculationGroupContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(calculation); + + var calculationGroupContext = new PipingCalculationGroupContext(calculationGroup, + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, calculationGroupContext); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingWithRemovedCalculationGroupContext_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(calculation); + + var calculationGroupContext = new PipingCalculationGroupContext(new CalculationGroup(), + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, calculationGroupContext); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_NestedViewCorrespondingWithRemovedParentCalculationGroupContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var nestedGroup = new CalculationGroup(); + nestedGroup.Children.Add(calculation); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(nestedGroup); + + var calculationGroupContext = new PipingCalculationGroupContext(calculationGroup, + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, calculationGroupContext); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_NestedViewNotCorrespondingWithRemovedParentCalculationGroupContext_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var nestedGroup = new CalculationGroup(); + nestedGroup.Children.Add(calculation); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(nestedGroup); + + var calculationGroupContext = new PipingCalculationGroupContext(new CalculationGroup(), + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, calculationGroupContext); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(new MacroStabilityInwardsFailureMechanism(), assessmentSection); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_NestedViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(calculation); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_NestedViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(calculation); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(new MacroStabilityInwardsFailureMechanism(), assessmentSection); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, new MacroStabilityInwardsFailureMechanism()); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseForData_NestedViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(calculation); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + } + + [Test] + public void CloseForData_NestedViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(calculation); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, new MacroStabilityInwardsFailureMechanism()); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsInputView + { + Data = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_NestedViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(calculation); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsInputView + { + Data = calculation + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + mocks.VerifyAll(); + } + } + + [Test] + public void CloseForData_NestedViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var calculation = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()); + var calculationGroup = new CalculationGroup(); + calculationGroup.Children.Add(calculation); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationGroup); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsInputView + { + Data = new MacroStabilityInwardsCalculationScenario(new GeneralMacroStabilityInwardsInput()) + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + mocks.VerifyAll(); + } + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsScenariosViewInfoTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsScenariosViewInfoTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsScenariosViewInfoTest.cs (revision e25d1dff1132d88462399833e9a76b1dc6b8b785) @@ -0,0 +1,316 @@ +// Copyright (C) Stichting Deltares 2017. 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.Linq; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.MacroStabilityInwards.Data; +using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects; +using Ringtoets.MacroStabilityInwards.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.MacroStabilityInwards.Plugin.Test.ViewInfos +{ + [TestFixture] + public class MacroStabilityInwardsScenariosViewInfoTest + { + private MockRepository mocks; + private MacroStabilityInwardsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new MacroStabilityInwardsPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(MacroStabilityInwardsScenariosView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(PipingScenariosContext), info.DataType); + Assert.AreEqual(typeof(CalculationGroup), info.ViewDataType); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ScenariosIcon, info.Image); + } + + [Test] + public void GetViewData_Always_ReturnsWrappedCalculationGroup() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var calculationsGroup = new CalculationGroup(); + var scenariosContext = new PipingScenariosContext(calculationsGroup, failureMechanism); + + // Call + object viewData = info.GetViewData(scenariosContext); + + // Assert + Assert.AreEqual(calculationsGroup, viewData); + } + + [Test] + public void GetViewName_Always_ReturnsScenarios() + { + // Setup + var calculationsGroup = new CalculationGroup + { + Name = "Test" + }; + + using (var view = new MacroStabilityInwardsScenariosView()) + { + // Call + string viewName = info.GetViewName(view, calculationsGroup); + + // Assert + Assert.AreEqual(RingtoetsCommonFormsResources.Scenarios_DisplayName, viewName); + } + } + + [Test] + public void AdditionalDataCheck_ScenariosContextWithFailureMechanismParent_ReturnsTrue() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var scenariosContext = new PipingScenariosContext(failureMechanism.CalculationsGroup, failureMechanism); + + // Call + bool additionalDataCheck = info.AdditionalDataCheck(scenariosContext); + + // Assert + Assert.IsTrue(additionalDataCheck); + } + + [Test] + public void AdditionalDataCheck_ScenariosContextWithoutFailureMechanismParent_ReturnsFalse() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var calculationsGroup = new CalculationGroup(); + var scenariosContext = new PipingScenariosContext(calculationsGroup, failureMechanism); + + // Call + bool additionalDataCheck = info.AdditionalDataCheck(scenariosContext); + + // Assert + Assert.IsFalse(additionalDataCheck); + } + + [Test] + public void CloseForData_AssessmentSectionRemovedWithoutFailureMechanism_ReturnsFalse() + { + // Setup + var calculationsGroup = new CalculationGroup(); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new IFailureMechanism[0]); + + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsScenariosView + { + Data = calculationsGroup + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var calculationsGroup = new CalculationGroup(); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsScenariosView + { + Data = calculationsGroup + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + + mocks.ReplayAll(); + + using (var view = new MacroStabilityInwardsScenariosView + { + Data = failureMechanism.CalculationsGroup + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + using (var view = new MacroStabilityInwardsScenariosView + { + Data = new CalculationGroup() + }) + { + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + using (var view = new MacroStabilityInwardsScenariosView + { + Data = failureMechanism.CalculationsGroup + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(new MacroStabilityInwardsFailureMechanism(), assessmentSection); + + using (var view = new MacroStabilityInwardsScenariosView + { + Data = failureMechanism.CalculationsGroup + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + using (var view = new MacroStabilityInwardsScenariosView + { + Data = failureMechanism.CalculationsGroup + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void AfterCreate_Always_SetsSpecificPropertiesToView() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var calculationsGroup = new CalculationGroup(); + var scenariosContext = new PipingScenariosContext(calculationsGroup, failureMechanism); + + using (var view = new MacroStabilityInwardsScenariosView()) + { + // Call + info.AfterCreate(view, scenariosContext); + + // Assert + Assert.AreSame(failureMechanism, view.MacroStabilityInwardsFailureMechanism); + } + } + } +} \ No newline at end of file Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/PipingCalculationsViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/PipingFailureMechanismResultViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/PipingInputViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e25d1dff1132d88462399833e9a76b1dc6b8b785 refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/ViewInfos/PipingScenariosViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?