Index: Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Forms/StabilityStoneCoverCalculationConfigurationHelper.cs =================================================================== diff -u -r9e6869de553715aefe4752478334c3a6a3f83340 -r1323a36fea2639e67dcf6f2273ad5b423d8c6b0a --- Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Forms/StabilityStoneCoverCalculationConfigurationHelper.cs (.../StabilityStoneCoverCalculationConfigurationHelper.cs) (revision 9e6869de553715aefe4752478334c3a6a3f83340) +++ Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Forms/StabilityStoneCoverCalculationConfigurationHelper.cs (.../StabilityStoneCoverCalculationConfigurationHelper.cs) (revision 1323a36fea2639e67dcf6f2273ad5b423d8c6b0a) @@ -23,8 +23,10 @@ using System.Collections.Generic; using System.Linq; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Revetment.Data; using Ringtoets.StabilityStoneCover.Data; namespace Ringtoets.StabilityStoneCover.Forms @@ -36,45 +38,53 @@ { /// /// Adds based on the - /// in the . + /// in the and sets their initial category type input based on the . /// /// Locations to base the calculation upon. /// The list to update. - /// Throw when any input parameter is null. - public static void AddCalculationsFromLocations( - IEnumerable locations, - List calculations - ) + /// The to set the category type input for. + /// Throw when any + /// or is null. + public static void AddCalculationsFromLocations(IEnumerable locations, + List calculations, + NormType normType) { if (locations == null) { throw new ArgumentNullException(nameof(locations)); } + if (calculations == null) { throw new ArgumentNullException(nameof(calculations)); } - foreach (ICalculationBase calculation in locations.Select(location => CreateStabilityStoneCoverWaveConditionsCalculation(location, calculations))) + + foreach (ICalculationBase calculation in locations.Select(location => CreateStabilityStoneCoverWaveConditionsCalculation(location, + calculations, + normType))) { calculations.Add(calculation); } } private static ICalculationBase CreateStabilityStoneCoverWaveConditionsCalculation( HydraulicBoundaryLocation hydraulicBoundaryLocation, - IEnumerable calculations) + IEnumerable calculations, + NormType normType) { string nameBase = hydraulicBoundaryLocation.Name; string name = NamingHelper.GetUniqueName(calculations, nameBase, c => c.Name); - return new StabilityStoneCoverWaveConditionsCalculation + var calculation = new StabilityStoneCoverWaveConditionsCalculation { Name = name, InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation } }; + WaveConditionsInputHelper.SetCategoryType(calculation.InputParameters, normType); + return calculation; } } } \ No newline at end of file Index: Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs =================================================================== diff -u -rf6d370ae60e36ea4f00c94013e0805d91cc7cc6f -r1323a36fea2639e67dcf6f2273ad5b423d8c6b0a --- Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs (.../StabilityStoneCoverPlugin.cs) (revision f6d370ae60e36ea4f00c94013e0805d91cc7cc6f) +++ Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs (.../StabilityStoneCoverPlugin.cs) (revision 1323a36fea2639e67dcf6f2273ad5b423d8c6b0a) @@ -32,6 +32,7 @@ using Core.Common.Util; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Forms; using Ringtoets.Common.Forms.ChangeHandlers; @@ -495,18 +496,22 @@ if (dialog.SelectedItems.Any()) { - GenerateStabilityStoneCoverCalculations(dialog.SelectedItems, nodeData.WrappedData.Children); + GenerateStabilityStoneCoverCalculations(dialog.SelectedItems, + nodeData.WrappedData.Children, + nodeData.AssessmentSection.FailureMechanismContribution.NormativeNorm); nodeData.NotifyObservers(); } } } private static void GenerateStabilityStoneCoverCalculations(IEnumerable hydraulicBoundaryLocations, - List calculationCollection) + List calculationCollection, + NormType normType) { StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations( hydraulicBoundaryLocations, - calculationCollection); + calculationCollection, + normType); } private static void AddWaveConditionsCalculation(StabilityStoneCoverWaveConditionsCalculationGroupContext nodeData) @@ -517,7 +522,7 @@ RingtoetsCommonDataResources.Calculation_DefaultName, c => c.Name) }; - WaveConditionsInputHelper.SetCategoryType(calculation.InputParameters, + WaveConditionsInputHelper.SetCategoryType(calculation.InputParameters, nodeData.AssessmentSection.FailureMechanismContribution.NormativeNorm); nodeData.WrappedData.Children.Add(calculation); Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Forms.Test/StabilityStoneCoverCalculationConfigurationHelperTest.cs =================================================================== diff -u -r5ca67bdbaab0f6a9fb7682c06140b93bb0f5b5bb -r1323a36fea2639e67dcf6f2273ad5b423d8c6b0a --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Forms.Test/StabilityStoneCoverCalculationConfigurationHelperTest.cs (.../StabilityStoneCoverCalculationConfigurationHelperTest.cs) (revision 5ca67bdbaab0f6a9fb7682c06140b93bb0f5b5bb) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Forms.Test/StabilityStoneCoverCalculationConfigurationHelperTest.cs (.../StabilityStoneCoverCalculationConfigurationHelperTest.cs) (revision 1323a36fea2639e67dcf6f2273ad5b423d8c6b0a) @@ -22,9 +22,13 @@ using System; using System.Collections.Generic; using System.Linq; +using Core.Common.TestUtil; using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Revetment.Data; using Ringtoets.StabilityStoneCover.Data; namespace Ringtoets.StabilityStoneCover.Forms.Test @@ -36,10 +40,13 @@ public void AddCalculationsFromLocations_LocationsIsNull_ThrowsArgumentNullException() { // Setup + var random = new Random(21); var calculations = new List(); // Call - TestDelegate test = () => StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(null, calculations); + TestDelegate test = () => StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(null, + calculations, + random.NextEnumValue()); // Assert string paramName = Assert.Throws(test).ParamName; @@ -50,10 +57,11 @@ public void AddCalculationsFromLocations_CalculationsIsNull_ThrowsArgumentNullException() { // Setup + var random = new Random(21); IEnumerable locations = Enumerable.Empty(); // Call - TestDelegate test = () => StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, null); + TestDelegate test = () => StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, null, random.NextEnumValue()); // Assert string paramName = Assert.Throws(test).ParamName; @@ -64,18 +72,23 @@ public void AddCalculationsFromLocations_EmptyCollections_ReturnsEmptyList() { // Setup + var random = new Random(21); IEnumerable locations = Enumerable.Empty(); var calculationBases = new List(); // Call - StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, calculationBases); + StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, calculationBases, random.NextEnumValue()); // Assert CollectionAssert.IsEmpty(calculationBases); } [Test] - public void AddCalculationsFromLocations_MultipleCalculationsEmptyCalculationBase_ReturnsUniquelyNamedCalculations() + [TestCase(NormType.LowerLimit, AssessmentSectionCategoryType.LowerLimitNorm)] + [TestCase(NormType.Signaling, AssessmentSectionCategoryType.SignalingNorm)] + public void AddCalculationsFromLocations_MultipleCalculationsEmptyCalculationBase_ReturnsUniquelyNamedCalculations( + NormType normType, + AssessmentSectionCategoryType expectedAssessmentSectionCategoryType) { // Setup const string name = "name"; @@ -87,21 +100,29 @@ var calculationBases = new List(); // Call - StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, calculationBases); + StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, calculationBases, normType); // Assert Assert.AreEqual(2, calculationBases.Count); var firstCalculation = (StabilityStoneCoverWaveConditionsCalculation) calculationBases.First(); Assert.AreEqual(name, firstCalculation.Name); - Assert.AreEqual(locations[0], firstCalculation.InputParameters.HydraulicBoundaryLocation); + AssessmentSectionCategoryWaveConditionsInput firstCalculationInput = firstCalculation.InputParameters; + Assert.AreEqual(locations[0], firstCalculationInput.HydraulicBoundaryLocation); + Assert.AreEqual(expectedAssessmentSectionCategoryType, firstCalculationInput.CategoryType); var secondCalculation = (StabilityStoneCoverWaveConditionsCalculation) calculationBases.ElementAt(1); Assert.AreEqual($"{name} (1)", secondCalculation.Name); - Assert.AreSame(locations[1], secondCalculation.InputParameters.HydraulicBoundaryLocation); + AssessmentSectionCategoryWaveConditionsInput secondCalculationInput = secondCalculation.InputParameters; + Assert.AreSame(locations[1], secondCalculationInput.HydraulicBoundaryLocation); + Assert.AreEqual(expectedAssessmentSectionCategoryType, secondCalculationInput.CategoryType); } [Test] - public void AddCalculationsFromLocations_MultipleCalculationsAndDuplicateNameInCalculationBase_ReturnsUniquelyNamedCalculations() + [TestCase(NormType.LowerLimit, AssessmentSectionCategoryType.LowerLimitNorm)] + [TestCase(NormType.Signaling, AssessmentSectionCategoryType.SignalingNorm)] + public void AddCalculationsFromLocations_MultipleCalculationsAndDuplicateNameInCalculationBase_ReturnsUniquelyNamedCalculations( + NormType normType, + AssessmentSectionCategoryType expectedAssessmentSectionCategoryType) { // Setup const string name = "name"; @@ -119,17 +140,21 @@ }; // Call - StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, calculationBases); + StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations(locations, calculationBases, normType); // Assert Assert.AreEqual(3, calculationBases.Count); var firstCalculation = (StabilityStoneCoverWaveConditionsCalculation) calculationBases.ElementAt(1); Assert.AreEqual($"{name} (1)", firstCalculation.Name); - Assert.AreEqual(locations[0], firstCalculation.InputParameters.HydraulicBoundaryLocation); + AssessmentSectionCategoryWaveConditionsInput firstCalculationInput = firstCalculation.InputParameters; + Assert.AreEqual(locations[0], firstCalculationInput.HydraulicBoundaryLocation); + Assert.AreEqual(expectedAssessmentSectionCategoryType, firstCalculationInput.CategoryType); var secondCalculation = (StabilityStoneCoverWaveConditionsCalculation) calculationBases.ElementAt(2); Assert.AreEqual($"{name} (2)", secondCalculation.Name); - Assert.AreSame(locations[1], secondCalculation.InputParameters.HydraulicBoundaryLocation); + AssessmentSectionCategoryWaveConditionsInput secondCalculationInput = secondCalculation.InputParameters; + Assert.AreSame(locations[1], secondCalculationInput.HydraulicBoundaryLocation); + Assert.AreEqual(expectedAssessmentSectionCategoryType, secondCalculationInput.CategoryType); } } } \ No newline at end of file Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/TreeNodeInfos/StabilityStoneCoverWaveConditionsCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rf6d370ae60e36ea4f00c94013e0805d91cc7cc6f -r1323a36fea2639e67dcf6f2273ad5b423d8c6b0a --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/TreeNodeInfos/StabilityStoneCoverWaveConditionsCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityStoneCoverWaveConditionsCalculationGroupContextTreeNodeInfoTest.cs) (revision f6d370ae60e36ea4f00c94013e0805d91cc7cc6f) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/TreeNodeInfos/StabilityStoneCoverWaveConditionsCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityStoneCoverWaveConditionsCalculationGroupContextTreeNodeInfoTest.cs) (revision 1323a36fea2639e67dcf6f2273ad5b423d8c6b0a) @@ -1415,11 +1415,10 @@ } [Test] - [TestCase(NormType.Signaling, AssessmentSectionCategoryType.SignalingNorm)] - [TestCase(NormType.LowerLimit, AssessmentSectionCategoryType.LowerLimitNorm)] + [TestCase(NormType.Signaling)] + [TestCase(NormType.LowerLimit)] public void ContextMenuStrip_ClickOnAddCalculationItem_AddCalculationToCalculationGroupAndNotifyObservers( - NormType normType, - AssessmentSectionCategoryType expectedAssessmentSectionCategoryType) + NormType normType) { // Setup var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); @@ -1464,12 +1463,11 @@ // Assert Assert.AreEqual(2, group.Children.Count); ICalculationBase newlyAddedItem = group.Children.Last(); - Assert.IsInstanceOf(newlyAddedItem); + var newCalculationItem = newlyAddedItem as StabilityStoneCoverWaveConditionsCalculation; + Assert.IsNotNull(newCalculationItem); Assert.AreEqual("Nieuwe berekening (1)", newlyAddedItem.Name, "An item with the same name default name already exists, therefore '(1)' needs to be appended."); - - var newCalculationItem = (StabilityStoneCoverWaveConditionsCalculation) newlyAddedItem; - Assert.AreEqual(expectedAssessmentSectionCategoryType, newCalculationItem.InputParameters.CategoryType); + Assert.AreEqual(GetCategoryTypeFromNormType(normType), newCalculationItem.InputParameters.CategoryType); } } } @@ -1478,6 +1476,9 @@ public void GivenDialogGenerateCalculationButtonClicked_WhenCalculationSelectedAndDialogClosed_ThenUpdateCalculationGroup() { // Given + var random = new Random(21); + var normType = random.NextEnumValue(); + using (var treeViewControl = new TreeViewControl()) { var existingGroup = new CalculationGroup(); @@ -1490,18 +1491,22 @@ existingcalculation } }; + var failureMechanism = new StabilityStoneCoverFailureMechanism(); - var assessmentSection = mocks.Stub(); var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation(); var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation(); - assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase + var assessmentSection = new AssessmentSectionStub { - Locations = + FailureMechanismContribution = { - hydraulicBoundaryLocation1, - hydraulicBoundaryLocation2 + NormativeNorm = normType } + }; + assessmentSection.HydraulicBoundaryDatabase.Locations.AddRange(new[] + { + hydraulicBoundaryLocation1, + hydraulicBoundaryLocation2 }); var observer = mocks.StrictMock(); @@ -1544,12 +1549,19 @@ Assert.AreSame(existingcalculation, group.Children[1]); Assert.NotNull(dialog); Assert.NotNull(grid); + + AssessmentSectionCategoryType expectedAssessmentSectionCategoryType = GetCategoryTypeFromNormType(normType); var firstCalculation = group.Children[2] as StabilityStoneCoverWaveConditionsCalculation; Assert.IsNotNull(firstCalculation); - Assert.AreSame(hydraulicBoundaryLocation1, firstCalculation.InputParameters.HydraulicBoundaryLocation); + AssessmentSectionCategoryWaveConditionsInput firstCalculationInputParameters = firstCalculation.InputParameters; + Assert.AreSame(hydraulicBoundaryLocation1, firstCalculationInputParameters.HydraulicBoundaryLocation); + Assert.AreEqual(expectedAssessmentSectionCategoryType, firstCalculationInputParameters.CategoryType); + var secondCalculation = group.Children[3] as StabilityStoneCoverWaveConditionsCalculation; Assert.IsNotNull(secondCalculation); - Assert.AreSame(hydraulicBoundaryLocation2, secondCalculation.InputParameters.HydraulicBoundaryLocation); + AssessmentSectionCategoryWaveConditionsInput secondCalculationInputParameters = secondCalculation.InputParameters; + Assert.AreSame(hydraulicBoundaryLocation2, secondCalculationInputParameters.HydraulicBoundaryLocation); + Assert.AreEqual(expectedAssessmentSectionCategoryType, secondCalculationInputParameters.CategoryType); } } @@ -1700,8 +1712,7 @@ var failureMechanism = new StabilityStoneCoverFailureMechanism(); failureMechanism.WaveConditionsCalculationGroup.Attach(observer); - IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks); - + var assessmentSection = new AssessmentSectionStub(); var context = new StabilityStoneCoverWaveConditionsCalculationGroupContext(failureMechanism.WaveConditionsCalculationGroup, null, failureMechanism, @@ -1905,5 +1916,18 @@ } }; } + + private static AssessmentSectionCategoryType GetCategoryTypeFromNormType(NormType normType) + { + switch (normType) + { + case NormType.LowerLimit: + return AssessmentSectionCategoryType.LowerLimitNorm; + case NormType.Signaling: + return AssessmentSectionCategoryType.SignalingNorm; + default: + throw new NotSupportedException(); + } + } } } \ No newline at end of file