Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Riskeer.StabilityPointStructures.Forms.csproj =================================================================== diff -u -rd363f5b55e823f5e4956e954950a616cb2468991 -r85f99d0f373b5ccc84747cd1db01c6039cb58053 --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Riskeer.StabilityPointStructures.Forms.csproj (.../Riskeer.StabilityPointStructures.Forms.csproj) (revision d363f5b55e823f5e4956e954950a616cb2468991) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Riskeer.StabilityPointStructures.Forms.csproj (.../Riskeer.StabilityPointStructures.Forms.csproj) (revision 85f99d0f373b5ccc84747cd1db01c6039cb58053) @@ -31,9 +31,7 @@ True Resources.resx - - UserControl - + Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresCalculationRow.cs =================================================================== diff -u -r19cb5416755b464820d056fa7e4576e1c2ada4d6 -r85f99d0f373b5ccc84747cd1db01c6039cb58053 --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresCalculationRow.cs (.../StabilityPointStructuresCalculationRow.cs) (revision 19cb5416755b464820d056fa7e4576e1c2ada4d6) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresCalculationRow.cs (.../StabilityPointStructuresCalculationRow.cs) (revision 85f99d0f373b5ccc84747cd1db01c6039cb58053) @@ -23,22 +23,23 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; +using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; using Riskeer.Common.Data.DikeProfiles; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.Structures; using Riskeer.Common.Forms.ChangeHandlers; using Riskeer.Common.Forms.Helpers; -using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.PropertyClasses; +using Riskeer.Common.Forms.Views; using Riskeer.StabilityPointStructures.Data; namespace Riskeer.StabilityPointStructures.Forms.Views { /// /// This class represents a row in the . /// - internal class StabilityPointStructuresCalculationRow : IHasColumnStateDefinitions + public class StabilityPointStructuresCalculationRow : CalculationRow>, IHasColumnStateDefinitions { private const int breakWaterTypeColumnIndex = 4; private const int breakWaterHeightColumnIndex = 5; @@ -47,29 +48,17 @@ private const int constructiveStrengthQuadraticLoadModelColumnIndex = 9; private const int stabilityLinearLoadModelColumnIndex = 10; private const int stabilityQuadraticLoadModelColumnIndex = 11; - private readonly IObservablePropertyChangeHandler propertyChangeHandler; /// /// Creates a new instance of . /// - /// The this row contains. + /// The this row contains. /// The handler responsible for handling effects of a property change. /// Thrown when any parameter is null. - public StabilityPointStructuresCalculationRow(StructuresCalculationScenario calculationScenario, - IObservablePropertyChangeHandler handler) + internal StabilityPointStructuresCalculationRow(StructuresCalculationScenario calculationScenario, + IObservablePropertyChangeHandler handler) + : base(calculationScenario, handler) { - if (calculationScenario == null) - { - throw new ArgumentNullException(nameof(calculationScenario)); - } - - if (handler == null) - { - throw new ArgumentNullException(nameof(handler)); - } - - CalculationScenario = calculationScenario; - propertyChangeHandler = handler; ColumnStateDefinitions = new Dictionary(); CreateColumnStateDefinitions(); UpdateUseBreakWaterColumnStateDefinitions(); @@ -78,220 +67,187 @@ } /// - /// Gets the this row contains. + /// Gets or sets the foreshore profile of the . /// - public StructuresCalculationScenario CalculationScenario { get; } - - /// - /// Gets or sets the name of the . - /// - public string Name - { - get => CalculationScenario.Name; - set - { - CalculationScenario.Name = value; - - CalculationScenario.NotifyObservers(); - } - } - - /// - /// Gets or sets the hydraulic boundary location of the . - /// - public DataGridViewComboBoxItemWrapper SelectableHydraulicBoundaryLocation - { - get - { - if (CalculationScenario.InputParameters.HydraulicBoundaryLocation == null) - { - return new DataGridViewComboBoxItemWrapper(null); - } - - return new DataGridViewComboBoxItemWrapper( - new SelectableHydraulicBoundaryLocation(CalculationScenario.InputParameters.HydraulicBoundaryLocation, null)); - } - set - { - HydraulicBoundaryLocation valueToSet = value?.WrappedObject?.HydraulicBoundaryLocation; - if (!ReferenceEquals(CalculationScenario.InputParameters.HydraulicBoundaryLocation, valueToSet)) - { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.HydraulicBoundaryLocation = valueToSet, propertyChangeHandler); - } - } - } - - /// - /// Gets or sets the foreshore profile of the . - /// public DataGridViewComboBoxItemWrapper ForeshoreProfile { - get => new DataGridViewComboBoxItemWrapper(CalculationScenario.InputParameters.ForeshoreProfile); + get => new DataGridViewComboBoxItemWrapper(Calculation.InputParameters.ForeshoreProfile); set { ForeshoreProfile valueToSet = value?.WrappedObject; - if (!ReferenceEquals(CalculationScenario.InputParameters.ForeshoreProfile, valueToSet)) + if (!ReferenceEquals(Calculation.InputParameters.ForeshoreProfile, valueToSet)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.ForeshoreProfile = valueToSet, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.ForeshoreProfile = valueToSet, PropertyChangeHandler); } } } /// - /// Gets or sets whether break water of the should be used. + /// Gets or sets whether break water of the should be used. /// public bool UseBreakWater { - get => CalculationScenario.InputParameters.UseBreakWater; + get => Calculation.InputParameters.UseBreakWater; set { - if (!CalculationScenario.InputParameters.UseBreakWater.Equals(value)) + if (!Calculation.InputParameters.UseBreakWater.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.UseBreakWater = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.UseBreakWater = value, PropertyChangeHandler); UpdateUseBreakWaterColumnStateDefinitions(); } } } /// - /// Gets or sets the break water type of the . + /// Gets or sets the break water type of the . /// public BreakWaterType BreakWaterType { - get => CalculationScenario.InputParameters.BreakWater.Type; + get => Calculation.InputParameters.BreakWater.Type; set { - if (!CalculationScenario.InputParameters.BreakWater.Type.Equals(value)) + if (!Calculation.InputParameters.BreakWater.Type.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.BreakWater.Type = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.BreakWater.Type = value, PropertyChangeHandler); } } } /// - /// Gets or sets the break water height of the . + /// Gets or sets the break water height of the . /// public RoundedDouble BreakWaterHeight { - get => CalculationScenario.InputParameters.BreakWater.Height; + get => Calculation.InputParameters.BreakWater.Height; set { - if (!CalculationScenario.InputParameters.BreakWater.Height.Equals(value)) + if (!Calculation.InputParameters.BreakWater.Height.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.BreakWater.Height = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.BreakWater.Height = value, PropertyChangeHandler); } } } /// - /// Gets or sets whether foreshore profile of the should be used. + /// Gets or sets whether foreshore profile of the should be used. /// public bool UseForeshoreGeometry { - get => CalculationScenario.InputParameters.UseForeshore; + get => Calculation.InputParameters.UseForeshore; set { - if (!CalculationScenario.InputParameters.UseForeshore.Equals(value)) + if (!Calculation.InputParameters.UseForeshore.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.UseForeshore = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.UseForeshore = value, PropertyChangeHandler); UpdateUseForeshoreColumnStateDefinitions(); } } } /// - /// Gets or sets the load schematization type of the . + /// Gets or sets the load schematization type of the . /// public LoadSchematizationType LoadSchematizationType { - get => CalculationScenario.InputParameters.LoadSchematizationType; + get => Calculation.InputParameters.LoadSchematizationType; set { - if (!CalculationScenario.InputParameters.LoadSchematizationType.Equals(value)) + if (!Calculation.InputParameters.LoadSchematizationType.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.LoadSchematizationType = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.LoadSchematizationType = value, PropertyChangeHandler); UpdateLoadSchematizationColumnStateDefinitions(); } } } /// - /// Gets or sets the constructive strength linear load model of the . + /// Gets or sets the constructive strength linear load model of the . /// public RoundedDouble ConstructiveStrengthLinearLoadModel { - get => CalculationScenario.InputParameters.ConstructiveStrengthLinearLoadModel.Mean; + get => Calculation.InputParameters.ConstructiveStrengthLinearLoadModel.Mean; set { - if (!CalculationScenario.InputParameters.ConstructiveStrengthLinearLoadModel.Mean.Equals(value)) + if (!Calculation.InputParameters.ConstructiveStrengthLinearLoadModel.Mean.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.ConstructiveStrengthLinearLoadModel.Mean = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.ConstructiveStrengthLinearLoadModel.Mean = value, PropertyChangeHandler); } } } /// - /// Gets or sets the constructive strength quadratic load model of the . + /// Gets or sets the constructive strength quadratic load model of the . /// public RoundedDouble ConstructiveStrengthQuadraticLoadModel { - get => CalculationScenario.InputParameters.ConstructiveStrengthQuadraticLoadModel.Mean; + get => Calculation.InputParameters.ConstructiveStrengthQuadraticLoadModel.Mean; set { - if (!CalculationScenario.InputParameters.ConstructiveStrengthQuadraticLoadModel.Mean.Equals(value)) + if (!Calculation.InputParameters.ConstructiveStrengthQuadraticLoadModel.Mean.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.ConstructiveStrengthQuadraticLoadModel.Mean = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.ConstructiveStrengthQuadraticLoadModel.Mean = value, PropertyChangeHandler); } } } /// - /// Gets or sets the stability of the linear load model of the . + /// Gets or sets the stability of the linear load model of the . /// public RoundedDouble StabilityLinearLoadModel { - get => CalculationScenario.InputParameters.StabilityLinearLoadModel.Mean; + get => Calculation.InputParameters.StabilityLinearLoadModel.Mean; set { - if (!CalculationScenario.InputParameters.StabilityLinearLoadModel.Mean.Equals(value)) + if (!Calculation.InputParameters.StabilityLinearLoadModel.Mean.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.StabilityLinearLoadModel.Mean = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.StabilityLinearLoadModel.Mean = value, PropertyChangeHandler); } } } /// - /// Gets or sets the stability of the quadratic load model of the . + /// Gets or sets the stability of the quadratic load model of the . /// public RoundedDouble StabilityQuadraticLoadModel { - get => CalculationScenario.InputParameters.StabilityQuadraticLoadModel.Mean; + get => Calculation.InputParameters.StabilityQuadraticLoadModel.Mean; set { - if (!CalculationScenario.InputParameters.StabilityQuadraticLoadModel.Mean.Equals(value)) + if (!Calculation.InputParameters.StabilityQuadraticLoadModel.Mean.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.StabilityQuadraticLoadModel.Mean = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.StabilityQuadraticLoadModel.Mean = value, PropertyChangeHandler); } } } /// - /// Gets or sets the evaluation level of the . + /// Gets or sets the evaluation level of the . /// public RoundedDouble EvaluationLevel { - get => CalculationScenario.InputParameters.EvaluationLevel; + get => Calculation.InputParameters.EvaluationLevel; set { - if (!CalculationScenario.InputParameters.EvaluationLevel.Equals(value)) + if (!Calculation.InputParameters.EvaluationLevel.Equals(value)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => CalculationScenario.InputParameters.EvaluationLevel = value, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.EvaluationLevel = value, PropertyChangeHandler); } } } public IDictionary ColumnStateDefinitions { get; } + public override Point2D GetCalculationLocation() + { + return Calculation.InputParameters.Structure?.Location; + } + + protected override HydraulicBoundaryLocation HydraulicBoundaryLocation + { + get => Calculation.InputParameters.HydraulicBoundaryLocation; + set => Calculation.InputParameters.HydraulicBoundaryLocation = value; + } + private void CreateColumnStateDefinitions() { ColumnStateDefinitions.Add(breakWaterTypeColumnIndex, new DataGridViewColumnStateDefinition()); @@ -319,7 +275,7 @@ private void UpdateUseForeshoreColumnStateDefinitions() { - ForeshoreProfile foreShoreProfileGeometry = CalculationScenario.InputParameters.ForeshoreProfile; + ForeshoreProfile foreShoreProfileGeometry = Calculation.InputParameters.ForeshoreProfile; if (foreShoreProfileGeometry == null || !foreShoreProfileGeometry.Geometry.Any()) { ColumnStateHelper.DisableColumn(ColumnStateDefinitions[useForeshoreColumnIndex]); Fisheye: Tag 85f99d0f373b5ccc84747cd1db01c6039cb58053 refers to a dead (removed) revision in file `Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresCalculationsView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresCalculationsView.cs =================================================================== diff -u -r3076354fa3a2bf2f027075f61ca660bffb576a45 -r85f99d0f373b5ccc84747cd1db01c6039cb58053 --- Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresCalculationsView.cs (.../StabilityPointStructuresCalculationsView.cs) (revision 3076354fa3a2bf2f027075f61ca660bffb576a45) +++ Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresCalculationsView.cs (.../StabilityPointStructuresCalculationsView.cs) (revision 85f99d0f373b5ccc84747cd1db01c6039cb58053) @@ -26,18 +26,15 @@ using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; -using Core.Common.Controls.Views; using Core.Common.Util; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.DikeProfiles; -using Riskeer.Common.Data.FailureMechanism; -using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.Structures; using Riskeer.Common.Forms; using Riskeer.Common.Forms.ChangeHandlers; using Riskeer.Common.Forms.Helpers; -using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.Common.Forms.Views; using Riskeer.StabilityPointStructures.Data; using Riskeer.StabilityPointStructures.Forms.PresentationObjects; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; @@ -47,23 +44,11 @@ /// /// This class is a view for configuring closing structures calculations. /// - public partial class StabilityPointStructuresCalculationsView : UserControl, ISelectionProvider, IView + public class StabilityPointStructuresCalculationsView : CalculationsView, StabilityPointStructuresInput, StabilityPointStructuresCalculationRow, StabilityPointStructuresFailureMechanism> { - private const int selectableHydraulicBoundaryLocationColumnIndex = 1; - private const int selectableForeshoreProfileColumnIndex = 2; - private readonly IAssessmentSection assessmentSection; - private readonly StabilityPointStructuresFailureMechanism failureMechanism; - private Observer failureMechanismObserver; - private Observer hydraulicBoundaryLocationsObserver; - private Observer stabilityPointStructuresObserver; - private RecursiveObserver inputObserver; - private RecursiveObserver> calculationScenarioObserver; - private RecursiveObserver calculationGroupObserver; + private const int foreshoreProfileColumnIndex = 2; + private readonly Observer stabilityPointStructuresObserver; - private CalculationGroup calculationGroup; - - public event EventHandler SelectionChanged; - /// /// Creates a new instance of . /// @@ -72,308 +57,175 @@ /// The assessment section. /// Thrown when any parameter is null. public StabilityPointStructuresCalculationsView(CalculationGroup data, StabilityPointStructuresFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + : base(data, failureMechanism, assessmentSection) { - if (data == null) + stabilityPointStructuresObserver = new Observer(UpdateGenerateCalculationsButtonState) { - throw new ArgumentNullException(nameof(data)); - } + Observable = FailureMechanism.StabilityPointStructures + }; + } - if (failureMechanism == null) - { - throw new ArgumentNullException(nameof(failureMechanism)); - } + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); - if (assessmentSection == null) + DataGridViewControl.CellFormatting += HandleCellStyling; + } + + protected override void Dispose(bool disposing) + { + if (disposing) { - throw new ArgumentNullException(nameof(assessmentSection)); + stabilityPointStructuresObserver.Dispose(); } - this.failureMechanism = failureMechanism; - this.assessmentSection = assessmentSection; - calculationGroup = data; + base.Dispose(disposing); + } - InitializeObservers(); + protected override object CreateSelectedItemFromCurrentRow(StabilityPointStructuresCalculationRow currentRow) + { + return new StabilityPointStructuresInputContext( + currentRow.Calculation.InputParameters, + currentRow.Calculation, + FailureMechanism, + AssessmentSection); + } - InitializeComponent(); - InitializeListBox(); - InitializeDataGridView(); - - UpdateSectionsListBox(); - UpdateDataGridViewDataSource(); - UpdateSelectableHydraulicBoundaryLocationsColumn(); - UpdateForeshoreProfilesColumn(); - UpdateGenerateCalculationsButtonState(); + protected override IEnumerable GetReferenceLocations() + { + return FailureMechanism.StabilityPointStructures.Select(sps => sps.Location); } - public object Selection => CreateSelectedItemFromCurrentRow(); - - public object Data + protected override bool IsCalculationIntersectionWithReferenceLineInSection(StructuresCalculationScenario calculation, IEnumerable lineSegments) { - get => calculationGroup; - set => calculationGroup = value as CalculationGroup; + return calculation.IsStructureIntersectionWithReferenceLineInSection(lineSegments); } - protected override void OnLoad(EventArgs e) + protected override StabilityPointStructuresCalculationRow CreateRow(StructuresCalculationScenario calculation) { - // Necessary to correctly load the content of the dropdown lists of the comboboxes... - UpdateDataGridViewDataSource(); + return new StabilityPointStructuresCalculationRow(calculation, new ObservablePropertyChangeHandler(calculation, calculation.InputParameters)); + } - base.OnLoad(e); - - dataGridViewControl.CellFormatting += HandleCellStyling; + protected override bool CanGenerateCalculations() + { + return FailureMechanism.StabilityPointStructures.Any(); } - protected override void Dispose(bool disposing) + protected override void GenerateCalculations() { - if (disposing) + var calculationGroup = (CalculationGroup) Data; + using (var dialog = new StructureSelectionDialog(Parent, FailureMechanism.StabilityPointStructures)) { - failureMechanismObserver.Dispose(); - inputObserver.Dispose(); - calculationScenarioObserver.Dispose(); - calculationGroupObserver.Dispose(); + dialog.ShowDialog(); - hydraulicBoundaryLocationsObserver.Dispose(); - stabilityPointStructuresObserver.Dispose(); - - components?.Dispose(); + if (dialog.SelectedItems.Any()) + { + StructureCalculationConfigurationHelper.GenerateCalculations(calculationGroup, dialog.SelectedItems.Cast()); + calculationGroup.NotifyObservers(); + } } - - base.Dispose(disposing); } - private void InitializeDataGridView() + protected override void InitializeDataGridView() { - dataGridViewControl.CurrentRowChanged += DataGridViewOnCurrentRowChangedHandler; + base.InitializeDataGridView(); - dataGridViewControl.AddTextBoxColumn( - nameof(StabilityPointStructuresCalculationRow.Name), - RiskeerCommonFormsResources.FailureMechanism_Name_DisplayName); - - dataGridViewControl.AddComboBoxColumn>( - nameof(StabilityPointStructuresCalculationRow.SelectableHydraulicBoundaryLocation), - RiskeerCommonFormsResources.HydraulicBoundaryLocation_DisplayName, - null, - nameof(DataGridViewComboBoxItemWrapper.This), - nameof(DataGridViewComboBoxItemWrapper.DisplayName)); - - dataGridViewControl.AddComboBoxColumn>( + DataGridViewControl.AddComboBoxColumn>( nameof(StabilityPointStructuresCalculationRow.ForeshoreProfile), RiskeerCommonFormsResources.Structure_ForeshoreProfile_DisplayName, null, nameof(DataGridViewComboBoxItemWrapper.This), nameof(DataGridViewComboBoxItemWrapper.DisplayName)); - dataGridViewControl.AddCheckBoxColumn(nameof(StabilityPointStructuresCalculationRow.UseBreakWater), + DataGridViewControl.AddCheckBoxColumn(nameof(StabilityPointStructuresCalculationRow.UseBreakWater), RiskeerCommonFormsResources.Use_BreakWater_DisplayName); - dataGridViewControl.AddComboBoxColumn(nameof(StabilityPointStructuresCalculationRow.BreakWaterType), + DataGridViewControl.AddComboBoxColumn(nameof(StabilityPointStructuresCalculationRow.BreakWaterType), RiskeerCommonFormsResources.CalculationsView_BreakWaterType_DisplayName, EnumDisplayWrapperHelper.GetEnumTypes(), nameof(EnumDisplayWrapper.Value), nameof(EnumDisplayWrapper.DisplayName)); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(StabilityPointStructuresCalculationRow.BreakWaterHeight), RiskeerCommonFormsResources.CalculationsView_BreakWaterHeight_DisplayName); - dataGridViewControl.AddCheckBoxColumn(nameof(StabilityPointStructuresCalculationRow.UseForeshoreGeometry), + DataGridViewControl.AddCheckBoxColumn(nameof(StabilityPointStructuresCalculationRow.UseForeshoreGeometry), RiskeerCommonFormsResources.Use_Foreshore_DisplayName); - dataGridViewControl.AddComboBoxColumn(nameof(StabilityPointStructuresCalculationRow.LoadSchematizationType), + DataGridViewControl.AddComboBoxColumn(nameof(StabilityPointStructuresCalculationRow.LoadSchematizationType), RiskeerCommonFormsResources.LoadSchematizationType_DisplayName, EnumDisplayWrapperHelper.GetEnumTypes(), nameof(EnumDisplayWrapper.Value), nameof(EnumDisplayWrapper.DisplayName)); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(StabilityPointStructuresCalculationRow.ConstructiveStrengthLinearLoadModel), $"{RiskeerCommonFormsResources.NormalDistribution_Mean_DisplayName}\r\n{RiskeerCommonFormsResources.ConstructiveStrength_Linear_LoadModel_DisplayName}"); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(StabilityPointStructuresCalculationRow.ConstructiveStrengthQuadraticLoadModel), $"{RiskeerCommonFormsResources.NormalDistribution_Mean_DisplayName}\r\n{RiskeerCommonFormsResources.ConstructiveStrength_Quadratic_LoadModel_DisplayName}"); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(StabilityPointStructuresCalculationRow.StabilityLinearLoadModel), $"{RiskeerCommonFormsResources.NormalDistribution_Mean_DisplayName}\r\n{RiskeerCommonFormsResources.Stability_Linear_LoadModel_DisplayName}"); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(StabilityPointStructuresCalculationRow.StabilityQuadraticLoadModel), $"{RiskeerCommonFormsResources.NormalDistribution_Mean_DisplayName}\r\n{RiskeerCommonFormsResources.Stability_Quadratic_LoadModel_DisplayName}"); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(StabilityPointStructuresCalculationRow.EvaluationLevel), RiskeerCommonFormsResources.Evaluation_Level_DisplayName); } - private void InitializeListBox() - { - listBox.DisplayMember = nameof(FailureMechanismSection.Name); - listBox.SelectedValueChanged += ListBoxOnSelectedValueChanged; - } + #region Prefill combo box list items - private void UpdateGenerateCalculationsButtonState() + protected override void PrefillComboBoxListItemsAtColumnLevel() { - buttonGenerateCalculations.Enabled = failureMechanism.StabilityPointStructures.Any(); - } + base.PrefillComboBoxListItemsAtColumnLevel(); - private StabilityPointStructuresInputContext CreateSelectedItemFromCurrentRow() - { - DataGridViewRow currentRow = dataGridViewControl.CurrentRow; + // 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. + var foreshoreProfiles = (DataGridViewComboBoxColumn) DataGridViewControl.GetColumnFromIndex(foreshoreProfileColumnIndex); - var calculationRow = (StabilityPointStructuresCalculationRow) currentRow?.DataBoundItem; - - StabilityPointStructuresInputContext selection = null; - if (calculationRow != null) + using (new SuspendDataGridViewColumnResizes(foreshoreProfiles)) { - selection = new StabilityPointStructuresInputContext( - calculationRow.CalculationScenario.InputParameters, - calculationRow.CalculationScenario, - failureMechanism, - assessmentSection); + SetItemsOnObjectCollection(foreshoreProfiles.Items, + GetForeshoreProfileDataSource(FailureMechanism.ForeshoreProfiles)); } - - return selection; } - private static void SetItemsOnObjectCollection(DataGridViewComboBoxCell.ObjectCollection objectCollection, object[] comboBoxItems) - { - objectCollection.Clear(); - objectCollection.AddRange(comboBoxItems); - } + #endregion - private static DataGridViewComboBoxItemWrapper[] GetSelectableHydraulicBoundaryLocationsDataSource( - IEnumerable selectableHydraulicBoundaryLocations = null) - { - var dataGridViewComboBoxItemWrappers = new List> - { - new DataGridViewComboBoxItemWrapper(null) - }; + #region Event handling - if (selectableHydraulicBoundaryLocations != null) - { - dataGridViewComboBoxItemWrappers.AddRange(selectableHydraulicBoundaryLocations.Select(hbl => new DataGridViewComboBoxItemWrapper(hbl))); - } - - return dataGridViewComboBoxItemWrappers.ToArray(); - } - - private void InitializeObservers() + private void HandleCellStyling(object sender, DataGridViewCellFormattingEventArgs e) { - failureMechanismObserver = new Observer(OnFailureMechanismUpdate) - { - Observable = failureMechanism - }; - hydraulicBoundaryLocationsObserver = new Observer(UpdateSelectableHydraulicBoundaryLocationsColumn) - { - Observable = assessmentSection.HydraulicBoundaryDatabase.Locations - }; - stabilityPointStructuresObserver = new Observer(UpdateGenerateCalculationsButtonState) - { - Observable = failureMechanism.StabilityPointStructures - }; - - // 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))) - { - Observable = calculationGroup - }; - calculationScenarioObserver = new RecursiveObserver>(() => dataGridViewControl.RefreshDataGridView(), pcg => pcg.Children) - { - Observable = calculationGroup - }; - calculationGroupObserver = new RecursiveObserver(UpdateDataGridViewDataSource, pcg => pcg.Children) - { - Observable = calculationGroup - }; + DataGridViewControl.FormatCellWithColumnStateDefinition(e.RowIndex, e.ColumnIndex); } - #region Data sources - - private void UpdateDataGridViewDataSource() - { - // Skip changes coming from the view itself - if (dataGridViewControl.IsCurrentCellInEditMode) - { - dataGridViewControl.AutoResizeColumns(); - } - - if (!(listBox.SelectedItem is FailureMechanismSection failureMechanismSection)) - { - dataGridViewControl.SetDataSource(null); - return; - } - - IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(failureMechanismSection.Points); - IEnumerable> calculationScenarios = calculationGroup - .GetCalculations() - .OfType>() - .Where(cs => cs.IsStructureIntersectionWithReferenceLineInSection(lineSegments)); - - PrefillComboBoxListItemsAtColumnLevel(); - - List dataSource = calculationScenarios.Select(cs => new StabilityPointStructuresCalculationRow(cs, new ObservablePropertyChangeHandler(cs, cs.InputParameters))).ToList(); - dataGridViewControl.SetDataSource(dataSource); - dataGridViewControl.ClearCurrentCell(); - - UpdateSelectableHydraulicBoundaryLocationsColumn(); - UpdateForeshoreProfilesColumn(); - } - #endregion #region Update combo box list items - #region Update SelectableHydraulicBoundaryLocations - - private void UpdateSelectableHydraulicBoundaryLocationsColumn() + protected override void UpdateColumns() { - var column = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableHydraulicBoundaryLocationColumnIndex); - - using (new SuspendDataGridViewColumnResizes(column)) - { - foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) - { - FillAvailableSelectableHydraulicBoundaryLocationsList(dataGridViewRow); - } - } + base.UpdateColumns(); + UpdateForeshoreProfilesColumn(); } - private void FillAvailableSelectableHydraulicBoundaryLocationsList(DataGridViewRow dataGridViewRow) - { - var rowData = (StabilityPointStructuresCalculationRow) dataGridViewRow.DataBoundItem; - IEnumerable locations = GetSelectableHydraulicBoundaryLocationsForCalculation(rowData.CalculationScenario); - - var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[selectableHydraulicBoundaryLocationColumnIndex]; - DataGridViewComboBoxItemWrapper[] dataGridViewComboBoxItemWrappers = GetSelectableHydraulicBoundaryLocationsDataSource(locations); - SetItemsOnObjectCollection(cell.Items, dataGridViewComboBoxItemWrappers); - } - - private IEnumerable GetSelectableHydraulicBoundaryLocationsForCalculation(StructuresCalculationScenario calculationScenario) - { - return GetSelectableHydraulicBoundaryLocations(assessmentSection?.HydraulicBoundaryDatabase.Locations, - calculationScenario.InputParameters.Structure); - } - - private static IEnumerable GetSelectableHydraulicBoundaryLocations( - IEnumerable hydraulicBoundaryLocations, StabilityPointStructure stabilityPointStructure) - { - Point2D referencePoint = stabilityPointStructure?.Location; - return SelectableHydraulicBoundaryLocationHelper.GetSortedSelectableHydraulicBoundaryLocations( - hydraulicBoundaryLocations, referencePoint); - } - - #endregion - #region Update ForeshoreProfiles private void UpdateForeshoreProfilesColumn() { - var column = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableForeshoreProfileColumnIndex); + var column = (DataGridViewComboBoxColumn) DataGridViewControl.GetColumnFromIndex(foreshoreProfileColumnIndex); using (new SuspendDataGridViewColumnResizes(column)) { - foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) + foreach (DataGridViewRow dataGridViewRow in DataGridViewControl.Rows) { FillAvailableForeshoreProfilesList(dataGridViewRow); } @@ -382,21 +234,21 @@ private void FillAvailableForeshoreProfilesList(DataGridViewRow dataGridViewRow) { - var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[selectableForeshoreProfileColumnIndex]; - DataGridViewComboBoxItemWrapper[] dataGridViewComboBoxItemWrappers = GetSelectableForeshoreProfileDataSource(failureMechanism.ForeshoreProfiles); + var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[foreshoreProfileColumnIndex]; + DataGridViewComboBoxItemWrapper[] dataGridViewComboBoxItemWrappers = GetForeshoreProfileDataSource(FailureMechanism.ForeshoreProfiles); SetItemsOnObjectCollection(cell.Items, dataGridViewComboBoxItemWrappers); } - private static DataGridViewComboBoxItemWrapper[] GetSelectableForeshoreProfileDataSource(IEnumerable selectableForeshoreProfiles = null) + private static DataGridViewComboBoxItemWrapper[] GetForeshoreProfileDataSource(IEnumerable foreshoreProfiles = null) { var dataGridViewComboBoxItemWrappers = new List> { new DataGridViewComboBoxItemWrapper(null) }; - if (selectableForeshoreProfiles != null) + if (foreshoreProfiles != null) { - dataGridViewComboBoxItemWrappers.AddRange(selectableForeshoreProfiles.Select(fp => new DataGridViewComboBoxItemWrapper(fp))); + dataGridViewComboBoxItemWrappers.AddRange(foreshoreProfiles.Select(fp => new DataGridViewComboBoxItemWrapper(fp))); } return dataGridViewComboBoxItemWrappers.ToArray(); @@ -405,99 +257,5 @@ #endregion #endregion - - #region Prefill combo box list items - - private void PrefillComboBoxListItemsAtColumnLevel() - { - 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(selectableHydraulicBoundaryLocationColumn)) - { - SetItemsOnObjectCollection(selectableHydraulicBoundaryLocationColumn.Items, - GetSelectableHydraulicBoundaryLocationsDataSource(GetSelectableHydraulicBoundaryLocationsFromFailureMechanism())); - } - - var selectableForeshoreProfiles = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableForeshoreProfileColumnIndex); - - using (new SuspendDataGridViewColumnResizes(selectableForeshoreProfiles)) - { - SetItemsOnObjectCollection(selectableForeshoreProfiles.Items, - GetSelectableForeshoreProfileDataSource(failureMechanism.ForeshoreProfiles)); - } - } - - private IEnumerable GetSelectableHydraulicBoundaryLocationsFromFailureMechanism() - { - List hydraulicBoundaryLocations = assessmentSection.HydraulicBoundaryDatabase.Locations; - - List selectableHydraulicBoundaryLocations = hydraulicBoundaryLocations.Select(hbl => new SelectableHydraulicBoundaryLocation(hbl, null)).ToList(); - - foreach (StabilityPointStructure stabilityPointStructure in failureMechanism.StabilityPointStructures) - { - selectableHydraulicBoundaryLocations.AddRange(GetSelectableHydraulicBoundaryLocations(hydraulicBoundaryLocations, stabilityPointStructure)); - } - - return selectableHydraulicBoundaryLocations; - } - - #endregion - - #region Event handling - - private void DataGridViewOnCurrentRowChangedHandler(object sender, EventArgs e) - { - OnSelectionChanged(); - } - - private void ListBoxOnSelectedValueChanged(object sender, EventArgs e) - { - UpdateDataGridViewDataSource(); - } - - private void OnGenerateCalculationsButtonClick(object sender, EventArgs e) - { - using (var dialog = new StructureSelectionDialog(Parent, failureMechanism.StabilityPointStructures)) - { - dialog.ShowDialog(); - - if (dialog.SelectedItems.Any()) - { - StructureCalculationConfigurationHelper.GenerateCalculations(calculationGroup, dialog.SelectedItems.Cast()); - calculationGroup.NotifyObservers(); - } - } - } - - private void OnFailureMechanismUpdate() - { - UpdateSectionsListBox(); - } - - private void UpdateSectionsListBox() - { - listBox.Items.Clear(); - - if (failureMechanism.Sections.Any()) - { - listBox.Items.AddRange(failureMechanism.Sections.Cast().ToArray()); - listBox.SelectedItem = failureMechanism.Sections.First(); - } - } - - private void OnSelectionChanged() - { - SelectionChanged?.Invoke(this, new EventArgs()); - } - - private void HandleCellStyling(object sender, DataGridViewCellFormattingEventArgs e) - { - dataGridViewControl.FormatCellWithColumnStateDefinition(e.RowIndex, e.ColumnIndex); - } - - #endregion } } \ No newline at end of file Fisheye: Tag 85f99d0f373b5ccc84747cd1db01c6039cb58053 refers to a dead (removed) revision in file `Riskeer/StabilityPointStructures/src/Riskeer.StabilityPointStructures.Forms/Views/StabilityPointStructuresCalculationsView.resx'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresCalculationRowTest.cs =================================================================== diff -u -r19cb5416755b464820d056fa7e4576e1c2ada4d6 -r85f99d0f373b5ccc84747cd1db01c6039cb58053 --- Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresCalculationRowTest.cs (.../StabilityPointStructuresCalculationRowTest.cs) (revision 19cb5416755b464820d056fa7e4576e1c2ada4d6) +++ Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresCalculationRowTest.cs (.../StabilityPointStructuresCalculationRowTest.cs) (revision 85f99d0f373b5ccc84747cd1db01c6039cb58053) @@ -32,9 +32,9 @@ using Riskeer.Common.Data.Structures; using Riskeer.Common.Data.TestUtil; using Riskeer.Common.Forms.ChangeHandlers; -using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.PropertyClasses; using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; using Riskeer.StabilityPointStructures.Data; using Riskeer.StabilityPointStructures.Data.TestUtil; using Riskeer.StabilityPointStructures.Forms.Views; @@ -47,57 +47,31 @@ private const int breakWaterTypeColumnIndex = 4; private const int breakWaterHeightColumnIndex = 5; private const int useForeshoreColumnIndex = 6; - private const int loadSchematizationTypeColumnIndex = 7; private const int constructiveStrengthLinearLoadModelColumnIndex = 8; private const int constructiveStrengthQuadraticLoadModelColumnIndex = 9; private const int stabilityLinearLoadModelColumnIndex = 10; private const int stabilityQuadraticLoadModelColumnIndex = 11; [Test] - public void Constructor_CalculationScenarioNull_ThrowsArgumentNullException() + public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var handler = mocks.Stub(); mocks.ReplayAll(); - // Call - void Call() => new StabilityPointStructuresCalculationRow(null, handler); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("calculationScenario", exception.ParamName); - mocks.VerifyAll(); - } - - [Test] - public void Constructor_HandlerNull_ThrowsArgumentNullException() - { - // Call - void Call() => new StabilityPointStructuresCalculationRow(new StructuresCalculationScenario(), null); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("handler", exception.ParamName); - } - - [Test] - public void Constructor_WithCalculation_PropertiesCorrectlySet() - { - // Setup - var mocks = new MockRepository(); - var handler = mocks.Stub(); - mocks.ReplayAll(); - var calculationScenario = new StructuresCalculationScenario(); // Call - var calculationRow = new StabilityPointStructuresCalculationRow(calculationScenario, handler); + var row = new StabilityPointStructuresCalculationRow(calculationScenario, handler); // Asserts - Assert.AreSame(calculationScenario, calculationRow.CalculationScenario); + Assert.IsInstanceOf>>(row); + Assert.IsInstanceOf(row); - IDictionary columnStateDefinitions = calculationRow.ColumnStateDefinitions; + Assert.AreSame(calculationScenario, row.Calculation); + + IDictionary columnStateDefinitions = row.ColumnStateDefinitions; Assert.AreEqual(7, columnStateDefinitions.Count); DataGridViewControlColumnStateDefinitionTestHelper.AssertColumnStateDefinition(columnStateDefinitions, breakWaterTypeColumnIndex); @@ -111,66 +85,6 @@ } [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"; - - var calculation = new StructuresCalculationScenario(); - var row = new StabilityPointStructuresCalculationRow(calculation, handler); - - calculation.Attach(observer); - - // Call - row.Name = newValue; - - // Assert - Assert.AreEqual(newValue, calculation.Name); - mockRepository.VerifyAll(); - } - - [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 StructuresCalculationScenario(); - - // Call & Assert - SetPropertyAndVerifyNotificationsAndOutputForCalculation(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 ForeshoreProfile_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() { // Setup Index: Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresCalculationsViewTest.cs =================================================================== diff -u -r8ac370ae3cc04a0cd7734374fc5efa4519285776 -r85f99d0f373b5ccc84747cd1db01c6039cb58053 --- Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresCalculationsViewTest.cs (.../StabilityPointStructuresCalculationsViewTest.cs) (revision 8ac370ae3cc04a0cd7734374fc5efa4519285776) +++ Riskeer/StabilityPointStructures/test/Riskeer.StabilityPointStructures.Forms.Test/Views/StabilityPointStructuresCalculationsViewTest.cs (.../StabilityPointStructuresCalculationsViewTest.cs) (revision 85f99d0f373b5ccc84747cd1db01c6039cb58053) @@ -23,15 +23,11 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Threading; 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 Core.Common.TestUtil; -using Core.Common.Util.Reflection; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; @@ -42,6 +38,7 @@ using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.Structures; using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.Views; using Riskeer.StabilityPointStructures.Data; using Riskeer.StabilityPointStructures.Data.TestUtil; using Riskeer.StabilityPointStructures.Forms.PresentationObjects; @@ -68,81 +65,27 @@ private Form testForm; [Test] - public void Constructor_CalculationGroupNull_ThrowsArgumentNullException() + public void Constructor_ExpectedValues() { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - // Call - void Call() => new StabilityPointStructuresCalculationsView(null, new TestStabilityPointStructuresFailureMechanism(), assessmentSection); + StabilityPointStructuresCalculationsView view = ShowCalculationsView(new CalculationGroup(), new StabilityPointStructuresFailureMechanism(), new AssessmentSectionStub()); // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("data", exception.ParamName); - mocks.VerifyAll(); - } + Assert.IsInstanceOf, StabilityPointStructuresInput, StabilityPointStructuresCalculationRow, StabilityPointStructuresFailureMechanism>>(view); - [Test] - public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() - { - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - void Call() => new StabilityPointStructuresCalculationsView(new CalculationGroup(), null, assessmentSection); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("failureMechanism", exception.ParamName); - mocks.VerifyAll(); + var button = (Button) new ControlTester("generateButton").TheObject; + Assert.AreEqual("Genereer &berekeningen...", button.Text); } [Test] - public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() - { - // Setup - StabilityPointStructuresFailureMechanism failureMechanism = new TestStabilityPointStructuresFailureMechanism(); - - // Call - void Call() => new StabilityPointStructuresCalculationsView(new CalculationGroup(), failureMechanism, null); - - // Assert - var exception = Assert.Throws(Call); - Assert.AreEqual("assessmentSection", exception.ParamName); - } - - [Test] - public void Constructor_ExpectedValues() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - ConfigureHydraulicBoundaryDatabase(assessmentSection); - StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); - - // Call - var calculationsView = new StabilityPointStructuresCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - - // Assert - Assert.IsInstanceOf(calculationsView); - Assert.IsInstanceOf(calculationsView); - Assert.IsInstanceOf(calculationsView); - mocks.VerifyAll(); - } - - [Test] public void Constructor_DataGridViewCorrectlyInitialized() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - ConfigureHydraulicBoundaryDatabase(assessmentSection); StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); // Call @@ -152,186 +95,47 @@ // Assert Assert.IsFalse(dataGridView.AutoGenerateColumns); + Assert.AreEqual(13, dataGridView.ColumnCount); + Assert.AreEqual("Naam", dataGridView.Columns[nameColumnIndex].HeaderText); + Assert.AreEqual("Hydraulische belastingenlocatie", dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex].HeaderText); + Assert.AreEqual("Voorlandprofiel", dataGridView.Columns[foreshoreProfileColumnIndex].HeaderText); + Assert.AreEqual("Gebruik dam", dataGridView.Columns[useBreakWaterColumnIndex].HeaderText); + Assert.AreEqual("Damtype", dataGridView.Columns[breakWaterTypeColumnIndex].HeaderText); + Assert.AreEqual("Damhoogte [m+NAP]", dataGridView.Columns[breakWaterHeightColumnIndex].HeaderText); + Assert.AreEqual("Gebruik voorlandgeometrie", dataGridView.Columns[useForeShoreGeometryColumnIndex].HeaderText); + Assert.AreEqual("Belastingschematisering", dataGridView.Columns[loadSchematizationTypeColumnIndex].HeaderText); + Assert.AreEqual("Verwachtingswaarde\r\nLineaire belastingschematisering constructieve sterkte [kN/m]", dataGridView.Columns[constructiveStrengthLinearLoadModelColumnIndex].HeaderText); + Assert.AreEqual("Verwachtingswaarde\r\nKwadratische belastingschematisering constructieve sterkte [kN/m]", dataGridView.Columns[constructiveStrengthQuadraticLoadModelColumnIndex].HeaderText); + Assert.AreEqual("Verwachtingswaarde\r\nLineaire belastingschematisering stabiliteit [kN/m²]", dataGridView.Columns[stabilityLinearLoadModelColumnIndex].HeaderText); + Assert.AreEqual("Verwachtingswaarde\r\nKwadratische belastingschematisering stabiliteit [kN/m²]", dataGridView.Columns[stabilityQuadraticLoadModelColumnIndex].HeaderText); + Assert.AreEqual("Analysehoogte [m+NAP]", dataGridView.Columns[evaluationLevelModelColumnIndex].HeaderText); - AssertColumnMembers(dataGridView.Columns.OfType().ToArray()); - AssertDataGridViewControlColumnHeaders(dataGridView); - mocks.VerifyAll(); - } + foreach (DataGridViewComboBoxColumn column in dataGridView.Columns.OfType().ToArray()) + { + Assert.AreEqual("DisplayName", column.DisplayMember); + } - [Test] - public void Constructor_ListBoxCorrectlyInitialized() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - ConfigureHydraulicBoundaryDatabase(assessmentSection); - StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); - - // Call - ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - - var listBox = (ListBox) new ControlTester("listBox").TheObject; - - // Assert - Assert.AreEqual(2, listBox.Items.Count); + Assert.AreEqual("This", ((IReadOnlyList) dataGridView.Columns.OfType().ToArray())[0].ValueMember); + Assert.AreEqual("This", ((IReadOnlyList) dataGridView.Columns.OfType().ToArray())[1].ValueMember); + Assert.AreEqual("Value", ((IReadOnlyList) dataGridView.Columns.OfType().ToArray())[2].ValueMember); mocks.VerifyAll(); } [Test] - public void AssessmentSection_HydraulicBoundaryDatabaseWithLocations_SelectableHydraulicBoundaryLocationsComboboxCorrectlyInitialized() + public void CalculationsView_CalculationsWithAllDataSet_DataGridViewCorrectlyInitialized() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - // Call - ShowFullyConfiguredCalculationsView(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 (2 m)", hydraulicBoundaryLocationComboboxItems[5].ToString()); - Assert.AreEqual("Location 2 (6 m)", hydraulicBoundaryLocationComboboxItems[6].ToString()); - mocks.VerifyAll(); - } - - [Test] - public void ButtonGenerateCalculations_StructuresPresent_ButtonEnabled() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - ConfigureHydraulicBoundaryDatabase(assessmentSection); - - StabilityPointStructuresCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection); - - var button = (Button) calculationsView.Controls.Find("buttonGenerateCalculations", true)[0]; - - // Call - bool state = button.Enabled; - - // Assert - Assert.IsTrue(state); - mocks.VerifyAll(); - } - - [Test] - public void CalculationsView_ChangingStructures_ButtonCorrectState() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - ConfigureHydraulicBoundaryDatabase(assessmentSection); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); + StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); - StabilityPointStructuresCalculationsView calculationsView = ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - - // Precondition - var button = (Button)calculationsView.Controls.Find("buttonGenerateCalculations", true)[0]; - Assert.IsFalse(button.Enabled); - - var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[] - { - new Point2D(0.0, 0.0), - new Point2D(5.0, 0.0) - }); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1 - }); - - failureMechanism.StabilityPointStructures.AddRange(new List - { - new TestStabilityPointStructure(new Point2D(0.0, 0.0), "Structure 1"), - new TestStabilityPointStructure(new Point2D(0.0, 0.0), "Structure 2") - }, string.Empty); - // Call - failureMechanism.StabilityPointStructures.NotifyObservers(); - - // Assert - Assert.IsTrue(button.Enabled); - mocks.VerifyAll(); - } - - [Test] - public void FailureMechanism_FailureMechanismWithSections_SectionsListBoxCorrectlyInitialized() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - ConfigureHydraulicBoundaryDatabase(assessmentSection); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[] - { - new Point2D(0.0, 0.0), - new Point2D(5.0, 0.0) - }); - var failureMechanismSection2 = new FailureMechanismSection("Section 2", new[] - { - new Point2D(5.0, 0.0), - new Point2D(10.0, 0.0) - }); - var failureMechanismSection3 = new FailureMechanismSection("Section 3", new[] - { - new Point2D(10.0, 0.0), - new Point2D(15.0, 0.0) - }); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1, - failureMechanismSection2, - failureMechanismSection3 - }); - - failureMechanism.ForeshoreProfiles.AddRange(new List - { - new TestForeshoreProfile("profiel1"), - new TestForeshoreProfile("profiel2") - }, string.Empty); - - // Call ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - // 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]); - mocks.VerifyAll(); - } - - [Test] - public void CalculationsView_CalculationsWithAllDataSet_DataGridViewCorrectlyInitialized() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - // Call - ShowFullyConfiguredCalculationsView(assessmentSection); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; // Assert @@ -342,7 +146,7 @@ Assert.AreEqual(13, cells.Count); Assert.AreEqual("Calculation 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual("Location 1 (2 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); - Assert.AreEqual("name", cells[foreshoreProfileColumnIndex].FormattedValue); + Assert.AreEqual("Profiel 1", cells[foreshoreProfileColumnIndex].FormattedValue); Assert.AreEqual(false, cells[useBreakWaterColumnIndex].FormattedValue); Assert.AreEqual("Havendam", cells[breakWaterTypeColumnIndex].FormattedValue); Assert.AreEqual(3.30.ToString("0.00", CultureInfo.CurrentCulture), cells[breakWaterHeightColumnIndex].FormattedValue); @@ -357,8 +161,8 @@ cells = rows[1].Cells; Assert.AreEqual(13, cells.Count); Assert.AreEqual("Calculation 2", cells[nameColumnIndex].FormattedValue); - Assert.AreEqual("Location 1 (4 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); - Assert.AreEqual("name", cells[foreshoreProfileColumnIndex].FormattedValue); + Assert.AreEqual("Location 2 (6 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); + Assert.AreEqual("Profiel 2", cells[foreshoreProfileColumnIndex].FormattedValue); Assert.AreEqual(false, cells[useBreakWaterColumnIndex].FormattedValue); Assert.AreEqual("Havendam", cells[breakWaterTypeColumnIndex].FormattedValue); Assert.AreEqual(3.30.ToString("0.00", CultureInfo.CurrentCulture), cells[breakWaterHeightColumnIndex].FormattedValue); @@ -373,67 +177,67 @@ } [Test] - [Apartment(ApartmentState.STA)] - public void CalculationsView_SelectingCellInRow_SelectionChangedFired() + public void ButtonGenerateCalculations_StructuresPresent_ButtonEnabled() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - ConfigureHydraulicBoundaryDatabase(assessmentSection); - StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); - using (var calculationsView = new StabilityPointStructuresCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection)) - { - var selectionChangedCount = 0; - calculationsView.SelectionChanged += (sender, args) => selectionChangedCount++; - var control = TypeUtils.GetField(calculationsView, "dataGridViewControl"); - WindowsFormsTestHelper.Show(control); + ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0]; + var button = (Button) new ControlTester("generateButton").TheObject; - // Call - EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(1, 0)); + // Call + bool state = button.Enabled; - // Assert - Assert.AreEqual(1, selectionChangedCount); - } - - WindowsFormsTestHelper.CloseAll(); + // Assert + Assert.IsTrue(state); mocks.VerifyAll(); } [Test] - public void CalculationsView_ChangingListBoxSelection_DataGridViewCorrectlySyncedAndSelectionChangedFired() + public void CalculationsView_ChangingStructures_ButtonCorrectState() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - StabilityPointStructuresCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var selectionChangedCount = 0; - calculationsView.SelectionChanged += (sender, args) => selectionChangedCount++; + ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - 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); + var button = (Button) new ControlTester("generateButton").TheObject; + Assert.IsFalse(button.Enabled); + var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[] + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + }); + + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + failureMechanismSection1 + }); + + failureMechanism.StabilityPointStructures.AddRange(new List + { + new TestStabilityPointStructure(new Point2D(0.0, 0.0), "Structure 1"), + new TestStabilityPointStructure(new Point2D(0.0, 0.0), "Structure 2") + }, string.Empty); + // Call - listBox.SelectedIndex = 1; + failureMechanism.StabilityPointStructures.NotifyObservers(); // Assert - Assert.AreEqual(1, dataGridView.Rows.Count); - Assert.AreEqual("Calculation 2", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); - Assert.AreEqual(2, selectionChangedCount); + Assert.IsTrue(button.Enabled); mocks.VerifyAll(); } @@ -455,10 +259,13 @@ // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - ShowFullyConfiguredCalculationsView(assessmentSection); + StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; // Call @@ -517,74 +324,6 @@ } [Test] - public void CalculationsViewWithFailureMechanism_WhenSectionsAddedAndFailureMechanismNotified_ThenSectionsListBoxCorrectlyUpdated() - { - // Given - var mocks = new MockRepository(); - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - ConfigureHydraulicBoundaryDatabase(assessmentSection); - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[] - { - new Point2D(0.0, 0.0), - new Point2D(5.0, 0.0) - }); - var failureMechanismSection2 = new FailureMechanismSection("Section 2", new[] - { - new Point2D(5.0, 0.0), - new Point2D(10.0, 0.0) - }); - var failureMechanismSection3 = new FailureMechanismSection("Section 3", new[] - { - new Point2D(10.0, 0.0), - new Point2D(15.0, 0.0) - }); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1, - failureMechanismSection2 - }); - - failureMechanism.ForeshoreProfiles.AddRange(new List - { - new TestForeshoreProfile("profiel1"), - new TestForeshoreProfile("profiel2") - }, string.Empty); - - ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - - var listBox = (ListBox) new ControlTester("listBox").TheObject; - - // Precondition - Assert.AreEqual(2, listBox.Items.Count); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1, - failureMechanismSection2, - failureMechanismSection3 - }); - - failureMechanism.ForeshoreProfiles.AddRange(new List - { - new TestForeshoreProfile("profiel3") - }, string.Empty); - - // When - failureMechanism.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]); - mocks.VerifyAll(); - } - - [Test] [TestCase(0, constructiveStrengthLinearLoadModelColumnIndex)] [TestCase(-123.45, constructiveStrengthLinearLoadModelColumnIndex)] [TestCase(1e-5, constructiveStrengthLinearLoadModelColumnIndex)] @@ -598,22 +337,23 @@ var calculationObserver = mocks.StrictMock(); var inputObserver = mocks.StrictMock(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - var newRoundedValue = (RoundedDouble) newValue; + StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(failureMechanism, assessmentSection); - StabilityPointStructuresCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection); + ShowCalculationsView(calculationGroup, failureMechanism, assessmentSection); - var data = (CalculationGroup) calculationsView.Data; - var calculation = (StructuresCalculationScenario) data.Children.First(); + var calculation = (StructuresCalculationScenario) calculationGroup.Children.First(); calculation.Attach(calculationObserver); calculation.InputParameters.Attach(inputObserver); var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; // Call - dataGridView.Rows[0].Cells[index].Value = newRoundedValue; + dataGridView.Rows[0].Cells[index].Value = (RoundedDouble) newValue; // Assert Assert.AreEqual("Gemiddelde moet groter zijn dan 0.", dataGridView.Rows[0].ErrorText); @@ -696,14 +436,17 @@ // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - StabilityPointStructuresCalculationsView view = ShowFullyConfiguredCalculationsView(assessmentSection); + StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(failureMechanism, assessmentSection); + ShowCalculationsView(calculationGroup, failureMechanism, assessmentSection); + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; // This step is necessary because setting the same value would not change the view state. - var calculationGroup = (CalculationGroup) view.Data; var calculation = (StructuresCalculationScenario) calculationGroup.GetCalculations().First(); calculation.InputParameters.UseBreakWater = !newValue; @@ -724,14 +467,17 @@ // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - StabilityPointStructuresCalculationsView view = ShowFullyConfiguredCalculationsView(assessmentSection); + StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(failureMechanism, assessmentSection); + ShowCalculationsView(calculationGroup, failureMechanism, assessmentSection); + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; // This step is necessary because setting the same value would not change the view state. - var calculationGroup = (CalculationGroup) view.Data; var calculation = (StructuresCalculationScenario) calculationGroup.GetCalculations().First(); calculation.InputParameters.LoadSchematizationType = controlValue; @@ -754,74 +500,28 @@ // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - StabilityPointStructuresCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection); + StabilityPointStructuresFailureMechanism failureMechanism = ConfigureFailureMechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(failureMechanism, assessmentSection); + StabilityPointStructuresCalculationsView view = ShowCalculationsView(calculationGroup, failureMechanism, assessmentSection); + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; dataGridView.CurrentCell = dataGridView.Rows[selectedRow].Cells[0]; // Call - object selection = calculationsView.Selection; + object selection = view.Selection; // Assert Assert.IsInstanceOf(selection); var dataRow = (StabilityPointStructuresCalculationRow) dataGridView.Rows[selectedRow].DataBoundItem; - Assert.AreSame(dataRow.CalculationScenario, ((StabilityPointStructuresInputContext) selection).Calculation); + Assert.AreSame(dataRow.Calculation, ((StabilityPointStructuresInputContext) selection).Calculation); mocks.VerifyAll(); } - [Test] - [TestCase(true)] - [TestCase(false)] - public void CalculationsView_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(); - - StabilityPointStructuresCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection); - - var data = (CalculationGroup) calculationsView.Data; - var calculation = (StructuresCalculationScenario) data.Children.First(); - - if (useCalculationWithOutput) - { - calculation.Output = new TestStructuresOutput(); - } - - 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(); - } - - private static void AssertColumnMembers(IReadOnlyList dataGridViewColumns) - { - foreach (DataGridViewComboBoxColumn column in dataGridViewColumns) - { - Assert.AreEqual("DisplayName", column.DisplayMember); - } - - Assert.AreEqual("This", dataGridViewColumns[0].ValueMember); - Assert.AreEqual("This", dataGridViewColumns[1].ValueMember); - Assert.AreEqual("Value", dataGridViewColumns[2].ValueMember); - } - public override void Setup() { base.Setup(); @@ -836,40 +536,6 @@ testForm.Dispose(); } - private StabilityPointStructuresCalculationsView ShowFullyConfiguredCalculationsView(IAssessmentSection assessmentSection) - { - ConfigureHydraulicBoundaryDatabase(assessmentSection); - - var failureMechanism = new StabilityPointStructuresFailureMechanism(); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - new FailureMechanismSection("Section 1", new[] - { - new Point2D(0.0, 0.0), - new Point2D(5.0, 0.0) - }), - new FailureMechanismSection("Section 2", new[] - { - new Point2D(5.0, 0.0), - new Point2D(10.0, 0.0) - }) - }); - - failureMechanism.StabilityPointStructures.AddRange(new List - { - new TestStabilityPointStructure(new Point2D(0.0, 0.0), "Structure 1"), - new TestStabilityPointStructure(new Point2D(0.0, 0.0), "Structure 2") - }, string.Empty); - failureMechanism.ForeshoreProfiles.AddRange(new List - { - new TestForeshoreProfile("profiel 1"), - new TestForeshoreProfile("profiel 2") - }, string.Empty); - - return ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); - } - private StabilityPointStructuresCalculationsView ShowCalculationsView(CalculationGroup calculationGroup, StabilityPointStructuresFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { var calculationsView = new StabilityPointStructuresCalculationsView(calculationGroup, failureMechanism, assessmentSection); @@ -907,7 +573,7 @@ }, InputParameters = { - Structure = new TestStabilityPointStructure(new Point2D(0.0, 0.0)), + Structure = failureMechanism.StabilityPointStructures.FirstOrDefault(), LoadSchematizationType = random.NextEnumValue(), ConstructiveStrengthLinearLoadModel = { @@ -947,7 +613,7 @@ }, InputParameters = { - Structure = new TestStabilityPointStructure(new Point2D(5.0, 0.0)), + Structure = failureMechanism.StabilityPointStructures.LastOrDefault(), LoadSchematizationType = random.NextEnumValue(), ConstructiveStrengthLinearLoadModel = { @@ -966,8 +632,8 @@ Mean = (RoundedDouble) 100.00 }, EvaluationLevel = (RoundedDouble) 10.00, - ForeshoreProfile = failureMechanism.ForeshoreProfiles.FirstOrDefault(), - HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(), + ForeshoreProfile = failureMechanism.ForeshoreProfiles.LastOrDefault(), + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.Last(), BreakWater = { Height = (RoundedDouble) 3.3, @@ -1000,31 +666,19 @@ }) }); + failureMechanism.StabilityPointStructures.AddRange(new List + { + new TestStabilityPointStructure(new Point2D(0.0, 0.0), "Structure 1"), + new TestStabilityPointStructure(new Point2D(0.0, 0.0), "Structure 2") + }, string.Empty); + failureMechanism.ForeshoreProfiles.AddRange(new List { - new TestForeshoreProfile("profiel1"), - new TestForeshoreProfile("profiel2") + new TestForeshoreProfile("Profiel 1", "1"), + new TestForeshoreProfile("Profiel 2", "2") }, string.Empty); return failureMechanism; } - - private static void AssertDataGridViewControlColumnHeaders(DataGridView dataGridView) - { - Assert.AreEqual(13, dataGridView.ColumnCount); - Assert.AreEqual("Naam", dataGridView.Columns[nameColumnIndex].HeaderText); - Assert.AreEqual("Hydraulische belastingenlocatie", dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex].HeaderText); - Assert.AreEqual("Voorlandprofiel", dataGridView.Columns[foreshoreProfileColumnIndex].HeaderText); - Assert.AreEqual("Gebruik dam", dataGridView.Columns[useBreakWaterColumnIndex].HeaderText); - Assert.AreEqual("Damtype", dataGridView.Columns[breakWaterTypeColumnIndex].HeaderText); - Assert.AreEqual("Damhoogte [m+NAP]", dataGridView.Columns[breakWaterHeightColumnIndex].HeaderText); - Assert.AreEqual("Gebruik voorlandgeometrie", dataGridView.Columns[useForeShoreGeometryColumnIndex].HeaderText); - Assert.AreEqual("Belastingschematisering", dataGridView.Columns[loadSchematizationTypeColumnIndex].HeaderText); - Assert.AreEqual("Verwachtingswaarde\r\nLineaire belastingschematisering constructieve sterkte [kN/m]", dataGridView.Columns[constructiveStrengthLinearLoadModelColumnIndex].HeaderText); - Assert.AreEqual("Verwachtingswaarde\r\nKwadratische belastingschematisering constructieve sterkte [kN/m]", dataGridView.Columns[constructiveStrengthQuadraticLoadModelColumnIndex].HeaderText); - Assert.AreEqual("Verwachtingswaarde\r\nLineaire belastingschematisering stabiliteit [kN/m²]", dataGridView.Columns[stabilityLinearLoadModelColumnIndex].HeaderText); - Assert.AreEqual("Verwachtingswaarde\r\nKwadratische belastingschematisering stabiliteit [kN/m²]", dataGridView.Columns[stabilityQuadraticLoadModelColumnIndex].HeaderText); - Assert.AreEqual("Analysehoogte [m+NAP]", dataGridView.Columns[evaluationLevelModelColumnIndex].HeaderText); - } } } \ No newline at end of file