Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationRow.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationRow.cs (.../MacroStabilityInwardsCalculationRow.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationRow.cs (.../MacroStabilityInwardsCalculationRow.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -21,11 +21,12 @@ using System; using Core.Common.Base.Data; +using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Forms.ChangeHandlers; -using Riskeer.Common.Forms.PresentationObjects; using Riskeer.Common.Forms.PropertyClasses; +using Riskeer.Common.Forms.Views; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Data.SoilProfile; @@ -34,70 +35,30 @@ /// /// This class represents a row of in the . /// - internal class MacroStabilityInwardsCalculationRow + public class MacroStabilityInwardsCalculationRow : CalculationRow { - 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 MacroStabilityInwardsCalculationRow(MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculation, + internal MacroStabilityInwardsCalculationRow(MacroStabilityInwardsCalculationScenario calculationScenario, IObservablePropertyChangeHandler handler) - { - if (macroStabilityInwardsCalculation == null) - { - throw new ArgumentNullException(nameof(macroStabilityInwardsCalculation)); - } + : base(calculationScenario, handler) {} - 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); - } + get => new DataGridViewComboBoxItemWrapper(Calculation.InputParameters.StochasticSoilModel); set { MacroStabilityInwardsStochasticSoilModel valueToSet = value?.WrappedObject; - if (!ReferenceEquals(MacroStabilityInwardsCalculation.InputParameters.StochasticSoilModel, valueToSet)) + if (!ReferenceEquals(Calculation.InputParameters.StochasticSoilModel, valueToSet)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.StochasticSoilModel = valueToSet, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.StochasticSoilModel = valueToSet, PropertyChangeHandler); } } } @@ -107,57 +68,34 @@ /// public DataGridViewComboBoxItemWrapper StochasticSoilProfile { - get - { - return new DataGridViewComboBoxItemWrapper(MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile); - } + get => new DataGridViewComboBoxItemWrapper(Calculation.InputParameters.StochasticSoilProfile); set { MacroStabilityInwardsStochasticSoilProfile valueToSet = value?.WrappedObject; - if (!ReferenceEquals(MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile, valueToSet)) + if (!ReferenceEquals(Calculation.InputParameters.StochasticSoilProfile, valueToSet)) { - PropertyChangeHelper.ChangePropertyAndNotify(() => MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile = valueToSet, propertyChangeHandler); + PropertyChangeHelper.ChangePropertyAndNotify(() => Calculation.InputParameters.StochasticSoilProfile = valueToSet, PropertyChangeHandler); } } } /// /// Gets the stochastic soil profile probability of the . /// - public RoundedDouble StochasticSoilProfileProbability + public RoundedDouble StochasticSoilProfileProbability => + Calculation.InputParameters.StochasticSoilProfile != null + ? new RoundedDouble(2, Calculation.InputParameters.StochasticSoilProfile.Probability * 100) + : new RoundedDouble(2); + + public override Point2D GetCalculationLocation() { - get - { - return MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile != null - ? new RoundedDouble(2, MacroStabilityInwardsCalculation.InputParameters.StochasticSoilProfile.Probability * 100) - : new RoundedDouble(2); - } + return Calculation.InputParameters.SurfaceLine?.ReferenceLineIntersectionWorldPoint; } - /// - /// Gets or sets the hydraulic boundary location of the . - /// - public DataGridViewComboBoxItemWrapper SelectableHydraulicBoundaryLocation + protected override HydraulicBoundaryLocation HydraulicBoundaryLocation { - 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); - } - } + get => Calculation.InputParameters.HydraulicBoundaryLocation; + set => Calculation.InputParameters.HydraulicBoundaryLocation = value; } } } \ No newline at end of file Fisheye: Tag 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 refers to a dead (removed) revision in file `Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.cs (.../MacroStabilityInwardsCalculationsView.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.cs (.../MacroStabilityInwardsCalculationsView.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -26,14 +26,11 @@ using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; -using Core.Common.Controls.Views; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; -using Riskeer.Common.Data.FailureMechanism; -using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Forms.ChangeHandlers; using Riskeer.Common.Forms.Helpers; -using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.Common.Forms.Views; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Data.SoilProfile; using Riskeer.MacroStabilityInwards.Forms.PresentationObjects; @@ -47,363 +44,202 @@ /// /// This class is a view for configuring macro stability inwards calculations. /// - public partial class MacroStabilityInwardsCalculationsView : UserControl, ISelectionProvider, IView + public class MacroStabilityInwardsCalculationsView : CalculationsView { - private const int stochasticSoilModelColumnIndex = 1; - private const int stochasticSoilProfileColumnIndex = 2; - private const int selectableHydraulicBoundaryLocationColumnIndex = 4; + private const int selectableHydraulicBoundaryLocationColumnIndex = 1; + private const int stochasticSoilModelColumnIndex = 2; + private const int stochasticSoilProfileColumnIndex = 3; - private readonly Observer hydraulicBoundaryLocationsObserver; - 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; - public event EventHandler SelectionChanged; - /// /// Creates a new instance of . /// - public MacroStabilityInwardsCalculationsView() + public MacroStabilityInwardsCalculationsView(CalculationGroup calculationGroup, MacroStabilityInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + : base(calculationGroup, failureMechanism, assessmentSection) { - InitializeComponent(); - InitializeDataGridView(); - InitializeListBox(); + surfaceLineObserver = new RecursiveObserver(() => + { + UpdateColumns(); + UpdateGenerateCalculationsButtonState(); + }, rpslc => rpslc) + { + Observable = failureMechanism.SurfaceLines + }; - failureMechanismObserver = new Observer(OnFailureMechanismUpdate); - hydraulicBoundaryLocationsObserver = new Observer(UpdateSelectableHydraulicBoundaryLocationsColumn); - // The concat is needed to observe the input of calculations in child groups. - inputObserver = new RecursiveObserver(UpdateDataGridViewDataSource, cg => cg.Children - .Concat(cg.Children - .OfType() - .Select(pc => pc.InputParameters))); - calculationGroupObserver = new RecursiveObserver(UpdateDataGridViewDataSource, cg => cg.Children); - calculationObserver = new RecursiveObserver(() => dataGridViewControl.RefreshDataGridView(), cg => cg.Children); - - surfaceLineObserver = new RecursiveObserver(UpdateDataGridViewDataSource, rpslc => rpslc); - - stochasticSoilModelsObserver = new Observer(OnStochasticSoilModelsUpdate); - stochasticSoilProfileObserver = new RecursiveObserver(() => dataGridViewControl.RefreshDataGridView(), ssmc => ssmc.SelectMany(ssm => ssm.StochasticSoilProfiles)); + stochasticSoilModelsObserver = new Observer(() => + { + UpdateColumns(); + UpdateGenerateCalculationsButtonState(); + }) + { + Observable = failureMechanism.StochasticSoilModels + }; + stochasticSoilProfileObserver = new RecursiveObserver( + () => DataGridViewControl.RefreshDataGridView(), + ssmc => ssmc.SelectMany(ssm => ssm.StochasticSoilProfiles)) + { + Observable = failureMechanism.StochasticSoilModels + }; } - /// - /// Gets or sets the macro stability inwards failure mechanism. - /// - public MacroStabilityInwardsFailureMechanism MacroStabilityInwardsFailureMechanism + protected override void OnLoad(EventArgs e) { - get - { - return macroStabilityInwardsFailureMechanism; - } - set - { - macroStabilityInwardsFailureMechanism = value; - stochasticSoilModelsObserver.Observable = macroStabilityInwardsFailureMechanism?.StochasticSoilModels; - failureMechanismObserver.Observable = macroStabilityInwardsFailureMechanism; - surfaceLineObserver.Observable = macroStabilityInwardsFailureMechanism?.SurfaceLines; - stochasticSoilProfileObserver.Observable = macroStabilityInwardsFailureMechanism?.StochasticSoilModels; + base.OnLoad(e); - UpdateStochasticSoilModelColumn(); - UpdateStochasticSoilProfileColumn(); - UpdateSelectableHydraulicBoundaryLocationsColumn(); - UpdateSectionsListBox(); - UpdateGenerateScenariosButtonState(); - } + GenerateButton.Text = RiskeerCommonFormsResources.CalculationGroup_Generate_Scenarios; } - /// - /// Gets or sets the assessment section. - /// - public IAssessmentSection AssessmentSection + protected override void Dispose(bool disposing) { - get + if (disposing) { - return assessmentSection; + surfaceLineObserver.Dispose(); + stochasticSoilProfileObserver.Dispose(); + stochasticSoilModelsObserver.Dispose(); } - set - { - assessmentSection = value; - hydraulicBoundaryLocationsObserver.Observable = assessmentSection?.HydraulicBoundaryDatabase.Locations; + base.Dispose(disposing); + } - UpdateSelectableHydraulicBoundaryLocationsColumn(); - } + protected override object CreateSelectedItemFromCurrentRow(MacroStabilityInwardsCalculationRow currentRow) + { + return new MacroStabilityInwardsInputContext( + currentRow.Calculation.InputParameters, + currentRow.Calculation, + FailureMechanism.SurfaceLines, + FailureMechanism.StochasticSoilModels, + FailureMechanism, + AssessmentSection); } - public object Selection + protected override IEnumerable GetReferenceLocations() { - get - { - return CreateSelectedItemFromCurrentRow(); - } + return FailureMechanism.SurfaceLines.Select(sl => sl.ReferenceLineIntersectionWorldPoint); } - public object Data + protected override bool IsCalculationIntersectionWithReferenceLineInSection(MacroStabilityInwardsCalculationScenario calculation, IEnumerable lineSegments) { - get - { - return calculationGroup; - } - set - { - calculationGroup = value as CalculationGroup; + return calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments); + } - 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 MacroStabilityInwardsCalculationRow CreateRow(MacroStabilityInwardsCalculationScenario calculation) + { + return new MacroStabilityInwardsCalculationRow(calculation, new ObservablePropertyChangeHandler(calculation, calculation.InputParameters)); } - protected override void OnLoad(EventArgs e) + protected override bool CanGenerateCalculations() { - // Necessary to correctly load the content of the dropdown lists of the comboboxes... - UpdateDataGridViewDataSource(); - base.OnLoad(e); + return FailureMechanism.SurfaceLines.Any() && FailureMechanism.StochasticSoilModels.Any(); } - protected override void Dispose(bool disposing) + protected override void GenerateCalculations() { - if (disposing) - { - dataGridViewControl.CellFormatting -= OnCellFormatting; - dataGridViewControl.CurrentRowChanged -= DataGridViewOnCurrentRowChangedHandler; + var calculationGroup = (CalculationGroup) Data; - hydraulicBoundaryLocationsObserver.Dispose(); - failureMechanismObserver.Dispose(); - inputObserver.Dispose(); - calculationObserver.Dispose(); - surfaceLineObserver.Dispose(); - calculationGroupObserver.Dispose(); - stochasticSoilProfileObserver.Dispose(); - stochasticSoilModelsObserver.Dispose(); - - components?.Dispose(); + var dialog = new MacroStabilityInwardsSurfaceLineSelectionDialog(Parent, FailureMechanism.SurfaceLines); + dialog.ShowDialog(); + IEnumerable calculationsStructure = MacroStabilityInwardsCalculationConfigurationHelper.GenerateCalculationItemsStructure( + dialog.SelectedItems, + FailureMechanism.StochasticSoilModels); + foreach (ICalculationBase item in calculationsStructure) + { + calculationGroup.Children.Add(item); } - base.Dispose(disposing); + calculationGroup.NotifyObservers(); } - private void InitializeDataGridView() + protected override void InitializeDataGridView() { - dataGridViewControl.CurrentRowChanged += DataGridViewOnCurrentRowChangedHandler; - dataGridViewControl.CellFormatting += OnCellFormatting; + DataGridViewControl.CellFormatting += OnCellFormatting; - dataGridViewControl.AddTextBoxColumn( - nameof(MacroStabilityInwardsCalculationRow.Name), - Resources.MacroStabilityInwardsCalculation_Name_DisplayName); + base.InitializeDataGridView(); - dataGridViewControl.AddComboBoxColumn>( + DataGridViewControl.AddComboBoxColumn>( nameof(MacroStabilityInwardsCalculationRow.StochasticSoilModel), Resources.MacroStabilityInwardsInput_StochasticSoilModel_DisplayName, null, nameof(DataGridViewComboBoxItemWrapper.This), nameof(DataGridViewComboBoxItemWrapper.DisplayName)); - dataGridViewControl.AddComboBoxColumn>( + DataGridViewControl.AddComboBoxColumn>( nameof(MacroStabilityInwardsCalculationRow.StochasticSoilProfile), Resources.MacroStabilityInwardsInput_StochasticSoilProfile_DisplayName, null, nameof(DataGridViewComboBoxItemWrapper.This), nameof(DataGridViewComboBoxItemWrapper.DisplayName)); - dataGridViewControl.AddTextBoxColumn( + DataGridViewControl.AddTextBoxColumn( nameof(MacroStabilityInwardsCalculationRow.StochasticSoilProfileProbability), Resources.MacroStabilityInwardsCalculationsView_InitializeDataGridView_Stochastic_soil_profile_probability); - dataGridViewControl.AddComboBoxColumn>( - nameof(MacroStabilityInwardsCalculationRow.SelectableHydraulicBoundaryLocation), - RiskeerCommonFormsResources.HydraulicBoundaryLocation_DisplayName, - null, - nameof(DataGridViewComboBoxItemWrapper.This), - nameof(DataGridViewComboBoxItemWrapper.DisplayName)); - UpdateStochasticSoilModelColumn(); UpdateStochasticSoilProfileColumn(); - UpdateSelectableHydraulicBoundaryLocationsColumn(); } - private void InitializeListBox() + protected override void UpdateColumns() { - listBox.DisplayMember = nameof(FailureMechanismSection.Name); - listBox.SelectedValueChanged += ListBoxOnSelectedValueChanged; + base.UpdateColumns(); + UpdateStochasticSoilModelColumn(); + UpdateStochasticSoilProfileColumn(); } - private void UpdateGenerateScenariosButtonState() - { - buttonGenerateScenarios.Enabled = macroStabilityInwardsFailureMechanism != null && - macroStabilityInwardsFailureMechanism.SurfaceLines.Any() && - macroStabilityInwardsFailureMechanism.StochasticSoilModels.Any(); - } + #region Event handling - private static void SetItemsOnObjectCollection(DataGridViewComboBoxCell.ObjectCollection objectCollection, object[] comboBoxItems) + private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { - objectCollection.Clear(); - objectCollection.AddRange(comboBoxItems); - } - - private MacroStabilityInwardsInputContext CreateSelectedItemFromCurrentRow() - { - DataGridViewRow currentRow = dataGridViewControl.CurrentRow; - - var calculationRow = (MacroStabilityInwardsCalculationRow) currentRow?.DataBoundItem; - - MacroStabilityInwardsInputContext selection = null; - if (calculationRow != null) + if (eventArgs.ColumnIndex == selectableHydraulicBoundaryLocationColumnIndex) { - selection = new MacroStabilityInwardsInputContext( - calculationRow.MacroStabilityInwardsCalculation.InputParameters, - calculationRow.MacroStabilityInwardsCalculation, - macroStabilityInwardsFailureMechanism.SurfaceLines, - macroStabilityInwardsFailureMechanism.StochasticSoilModels, - macroStabilityInwardsFailureMechanism, - assessmentSection); + DataGridViewRow dataGridViewRow = DataGridViewControl.GetRowFromIndex(eventArgs.RowIndex); + dataGridViewRow.Cells[selectableHydraulicBoundaryLocationColumnIndex].ReadOnly = dataGridViewRow.DataBoundItem is MacroStabilityInwardsCalculationRow dataItem + && dataItem.Calculation.InputParameters.UseAssessmentLevelManualInput; } - - return selection; } - private static IEnumerable GetSelectableHydraulicBoundaryLocations( - IEnumerable hydraulicBoundaryLocations, MacroStabilityInwardsSurfaceLine surfaceLine) - { - Point2D referencePoint = surfaceLine?.ReferenceLineIntersectionWorldPoint; - return SelectableHydraulicBoundaryLocationHelper.GetSortedSelectableHydraulicBoundaryLocations( - hydraulicBoundaryLocations, referencePoint); - } + #endregion #region Data sources - private void UpdateDataGridViewDataSource() + private static IEnumerable> GetStochasticSoilModelsDataSource( + IEnumerable stochasticSoilModels) { - // Skip changes coming from the view itself - if (dataGridViewControl.IsCurrentCellInEditMode) + var dataGridViewComboBoxItemWrappers = new List> { - UpdateStochasticSoilProfileColumn(); + new DataGridViewComboBoxItemWrapper(null) + }; - dataGridViewControl.AutoResizeColumns(); + dataGridViewComboBoxItemWrappers.AddRange(stochasticSoilModels.Select(stochasticSoilModel => new DataGridViewComboBoxItemWrapper(stochasticSoilModel))); - return; - } - - var failureMechanismSection = listBox.SelectedItem as FailureMechanismSection; - if (failureMechanismSection == null || calculationGroup == null) - { - dataGridViewControl.SetDataSource(null); - return; - } - - IEnumerable lineSegments = Math2D.ConvertPointsToLineSegments(failureMechanismSection.Points); - IEnumerable calculations = calculationGroup - .GetCalculations() - .OfType() - .Where(pc => pc.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments)); - - PrefillComboBoxListItemsAtColumnLevel(); - - List dataSource = calculations.Select(pc => new MacroStabilityInwardsCalculationRow(pc, new ObservablePropertyChangeHandler(pc, pc.InputParameters))).ToList(); - dataGridViewControl.SetDataSource(dataSource); - dataGridViewControl.ClearCurrentCell(); - - UpdateStochasticSoilModelColumn(); - UpdateStochasticSoilProfileColumn(); - UpdateSelectableHydraulicBoundaryLocationsColumn(); + return dataGridViewComboBoxItemWrappers.ToArray(); } - private static IEnumerable> GetStochasticSoilModelsDataSource(IEnumerable stochasticSoilModels) + private static IEnumerable> GetSoilProfilesDataSource( + IEnumerable stochasticSoilProfiles) { - yield return new DataGridViewComboBoxItemWrapper(null); - - foreach (MacroStabilityInwardsStochasticSoilModel stochasticSoilModel in stochasticSoilModels) + var dataGridViewComboBoxItemWrappers = new List> { - yield return new DataGridViewComboBoxItemWrapper(stochasticSoilModel); - } - } - - private static IEnumerable> GetSoilProfilesDataSource(IEnumerable stochasticSoilProfiles) - { - yield return new DataGridViewComboBoxItemWrapper(null); - - foreach (MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile in stochasticSoilProfiles) - { - yield return new DataGridViewComboBoxItemWrapper(stochasticSoilProfile); - } - } - - private static List> GetSelectableHydraulicBoundaryLocationsDataSource(IEnumerable selectableHydraulicBoundaryLocations = null) - { - var dataGridViewComboBoxItemWrappers = new List> - { - new DataGridViewComboBoxItemWrapper(null) + new DataGridViewComboBoxItemWrapper(null) }; - if (selectableHydraulicBoundaryLocations != null) - { - dataGridViewComboBoxItemWrappers.AddRange(selectableHydraulicBoundaryLocations.Select(hbl => new DataGridViewComboBoxItemWrapper(hbl))); - } + dataGridViewComboBoxItemWrappers.AddRange(stochasticSoilProfiles.Select(stochasticSoilProfile => new DataGridViewComboBoxItemWrapper(stochasticSoilProfile))); - return dataGridViewComboBoxItemWrappers; + return dataGridViewComboBoxItemWrappers.ToArray(); } #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) - { - return GetSelectableHydraulicBoundaryLocations(assessmentSection?.HydraulicBoundaryDatabase.Locations, - macroStabilityInwardsCalculation.InputParameters.SurfaceLine); - } - - #endregion - #region Update Stochastic Soil Model Column private void UpdateStochasticSoilModelColumn() { - using (new SuspendDataGridViewColumnResizes(dataGridViewControl.GetColumnFromIndex(stochasticSoilModelColumnIndex))) + using (new SuspendDataGridViewColumnResizes(DataGridViewControl.GetColumnFromIndex(stochasticSoilModelColumnIndex))) { - foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) + foreach (DataGridViewRow dataGridViewRow in DataGridViewControl.Rows) { FillAvailableSoilModelsList(dataGridViewRow); } @@ -413,22 +249,17 @@ private void FillAvailableSoilModelsList(DataGridViewRow dataGridViewRow) { var rowData = (MacroStabilityInwardsCalculationRow) dataGridViewRow.DataBoundItem; - IEnumerable stochasticSoilModels = GetSoilModelsForCalculation(rowData.MacroStabilityInwardsCalculation); + IEnumerable stochasticSoilModels = GetSoilModelsForCalculation(rowData.Calculation); var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[stochasticSoilModelColumnIndex]; SetItemsOnObjectCollection(cell.Items, GetStochasticSoilModelsDataSource(stochasticSoilModels).ToArray()); } - private IEnumerable GetSoilModelsForCalculation(MacroStabilityInwardsCalculation macroStabilityInwardsCalculation) + private IEnumerable GetSoilModelsForCalculation(MacroStabilityInwardsCalculation calculation) { - if (macroStabilityInwardsFailureMechanism == null) - { - return Enumerable.Empty(); - } - return MacroStabilityInwardsCalculationConfigurationHelper.GetStochasticSoilModelsForSurfaceLine( - macroStabilityInwardsCalculation.InputParameters.SurfaceLine, - macroStabilityInwardsFailureMechanism.StochasticSoilModels); + calculation.InputParameters.SurfaceLine, + FailureMechanism.StochasticSoilModels); } #endregion @@ -437,34 +268,31 @@ private void UpdateStochasticSoilProfileColumn() { - using (new SuspendDataGridViewColumnResizes(dataGridViewControl.GetColumnFromIndex(stochasticSoilProfileColumnIndex))) + using (new SuspendDataGridViewColumnResizes(DataGridViewControl.GetColumnFromIndex(stochasticSoilProfileColumnIndex))) { - foreach (DataGridViewRow dataGridViewRow in dataGridViewControl.Rows) + foreach (DataGridViewRow dataGridViewRow in DataGridViewControl.Rows) { FillAvailableSoilProfilesList(dataGridViewRow); } } } - private void FillAvailableSoilProfilesList(DataGridViewRow dataGridViewRow) + private static void FillAvailableSoilProfilesList(DataGridViewRow dataGridViewRow) { var rowData = (MacroStabilityInwardsCalculationRow) dataGridViewRow.DataBoundItem; - MacroStabilityInwardsInputService.SyncStochasticSoilProfileWithStochasticSoilModel(rowData.MacroStabilityInwardsCalculation.InputParameters); + MacroStabilityInwardsInputService.SyncStochasticSoilProfileWithStochasticSoilModel(rowData.Calculation.InputParameters); - IEnumerable stochasticSoilProfiles = GetSoilProfilesForCalculation(rowData.MacroStabilityInwardsCalculation); + IEnumerable stochasticSoilProfiles = GetSoilProfilesForCalculation(rowData.Calculation); var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[stochasticSoilProfileColumnIndex]; SetItemsOnObjectCollection(cell.Items, GetSoilProfilesDataSource(stochasticSoilProfiles).ToArray()); } - private static IEnumerable GetSoilProfilesForCalculation(MacroStabilityInwardsCalculation macroStabilityInwardsCalculation) + private static IEnumerable GetSoilProfilesForCalculation(MacroStabilityInwardsCalculation calculation) { - if (macroStabilityInwardsCalculation.InputParameters.StochasticSoilModel == null) - { - return Enumerable.Empty(); - } - - return macroStabilityInwardsCalculation.InputParameters.StochasticSoilModel.StochasticSoilProfiles; + return calculation.InputParameters.StochasticSoilModel != null + ? calculation.InputParameters.StochasticSoilModel.StochasticSoilProfiles + : Enumerable.Empty(); } #endregion @@ -473,140 +301,36 @@ #region Prefill combo box list items - private void PrefillComboBoxListItemsAtColumnLevel() + protected override void PrefillComboBoxListItemsAtColumnLevel() { - var stochasticSoilModelColumn = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(stochasticSoilModelColumnIndex); - var stochasticSoilProfileColumn = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(stochasticSoilProfileColumnIndex); - var selectableHydraulicBoundaryLocationColumn = (DataGridViewComboBoxColumn) dataGridViewControl.GetColumnFromIndex(selectableHydraulicBoundaryLocationColumnIndex); + base.PrefillComboBoxListItemsAtColumnLevel(); + var stochasticSoilModelColumn = (DataGridViewComboBoxColumn) DataGridViewControl.GetColumnFromIndex(stochasticSoilModelColumnIndex); + var stochasticSoilProfileColumn = (DataGridViewComboBoxColumn) DataGridViewControl.GetColumnFromIndex(stochasticSoilProfileColumnIndex); + // 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)) { - MacroStabilityInwardsStochasticSoilModelCollection stochasticSoilModels = macroStabilityInwardsFailureMechanism.StochasticSoilModels; + MacroStabilityInwardsStochasticSoilModelCollection stochasticSoilModels = FailureMechanism.StochasticSoilModels; SetItemsOnObjectCollection(stochasticSoilModelColumn.Items, GetStochasticSoilModelsDataSource(stochasticSoilModels).ToArray()); } using (new SuspendDataGridViewColumnResizes(stochasticSoilProfileColumn)) { - MacroStabilityInwardsStochasticSoilProfile[] soilProfiles = GetStochasticSoilProfilesFromStochasticSoilModels(); - SetItemsOnObjectCollection(stochasticSoilProfileColumn.Items, GetSoilProfilesDataSource(soilProfiles).ToArray()); + IEnumerable stochasticSoilProfiles = GetStochasticSoilProfilesFromStochasticSoilModels(); + SetItemsOnObjectCollection(stochasticSoilProfileColumn.Items, GetSoilProfilesDataSource(stochasticSoilProfiles).ToArray()); } - - using (new SuspendDataGridViewColumnResizes(selectableHydraulicBoundaryLocationColumn)) - { - SetItemsOnObjectCollection(selectableHydraulicBoundaryLocationColumn.Items, - GetSelectableHydraulicBoundaryLocationsDataSource(GetSelectableHydraulicBoundaryLocationsFromFailureMechanism()).ToArray()); - } } - private IEnumerable GetSelectableHydraulicBoundaryLocationsFromFailureMechanism() + private IEnumerable GetStochasticSoilProfilesFromStochasticSoilModels() { - if (assessmentSection == 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 (MacroStabilityInwardsSurfaceLine surfaceLine in MacroStabilityInwardsFailureMechanism.SurfaceLines) - { - selectableHydraulicBoundaryLocations.AddRange(GetSelectableHydraulicBoundaryLocations(hydraulicBoundaryLocations, surfaceLine)); - } - - return selectableHydraulicBoundaryLocations; + return FailureMechanism.StochasticSoilModels + .SelectMany(ssm => ssm.StochasticSoilProfiles) + .Distinct(); } - private MacroStabilityInwardsStochasticSoilProfile[] GetStochasticSoilProfilesFromStochasticSoilModels() - { - return macroStabilityInwardsFailureMechanism?.StochasticSoilModels - .SelectMany(ssm => ssm.StochasticSoilProfiles) - .Distinct() - .ToArray(); - } - #endregion - - #region Event handling - - private void DataGridViewOnCurrentRowChangedHandler(object sender, EventArgs e) - { - OnSelectionChanged(); - } - - private void ListBoxOnSelectedValueChanged(object sender, EventArgs e) - { - UpdateDataGridViewDataSource(); - } - - private void OnGenerateScenariosButtonClick(object sender, EventArgs e) - { - if (calculationGroup == null) - { - return; - } - - var dialog = new MacroStabilityInwardsSurfaceLineSelectionDialog(Parent, macroStabilityInwardsFailureMechanism.SurfaceLines); - dialog.ShowDialog(); - IEnumerable calculationsStructure = MacroStabilityInwardsCalculationConfigurationHelper.GenerateCalculationItemsStructure( - dialog.SelectedItems, - macroStabilityInwardsFailureMechanism.StochasticSoilModels); - 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; - - dataGridViewRow.Cells[selectableHydraulicBoundaryLocationColumnIndex].ReadOnly = dataItem != null - && dataItem.MacroStabilityInwardsCalculation.InputParameters.UseAssessmentLevelManualInput; - } - } - - #endregion } } \ No newline at end of file Fisheye: Tag 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 refers to a dead (removed) revision in file `Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsCalculationsView.resx'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs =================================================================== diff -u -rc237d392efd465a39343760f0b7409cd6861b18a -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision c237d392efd465a39343760f0b7409cd6861b18a) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -265,12 +265,8 @@ GetViewName = (view, context) => context.WrappedData.Name, Image = RiskeerCommonFormsResources.GeneralFolderIcon, AdditionalDataCheck = context => context.WrappedData == context.FailureMechanism.CalculationsGroup, - CloseForData = CloseCalculationsViewForData, - AfterCreate = (view, context) => - { - view.AssessmentSection = context.AssessmentSection; - view.MacroStabilityInwardsFailureMechanism = context.FailureMechanism; - } + CreateInstance = context => new MacroStabilityInwardsCalculationsView(context.WrappedData, context.FailureMechanism, context.AssessmentSection), + CloseForData = CloseCalculationsViewForData }; yield return new ViewInfo Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationRowTest.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationRowTest.cs (.../MacroStabilityInwardsCalculationRowTest.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationRowTest.cs (.../MacroStabilityInwardsCalculationRowTest.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -43,41 +43,13 @@ public class MacroStabilityInwardsCalculationRowTest { [Test] - public void Constructor_WithoutCalculation_ThrowsArgumentNullException() + public void Constructor_ExpectedValues() { // 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(), 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(); - var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); MacroStabilityInwardsStochasticSoilModel stochasticSoilModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(); @@ -100,7 +72,7 @@ var row = new MacroStabilityInwardsCalculationRow(calculation, handler); // Assert - Assert.AreSame(calculation, row.MacroStabilityInwardsCalculation); + Assert.AreSame(calculation, row.Calculation); Assert.AreEqual(calculation.Name, row.Name); Assert.AreSame(calculation.InputParameters.StochasticSoilModel, row.StochasticSoilModel.WrappedObject); Assert.AreSame(calculation.InputParameters.StochasticSoilProfile, row.StochasticSoilProfile.WrappedObject); @@ -111,54 +83,6 @@ } [Test] - public void Constructor_WithCalculationWithInvalidInput_PropertiesFromCalculation() - { - // Setup - var mocks = new MockRepository(); - var handler = mocks.Stub(); - mocks.ReplayAll(); - - MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput(); - - // 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(2, row.StochasticSoilProfileProbability.NumberOfDecimalPlaces); - Assert.AreEqual(0, row.StochasticSoilProfileProbability, row.StochasticSoilProfileProbability.GetAccuracy()); - 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"; - - var calculation = new MacroStabilityInwardsCalculationScenario(); - 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 Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs =================================================================== diff -u -r56d072b8342f3e54ba89124ab918bd1529e257a3 -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs (.../MacroStabilityInwardsCalculationsViewTest.cs) (revision 56d072b8342f3e54ba89124ab918bd1529e257a3) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs (.../MacroStabilityInwardsCalculationsViewTest.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -20,15 +20,11 @@ // All rights reserved. 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; @@ -37,6 +33,7 @@ using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.Views; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Data.SoilProfile; using Riskeer.MacroStabilityInwards.Data.TestUtil; @@ -50,444 +47,227 @@ 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 selectableHydraulicBoundaryLocationsColumnIndex = 1; + private const int stochasticSoilModelsColumnIndex = 2; + private const int stochasticSoilProfilesColumnIndex = 3; + private const int stochasticSoilProfilesProbabilityColumnIndex = 4; private Form testForm; [Test] - public void Constructor_DefaultValues() + public void Constructor_ExpectedValues() { // Call - using (var calculationsView = new MacroStabilityInwardsCalculationsView()) - { - // Assert - Assert.IsInstanceOf(calculationsView); - Assert.IsInstanceOf(calculationsView); - Assert.IsInstanceOf(calculationsView); - Assert.IsNull(calculationsView.Data); - Assert.IsNull(calculationsView.MacroStabilityInwardsFailureMechanism); - Assert.IsNull(calculationsView.AssessmentSection); - } + MacroStabilityInwardsCalculationsView view = ShowMacroStabilityInwardsCalculationsView(new CalculationGroup(), new MacroStabilityInwardsFailureMechanism(), new AssessmentSectionStub()); + + // Assert + Assert.IsInstanceOf>(view); + + var button = (Button)new ControlTester("generateButton").TheObject; + Assert.AreEqual("Genereer &scenario's...", button.Text); } [Test] public void Constructor_DataGridViewCorrectlyInitialized() { // Call - using (ShowMacroStabilityInwardsCalculationsView()) - { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + ShowMacroStabilityInwardsCalculationsView(new CalculationGroup(), new MacroStabilityInwardsFailureMechanism(), new AssessmentSectionStub()); - // Assert - Assert.IsFalse(dataGridView.AutoGenerateColumns); - Assert.AreEqual(5, dataGridView.ColumnCount); + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - foreach (DataGridViewComboBoxColumn column in dataGridView.Columns.OfType()) - { - Assert.AreEqual("This", column.ValueMember); - Assert.AreEqual("DisplayName", column.DisplayMember); - } + // Assert + Assert.IsFalse(dataGridView.AutoGenerateColumns); + Assert.AreEqual(5, dataGridView.ColumnCount); - var soilProfilesCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[stochasticSoilProfilesColumnIndex]; - DataGridViewComboBoxCell.ObjectCollection soilProfilesComboboxItems = soilProfilesCombobox.Items; - Assert.AreEqual(0, soilProfilesComboboxItems.Count); // Row dependent + Assert.AreEqual("Naam", dataGridView.Columns[nameColumnIndex].HeaderText); + Assert.AreEqual("Hydraulische belastingenlocatie", dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex].HeaderText); + Assert.AreEqual("Stochastisch ondergrondmodel", dataGridView.Columns[stochasticSoilModelsColumnIndex].HeaderText); + Assert.AreEqual("Ondergrondschematisatie", dataGridView.Columns[stochasticSoilProfilesColumnIndex].HeaderText); + Assert.AreEqual("Aandeel van schematisatie\r\nin het stochastische ondergrondmodel\r\n[%]", dataGridView.Columns[stochasticSoilProfilesProbabilityColumnIndex].HeaderText); - var hydraulicBoundaryLocationCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex]; - DataGridViewComboBoxCell.ObjectCollection hydraulicBoundaryLocationComboboxItems = hydraulicBoundaryLocationCombobox.Items; - Assert.AreEqual(0, hydraulicBoundaryLocationComboboxItems.Count); // Row dependent - } - } - - [Test] - public void Constructor_DataGridViewControlColumnHeadersCorrectlyInitialized_() - { - // Call - using (ShowMacroStabilityInwardsCalculationsView()) + foreach (DataGridViewComboBoxColumn column in dataGridView.Columns.OfType()) { - // Assert - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - Assert.AreEqual(5, dataGridView.ColumnCount); - Assert.AreEqual("Naam", dataGridView.Columns[nameColumnIndex].HeaderText); - Assert.AreEqual("Stochastisch ondergrondmodel", dataGridView.Columns[stochasticSoilModelsColumnIndex].HeaderText); - Assert.AreEqual("Ondergrondschematisatie", dataGridView.Columns[stochasticSoilProfilesColumnIndex].HeaderText); - Assert.AreEqual("Aandeel van schematisatie\r\nin het stochastische ondergrondmodel\r\n[%]", dataGridView.Columns[stochasticSoilProfilesProbabilityColumnIndex].HeaderText); - Assert.AreEqual("Hydraulische belastingenlocatie", dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex].HeaderText); + Assert.AreEqual("This", column.ValueMember); + Assert.AreEqual("DisplayName", column.DisplayMember); } - } - [Test] - public void Constructor_ListBoxCorrectlyInitialized() - { - // Call - using (ShowMacroStabilityInwardsCalculationsView()) - { - var listBox = (ListBox) new ControlTester("listBox").TheObject; + var soilProfilesCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[stochasticSoilProfilesColumnIndex]; + DataGridViewComboBoxCell.ObjectCollection soilProfilesComboboxItems = soilProfilesCombobox.Items; + Assert.AreEqual(0, soilProfilesComboboxItems.Count); // Row dependent - // Assert - Assert.AreEqual(0, listBox.Items.Count); - } + var hydraulicBoundaryLocationCombobox = (DataGridViewComboBoxColumn) dataGridView.Columns[selectableHydraulicBoundaryLocationsColumnIndex]; + DataGridViewComboBoxCell.ObjectCollection hydraulicBoundaryLocationComboboxItems = hydraulicBoundaryLocationCombobox.Items; + Assert.AreEqual(0, hydraulicBoundaryLocationComboboxItems.Count); // Row dependent } [Test] - public void Data_SetToNull_DoesNotThrow() + public void MacroStabilityInwardsCalculationsView_CalculationsWithCorrespondingStochasticSoilModel_StochasticSoilModelsComboboxCorrectlyInitialized() { // 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(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowSimpleMacroStabilityInwardsCalculationsViewWithoutSurfaceLines( - assessmentSection, new HydraulicBoundaryDatabase())) - { - // Call - macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); - // 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()); - } + // Call + ShowMacroStabilityInwardsCalculationsView(ConfigureCalculationGroup(assessmentSection, failureMechanism), + failureMechanism, assessmentSection); - mocks.VerifyAll(); - } + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; - [Test] - public void AssessmentSection_WithSurfaceLinesHydraulicBoundaryDatabaseNotLinked_SelectableHydraulicBoundaryLocationsComboboxCorrectlyInitialized() - { - // Setup - var mocks = new MockRepository(); - IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); - assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); - assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); - mocks.ReplayAll(); + // Assert + DataGridViewComboBoxCell.ObjectCollection stochasticSoilModelsComboboxItems = ((DataGridViewComboBoxCell)dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex]).Items; + Assert.AreEqual(2, stochasticSoilModelsComboboxItems.Count); + Assert.AreEqual("", stochasticSoilModelsComboboxItems[0].ToString()); + Assert.AreEqual("Model A", stochasticSoilModelsComboboxItems[1].ToString()); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowSimpleMacroStabilityInwardsCalculationsViewWithSurfaceLines( - assessmentSection)) - { - // Call - macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; + 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()); - // 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() + public void MacroStabilityInwardsCalculationsView_CalculationsWithCorrespondingSoilProfiles_SoilProfilesComboboxCorrectlyInitialized() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( - assessmentSection)) - { - // Call - macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); - // 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()); - } + // Call + ShowMacroStabilityInwardsCalculationsView(ConfigureCalculationGroup(assessmentSection, failureMechanism), + failureMechanism, assessmentSection); - mocks.VerifyAll(); - } + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; - [Test] - public void MacroStabilityInwardsFailureMechanism_FailureMechanismWithSections_SectionsListBoxCorrectlyInitialized() - { - // Setup - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - 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) - }); + // 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()); - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1, - failureMechanismSection2, - failureMechanismSection3 - }); + soilProfilesComboboxItems = ((DataGridViewComboBoxCell)dataGridView.Rows[1].Cells[stochasticSoilProfilesColumnIndex]).Items; + Assert.AreEqual(2, soilProfilesComboboxItems.Count); + Assert.AreEqual("", soilProfilesComboboxItems[0].ToString()); + Assert.AreEqual("Profile 5", soilProfilesComboboxItems[1].ToString()); - 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(2, stochasticSoilModelsComboboxItems.Count); - Assert.AreEqual("", stochasticSoilModelsComboboxItems[0].ToString()); - Assert.AreEqual("Model A", stochasticSoilModelsComboboxItems[1].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(2, soilProfilesComboboxItems.Count); - Assert.AreEqual("", soilProfilesComboboxItems[0].ToString()); - Assert.AreEqual("Profile 5", soilProfilesComboboxItems[1].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(5, cells.Count); - Assert.AreEqual("Calculation 1", cells[nameColumnIndex].FormattedValue); - Assert.AreEqual("Model A", cells[stochasticSoilModelsColumnIndex].FormattedValue); - Assert.AreEqual("", cells[stochasticSoilProfilesColumnIndex].FormattedValue); - Assert.AreEqual(GetFormattedProbabilityValue(0), cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); - Assert.AreEqual("Location 1 (2 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); - - cells = rows[1].Cells; - Assert.AreEqual(5, 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(GetFormattedProbabilityValue(30), cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); - Assert.AreEqual("Location 2 (5 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); - } - - mocks.VerifyAll(); - } - - [Test] - [Apartment(ApartmentState.STA)] - public void MacroStabilityInwardsCalculationsView_SelectingCellInRow_SelectionChangedFired() - { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - ConfigureHydraulicBoundaryDatabase(assessmentSection); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); - MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailuremechanism(); - using (var calculationsView = new MacroStabilityInwardsCalculationsView - { - AssessmentSection = assessmentSection, - MacroStabilityInwardsFailureMechanism = failureMechanism, - Data = ConfigureCalculationGroup(assessmentSection, failureMechanism) - }) - { - var selectionChangedCount = 0; - calculationsView.SelectionChanged += (sender, args) => selectionChangedCount++; + // Call + ShowMacroStabilityInwardsCalculationsView(ConfigureCalculationGroup(assessmentSection, failureMechanism), + failureMechanism, assessmentSection); - var control = TypeUtils.GetField(calculationsView, "dataGridViewControl"); - WindowsFormsTestHelper.Show(control); + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0]; + // Assert + DataGridViewRowCollection rows = dataGridView.Rows; + Assert.AreEqual(2, rows.Count); - // Call - EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(1, 0)); + DataGridViewCellCollection cells = rows[0].Cells; + Assert.AreEqual(5, cells.Count); + Assert.AreEqual("Calculation 1", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("Location 1 (2 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); + Assert.AreEqual("Model A", cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("", cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual(GetFormattedProbabilityValue(0), cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); - // Assert - Assert.AreEqual(1, selectionChangedCount); - } + cells = rows[1].Cells; + Assert.AreEqual(5, cells.Count); + Assert.AreEqual("Calculation 2", cells[nameColumnIndex].FormattedValue); + Assert.AreEqual("Location 2 (5 m)", cells[selectableHydraulicBoundaryLocationsColumnIndex].FormattedValue); + Assert.AreEqual("Model E", cells[stochasticSoilModelsColumnIndex].FormattedValue); + Assert.AreEqual("Profile 5", cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual(GetFormattedProbabilityValue(30), cells[stochasticSoilProfilesProbabilityColumnIndex].FormattedValue); - WindowsFormsTestHelper.CloseAll(); mocks.VerifyAll(); } [Test] - public void MacroStabilityInwardsCalculationsView_ChangingListBoxSelection_DataGridViewCorrectlySyncedAndSelectionChangedFired() + public void ButtonGenerateScenarios_WithoutSurfaceLines_ButtonDisabled() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); 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(2, selectionChangedCount); - } - - mocks.VerifyAll(); - } - - [Test] - public void ButtonGenerateScenarios_WithoutSurfaceLines_ButtonDisabled() - { - // Setup var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.StochasticSoilModels.AddRange(new[] { MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() }, "path"); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; - var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + ShowMacroStabilityInwardsCalculationsView(new CalculationGroup(), failureMechanism, assessmentSection); - // Call - bool state = button.Enabled; + var button = (Button)new ControlTester("generateButton").TheObject; - // Assert - Assert.IsFalse(state); - } + // Call + bool state = button.Enabled; + + // Assert + Assert.IsFalse(state); + mocks.VerifyAll(); } [Test] public void ButtonGenerateScenarios_WithoutSoilModels_ButtonDisabled() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + mocks.ReplayAll(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.SurfaceLines.AddRange(new[] { new MacroStabilityInwardsSurfaceLine(string.Empty) }, "path"); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; - var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + ShowMacroStabilityInwardsCalculationsView(new CalculationGroup(), failureMechanism, assessmentSection); - // Call - bool state = button.Enabled; + var button = (Button)new ControlTester("generateButton").TheObject; - // Assert - Assert.IsFalse(state); - } + // Call + bool state = button.Enabled; + + // Assert + Assert.IsFalse(state); + mocks.VerifyAll(); } [Test] public void ButtonGenerateScenarios_WithSurfaceLinesAndSoilModels_ButtonEnabled() { // Setup - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + mocks.ReplayAll(); + const string arbitrarySourcePath = "path"; + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.SurfaceLines.AddRange(new[] { new MacroStabilityInwardsSurfaceLine(string.Empty) @@ -497,120 +277,29 @@ MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() }, arbitrarySourcePath); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + ShowMacroStabilityInwardsCalculationsView(new CalculationGroup(), failureMechanism, assessmentSection); - var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; + var button = (Button)new ControlTester("generateButton").TheObject; - // Call - bool state = button.Enabled; + // Call + bool state = button.Enabled; - // Assert - Assert.IsTrue(state); - } + // Assert + Assert.IsTrue(state); + mocks.VerifyAll(); } [Test] - public void GivenMacroStabilityInwardsCalculationsViewWithFailureMechanism_WhenSectionsAddedAndFailureMechanismNotified_ThenSectionsListBoxCorrectlyUpdated() - { - // Given - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - 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) - }); - - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; - - var listBox = (ListBox) new ControlTester("listBox").TheObject; - - // Precondition - Assert.AreEqual(0, listBox.Items.Count); - - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - failureMechanismSection1, - failureMechanismSection2, - failureMechanismSection3 - }); - - // 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]); - } - } - - [Test] public void GivenMacroStabilityInwardsCalculationsView_WhenGenerateScenariosButtonClicked_ThenShowViewWithSurfaceLines() { // Given - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - const string arbitraryFilePath = "path"; - failureMechanism.SurfaceLines.AddRange(new[] - { - new MacroStabilityInwardsSurfaceLine("Line A"), - new MacroStabilityInwardsSurfaceLine("Line B") - }, arbitraryFilePath); - failureMechanism.StochasticSoilModels.AddRange(new[] - { - MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() - }, arbitraryFilePath); - - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; - macroStabilityInwardsCalculationsView.Data = failureMechanism.CalculationsGroup; - var button = new ButtonTester("buttonGenerateScenarios", testForm); - - MacroStabilityInwardsSurfaceLineSelectionDialog selectionDialog = null; - DataGridViewControl grid = null; - DialogBoxHandler = (name, wnd) => - { - selectionDialog = (MacroStabilityInwardsSurfaceLineSelectionDialog) 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(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); const string arbitraryFilePath = "path"; + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.SurfaceLines.AddRange(new[] { new MacroStabilityInwardsSurfaceLine("Line A"), @@ -620,67 +309,75 @@ { MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() }, arbitraryFilePath); - failureMechanism.CalculationsGroup.Attach(observer); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) + ShowMacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + var button = new ButtonTester("generateButton", testForm); + + MacroStabilityInwardsSurfaceLineSelectionDialog selectionDialog = null; + DataGridViewControl grid = null; + DialogBoxHandler = (name, wnd) => { - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + selectionDialog = (MacroStabilityInwardsSurfaceLineSelectionDialog)new FormTester(name).TheObject; + grid = (DataGridViewControl)new ControlTester("DataGridViewControl", selectionDialog).TheObject; - var button = new ButtonTester("buttonGenerateScenarios", testForm); + new ButtonTester("CustomCancelButton", selectionDialog).Click(); + }; - // When - button.Click(); + // When + button.Click(); - // Then - mocks.VerifyAll(); - } + // Then + Assert.NotNull(selectionDialog); + Assert.NotNull(grid); + Assert.AreEqual(2, grid.Rows.Count); + mocks.VerifyAll(); } [Test] [TestCase("DoForSelectedButton")] [TestCase("CustomCancelButton")] - public void GivenCalculationsViewGenerateScenariosButtonClicked_WhenDialogClosed_ThenNotifyCalculationGroup(string buttonName) + public void GivenMacroStabilityInwardsCalculationsViewGenerateScenariosButtonClicked_WhenDialogClosed_ThenNotifyCalculationGroup(string buttonName) { // Given var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); + const string arbitraryFilePath = "path"; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - const string arbitryFilePath = "path"; failureMechanism.SurfaceLines.AddRange(new[] { new MacroStabilityInwardsSurfaceLine("Line A"), new MacroStabilityInwardsSurfaceLine("Line B") - }, arbitryFilePath); + }, arbitraryFilePath); failureMechanism.StochasticSoilModels.AddRange(new[] { MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() - }, arbitryFilePath); + }, arbitraryFilePath); failureMechanism.CalculationsGroup.Attach(observer); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; - macroStabilityInwardsCalculationsView.Data = failureMechanism.CalculationsGroup; - var button = new ButtonTester("buttonGenerateScenarios", testForm); + ShowMacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); - DialogBoxHandler = (name, wnd) => - { - var selectionDialog = (MacroStabilityInwardsSurfaceLineSelectionDialog) new FormTester(name).TheObject; - var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; - selectionView.Rows[0].Cells[0].Value = true; + var button = new ButtonTester("generateButton", testForm); - // When - new ButtonTester(buttonName, selectionDialog).Click(); - }; + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (MacroStabilityInwardsSurfaceLineSelectionDialog)new FormTester(name).TheObject; + var selectionView = (DataGridViewControl)new ControlTester("DataGridViewControl", selectionDialog).TheObject; + selectionView.Rows[0].Cells[0].Value = true; - button.Click(); + // When + new ButtonTester(buttonName, selectionDialog).Click(); + }; - // Then - mocks.VerifyAll(); - } + button.Click(); + + // Then + mocks.VerifyAll(); } [Test] @@ -689,267 +386,180 @@ // Given var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - ConfigureHydraulicBoundaryDatabase(assessmentSection); - MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism = ConfigureSimpleFailureMechanism(); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureSimpleFailureMechanism(); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView(assessmentSection, - macroStabilityInwardsFailureMechanism, - macroStabilityInwardsFailureMechanism.CalculationsGroup)) - { - var button = new ButtonTester("buttonGenerateScenarios", testForm); + ShowMacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); - DialogBoxHandler = (name, wnd) => - { - var selectionDialog = (MacroStabilityInwardsSurfaceLineSelectionDialog) new FormTester(name).TheObject; - var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; - selectionView.Rows[0].Cells[0].Value = true; + var button = new ButtonTester("generateButton", testForm); - // When - new ButtonTester("DoForSelectedButton", selectionDialog).Click(); - }; + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (MacroStabilityInwardsSurfaceLineSelectionDialog)new FormTester(name).TheObject; + var selectionView = (DataGridViewControl)new ControlTester("DataGridViewControl", selectionDialog).TheObject; + selectionView.Rows[0].Cells[0].Value = true; - button.Click(); + // When + new ButtonTester("DoForSelectedButton", selectionDialog).Click(); + }; - // Then - MacroStabilityInwardsCalculationScenario[] macroStabilityInwardsCalculationScenarios = macroStabilityInwardsFailureMechanism.Calculations.OfType().ToArray(); - MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult1 = macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.SectionResults.First(); - MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult2 = macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.SectionResults.ElementAt(1); + button.Click(); - Assert.AreEqual(2, failureMechanismSectionResult1.GetCalculationScenarios(macroStabilityInwardsCalculationScenarios).Count()); + // Then + MacroStabilityInwardsCalculationScenario[] calculationScenarios = failureMechanism.Calculations.OfType().ToArray(); + MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult1 = failureMechanism.SectionResults.First(); + MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult2 = failureMechanism.SectionResults.ElementAt(1); - foreach (MacroStabilityInwardsCalculationScenario calculationScenario in failureMechanismSectionResult1.GetCalculationScenarios(macroStabilityInwardsCalculationScenarios)) - { - Assert.IsInstanceOf(calculationScenario); - } + Assert.AreEqual(2, failureMechanismSectionResult1.GetCalculationScenarios(calculationScenarios).Count()); - CollectionAssert.IsEmpty(failureMechanismSectionResult2.GetCalculationScenarios(macroStabilityInwardsCalculationScenarios)); + foreach (MacroStabilityInwardsCalculationScenario calculationScenario in failureMechanismSectionResult1.GetCalculationScenarios(calculationScenarios)) + { + Assert.IsInstanceOf(calculationScenario); } + + CollectionAssert.IsEmpty(failureMechanismSectionResult2.GetCalculationScenarios(calculationScenarios)); + mocks.VerifyAll(); } [Test] public void GivenMacroStabilityInwardsCalculationsViewGenerateScenariosCancelButtonClicked_WhenDialogClosed_CalculationsNotUpdated() { // Given - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism = ConfigureSimpleFailureMechanism(); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + mocks.ReplayAll(); - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = macroStabilityInwardsFailureMechanism; - macroStabilityInwardsCalculationsView.Data = macroStabilityInwardsFailureMechanism.CalculationsGroup; + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureSimpleFailureMechanism(); + ShowMacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); - var button = new ButtonTester("buttonGenerateScenarios", testForm); + var button = new ButtonTester("generateButton", testForm); - DialogBoxHandler = (name, wnd) => - { - var selectionDialog = (MacroStabilityInwardsSurfaceLineSelectionDialog) new FormTester(name).TheObject; - var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; - selectionView.Rows[0].Cells[0].Value = true; + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = (MacroStabilityInwardsSurfaceLineSelectionDialog)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(); - }; + // When + new ButtonTester("CustomCancelButton", selectionDialog).Click(); + }; - button.Click(); + button.Click(); - // Then - CollectionAssert.IsEmpty(macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.Calculations); - } + // Then + CollectionAssert.IsEmpty(failureMechanism.Calculations); + mocks.VerifyAll(); } [Test] public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSoilModelAndNotify_ThenButtonDisabled() { // Given - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + mocks.ReplayAll(); - // When - failureMechanism.StochasticSoilModels.AddRange(new[] - { - MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() - }, "path"); - failureMechanism.NotifyObservers(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + ShowMacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); - // 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()) + // When + failureMechanism.StochasticSoilModels.AddRange(new[] { - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() + }, "path"); + failureMechanism.NotifyObservers(); - // When - failureMechanism.SurfaceLines.AddRange(new[] - { - new MacroStabilityInwardsSurfaceLine(string.Empty) - }, "path"); - failureMechanism.NotifyObservers(); - - // Then - var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; - Assert.IsFalse(button.Enabled); - } + // Then + var button = (Button)new ControlTester("generateButton").TheObject; + Assert.IsFalse(button.Enabled); + mocks.VerifyAll(); } [Test] - public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSurfaceLineAndSoilModelAndDoNotNotifyObservers_ThenButtonDisabled() + public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSurfaceLineAndNotify_ThenButtonDisabled() { // Given - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); + mocks.ReplayAll(); - // When - const string arbitraryFilePath = "path"; - failureMechanism.SurfaceLines.AddRange(new[] - { - new MacroStabilityInwardsSurfaceLine(string.Empty) - }, arbitraryFilePath); - failureMechanism.StochasticSoilModels.AddRange(new[] - { - MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() - }, arbitraryFilePath); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + ShowMacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); - // 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()) + // When + failureMechanism.SurfaceLines.AddRange(new[] { - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; + new MacroStabilityInwardsSurfaceLine(string.Empty) + }, "path"); + failureMechanism.NotifyObservers(); - // When - const string arbitraryFilePath = "path"; - failureMechanism.SurfaceLines.AddRange(new[] - { - new MacroStabilityInwardsSurfaceLine(string.Empty) - }, arbitraryFilePath); - failureMechanism.StochasticSoilModels.AddRange(new[] - { - MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() - }, arbitraryFilePath); - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism.NotifyObservers(); - - // Then - var button = (Button) macroStabilityInwardsCalculationsView.Controls.Find("buttonGenerateScenarios", true)[0]; - Assert.IsTrue(button.Enabled); - } + // Then + var button = (Button)new ControlTester("generateButton").TheObject; + Assert.IsFalse(button.Enabled); + mocks.VerifyAll(); } [Test] - public void GivenFailureMechanismWithSurfaceLinesAndSoilModels_WhenSurfaceLinesAndSoilModelsClearedAndNotifyObservers_ThenButtonDisabled() + public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSurfaceLineAndSoilModelAndDoNotNotifyObservers_ThenButtonDisabled() { // Given - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView()) - { - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - const string arbitraryFilePath = "path"; - failureMechanism.SurfaceLines.AddRange(new[] - { - new MacroStabilityInwardsSurfaceLine(string.Empty) - }, arbitraryFilePath); - failureMechanism.StochasticSoilModels.AddRange(new[] - { - MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() - }, 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(0)] - [TestCase(1)] - public void Selection_Always_ReturnsTheSelectedRowObject(int selectedRow) - { - // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( - assessmentSection)) + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + ShowMacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + + // When + const string arbitraryFilePath = "path"; + failureMechanism.SurfaceLines.AddRange(new[] { - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + new MacroStabilityInwardsSurfaceLine(string.Empty) + }, arbitraryFilePath); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel() + }, arbitraryFilePath); - dataGridView.CurrentCell = dataGridView.Rows[selectedRow].Cells[0]; - - // Call - object selection = macroStabilityInwardsCalculationsView.Selection; - - // Assert - Assert.IsInstanceOf(selection); - var dataRow = (MacroStabilityInwardsCalculationRow) dataGridView.Rows[selectedRow].DataBoundItem; - Assert.AreSame(dataRow.MacroStabilityInwardsCalculation, ((MacroStabilityInwardsInputContext) selection).MacroStabilityInwardsCalculation); - } - + // Then + var button = (Button)new ControlTester("generateButton").TheObject; + Assert.IsFalse(button.Enabled); mocks.VerifyAll(); } [Test] - [TestCase(true)] - [TestCase(false)] - public void MacroStabilityInwardsCalculationsView_EditingNameViaDataGridView_ObserversCorrectlyNotified(bool useCalculationWithOutput) + [TestCase(0)] + [TestCase(1)] + public void Selection_Always_ReturnsTheSelectedRowObject(int selectedRow) { // Setup var mocks = new MockRepository(); - var calculationObserver = mocks.StrictMock(); - var calculationInputObserver = mocks.StrictMock(); - - calculationObserver.Expect(o => o.UpdateObserver()); - var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( - assessmentSection)) - { - var data = (CalculationGroup) macroStabilityInwardsCalculationsView.Data; - var calculation = (MacroStabilityInwardsCalculationScenario) data.Children.First(); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); - if (useCalculationWithOutput) - { - calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); - } + MacroStabilityInwardsCalculationsView view = ShowMacroStabilityInwardsCalculationsView(ConfigureCalculationGroup(assessmentSection, failureMechanism), + failureMechanism, assessmentSection); - calculation.Attach(calculationObserver); - calculation.InputParameters.Attach(calculationInputObserver); + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + dataGridView.CurrentCell = dataGridView.Rows[selectedRow].Cells[0]; - // Call - dataGridView.Rows[0].Cells[nameColumnIndex].Value = "New name"; + // Call + object selection = view.Selection; - // Assert - calculation.Output = null; - } + // Assert + Assert.IsInstanceOf(selection); + var dataRow = (MacroStabilityInwardsCalculationRow)dataGridView.Rows[selectedRow].DataBoundItem; + Assert.AreSame(dataRow.Calculation, ((MacroStabilityInwardsInputContext)selection).MacroStabilityInwardsCalculation); mocks.VerifyAll(); } @@ -986,36 +596,30 @@ ConfigureHydraulicBoundaryDatabase(assessmentSection); assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); - assessmentSection.Replay(); + mocks.ReplayAll(); - MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailuremechanism(); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( - assessmentSection, failureMechanism, calculationGroup)) - { - mocks.ReplayAll(); + ShowMacroStabilityInwardsCalculationsView(calculationGroup, failureMechanism, assessmentSection); - var data = (CalculationGroup) macroStabilityInwardsCalculationsView.Data; - var calculation = (MacroStabilityInwardsCalculationScenario) data.Children[1]; + var calculation = (MacroStabilityInwardsCalculationScenario)calculationGroup.Children[1]; - if (useCalculationWithOutput) - { - calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); - } + if (useCalculationWithOutput) + { + calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); + } - calculation.Attach(calculationObserver); - calculation.InputParameters.Attach(calculationInputObserver); + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; - // Call - dataGridView.Rows[1].Cells[cellIndex].Value = newValue is double ? (RoundedDouble) (double) newValue : newValue; + // Call + dataGridView.Rows[1].Cells[cellIndex].Value = newValue is double value ? (RoundedDouble)value : newValue; - // Assert - calculation.Output = null; - } - + // Assert + Assert.IsNull(calculation.Output); mocks.VerifyAll(); } @@ -1025,37 +629,37 @@ // Given var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( - assessmentSection)) - { - var data = (CalculationGroup) macroStabilityInwardsCalculationsView.Data; - var calculation = (MacroStabilityInwardsCalculationScenario) data.Children[1]; + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + ShowMacroStabilityInwardsCalculationsView(calculationGroup, failureMechanism, assessmentSection); - var refreshed = 0; + var calculation = (MacroStabilityInwardsCalculationScenario)calculationGroup.Children[1]; - // Precondition - var currentCell = (DataGridViewTextBoxCell) dataGridView.Rows[1].Cells[stochasticSoilProfilesProbabilityColumnIndex]; - Assert.AreEqual(GetFormattedProbabilityValue(30), currentCell.FormattedValue); + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; - MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfileToChange = calculation.InputParameters.StochasticSoilProfile; - var updatedProfile = new MacroStabilityInwardsStochasticSoilProfile( - 0.5, stochasticSoilProfileToChange.SoilProfile); - dataGridView.Invalidated += (sender, args) => refreshed++; + var refreshed = 0; - // When - stochasticSoilProfileToChange.Update(updatedProfile); - stochasticSoilProfileToChange.NotifyObservers(); + // Precondition + var currentCell = (DataGridViewTextBoxCell)dataGridView.Rows[1].Cells[stochasticSoilProfilesProbabilityColumnIndex]; + Assert.AreEqual(GetFormattedProbabilityValue(30), currentCell.FormattedValue); - // Then - Assert.AreEqual(1, refreshed); - var cell = (DataGridViewTextBoxCell) dataGridView.Rows[1].Cells[stochasticSoilProfilesProbabilityColumnIndex]; - Assert.AreEqual(GetFormattedProbabilityValue(50), cell.FormattedValue); - } + MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfileToChange = calculation.InputParameters.StochasticSoilProfile; + var updatedProfile = new MacroStabilityInwardsStochasticSoilProfile(0.5, 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(GetFormattedProbabilityValue(50), cell.FormattedValue); + mocks.VerifyAll(); } @@ -1065,54 +669,55 @@ // Given var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView( - assessmentSection)) - { - var data = (CalculationGroup) macroStabilityInwardsCalculationsView.Data; - var calculation = (MacroStabilityInwardsCalculationScenario) data.Children[0]; + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); - DataGridViewControl dataGridView = macroStabilityInwardsCalculationsView.Controls.Find("dataGridViewControl", true).OfType().First(); - ListBox listBox = macroStabilityInwardsCalculationsView.Controls.Find("listBox", true).OfType().First(); + MacroStabilityInwardsCalculationsView view = ShowMacroStabilityInwardsCalculationsView(calculationGroup, failureMechanism, assessmentSection); - // 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); + var calculation = (MacroStabilityInwardsCalculationScenario)calculationGroup.Children[0]; - listBox.SelectedIndex = 1; - Assert.AreEqual(1, dataGridView.Rows.Count); - Assert.AreEqual("Calculation 2", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + DataGridViewControl dataGridView = view.Controls.Find("dataGridViewControl", true).OfType().First(); + ListBox listBox = view.Controls.Find("listBox", true).OfType().First(); - MacroStabilityInwardsSurfaceLine surfaceLineToChange = calculation.InputParameters.SurfaceLine; - var updatedSurfaceLine = new MacroStabilityInwardsSurfaceLine(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) - }); + // 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); - // When - surfaceLineToChange.CopyProperties(updatedSurfaceLine); - surfaceLineToChange.NotifyObservers(); + listBox.SelectedIndex = 1; + Assert.AreEqual(1, dataGridView.Rows.Count); + Assert.AreEqual("Calculation 2", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); - // Then - listBox.SelectedIndex = 0; - Assert.AreEqual(1, dataGridView.Rows.Count); - Assert.AreEqual("Calculation 2", dataGridView.Rows[0].Cells[nameColumnIndex].FormattedValue); + MacroStabilityInwardsSurfaceLine surfaceLineToChange = calculation.InputParameters.SurfaceLine; + var updatedSurfaceLine = new MacroStabilityInwardsSurfaceLine(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) + }); - 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); - } + // 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(); } @@ -1123,29 +728,30 @@ // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + ConfigureHydraulicBoundaryDatabase(assessmentSection); mocks.ReplayAll(); - using (MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowFullyConfiguredMacroStabilityInwardsCalculationsView(assessmentSection)) - { - var data = (CalculationGroup) macroStabilityInwardsCalculationsView.Data; - var calculation = (MacroStabilityInwardsCalculationScenario) data.Children.First(); + MacroStabilityInwardsFailureMechanism failureMechanism = ConfigureFailureMechanism(); + CalculationGroup calculationGroup = ConfigureCalculationGroup(assessmentSection, failureMechanism); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + ShowMacroStabilityInwardsCalculationsView(calculationGroup, failureMechanism, assessmentSection); - // Call - calculation.InputParameters.UseAssessmentLevelManualInput = useAssessmentLevelManualInput; - calculation.InputParameters.NotifyObservers(); + var calculation = (MacroStabilityInwardsCalculationScenario)calculationGroup.Children.First(); - // Assert - Assert.IsFalse(dataGridView.Rows[0].ReadOnly); + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; - var currentCellUpdated = (DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[selectableHydraulicBoundaryLocationsColumnIndex]; - Assert.AreEqual(useAssessmentLevelManualInput, currentCellUpdated.ReadOnly); - } + // Call + calculation.InputParameters.UseAssessmentLevelManualInput = useAssessmentLevelManualInput; + calculation.InputParameters.NotifyObservers(); + // Assert + Assert.IsFalse(dataGridView.Rows[0].ReadOnly); + + var currentCellUpdated = (DataGridViewComboBoxCell)dataGridView.Rows[0].Cells[selectableHydraulicBoundaryLocationsColumnIndex]; + Assert.AreEqual(useAssessmentLevelManualInput, currentCellUpdated.ReadOnly); + mocks.VerifyAll(); } - public override void Setup() { base.Setup(); @@ -1160,30 +766,6 @@ testForm.Dispose(); } - 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) { assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase @@ -1196,140 +778,6 @@ }); } - private MacroStabilityInwardsCalculationsView ShowSimpleMacroStabilityInwardsCalculationsViewWithSurfaceLines(IAssessmentSection assessmentSection) - { - var surfaceLine1 = new MacroStabilityInwardsSurfaceLine("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 MacroStabilityInwardsSurfaceLine("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"); - - 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) - }) - }); - - MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView(); - - macroStabilityInwardsCalculationsView.Data = new CalculationGroup - { - Children = - { - new MacroStabilityInwardsCalculationScenario - { - Name = "Calculation 1", - InputParameters = - { - SurfaceLine = surfaceLine1 - } - }, - new MacroStabilityInwardsCalculationScenario - { - 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); - hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation1); - hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation2); - - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); - - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - 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) - }) - }); - - MacroStabilityInwardsCalculationsView macroStabilityInwardsCalculationsView = ShowMacroStabilityInwardsCalculationsView(); - - macroStabilityInwardsCalculationsView.Data = new CalculationGroup - { - Children = - { - new MacroStabilityInwardsCalculationScenario - { - Name = "Calculation 1", - InputParameters = - { - HydraulicBoundaryLocation = hydraulicBoundaryLocation1 - } - }, - new MacroStabilityInwardsCalculationScenario - { - Name = "Calculation 2", - InputParameters = - { - HydraulicBoundaryLocation = hydraulicBoundaryLocation2 - } - } - } - }; - - macroStabilityInwardsCalculationsView.AssessmentSection = assessmentSection; - macroStabilityInwardsCalculationsView.MacroStabilityInwardsFailureMechanism = failureMechanism; - - return macroStabilityInwardsCalculationsView; - } - private static MacroStabilityInwardsFailureMechanism ConfigureSimpleFailureMechanism() { var surfaceLine1 = new MacroStabilityInwardsSurfaceLine("Surface line 1") @@ -1421,7 +869,7 @@ }; } - private static MacroStabilityInwardsFailureMechanism ConfigureFailuremechanism() + private static MacroStabilityInwardsFailureMechanism ConfigureFailureMechanism() { var surfaceLine1 = new MacroStabilityInwardsSurfaceLine("Surface line 1") { @@ -1534,14 +982,15 @@ return failureMechanism; } - private MacroStabilityInwardsCalculationsView ShowMacroStabilityInwardsCalculationsView() + private MacroStabilityInwardsCalculationsView ShowMacroStabilityInwardsCalculationsView(CalculationGroup calculationGroup, MacroStabilityInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) { - var calculationsView = new MacroStabilityInwardsCalculationsView(); + var view = new MacroStabilityInwardsCalculationsView(calculationGroup, failureMechanism, assessmentSection); - testForm.Controls.Add(calculationsView); + testForm.Controls.Add(view); testForm.Show(); - return calculationsView; + return view; } private static string GetFormattedProbabilityValue(double value) Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsCalculationsViewIntegrationTest.cs =================================================================== diff -u -r77f595651b934a75a5625828a9027d7c48e8e5f9 -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsCalculationsViewIntegrationTest.cs (.../MacroStabilityInwardsCalculationsViewIntegrationTest.cs) (revision 77f595651b934a75a5625828a9027d7c48e8e5f9) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Integration.Test/MacroStabilityInwardsCalculationsViewIntegrationTest.cs (.../MacroStabilityInwardsCalculationsViewIntegrationTest.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -26,7 +26,6 @@ using NUnit.Framework; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; -using Riskeer.Common.Data.FailureMechanism; using Riskeer.Integration.Data; using Riskeer.Integration.TestUtil; using Riskeer.MacroStabilityInwards.Data; @@ -39,35 +38,31 @@ 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 hydraulicBoundaryLocationsColumnIndex = 1; + private const int stochasticSoilModelsColumnIndex = 2; + private const int stochasticSoilProfilesColumnIndex = 3; + private const int stochasticSoilProfilesProbabilityColumnIndex = 4; [Test] public void MacroStabilityInwardsCalculationsView_DataImportedOrChanged_ChangesCorrectlyObservedAndSynced() { // Setup using (var form = new Form()) { + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + MacroStabilityInwardsFailureMechanism failureMechanism = assessmentSection.MacroStabilityInwards; + // Show the view - var calculationsView = new MacroStabilityInwardsCalculationsView(); + var calculationsView = new MacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); 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); Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsCalculationsViewInfoTest.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsCalculationsViewInfoTest.cs (.../MacroStabilityInwardsCalculationsViewInfoTest.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/ViewInfos/MacroStabilityInwardsCalculationsViewInfoTest.cs (.../MacroStabilityInwardsCalculationsViewInfoTest.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -26,7 +26,7 @@ using Rhino.Mocks; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; -using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.Hydraulics; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Data.SoilProfile; using Riskeer.MacroStabilityInwards.Forms.PresentationObjects; @@ -39,14 +39,12 @@ [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)); } @@ -70,8 +68,8 @@ public void GetViewData_Always_ReturnsWrappedCalculationGroup() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); @@ -89,52 +87,59 @@ } [Test] - public void GetViewName_WithMacroStabilityInwardsCalculationGroupContext_ReturnsCalculationGroupName() + public void GetViewName_WithContext_ReturnsCalculationGroupName() { // Setup + const string calculationGroupName = "Test"; + + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase()); mocks.ReplayAll(); - var calculationsView = new MacroStabilityInwardsCalculationsView(); - - const string calculationGroupName = "Test"; - var calculationGroup = new CalculationGroup { Name = calculationGroupName }; - var calculationGroupContext = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, - null, - Enumerable.Empty(), - Enumerable.Empty(), - new MacroStabilityInwardsFailureMechanism(), - assessmentSection); - // Call - string name = info.GetViewName(calculationsView, calculationGroupContext); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (var calculationsView = new MacroStabilityInwardsCalculationsView(calculationGroup, failureMechanism, assessmentSection)) + { + var context = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); - // Assert - Assert.AreEqual(calculationGroupName, name); + // Call + string name = info.GetViewName(calculationsView, context); + + // Assert + Assert.AreEqual(calculationGroupName, name); + } + mocks.VerifyAll(); } [Test] public void AdditionalDataCheck_CalculationGroupContextWithFailureMechanismParent_ReturnsTrue() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - var calculationGroupContext = new MacroStabilityInwardsCalculationGroupContext(failureMechanism.CalculationsGroup, - null, - Enumerable.Empty(), - Enumerable.Empty(), - failureMechanism, - assessmentSection); + var context = new MacroStabilityInwardsCalculationGroupContext(failureMechanism.CalculationsGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); // Call - bool additionalDataCheck = info.AdditionalDataCheck(calculationGroupContext); + bool additionalDataCheck = info.AdditionalDataCheck(context); // Assert Assert.IsTrue(additionalDataCheck); @@ -145,196 +150,168 @@ public void AdditionalDataCheck_CalculationGroupContextWithoutFailureMechanismParent_ReturnsFalse() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var calculationGroup = new CalculationGroup(); - var calculationGroupContext = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, - null, - Enumerable.Empty(), - Enumerable.Empty(), - failureMechanism, - assessmentSection); + var context = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); // Call - bool additionalDataCheck = info.AdditionalDataCheck(calculationGroupContext); + bool additionalDataCheck = info.AdditionalDataCheck(context); // 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 mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - assessmentSection.Stub(asm => asm.GetFailureMechanisms()).Return(new[] + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase()); + var assessmentSectionToRemove = mocks.Stub(); + assessmentSectionToRemove.Stub(asm => asm.GetFailureMechanisms()).Return(new[] { new MacroStabilityInwardsFailureMechanism() }); mocks.ReplayAll(); - var view = new MacroStabilityInwardsCalculationsView + using (var view = new MacroStabilityInwardsCalculationsView(new CalculationGroup(), new MacroStabilityInwardsFailureMechanism(), assessmentSection)) { - Data = new CalculationGroup() - }; + // Call + bool closeForData = info.CloseForData(view, assessmentSectionToRemove); - // Call - bool closeForData = info.CloseForData(view, assessmentSection); + // Assert + Assert.IsFalse(closeForData); + } - // 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[] + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase()); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] { failureMechanism }); mocks.ReplayAll(); - var view = new MacroStabilityInwardsCalculationsView + using (var view = new MacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection)) { - Data = failureMechanism.CalculationsGroup - }; + // Call + bool closeForData = info.CloseForData(view, assessmentSection); - // Call - bool closeForData = info.CloseForData(view, assessmentSection); + // Assert + Assert.IsTrue(closeForData); + } - // Assert - Assert.IsTrue(closeForData); mocks.VerifyAll(); } [Test] public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase()); mocks.ReplayAll(); - var view = new MacroStabilityInwardsCalculationsView(); - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (var view = new MacroStabilityInwardsCalculationsView(new CalculationGroup(), new MacroStabilityInwardsFailureMechanism(), assessmentSection)) + { + // Call + bool closeForData = info.CloseForData(view, new MacroStabilityInwardsFailureMechanism()); - view.Data = new CalculationGroup(); + // Assert + Assert.IsFalse(closeForData); + } - // Call - bool closeForData = info.CloseForData(view, failureMechanism); - - // Assert - Assert.IsFalse(closeForData); mocks.VerifyAll(); } [Test] public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() { // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase()); mocks.ReplayAll(); - var view = new MacroStabilityInwardsCalculationsView(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + using (var view = new MacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection)) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanism); - view.Data = failureMechanism.CalculationsGroup; + // Assert + Assert.IsTrue(closeForData); + } - // Call - bool closeForData = info.CloseForData(view, failureMechanism); - - // Assert - Assert.IsTrue(closeForData); mocks.VerifyAll(); } [Test] public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase()); mocks.ReplayAll(); - var view = new MacroStabilityInwardsCalculationsView(); - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(new MacroStabilityInwardsFailureMechanism(), assessmentSection); + using (var view = new MacroStabilityInwardsCalculationsView(new CalculationGroup(), new MacroStabilityInwardsFailureMechanism(), assessmentSection)) + { + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(new MacroStabilityInwardsFailureMechanism(), assessmentSection); - view.Data = failureMechanism.CalculationsGroup; + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); - // Call - bool closeForData = info.CloseForData(view, failureMechanismContext); + // Assert + Assert.IsFalse(closeForData); + } - // Assert - Assert.IsFalse(closeForData); mocks.VerifyAll(); } [Test] public void CloseForData_ViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue() { // Setup + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase()); mocks.ReplayAll(); - var view = new MacroStabilityInwardsCalculationsView(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); + using (var view = new MacroStabilityInwardsCalculationsView(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection)) + { + var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); - view.Data = failureMechanism.CalculationsGroup; + // Call + bool closeForData = info.CloseForData(view, failureMechanismContext); - // Call - bool closeForData = info.CloseForData(view, failureMechanismContext); + // Assert + Assert.IsTrue(closeForData); + } - // Assert - Assert.IsTrue(closeForData); mocks.VerifyAll(); } - - [Test] - public void AfterCreate_Always_SetsSpecificPropertiesToView() - { - // Setup - var view = mocks.StrictMock(); - var assessmentSection = mocks.Stub(); - var failureMechanism = mocks.StrictMock(); - var calculationsGroup = mocks.StrictMock(); - var calculationGroupContext = new MacroStabilityInwardsCalculationGroupContext(calculationsGroup, null, Enumerable.Empty(), Enumerable.Empty(), failureMechanism, assessmentSection); - - view.Expect(v => v.AssessmentSection = assessmentSection); - view.Expect(v => v.MacroStabilityInwardsFailureMechanism = failureMechanism); - - mocks.ReplayAll(); - - // Call - info.AfterCreate(view, calculationGroupContext); - - // Assert - mocks.VerifyAll(); - } } } \ No newline at end of file Index: Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingCalculationsView.cs =================================================================== diff -u -r1e284c55476808184609366e076a3f6d0e47d87f -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision 1e284c55476808184609366e076a3f6d0e47d87f) +++ Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -93,7 +93,6 @@ { base.OnLoad(e); - // Set button text GenerateButton.Text = RiskeerCommonFormsResources.CalculationGroup_Generate_Scenarios; } @@ -203,6 +202,13 @@ UpdateStochasticSoilProfileColumn(); } + protected override void UpdateColumns() + { + base.UpdateColumns(); + UpdateStochasticSoilModelColumn(); + UpdateStochasticSoilProfileColumn(); + } + #region Data sources private static IEnumerable> GetStochasticSoilModelsDataSource( @@ -292,12 +298,9 @@ private static IEnumerable GetSoilProfilesForCalculation(PipingCalculation pipingCalculation) { - if (pipingCalculation.InputParameters.StochasticSoilModel == null) - { - return Enumerable.Empty(); - } - - return pipingCalculation.InputParameters.StochasticSoilModel.StochasticSoilProfiles; + return pipingCalculation.InputParameters.StochasticSoilModel != null + ? pipingCalculation.InputParameters.StochasticSoilModel.StochasticSoilProfiles + : Enumerable.Empty(); } #endregion @@ -340,19 +343,11 @@ #region Event handling - protected override void UpdateColumns() - { - base.UpdateColumns(); - UpdateStochasticSoilModelColumn(); - UpdateStochasticSoilProfileColumn(); - } - private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { if (eventArgs.ColumnIndex == selectableHydraulicBoundaryLocationColumnIndex) { DataGridViewRow dataGridViewRow = DataGridViewControl.GetRowFromIndex(eventArgs.RowIndex); - dataGridViewRow.Cells[selectableHydraulicBoundaryLocationColumnIndex].ReadOnly = dataGridViewRow.DataBoundItem is PipingCalculationRow dataItem && dataItem.Calculation.InputParameters.UseAssessmentLevelManualInput; } Index: Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ViewInfos/PipingCalculationsViewInfoTest.cs =================================================================== diff -u -r72b35179da7cece144a0319a96122cf3eba0192c -r8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1 --- Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ViewInfos/PipingCalculationsViewInfoTest.cs (.../PipingCalculationsViewInfoTest.cs) (revision 72b35179da7cece144a0319a96122cf3eba0192c) +++ Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/ViewInfos/PipingCalculationsViewInfoTest.cs (.../PipingCalculationsViewInfoTest.cs) (revision 8dd568726bfcaf1f2c517f6e7c76ebe2b0f7e8b1) @@ -105,15 +105,15 @@ var failureMechanism = new PipingFailureMechanism(); using (var calculationsView = new PipingCalculationsView(calculationGroup, failureMechanism, assessmentSection)) { - var pipingCalculationGroupContext = new PipingCalculationGroupContext(calculationGroup, - null, - Enumerable.Empty(), - Enumerable.Empty(), - failureMechanism, - assessmentSection); + var context = new PipingCalculationGroupContext(calculationGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); // Call - string name = info.GetViewName(calculationsView, pipingCalculationGroupContext); + string name = info.GetViewName(calculationsView, context); // Assert Assert.AreEqual(calculationGroupName, name); @@ -123,31 +123,31 @@ } [Test] - public void AdditionalDataCheck_PipingCalculationGroupContextWithPipingFailureMechanismParent_ReturnsTrue() + public void AdditionalDataCheck_CalculationGroupContextWithFailureMechanismParent_ReturnsTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - var pipingFailureMechanism = new PipingFailureMechanism(); - var pipingCalculationGroupContext = new PipingCalculationGroupContext(pipingFailureMechanism.CalculationsGroup, - null, - Enumerable.Empty(), - Enumerable.Empty(), - pipingFailureMechanism, - assessmentSection); + var failureMechanism = new PipingFailureMechanism(); + var context = new PipingCalculationGroupContext(failureMechanism.CalculationsGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); // Call - bool additionalDataCheck = info.AdditionalDataCheck(pipingCalculationGroupContext); + bool additionalDataCheck = info.AdditionalDataCheck(context); // Assert Assert.IsTrue(additionalDataCheck); mocks.VerifyAll(); } [Test] - public void AdditionalDataCheck_PipingCalculationGroupContextWithoutPipingFailureMechanismParent_ReturnsFalse() + public void AdditionalDataCheck_CalculationGroupContextWithoutFailureMechanismParent_ReturnsFalse() { // Setup var mocks = new MockRepository(); @@ -156,15 +156,15 @@ var failureMechanism = new PipingFailureMechanism(); var calculationGroup = new CalculationGroup(); - var pipingCalculationGroupContext = new PipingCalculationGroupContext(calculationGroup, - null, - Enumerable.Empty(), - Enumerable.Empty(), - failureMechanism, - assessmentSection); + var context = new PipingCalculationGroupContext(calculationGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + failureMechanism, + assessmentSection); // Call - bool additionalDataCheck = info.AdditionalDataCheck(pipingCalculationGroupContext); + bool additionalDataCheck = info.AdditionalDataCheck(context); // Assert Assert.IsFalse(additionalDataCheck); @@ -241,6 +241,7 @@ // Assert Assert.IsFalse(closeForData); } + mocks.VerifyAll(); } @@ -262,6 +263,7 @@ // Assert Assert.IsTrue(closeForData); } + mocks.VerifyAll(); }