Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs =================================================================== diff -u -r230b86184fb335b764af770f1c9fb8a1ec76fe3a -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs (.../PipingCalculationConfigurationHelper.cs) (revision 230b86184fb335b764af770f1c9fb8a1ec76fe3a) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs (.../PipingCalculationConfigurationHelper.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -36,7 +36,7 @@ /// public static class PipingCalculationConfigurationHelper { - private static ILog log = LogManager.GetLogger(typeof(PipingCalculationConfigurationHelper)); + private static readonly ILog log = LogManager.GetLogger(typeof(PipingCalculationConfigurationHelper)); /// /// Creates a structure of and based on combination of the Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/PipingInputContext.cs =================================================================== diff -u -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/PipingInputContext.cs (.../PipingInputContext.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PresentationObjects/PipingInputContext.cs (.../PipingInputContext.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -20,7 +20,6 @@ // All rights reserved. using System.Collections.Generic; -using System.Linq; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Piping.Data; using Ringtoets.Piping.Primitives; @@ -44,36 +43,5 @@ /// When any input parameter is null. public PipingInputContext(PipingInput pipingInput, IEnumerable surfaceLines, IEnumerable stochasticSoilModels, IAssessmentSection assessmentSection) : base(pipingInput, surfaceLines, stochasticSoilModels, assessmentSection) {} - - /// - /// Sets and that matching the input of a calculation if there is one matching - /// or respectively. - /// - public void SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine() - { - var available = PipingCalculationConfigurationHelper.GetStochasticSoilModelsForSurfaceLine(WrappedData.SurfaceLine, AvailableStochasticSoilModels).ToList(); - if (available.Count == 1) - { - if (WrappedData.StochasticSoilModel == available.First()) - { - return; - } - WrappedData.StochasticSoilModel = available.First(); - } - SetStochasticSoilProfile(); - } - - private void SetStochasticSoilProfile() - { - if (WrappedData.StochasticSoilModel != null) - { - if (WrappedData.StochasticSoilModel.StochasticSoilProfiles.Count == 1) - { - WrappedData.StochasticSoilProfile = WrappedData.StochasticSoilModel.StochasticSoilProfiles.First(); - return; - } - } - WrappedData.StochasticSoilProfile = null; - } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs =================================================================== diff -u -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs (.../PipingInputContextProperties.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs (.../PipingInputContextProperties.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -33,6 +33,7 @@ using Ringtoets.Piping.Forms.TypeConverters; using Ringtoets.Piping.Forms.UITypeEditors; using Ringtoets.Piping.Primitives; +using Ringtoets.Piping.Service; namespace Ringtoets.Piping.Forms.PropertyClasses { @@ -171,7 +172,7 @@ if (!ReferenceEquals(value, data.WrappedData.SurfaceLine)) { data.WrappedData.SurfaceLine = value; - data.SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine(); + PipingInputService.SetMatchingStochasticSoilModel(data.WrappedData, GetAvailableStochasticSoilModels()); data.WrappedData.NotifyObservers(); } } @@ -192,6 +193,7 @@ if (!ReferenceEquals(value, data.WrappedData.StochasticSoilModel)) { data.WrappedData.StochasticSoilModel = value; + PipingInputService.SyncStochasticSoilProfileWithStochasticSoilModel(data.WrappedData); data.WrappedData.NotifyObservers(); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingInputContextStochasticSoilModelSelectionEditor.cs =================================================================== diff -u -rcda9bb0707f49cfb8e685d3ec04da01240c73f26 -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingInputContextStochasticSoilModelSelectionEditor.cs (.../PipingInputContextStochasticSoilModelSelectionEditor.cs) (revision cda9bb0707f49cfb8e685d3ec04da01240c73f26) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/UITypeEditors/PipingInputContextStochasticSoilModelSelectionEditor.cs (.../PipingInputContextStochasticSoilModelSelectionEditor.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -26,6 +26,10 @@ namespace Ringtoets.Piping.Forms.UITypeEditors { + /// + /// This class defines a drop down list edit-control from which the user can select a + /// from a collection. + /// public class PipingInputContextStochasticSoilModelSelectionEditor : PipingInputContextSelectionEditor { /// Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs =================================================================== diff -u -r296f8749c44298b42ad22170e0b2e0b935b394bd -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision 296f8749c44298b42ad22170e0b2e0b935b394bd) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -36,6 +36,7 @@ using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.Properties; using Ringtoets.Piping.Primitives; +using Ringtoets.Piping.Service; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Piping.Forms.Views @@ -182,7 +183,6 @@ HeaderText = Resources.PipingInput_StochasticSoilModel_DisplayName, Name = "column_SoilModel", ValueMember = "This", - ValueType = typeof(DataGridViewComboBoxItemWrapper), DisplayMember = "DisplayName" }; @@ -275,13 +275,6 @@ } } - private void OnStochasticSoilModelsUpdate() - { - UpdateGenerateScenariosButtonState(); - UpdateStochasticSoilModelColumn(); - UpdateStochasticSoilProfileColumn(); - } - private void UpdateStochasticSoilModelColumn() { using (new SuspendDataGridViewColumnResizes(stochasticSoilModelColumn)) @@ -311,52 +304,6 @@ pipingFailureMechanism.StochasticSoilModels.Any(); } - private void RefreshDataGridView() - { - dataGridView.Refresh(); - dataGridView.AutoResizeColumns(); - } - - private void UpdateDataGridViewDataSource() - { - // Skip changes coming from the view itself - if (dataGridView.IsCurrentCellInEditMode) - { - updatingDataSource = true; - UpdateStochasticSoilProfileColumn(); - updatingDataSource = false; - - dataGridView.AutoResizeColumns(); - - return; - } - - var failureMechanismSection = listBox.SelectedItem as FailureMechanismSection; - if (failureMechanismSection == null) - { - dataGridView.DataSource = null; - return; - } - - var lineSegments = Math2D.ConvertLinePointsToLineSegments(failureMechanismSection.Points); - var pipingCalculations = pipingCalculationGroup - .GetPipingCalculations() - .Where(pc => IsSurfaceLineIntersectionWithReferenceLineInSection(pc.InputParameters.SurfaceLine, lineSegments)); - - updatingDataSource = true; - - PrefillComboBoxListItemsAtColumnLevel(); - - dataGridView.DataSource = pipingCalculations - .Select(pc => new PipingCalculationRow(pc)) - .ToList(); - - UpdateStochasticSoilModelColumn(); - UpdateStochasticSoilProfileColumn(); - - updatingDataSource = false; - } - private static bool IsSurfaceLineIntersectionWithReferenceLineInSection(RingtoetsPipingSurfaceLine surfaceLine, IEnumerable lineSegments) { if (surfaceLine == null) @@ -373,12 +320,14 @@ IEnumerable stochasticSoilModels = GetSoilModelsForCalculation(rowData.PipingCalculation); var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[stochasticSoilModelColumn.Index]; - SetItemsOnObjectCollection(cell.Items, GetStochasticSoilModelColumnsDataSource(stochasticSoilModels).ToArray()); + SetItemsOnObjectCollection(cell.Items, GetStochasticSoilModelsDataSource(stochasticSoilModels).ToArray()); } private void FillAvailableSoilProfilesList(DataGridViewRow dataGridViewRow) { var rowData = (PipingCalculationRow) dataGridViewRow.DataBoundItem; + PipingInputService.SyncStochasticSoilProfileWithStochasticSoilModel(rowData.PipingCalculation.InputParameters); + IEnumerable stochasticSoilProfiles = GetSoilProfilesForCalculation(rowData.PipingCalculation); var cell = (DataGridViewComboBoxCell) dataGridViewRow.Cells[stochasticSoilProfileColumn.Index]; @@ -411,49 +360,95 @@ objectCollection.AddRange(comboBoxItems); } - private void OnPipingFailureMechanismUpdate() - { - UpdateGenerateScenariosButtonState(); - UpdateSectionsListBox(); - } + #region Data sources - private void UpdateSectionsListBox() + private void UpdateDataGridViewDataSource() { - listBox.Items.Clear(); + // Skip changes coming from the view itself + if (dataGridView.IsCurrentCellInEditMode) + { + updatingDataSource = true; - if (pipingFailureMechanism != null && pipingFailureMechanism.Sections.Any()) + UpdateStochasticSoilProfileColumn(); + updatingDataSource = false; + + dataGridView.AutoResizeColumns(); + + return; + } + + var failureMechanismSection = listBox.SelectedItem as FailureMechanismSection; + if (failureMechanismSection == null) { - listBox.Items.AddRange(pipingFailureMechanism.Sections.Cast().ToArray()); - listBox.SelectedItem = pipingFailureMechanism.Sections.First(); + dataGridView.DataSource = null; + return; } + + var lineSegments = Math2D.ConvertLinePointsToLineSegments(failureMechanismSection.Points); + var pipingCalculations = pipingCalculationGroup + .GetPipingCalculations() + .Where(pc => IsSurfaceLineIntersectionWithReferenceLineInSection(pc.InputParameters.SurfaceLine, lineSegments)); + + updatingDataSource = true; + + PrefillComboBoxListItemsAtColumnLevel(); + + dataGridView.DataSource = pipingCalculations + .Select(pc => new PipingCalculationRow(pc)) + .ToList(); + + UpdateStochasticSoilModelColumn(); + UpdateStochasticSoilProfileColumn(); + + updatingDataSource = false; } - private static IEnumerable> GetStochasticSoilModelColumnsDataSource(IEnumerable stochasticSoilModels = null) + private static IEnumerable> GetPrefillStochasticSoilModelsDataSource(IEnumerable stochasticSoilModels) { yield return new DataGridViewComboBoxItemWrapper(null); - if (stochasticSoilModels != null) + foreach (StochasticSoilModel stochasticSoilModel in stochasticSoilModels) { - foreach (StochasticSoilModel stochasticSoilModel in stochasticSoilModels) - { - yield return new DataGridViewComboBoxItemWrapper(stochasticSoilModel); - } + yield return new DataGridViewComboBoxItemWrapper(stochasticSoilModel); } } - private static IEnumerable> GetSoilProfilesDataSource(IEnumerable stochasticSoilProfiles = null) + private static IEnumerable> GetStochasticSoilModelsDataSource(IEnumerable stochasticSoilModels) { + var stochasticSoilModelsArray = stochasticSoilModels.ToArray(); + if (stochasticSoilModelsArray.Length != 1) + { + yield return new DataGridViewComboBoxItemWrapper(null); + } + foreach (StochasticSoilModel stochasticSoilModel in stochasticSoilModelsArray) + { + yield return new DataGridViewComboBoxItemWrapper(stochasticSoilModel); + } + } + + private static IEnumerable> GetPrefillSoilProfilesDataSource(IEnumerable stochasticSoilProfiles) + { yield return new DataGridViewComboBoxItemWrapper(null); - if (stochasticSoilProfiles != null) + foreach (StochasticSoilProfile stochasticSoilProfile in stochasticSoilProfiles) { - foreach (StochasticSoilProfile stochasticSoilProfile in stochasticSoilProfiles) - { - yield return new DataGridViewComboBoxItemWrapper(stochasticSoilProfile); - } + yield return new DataGridViewComboBoxItemWrapper(stochasticSoilProfile); } } + private static IEnumerable> GetSoilProfilesDataSource(IEnumerable stochasticSoilProfiles) + { + var stochasticSoilProfilesArray = stochasticSoilProfiles.ToArray(); + if (stochasticSoilProfilesArray.Length != 1) + { + yield return new DataGridViewComboBoxItemWrapper(null); + } + foreach (StochasticSoilProfile stochasticSoilProfile in stochasticSoilProfilesArray) + { + yield return new DataGridViewComboBoxItemWrapper(stochasticSoilProfile); + } + } + private static List> GetHydraulicBoundaryLocationsDataSource(IEnumerable hydraulicBoundaryLocations = null) { var dataGridViewComboBoxItemWrappers = new List> @@ -469,6 +464,8 @@ return dataGridViewComboBoxItemWrappers; } + #endregion + #region Prefill combo box list items private void PrefillComboBoxListItemsAtColumnLevel() @@ -479,12 +476,12 @@ using (new SuspendDataGridViewColumnResizes(stochasticSoilModelColumn)) { var stochasticSoilModels = pipingFailureMechanism.StochasticSoilModels; - SetItemsOnObjectCollection(stochasticSoilModelColumn.Items, GetStochasticSoilModelColumnsDataSource(stochasticSoilModels).ToArray()); + SetItemsOnObjectCollection(stochasticSoilModelColumn.Items, GetPrefillStochasticSoilModelsDataSource(stochasticSoilModels).ToArray()); } using (new SuspendDataGridViewColumnResizes(stochasticSoilProfileColumn)) { var pipingSoilProfiles = GetPipingStochasticSoilProfilesFromStochasticSoilModels(); - SetItemsOnObjectCollection(stochasticSoilProfileColumn.Items, GetSoilProfilesDataSource(pipingSoilProfiles).ToArray()); + SetItemsOnObjectCollection(stochasticSoilProfileColumn.Items, GetPrefillSoilProfilesDataSource(pipingSoilProfiles).ToArray()); } using (new SuspendDataGridViewColumnResizes(hydraulicBoundaryLocationColumn)) { @@ -502,9 +499,9 @@ if (pipingFailureMechanism != null) { return pipingFailureMechanism.StochasticSoilModels - .SelectMany(ssm => ssm.StochasticSoilProfiles) - .Distinct() - .ToArray(); + .SelectMany(ssm => ssm.StochasticSoilProfiles) + .Distinct() + .ToArray(); } return null; } @@ -724,6 +721,12 @@ UpdateApplicationSelection(); } + private void RefreshDataGridView() + { + dataGridView.Refresh(); + dataGridView.AutoResizeColumns(); + } + private void OnGenerateScenariosButtonClick(object sender, EventArgs e) { var dialog = new PipingSurfaceLineSelectionDialog(Parent, pipingFailureMechanism.SurfaceLines); @@ -740,6 +743,30 @@ pipingCalculationGroup.NotifyObservers(); } + private void OnPipingFailureMechanismUpdate() + { + UpdateGenerateScenariosButtonState(); + UpdateSectionsListBox(); + } + + private void OnStochasticSoilModelsUpdate() + { + UpdateGenerateScenariosButtonState(); + UpdateStochasticSoilModelColumn(); + UpdateStochasticSoilProfileColumn(); + } + + private void UpdateSectionsListBox() + { + listBox.Items.Clear(); + + if (pipingFailureMechanism != null && pipingFailureMechanism.Sections.Any()) + { + listBox.Items.AddRange(pipingFailureMechanism.Sections.Cast().ToArray()); + listBox.SelectedItem = pipingFailureMechanism.Sections.First(); + } + } + private void UpdateApplicationSelection() { if (ApplicationSelection == null) Index: Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingInputService.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingInputService.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingInputService.cs (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -0,0 +1,78 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Collections.Generic; +using System.Linq; +using Ringtoets.Piping.Data; + +namespace Ringtoets.Piping.Service +{ + /// + /// Class responsible for piping input properties in sync. + /// + public static class PipingInputService + { + /// + /// Sets and that matching the input of a calculation if there is one matching + /// or respectively. + /// + /// The input parameters to set the . + /// The available stochastic soil models. + public static void SetMatchingStochasticSoilModel(PipingInput pipingInput, IEnumerable availableStochasticSoilModels) + { + var available = availableStochasticSoilModels.ToList(); + if (available.Count == 0) + { + pipingInput.StochasticSoilModel = null; + } + else if (available.Count == 1) + { + if (pipingInput.StochasticSoilModel == available.First()) + { + return; + } + + pipingInput.StochasticSoilModel = available.First(); + } + SyncStochasticSoilProfileWithStochasticSoilModel(pipingInput); + } + + /// + /// Sets the to the corresponding : + /// null if no is set. + /// The first element of when it is the only element. + /// + /// + /// The input parameters to set the . + public static void SyncStochasticSoilProfileWithStochasticSoilModel(PipingInput pipingInput) + { + if (pipingInput.StochasticSoilModel != null) + { + if (pipingInput.StochasticSoilModel.StochasticSoilProfiles.Count == 1) + { + pipingInput.StochasticSoilProfile = pipingInput.StochasticSoilModel.StochasticSoilProfiles.First(); + return; + } + } + pipingInput.StochasticSoilProfile = null; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Service/Ringtoets.Piping.Service.csproj =================================================================== diff -u -r44055100aa3c3f382227becdaeae7d97c75d386c -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/src/Ringtoets.Piping.Service/Ringtoets.Piping.Service.csproj (.../Ringtoets.Piping.Service.csproj) (revision 44055100aa3c3f382227becdaeae7d97c75d386c) +++ Ringtoets/Piping/src/Ringtoets.Piping.Service/Ringtoets.Piping.Service.csproj (.../Ringtoets.Piping.Service.csproj) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -58,6 +58,7 @@ + Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs =================================================================== diff -u -r230b86184fb335b764af770f1c9fb8a1ec76fe3a -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs (.../PipingCalculationConfigurationHelperTest.cs) (revision 230b86184fb335b764af770f1c9fb8a1ec76fe3a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs (.../PipingCalculationConfigurationHelperTest.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -51,7 +51,7 @@ #region GetPipingSoilProfilesForSurfaceLine [Test] - public void GetStochasticSoilModelsForSurfaceLine_SurfaceLineIntersectingSoilModel_ReturnSoilProfilesOfSoilModel() + public void GetStochasticSoilModelsForSurfaceLine_SurfaceLineIntersectingSoilModel_ReturnSoilModel() { // Setup var soilProfile1 = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) @@ -267,7 +267,7 @@ } [Test] - public void GetStochasticSoilModelsForSurfaceLine_SurfaceLineOverlappingSoilModel_ReturnSoilProfilesOfSoilModel() + public void GetStochasticSoilModelsForSurfaceLine_SurfaceLineOverlappingSoilModels_ReturnSoilModels() { // Setup var soilProfile1 = new StochasticSoilProfile(1.0, SoilProfileType.SoilProfile1D, 1) Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingInputContextTest.cs =================================================================== diff -u -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingInputContextTest.cs (.../PipingInputContextTest.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/PipingInputContextTest.cs (.../PipingInputContextTest.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -20,15 +20,12 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Linq; using Core.Common.Base; -using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.TestUtil; using Ringtoets.Piping.Forms.PresentationObjects; @@ -93,218 +90,6 @@ } [Test] - public void SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine_NewStochasticSoilModelWithOneStochasticSoilProfile_SetsStochasticSoilProfile() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.StrictMock(); - mocks.ReplayAll(); - - var surfaceLine = new RingtoetsPipingSurfaceLine - { - Name = "Surface line 1", - ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) - }; - surfaceLine.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 stochasticSoilProfile = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) - { - SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] - { - new PipingSoilLayer(-5.0), - new PipingSoilLayer(-2.0), - new PipingSoilLayer(1.0) - }, SoilProfileType.SoilProfile1D, 1) - }; - - var stochasticSoilModel = new StochasticSoilModel(1, "Model A", "Model B") - { - Geometry = - { - new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) - }, - StochasticSoilProfiles = - { - stochasticSoilProfile - } - }; - - var pipingInput = new PipingInput(new GeneralPipingInput()); - - pipingInput.SurfaceLine = surfaceLine; - - PipingInputContext pipingInputContext = new PipingInputContext(pipingInput, new[] - { - surfaceLine - }, new[] - { - stochasticSoilModel - }, assessmentSection); - - // Call - pipingInputContext.SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine(); - - // Assert - Assert.AreEqual(stochasticSoilModel, pipingInputContext.WrappedData.StochasticSoilModel); - Assert.AreEqual(stochasticSoilProfile, pipingInputContext.WrappedData.StochasticSoilProfile); - - mocks.VerifyAll(); - } - - [Test] - public void SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine_NewStochasticSoilModelWithMultipleStochasticSoilProfiles_SetsStochasticSoilProfileToNull() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.StrictMock(); - mocks.ReplayAll(); - - var surfaceLine = new RingtoetsPipingSurfaceLine - { - Name = "Surface line 1", - ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) - }; - surfaceLine.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 stochasticSoilModel = new StochasticSoilModel(1, "Model A", "Model B") - { - Geometry = - { - new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) - }, - StochasticSoilProfiles = - { - new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) - { - SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] - { - new PipingSoilLayer(-5.0), - new PipingSoilLayer(-2.0), - new PipingSoilLayer(1.0) - }, SoilProfileType.SoilProfile1D, 1) - }, - new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) - { - SoilProfile = new PipingSoilProfile("Profile 2", -10.0, new[] - { - new PipingSoilLayer(-5.0), - new PipingSoilLayer(-2.0), - new PipingSoilLayer(1.0) - }, SoilProfileType.SoilProfile1D, 2) - } - } - }; - - var pipingInput = new PipingInput(new GeneralPipingInput()); - pipingInput.SurfaceLine = surfaceLine; - - PipingInputContext pipingInputContext = new PipingInputContext(pipingInput, new[] - { - surfaceLine - }, new[] - { - stochasticSoilModel - }, assessmentSection); - - // Call - pipingInputContext.SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine(); - - // Assert - Assert.AreEqual(stochasticSoilModel, pipingInputContext.WrappedData.StochasticSoilModel); - Assert.IsNull(pipingInputContext.WrappedData.StochasticSoilProfile); - - mocks.VerifyAll(); - } - - [Test] - public void SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine_MatchingStochasticSoilProfileAlreadySet_DoesNotSetsStochasticSoilProfileToNull() - { - // Setup - var mocks = new MockRepository(); - var assessmentSection = mocks.StrictMock(); - mocks.ReplayAll(); - - var surfaceLine = new RingtoetsPipingSurfaceLine - { - Name = "Surface line 1", - ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) - }; - surfaceLine.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 stochasticSoilProfile = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) - { - SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] - { - new PipingSoilLayer(-5.0), - new PipingSoilLayer(-2.0), - new PipingSoilLayer(1.0) - }, SoilProfileType.SoilProfile1D, 1) - }; - - var stochasticSoilModel = new StochasticSoilModel(1, "Model A", "Model B") - { - Geometry = - { - new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) - }, - StochasticSoilProfiles = - { - stochasticSoilProfile, - new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1) - { - SoilProfile = new PipingSoilProfile("Profile 2", -10.0, new[] - { - new PipingSoilLayer(-5.0), - new PipingSoilLayer(-2.0), - new PipingSoilLayer(1.0) - }, SoilProfileType.SoilProfile1D, 2) - } - } - }; - - var pipingInput = new PipingInput(new GeneralPipingInput()); - pipingInput.SurfaceLine = surfaceLine; - - PipingInputContext pipingInputContext = new PipingInputContext(pipingInput, new[] - { - surfaceLine - }, new[] - { - stochasticSoilModel - }, assessmentSection); - - // Precondition - pipingInputContext.WrappedData.StochasticSoilModel = stochasticSoilModel; - pipingInputContext.WrappedData.StochasticSoilProfile = stochasticSoilProfile; - - // Call - pipingInputContext.SetStochasticSoilModelAndStochasticSoilProfileForSurfaceLine(); - - // Assert - Assert.AreEqual(stochasticSoilModel, pipingInputContext.WrappedData.StochasticSoilModel); - Assert.AreEqual(stochasticSoilProfile, pipingInputContext.WrappedData.StochasticSoilProfile); - - mocks.VerifyAll(); - } - - [Test] public void Attach_Observer_ObserverAttachedToPipingInput() { // Setup Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs =================================================================== diff -u -r614c1aa4bf54ed2852d93a58ba8d49b549d5f46c -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs (.../PipingInputContextPropertiesTest.cs) (revision 614c1aa4bf54ed2852d93a58ba8d49b549d5f46c) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingInputContextPropertiesTest.cs (.../PipingInputContextPropertiesTest.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -180,28 +180,31 @@ var saturatedVolumicWeightOfCoverageLoayer = new ShiftedLognormalDistribution(2); var surfaceLine = ValidSurfaceLine(0.0, 4.0); - StochasticSoilProfile stochasticSoilProfile = new StochasticSoilProfile(0.0, SoilProfileType.SoilProfile1D, 0) - { - SoilProfile = new TestPipingSoilProfile() - }; - StochasticSoilModel stochasticSoilModel = new StochasticSoilModel(0, "StochasticSoilModelName", "StochasticSoilModelSegmentName"); - stochasticSoilModel.StochasticSoilProfiles.Add(stochasticSoilProfile); + StochasticSoilModel stochasticSoilModel1 = ValidStochasticSoilModel(0.0, 4.0); + StochasticSoilModel stochasticSoilModel2 = ValidStochasticSoilModel(0.0, 4.0); + var stochasticSoilProfile2 = stochasticSoilModel2.StochasticSoilProfiles.First(); + stochasticSoilModel2.StochasticSoilProfiles.Add(new StochasticSoilProfile(0.0,SoilProfileType.SoilProfile1D, 1234)); + // Call new PipingInputContextProperties { Data = new PipingInputContext(inputParameters, Enumerable.Empty(), - Enumerable.Empty(), + new[] + { + stochasticSoilModel1, + stochasticSoilModel2 + }, assessmentSectionMock), DampingFactorExit = new LognormalDistributionDesignVariable(dampingFactorExit), PhreaticLevelExit = new NormalDistributionDesignVariable(phreaticLevelExit), Diameter70 = new LognormalDistributionDesignVariable(diameter70), DarcyPermeability = new LognormalDistributionDesignVariable(darcyPermeability), SaturatedVolumicWeightOfCoverageLayer = new ShiftedLognormalDistributionDesignVariable(saturatedVolumicWeightOfCoverageLoayer), SurfaceLine = surfaceLine, - StochasticSoilModel = stochasticSoilModel, - StochasticSoilProfile = stochasticSoilProfile, + StochasticSoilModel = stochasticSoilModel2, + StochasticSoilProfile = stochasticSoilProfile2, HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(assessmentLevel) }; @@ -236,8 +239,8 @@ inputParameters.SaturatedVolumicWeightOfCoverageLayer.GetAccuracy()); Assert.AreEqual(surfaceLine, inputParameters.SurfaceLine); - Assert.AreEqual(stochasticSoilModel, inputParameters.StochasticSoilModel); - Assert.AreEqual(stochasticSoilProfile, inputParameters.StochasticSoilProfile); + Assert.AreEqual(stochasticSoilModel2, inputParameters.StochasticSoilModel); + Assert.AreEqual(stochasticSoilProfile2, inputParameters.StochasticSoilModel.StochasticSoilProfiles.First()); mocks.VerifyAll(); } @@ -471,7 +474,7 @@ } [Test] - public void SurfaceLine_NewSurfaceLine_SoilProfileSetToNull() + public void SurfaceLine_NewSurfaceLine_StochasticSoilModelAndSoilProfileSetToNull() { // Setup var mocks = new MockRepository(); @@ -495,6 +498,7 @@ properties.SurfaceLine = ValidSurfaceLine(0, 2); // Assert + Assert.IsNull(inputParameters.StochasticSoilModel); Assert.IsNull(inputParameters.StochasticSoilProfile); } @@ -511,29 +515,36 @@ { SoilProfile = new TestPipingSoilProfile() }; + var stochasticSoilModel = new StochasticSoilModel(0, "StochasticSoilModelName", "StochasticSoilModelSegmentName"); + stochasticSoilModel.StochasticSoilProfiles.Add(stochasticSoilProfile); var inputParameters = new PipingInput(new GeneralPipingInput()) { SurfaceLine = testSurfaceLine, + StochasticSoilModel = stochasticSoilModel, StochasticSoilProfile = stochasticSoilProfile }; var properties = new PipingInputContextProperties { Data = new PipingInputContext(inputParameters, Enumerable.Empty(), - Enumerable.Empty(), + new[] + { + stochasticSoilModel + }, assessmentSectionMock) }; // Call properties.SurfaceLine = testSurfaceLine; // Assert + Assert.AreSame(stochasticSoilModel, inputParameters.StochasticSoilModel); Assert.AreSame(stochasticSoilProfile, inputParameters.StochasticSoilProfile); } [Test] - public void SurfaceLine_DifferentSurfaceLine_SoilProfileSetToNull() + public void SurfaceLine_DifferentSurfaceLine_StochasticSoilModelAndSoilProfileSetToNull() { // Setup var mocks = new MockRepository(); @@ -544,28 +555,78 @@ { SoilProfile = new TestPipingSoilProfile() }; - + var stochasticSoilModel = new StochasticSoilModel(0, "StochasticSoilModelName", "StochasticSoilModelSegmentName"); + stochasticSoilModel.StochasticSoilProfiles.Add(testPipingSoilProfile); var inputParameters = new PipingInput(new GeneralPipingInput()) { SurfaceLine = ValidSurfaceLine(0, 2), + StochasticSoilModel = stochasticSoilModel, StochasticSoilProfile = testPipingSoilProfile }; var properties = new PipingInputContextProperties { Data = new PipingInputContext(inputParameters, Enumerable.Empty(), - Enumerable.Empty(), + new[] + { + stochasticSoilModel + }, assessmentSectionMock) }; // Call properties.SurfaceLine = ValidSurfaceLine(0, 2); // Assert + Assert.IsNull(inputParameters.StochasticSoilModel); Assert.IsNull(inputParameters.StochasticSoilProfile); } [Test] + public void StochasticSoilProfile_DifferentStochasticSoilModel_SoilProfileSetToNull() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var testSurfaceLine = ValidSurfaceLine(0, 2); + var stochasticSoilProfile1 = new StochasticSoilProfile(0.0, SoilProfileType.SoilProfile1D, 0) + { + SoilProfile = new TestPipingSoilProfile() + }; + var stochasticSoilModel1 = new StochasticSoilModel(0, "StochasticSoilModel1Name", "StochasticSoilModelSegment1Name"); + stochasticSoilModel1.StochasticSoilProfiles.Add(stochasticSoilProfile1); + + var stochasticSoilProfile2 = new StochasticSoilProfile(0.0, SoilProfileType.SoilProfile1D, 0) + { + SoilProfile = new TestPipingSoilProfile() + }; + var stochasticSoilModel2 = new StochasticSoilModel(0, "StochasticSoilModel2Name", "StochasticSoilModelSegment2Name"); + stochasticSoilModel1.StochasticSoilProfiles.Add(stochasticSoilProfile2); + + var inputParameters = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = testSurfaceLine, + StochasticSoilModel = stochasticSoilModel1, + StochasticSoilProfile = stochasticSoilProfile1 + }; + var properties = new PipingInputContextProperties + { + Data = new PipingInputContext(inputParameters, + Enumerable.Empty(), + Enumerable.Empty(), + assessmentSectionMock) + }; + + // Call + properties.StochasticSoilModel = stochasticSoilModel2; + + // Assert + Assert.IsNull(inputParameters.StochasticSoilProfile); + } + + [Test] [TestCase(1)] [TestCase(2)] public void GivenCompletePipingInputContextProperties_WhenPhreaticLevelExitPropertiesSetThroughProperties_ThenPiezometricHeadExitUpdated(int propertyIndexToChange) @@ -605,6 +666,18 @@ mocks.VerifyAll(); } + private static StochasticSoilModel ValidStochasticSoilModel(double xMin, double xMax) + { + var stochasticSoilModel = new StochasticSoilModel(0, "StochasticSoilModelName", "StochasticSoilModelSegmentName"); + stochasticSoilModel.StochasticSoilProfiles.Add(new StochasticSoilProfile(0.0, SoilProfileType.SoilProfile1D, 1234) + { + SoilProfile = new TestPipingSoilProfile() + }); + stochasticSoilModel.Geometry.Add(new Point2D(xMin, 1.0)); + stochasticSoilModel.Geometry.Add(new Point2D(xMax, 0.0)); + return stochasticSoilModel; + } + private static RingtoetsPipingSurfaceLine ValidSurfaceLine(double xMin, double xMax) { var surfaceLine = new RingtoetsPipingSurfaceLine(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -r473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6 -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 473efe5f1b2aff98ffc7ad1d826c3ef90f77a7a6) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -98,6 +98,7 @@ + Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingInputContextStochasticSoilModelSelectionEditorTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingInputContextStochasticSoilModelSelectionEditorTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/UITypeEditors/PipingInputContextStochasticSoilModelSelectionEditorTest.cs (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -0,0 +1,161 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.ComponentModel; +using System.Linq; +using System.Windows.Forms.Design; +using Core.Common.Base.Geometry; +using Core.Common.Gui.PropertyBag; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.Forms.PresentationObjects; +using Ringtoets.Piping.Forms.PropertyClasses; +using Ringtoets.Piping.Forms.UITypeEditors; +using Ringtoets.Piping.KernelWrapper.TestUtil; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Forms.Test.UITypeEditors +{ + [TestFixture] + public class PipingInputContextStochasticSoilModelSelectionEditorTest + { + [Test] + public void EditValue_NoCurrentItemInAvailableItems_ReturnsOriginalValue() + { + // Setup + var mockRepository = new MockRepository(); + var provider = mockRepository.DynamicMock(); + var service = mockRepository.DynamicMock(); + var context = mockRepository.DynamicMock(); + var assessmentSectionMock = mockRepository.StrictMock(); + + var pipingInput = new PipingInput(new GeneralPipingInput()) + { + StochasticSoilModel = new StochasticSoilModel(0, "StochasticSoilModelName", "StochasticSoilModelSegmentName") + }; + var pipingInputContext = new PipingInputContext(pipingInput, + Enumerable.Empty(), + new[] + { + new TestStochasticSoilModel() + }, + assessmentSectionMock); + + var properties = new PipingInputContextProperties + { + Data = pipingInputContext + }; + + var editor = new PipingInputContextStochasticSoilModelSelectionEditor(); + var someValue = new object(); + var propertyBag = new DynamicPropertyBag(properties); + + provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); + service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); + context.Expect(c => c.Instance).Return(propertyBag); + + mockRepository.ReplayAll(); + + // Call + var result = editor.EditValue(context, provider, someValue); + + // Assert + Assert.AreSame(someValue, result); + + mockRepository.VerifyAll(); + } + + [Test] + public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() + { + // Setup + var mockRepository = new MockRepository(); + var provider = mockRepository.DynamicMock(); + var service = mockRepository.DynamicMock(); + var context = mockRepository.DynamicMock(); + var assessmentSectionMock = mockRepository.StrictMock(); + + var stochasticSoilProfile = new StochasticSoilProfile(1.0, SoilProfileType.SoilProfile1D, 0) + { + SoilProfile = new TestPipingSoilProfile() + }; + var stochasticSoilModel = new StochasticSoilModel(0, "Model", string.Empty) + { + Geometry = + { + new Point2D(0, 2), + new Point2D(4, 2) + }, + StochasticSoilProfiles = + { + stochasticSoilProfile + } + }; + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(2, 1, 0), + new Point3D(2, 3, 0) + }); + + var pipingInput = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine, + StochasticSoilModel = stochasticSoilModel, + StochasticSoilProfile = stochasticSoilProfile + }; + var inputParametersContext = new PipingInputContext(pipingInput, + Enumerable.Empty(), + new[] + { + stochasticSoilModel + }, + assessmentSectionMock); + + var properties = new PipingInputContextProperties + { + Data = inputParametersContext + }; + + var editor = new PipingInputContextStochasticSoilModelSelectionEditor(); + var someValue = new object(); + var propertyBag = new DynamicPropertyBag(properties); + + provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); + service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); + context.Expect(c => c.Instance).Return(propertyBag); + + mockRepository.ReplayAll(); + + // Call + var result = editor.EditValue(context, provider, someValue); + + // Assert + Assert.AreSame(stochasticSoilModel, result); + + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs =================================================================== diff -u -r79545aa87d2fffbac4fc5b2aadb24db37270db8e -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs (.../PipingCalculationsViewTest.cs) (revision 79545aa87d2fffbac4fc5b2aadb24db37270db8e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs (.../PipingCalculationsViewTest.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -265,9 +265,8 @@ // Assert var 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()); + Assert.AreEqual(1, stochasticSoilModelsComboboxItems.Count); + Assert.AreEqual("Model A", stochasticSoilModelsComboboxItems[0].ToString()); stochasticSoilModelsComboboxItems = ((DataGridViewComboBoxCell) dataGridView.Rows[1].Cells[stochasticSoilModelsColumnIndex]).Items; Assert.AreEqual(3, stochasticSoilModelsComboboxItems.Count); @@ -292,9 +291,8 @@ 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()); + Assert.AreEqual(1, soilProfilesComboboxItems.Count); + Assert.AreEqual("Profile 5", soilProfilesComboboxItems[0].ToString()); } [Test] @@ -313,7 +311,7 @@ Assert.AreEqual(8, cells.Count); Assert.AreEqual("Calculation 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual("Model A", cells[stochasticSoilModelsColumnIndex].FormattedValue); - Assert.AreEqual("Profile 1", cells[stochasticSoilProfilesColumnIndex].FormattedValue); + Assert.AreEqual("", cells[stochasticSoilProfilesColumnIndex].FormattedValue); Assert.AreEqual("Location 1", cells[hydraulicBoundaryLocationsColumnIndex].FormattedValue); Assert.AreEqual(1.111.ToString(CultureInfo.CurrentCulture), cells[dampingFactorExitMeanColumnIndex].FormattedValue); Assert.AreEqual(2.222.ToString(CultureInfo.CurrentCulture), cells[phreaticLevelExitMeanColumnIndex].FormattedValue); Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingCalculationsViewIntegrationTest.cs =================================================================== diff -u -rc4d2af65ad23757fb3bd11f93458839bc1787ded -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingCalculationsViewIntegrationTest.cs (.../PipingCalculationsViewIntegrationTest.cs) (revision c4d2af65ad23757fb3bd11f93458839bc1787ded) +++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingCalculationsViewIntegrationTest.cs (.../PipingCalculationsViewIntegrationTest.cs) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -73,7 +73,9 @@ // Import soil models and profiles and ensure the corresponding combobox items are updated ImportSoilProfiles(assessmentSection); - Assert.AreEqual(2, ((DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex]).Items.Count); + pipingCalculation1.InputParameters.StochasticSoilModel = assessmentSection.PipingFailureMechanism.StochasticSoilModels.First(sl => sl.Name == "PK001_0001_Piping"); + Assert.AreEqual(1, ((DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex]).Items.Count); + Assert.AreEqual("PK001_0001_Piping", dataGridView.Rows[0].Cells[stochasticSoilModelsColumnIndex].FormattedValue); Assert.AreEqual(1, ((DataGridViewComboBoxCell) dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex]).Items.Count); Assert.AreEqual("", dataGridView.Rows[0].Cells[stochasticSoilProfilesColumnIndex].FormattedValue); Index: Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingInputServiceTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingInputServiceTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingInputServiceTest.cs (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -0,0 +1,170 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Service.Test +{ + [TestFixture] + public class PipingInputServiceTest + { + [Test] + public void SetMatchingStochasticSoilModel_SurfaceLineOverlappingSingleSoilModel_SetsSoilModel() + { + // Setup + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + soilModel.StochasticSoilProfiles.Add(new StochasticSoilProfile(1.0, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }); + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) + }); + var pipingInput = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine + }; + + // Call + PipingInputService.SetMatchingStochasticSoilModel(pipingInput, new[] + { + soilModel + }); + + // Assert + Assert.AreEqual(soilModel, pipingInput.StochasticSoilModel); + } + + [Test] + public void SetMatchingStochasticSoilModel_SurfaceLineOverlappingMultipleSoilModels_DoesNotSetModel() + { + // Setup + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) + }); + var pipingInput = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine + }; + var soilModel1 = new StochasticSoilModel(1, "A", "B"); + soilModel1.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + soilModel1.StochasticSoilProfiles.Add(new StochasticSoilProfile(1.0, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }); + var soilModel2 = new StochasticSoilModel(2, "C", "D"); + soilModel2.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + soilModel2.StochasticSoilProfiles.Add(new StochasticSoilProfile(1.0, SoilProfileType.SoilProfile1D, 1) + { + SoilProfile = new PipingSoilProfile("Profile 1", -10.0, new[] + { + new PipingSoilLayer(-5.0), + new PipingSoilLayer(-2.0), + new PipingSoilLayer(1.0) + }, SoilProfileType.SoilProfile1D, 1) + }); + + // Call + PipingInputService.SetMatchingStochasticSoilModel(pipingInput, new[] + { + soilModel1, + soilModel2 + }); + + // Assert + Assert.IsNull(pipingInput.StochasticSoilModel); + } + + [Test] + public void SyncStochasticSoilProfileWithStochasticSoilModel_SingleStochasticSoilProfileInStochasticSoilModel_SetsStochasticSoilProfile() + { + // Setup + var soilProfile = new StochasticSoilProfile(0.3, SoilProfileType.SoilProfile1D, 1); + + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.StochasticSoilProfiles.Add(soilProfile); + + var pipingInput = new PipingInput(new GeneralPipingInput()); + pipingInput.StochasticSoilModel = soilModel; + + // Call + PipingInputService.SyncStochasticSoilProfileWithStochasticSoilModel(pipingInput); + + // Assert + Assert.AreEqual(soilProfile, pipingInput.StochasticSoilProfile); + } + + [Test] + public void SyncStochasticSoilProfileWithStochasticSoilModel_MultipleStochasticSoilProfilesInStochasticSoilModel_DoesNotSetStochasticSoilProfile() + { + // Setup + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.StochasticSoilProfiles.AddRange(new[] + { + new StochasticSoilProfile(0.0, SoilProfileType.SoilProfile1D, 1), + new StochasticSoilProfile(1.1, SoilProfileType.SoilProfile1D, 2) + }); + var pipingInput = new PipingInput(new GeneralPipingInput()); + pipingInput.StochasticSoilModel = soilModel; + + // Call + PipingInputService.SyncStochasticSoilProfileWithStochasticSoilModel(pipingInput); + + // Assert + Assert.IsNull(pipingInput.StochasticSoilProfile); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/Ringtoets.Piping.Service.Test.csproj =================================================================== diff -u -r238411e28abf2f71dc0a5715ca940c6e87df9392 -rd515de49557312e4af41b1c051c900d39d1f9e2f --- Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/Ringtoets.Piping.Service.Test.csproj (.../Ringtoets.Piping.Service.Test.csproj) (revision 238411e28abf2f71dc0a5715ca940c6e87df9392) +++ Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/Ringtoets.Piping.Service.Test.csproj (.../Ringtoets.Piping.Service.Test.csproj) (revision d515de49557312e4af41b1c051c900d39d1f9e2f) @@ -60,6 +60,7 @@ + @@ -89,6 +90,10 @@ {D64E4F0E-E341-496F-82B2-941AD202B4E3} Ringtoets.Piping.KernelWrapper + + {14C6F716-64E2-4BC4-A1EF-05865FCEFA4C} + Ringtoets.Piping.Primitives + {10B8D63D-87E8-46DF-ACA9-A8CF22EE8FB5} Ringtoets.Piping.Service @@ -107,6 +112,9 @@ + + Copying.licenseheader +