diff --git a/Application/Ringtoets/src/Application.Ringtoets.Migration.Core/EmbeddedResources/Migration_5_17.1.sql b/Application/Ringtoets/src/Application.Ringtoets.Migration.Core/EmbeddedResources/Migration_5_17.1.sql index 01fa23818bf..bd16e66d37c 100644 --- a/Application/Ringtoets/src/Application.Ringtoets.Migration.Core/EmbeddedResources/Migration_5_17.1.sql +++ b/Application/Ringtoets/src/Application.Ringtoets.Migration.Core/EmbeddedResources/Migration_5_17.1.sql @@ -5,7 +5,7 @@ TargetProject version: 17.1 */ PRAGMA foreign_keys = OFF; -ATTACH DATABASE [{0}] AS SOURCEPROJECT; +ATTACH DATABASE '{0}' AS SOURCEPROJECT; INSERT INTO AssessmentSectionEntity SELECT * FROM [SOURCEPROJECT].AssessmentSectionEntity; INSERT INTO CalculationGroupEntity SELECT * FROM [SOURCEPROJECT].CalculationGroupEntity; @@ -35,7 +35,7 @@ SELECT CASE WHEN Suffix THEN [Name] || SUBSTR(QUOTE(ZEROBLOB((SuffixPreLength + 1) / 2)), 3, SuffixPreLength) || Suffix ELSE [Name] END as [Id], - CASE WHEN Suffix THEN [Name] || '(' || Suffix || ')' ELSE [Name] END as [Name], + [Name], [Orientation], [BreakWaterType], [BreakWaterHeight], @@ -46,7 +46,7 @@ SELECT [Y], [X0], [Order] - FROM (SELECT *, MaxLength - LENGTH(NAME) as SuffixPreLength, (SELECT count(*) + FROM (SELECT *, MaxLength - LENGTH(NAME) as SuffixPreLength, (SELECT DP.rowid FROM [SOURCEPROJECT].DikeProfileEntity WHERE DP.DikeProfileEntityId > DikeProfileEntityId AND DP.Name IS Name @@ -85,39 +85,39 @@ SELECT FROM [SOURCEPROJECT].ForeshoreProfileEntity; INSERT INTO GrassCoverErosionInwardsCalculationEntity ( [GrassCoverErosionInwardsCalculationEntityId], - [CalculationGroupEntityId], - [HydraulicLocationEntityId], - [DikeProfileEntityId], - [Order], - [Name], - [Comments], - [Orientation], - [CriticalFlowRateMean], - [CriticalFlowRateStandardDeviation], - [UseForeshore], - [DikeHeightCalculationType], - [DikeHeight], - [UseBreakWater], - [BreakWaterType], - [BreakWaterHeight], + [CalculationGroupEntityId], + [HydraulicLocationEntityId], + [DikeProfileEntityId], + [Order], + [Name], + [Comments], + [Orientation], + [CriticalFlowRateMean], + [CriticalFlowRateStandardDeviation], + [UseForeshore], + [DikeHeightCalculationType], + [DikeHeight], + [UseBreakWater], + [BreakWaterType], + [BreakWaterHeight], [OvertoppingRateCalculationType]) SELECT [GrassCoverErosionInwardsCalculationEntityId], - [CalculationGroupEntityId], - [HydraulicLocationEntityId], - [DikeProfileEntityId], - [Order], - [Name], - [Comments], - [Orientation], - [CriticalFlowRateMean], - [CriticalFlowRateStandardDeviation], - [UseForeshore], - [DikeHeightCalculationType], - [DikeHeight], - [UseBreakWater], - [BreakWaterType], - [BreakWaterHeight], + [CalculationGroupEntityId], + [HydraulicLocationEntityId], + [DikeProfileEntityId], + [Order], + [Name], + [Comments], + [Orientation], + [CriticalFlowRateMean], + [CriticalFlowRateStandardDeviation], + [UseForeshore], + [DikeHeightCalculationType], + [DikeHeight], + [UseBreakWater], + [BreakWaterType], + [BreakWaterHeight], 1 FROM [SOURCEPROJECT].GrassCoverErosionInwardsCalculationEntity; INSERT INTO GrassCoverErosionInwardsFailureMechanismMetaEntity ( @@ -189,20 +189,35 @@ INSERT INTO StabilityPointStructuresFailureMechanismMetaEntity SELECT * FROM [SO INSERT INTO StabilityPointStructuresSectionResultEntity SELECT * FROM [SOURCEPROJECT].StabilityPointStructuresSectionResultEntity; INSERT INTO StabilityStoneCoverSectionResultEntity SELECT * FROM [SOURCEPROJECT].StabilityStoneCoverSectionResultEntity; INSERT INTO StabilityStoneCoverWaveConditionsCalculationEntity SELECT * FROM [SOURCEPROJECT].StabilityStoneCoverWaveConditionsCalculationEntity; -INSERT INTO StochasticSoilModelEntity +INSERT INTO StochasticSoilModelEntity ( + [StochasticSoilModelEntityId], + [FailureMechanismEntityId], + [Name], + [SegmentName], + [StochasticSoilModelSegmentPointXml], + [Order]) SELECT [StochasticSoilModelEntityId], [FailuremechanismEntityId], - CASE WHEN Suffix THEN [Name] || '(' || Suffix || ')' ELSE [Name] END as [Name], + CASE WHEN Suffix THEN [Name] || ' (' || SUBSTR(QUOTE(ZEROBLOB((SuffixPreLength + 1) / 2)), 3, SuffixPreLength) || Suffix || ')' ELSE [Name] END AS [Name], [SegmentName], [StochasticSoilModelSegmentPointXml], [Order] - FROM (SELECT *, (SELECT count(*) - FROM [SOURCEPROJECT].StochasticSoilModelEntity - WHERE SSM.StochasticSoilModelEntityId > StochasticSoilModelEntityId - AND SSM.Name IS Name - AND SSM.FailuremechanismEntityId = FailuremechanismEntityId) as Suffix - FROM [SOURCEPROJECT].StochasticSoilModelEntity SSM); + FROM + ( + SELECT *, MAX(MaxLength - LENGTH(NAME), 0) as SuffixPreLength, + ( + SELECT COUNT() + FROM [SOURCEPROJECT].StochasticSoilModelEntity + WHERE SSM.StochasticSoilModelEntityId > StochasticSoilModelEntityId + AND SSM.Name IS Name + AND SSM.FailuremechanismEntityId = FailuremechanismEntityId + ) AS Suffix + FROM [SOURCEPROJECT].StochasticSoilModelEntity SSM + JOIN ( + SELECT MAX(LENGTH(Name)-3) as MaxLength FROM [SOURCEPROJECT].StochasticSoilModelEntity + ) + ); INSERT INTO StochasticSoilProfileEntity SELECT [StochasticSoilProfileEntityId], @@ -216,21 +231,37 @@ SELECT [Order] FROM [SOURCEPROJECT].StochasticSoilProfileEntity; INSERT INTO StrengthStabilityLengthwiseConstructionSectionResultEntity SELECT * FROM [SOURCEPROJECT].StrengthStabilityLengthwiseConstructionSectionResultEntity; -INSERT INTO SurfaceLineEntity +INSERT INTO SurfaceLineEntity ( + [SurfaceLineEntityId], + [FailureMechanismEntityId], + [Name], + [ReferenceLineIntersectionX], + [ReferenceLineIntersectionY], + [PointsXml], + [Order]) SELECT [SurfaceLineEntityId], [FailuremechanismEntityId], - CASE WHEN Suffix THEN [Name] || '(' || Suffix || ')' ELSE [Name] END as [Name], + CASE WHEN Suffix THEN [Name] || ' (' || SUBSTR(QUOTE(ZEROBLOB((SuffixPreLength + 1) / 2)), 3, SuffixPreLength) || Suffix || ')' ELSE [Name] END AS [Name], [ReferenceLineIntersectionX], [ReferenceLineIntersectionY], [PointsXml], - [Order] - FROM (SELECT *, (SELECT count(*) - FROM [SOURCEPROJECT].SurfaceLineEntity - WHERE SL.SurfaceLineEntityId > SurfaceLineEntityId - AND SL.Name IS Name - AND SL.FailuremechanismEntityId = FailuremechanismEntityId) as Suffix - FROM [SOURCEPROJECT].SurfaceLineEntity SL); + [Order] + FROM + ( + SELECT *, MAX(MaxLength - LENGTH(NAME), 0) as SuffixPreLength, + ( + SELECT COUNT() + FROM [SOURCEPROJECT].SurfaceLineEntity + WHERE SL.SurfaceLineEntityId > SurfaceLineEntityId + AND SL.Name IS Name + AND SL.FailuremechanismEntityId = FailuremechanismEntityId + ) AS Suffix + FROM [SOURCEPROJECT].SurfaceLineEntity SL + JOIN ( + SELECT MAX(LENGTH(Name)-3) as MaxLength FROM [SOURCEPROJECT].SurfaceLineEntity + ) + ); INSERT INTO TechnicalInnovationSectionResultEntity SELECT * FROM [SOURCEPROJECT].TechnicalInnovationSectionResultEntity; INSERT INTO VersionEntity ( [VersionId], @@ -295,7 +326,7 @@ SELECT BackgroundDataEntityId, /* Write migration logging */ -ATTACH DATABASE [{1}] AS LOGDATABASE; +ATTACH DATABASE '{1}' AS LOGDATABASE; CREATE TEMP TABLE log_output_deleted ( 'NrDeleted' INTEGER NOT NULL diff --git a/Application/Ringtoets/test/Application.Ringtoets.Migration.Core.Test/test-data/Empty valid [Release 16.4].rtd b/Application/Ringtoets/test/Application.Ringtoets.Migration.Core.Test/test-data/Empty valid [Release 16.4].rtd new file mode 100644 index 00000000000..8738529735e Binary files /dev/null and b/Application/Ringtoets/test/Application.Ringtoets.Migration.Core.Test/test-data/Empty valid [Release 16.4].rtd differ diff --git a/Application/Ringtoets/test/Application.Ringtoets.Migration.Core.Test/test-data/FullTestProject164.rtd b/Application/Ringtoets/test/Application.Ringtoets.Migration.Core.Test/test-data/FullTestProject164.rtd index 91a09ebc03a..314dd2e2d2e 100644 Binary files a/Application/Ringtoets/test/Application.Ringtoets.Migration.Core.Test/test-data/FullTestProject164.rtd and b/Application/Ringtoets/test/Application.Ringtoets.Migration.Core.Test/test-data/FullTestProject164.rtd differ diff --git a/Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/MigrationTo171IntegrationTest.cs b/Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/MigrationTo171IntegrationTest.cs index 31382d0881f..c0e35700047 100644 --- a/Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/MigrationTo171IntegrationTest.cs +++ b/Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/MigrationTo171IntegrationTest.cs @@ -35,6 +35,33 @@ public class MigrationTo171IntegrationTest { private const string newVersion = "17.1"; + [Test] + public void Given164Project_WhenMigratingTo171WithSquareBracketsInPath_DoesNotThrowException() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration.Core, + "Empty valid [Release 16.4].rtd"); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + const string name = nameof(Given164Project_WhenMigratingTo171WithSquareBracketsInPath_DoesNotThrowException); + string targetFilePath = TestHelper.GetScratchPadPath(name); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(name, "[Release 16.4]", ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // When + TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + Assert.DoesNotThrow(call); + } + } + [Test] public void Given164Project_WhenUpgradedTo171_ThenProjectAsExpected() { @@ -157,8 +184,9 @@ private static void AssertTablesContentMigrated(MigratedDatabaseReader reader, s private static void AssertDikeProfiles(MigratedDatabaseReader reader) { const string validateDikeProfiles = - "SELECT COUNT(DISTINCT(Name)) = COUNT() " + - "AND COUNT(DISTINCT(Id)) = COUNT() FROM DikeProfileEntity"; + "SELECT COUNT(DISTINCT(Id)) = COUNT() " + + "FROM DikeProfileEntity " + + "GROUP BY [FailureMechanismEntityId]"; reader.AssertReturnedDataIsValid(validateDikeProfiles); } diff --git a/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsOutputProperties.cs b/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsOutputProperties.cs index 82227916b9e..11879720e71 100644 --- a/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsOutputProperties.cs +++ b/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsOutputProperties.cs @@ -43,7 +43,8 @@ public class GrassCoverErosionInwardsOutputProperties : ObjectProperties ClearData(GrassCoverErosionInwardsFailureMechanism failureMechanism) { - return GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles(failureMechanism); + return GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles( + failureMechanism.Calculations.Cast(), + failureMechanism.DikeProfiles, + failureMechanism.SectionResults); } } } \ No newline at end of file diff --git a/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs b/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs index f35a450b24e..2f49c369787 100644 --- a/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs +++ b/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategy.cs @@ -82,8 +82,11 @@ protected override IEnumerable UpdateObjectAndDependentData(DikePro protected override IEnumerable RemoveObjectAndDependentData(DikeProfile removedObject) { - return GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(FailureMechanism, - removedObject); + return GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile( + removedObject, + FailureMechanism.Calculations.Cast(), + FailureMechanism.DikeProfiles, + FailureMechanism.SectionResults); } private IEnumerable UpdateDikeDependentData(DikeProfile objectToUpdate) @@ -99,6 +102,11 @@ private IEnumerable UpdateDikeDependentData(DikeProfile objectToUpd affectedObjects.Add(calculation.InputParameters); affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + if (!objectToUpdate.ForeshoreGeometry.Any()) + { + calculation.InputParameters.UseForeshore = false; + } + GrassCoverErosionInwardsHelper.UpdateCalculationToSectionResultAssignments( FailureMechanism.SectionResults, FailureMechanism.Calculations.Cast()); diff --git a/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs b/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs index d0e241731b8..aedaa66fcf8 100644 --- a/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs +++ b/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsDataSynchronizationService.cs @@ -28,6 +28,7 @@ using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Service; using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Utils; namespace Ringtoets.GrassCoverErosionInwards.Service { @@ -145,74 +146,111 @@ public static ClearResults ClearReferenceLineDependentData(GrassCoverErosionInwa } /// - /// Removes the from the + /// Removes the , unassigns them from the /// and clears all the data that depends on it, either directly or indirectly. /// - /// The failure mechanism. - /// The dike profile to be removed. + /// The dike profile to remove. + /// The calculations that may have + /// assigned. + /// The collection of in + /// which is contained. + /// The section results that may have an assignment to a calculation + /// based on the . /// An of all affected objects by this operation. /// Thrown when any input argument is null. - public static IEnumerable RemoveDikeProfile(GrassCoverErosionInwardsFailureMechanism failureMechanism, - DikeProfile dikeProfile) + public static IEnumerable RemoveDikeProfile(DikeProfile dikeProfileToRemove, + IEnumerable calculations, + DikeProfileCollection dikeProfiles, + IEnumerable sectionResults) { - if (failureMechanism == null) + if (dikeProfileToRemove == null) { - throw new ArgumentNullException(nameof(failureMechanism)); + throw new ArgumentNullException(nameof(dikeProfileToRemove)); + } + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); } - if (dikeProfile == null) + if (dikeProfiles == null) { - throw new ArgumentNullException(nameof(dikeProfile)); + throw new ArgumentNullException(nameof(dikeProfiles)); + } + if (sectionResults == null) + { + throw new ArgumentNullException(nameof(sectionResults)); } - IEnumerable affectedCalculations = failureMechanism.Calculations - .Cast() - .Where(calc => ReferenceEquals(dikeProfile, calc.InputParameters.DikeProfile)); + IEnumerable affectedCalculations = + calculations.Where(calc => ReferenceEquals(dikeProfileToRemove, calc.InputParameters.DikeProfile)); var affectedObjects = new List { - failureMechanism.DikeProfiles + dikeProfiles }; - foreach (GrassCoverErosionInwardsCalculation calculation in affectedCalculations) - { - affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); - affectedObjects.AddRange(ClearDikeProfile(calculation.InputParameters)); - } + affectedObjects.AddRange(ClearDikeProfileDependentData(sectionResults, affectedCalculations, calculations)); - failureMechanism.DikeProfiles.Remove(dikeProfile); + dikeProfiles.Remove(dikeProfileToRemove); return affectedObjects; } /// - /// Removes all the from the - /// and clears all data that depends on it, either directly or indirectly. + /// Clears , unassigns the elements from the + /// and clears all the data that depends on it, either directly or indirectly. /// - /// The failure mechanism for which all - /// the dike profiles need to be removed. - /// An of all affected objects. - /// Thrown when - /// is null. - public static IEnumerable RemoveAllDikeProfiles(GrassCoverErosionInwardsFailureMechanism failureMechanism) + /// The calculations that may have + /// an assigned element of . + /// The collection to be cleared. + /// The section results that may have an assignment to a calculation + /// based on the elements of . + /// An of all affected objects by this operation. + /// Thrown when any input argument is null. + public static IEnumerable RemoveAllDikeProfiles(IEnumerable calculations, + DikeProfileCollection dikeProfiles, + IEnumerable sectionResults) { - if (failureMechanism == null) + if (calculations == null) { - throw new ArgumentNullException(nameof(failureMechanism)); + throw new ArgumentNullException(nameof(calculations)); + } + if (dikeProfiles == null) + { + throw new ArgumentNullException(nameof(dikeProfiles)); + } + if (sectionResults == null) + { + throw new ArgumentNullException(nameof(sectionResults)); } IEnumerable affectedCalculations = - failureMechanism.Calculations - .Cast() - .Where(calc => calc.InputParameters.DikeProfile != null) - .ToArray(); + calculations.Where(calc => calc.InputParameters.DikeProfile != null) + .ToArray(); + + var affectedObjects = new List + { + dikeProfiles + }; + affectedObjects.AddRange(ClearDikeProfileDependentData(sectionResults, + affectedCalculations, + calculations)); + + dikeProfiles.Clear(); + return affectedObjects; + } + private static IEnumerable ClearDikeProfileDependentData( + IEnumerable sectionResults, + IEnumerable calculationsWithRemovedDikeProfile, + IEnumerable calculations) + { var affectedObjects = new List(); - foreach (GrassCoverErosionInwardsCalculation calculation in affectedCalculations) + foreach (GrassCoverErosionInwardsCalculation calculation in calculationsWithRemovedDikeProfile) { affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); affectedObjects.AddRange(ClearDikeProfile(calculation.InputParameters)); } - - failureMechanism.DikeProfiles.Clear(); - affectedObjects.Add(failureMechanism.DikeProfiles); + affectedObjects.AddRange(GrassCoverErosionInwardsHelper.UpdateCalculationToSectionResultAssignments( + sectionResults, + calculations)); return affectedObjects; } diff --git a/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Ringtoets.GrassCoverErosionInwards.Service.csproj b/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Ringtoets.GrassCoverErosionInwards.Service.csproj index be906a04931..330d77e789e 100644 --- a/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Ringtoets.GrassCoverErosionInwards.Service.csproj +++ b/Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Ringtoets.GrassCoverErosionInwards.Service.csproj @@ -94,6 +94,11 @@ Ringtoets.GrassCoverErosionInwards.Data False + + {99573570-EE00-4264-8147-26A1B25DB23F} + Ringtoets.GrassCoverErosionInwards.Utils + False + diff --git a/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsOutputPropertiesTest.cs b/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsOutputPropertiesTest.cs index feb98d4e8dc..e1101cd64c8 100644 --- a/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsOutputPropertiesTest.cs +++ b/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/PropertyClasses/GrassCoverErosionInwardsOutputPropertiesTest.cs @@ -167,7 +167,7 @@ public void PropertyAttributes_WithDikeHeightAndOvertoppingRateCalculated_Return var probabilityAssessmentOutput = new ProbabilityAssessmentOutput(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN); var dikeHeightOutput = new TestDikeHeightOutput(double.NaN); var overtoppingRateOutput = new TestOvertoppingRateOutput(double.NaN); - var output = new GrassCoverErosionInwardsOutput(double.NaN, true, probabilityAssessmentOutput, + var output = new GrassCoverErosionInwardsOutput(10, true, probabilityAssessmentOutput, dikeHeightOutput, overtoppingRateOutput); @@ -207,7 +207,7 @@ public void PropertyAttributes_WithDikeHeightAndOvertoppingRateCalculated_Return overtoppingRateOutput = new TestOvertoppingRateOutput(double.NaN); } - var output = new GrassCoverErosionInwardsOutput(double.NaN, true, probabilityAssessmentOutput, + var output = new GrassCoverErosionInwardsOutput(2, true, probabilityAssessmentOutput, dikeHeightOutput, overtoppingRateOutput); @@ -235,11 +235,13 @@ public void PropertyAttributes_WithDikeHeightAndOvertoppingRateCalculated_Return } [Test] - public void PropertyAttributes_WithoutDikeHeightAndOvertoppingRateCalculated_ReturnExpectedValues() + [TestCase(double.NaN)] + [TestCase(10)] + public void PropertyAttributes_WithoutDikeHeightAndOvertoppingRateCalculated_ReturnExpectedValues(double waveHeight) { // Setup var probabilityAssessmentOutput = new ProbabilityAssessmentOutput(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN); - var output = new GrassCoverErosionInwardsOutput(double.NaN, true, probabilityAssessmentOutput, null, null); + var output = new GrassCoverErosionInwardsOutput(waveHeight, true, probabilityAssessmentOutput, null, null); // Call var properties = new GrassCoverErosionInwardsOutputProperties @@ -248,13 +250,15 @@ public void PropertyAttributes_WithoutDikeHeightAndOvertoppingRateCalculated_Ret }; // Assert + int propertiesCount = double.IsNaN(waveHeight) ? 6 : 7; + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); - Assert.AreEqual(7, dynamicProperties.Count); + Assert.AreEqual(propertiesCount, dynamicProperties.Count); - AssertResultOutputProperties(dynamicProperties); + AssertResultOutputProperties(dynamicProperties, !double.IsNaN(waveHeight)); } - private static void AssertResultOutputProperties(PropertyDescriptorCollection dynamicProperties) + private static void AssertResultOutputProperties(PropertyDescriptorCollection dynamicProperties, bool waveHeightCalculated = true) { const string resultCategory = "\t\tResultaat"; PropertyDescriptor requiredProbabilityProperty = dynamicProperties[requiredProbabilityPropertyIndex]; @@ -292,14 +296,21 @@ private static void AssertResultOutputProperties(PropertyDescriptorCollection dy "De veiligheidsfactor voor deze berekening.", true); - PropertyDescriptor waveHeightProperty = dynamicProperties[waveHeightIndex]; - PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(waveHeightProperty, - resultCategory, - "Indicatieve golfhoogte (Hs) [m]", - "De golfhoogte van de overslag deelberekening.", - true); + if (waveHeightCalculated) + { + PropertyDescriptor waveHeightProperty = dynamicProperties[waveHeightIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(waveHeightProperty, + resultCategory, + "Indicatieve golfhoogte (Hs) [m]", + "De golfhoogte van de overslag deelberekening.", + true); + } + + int realDominantIndex = waveHeightCalculated + ? isDominantIndex + : isDominantIndex - 1; - PropertyDescriptor isDominantProperty = dynamicProperties[isDominantIndex]; + PropertyDescriptor isDominantProperty = dynamicProperties[realDominantIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isDominantProperty, resultCategory, "Overslag dominant [-]", diff --git a/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategyTest.cs b/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategyTest.cs index 48f9b4e40c1..0145905940a 100644 --- a/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategyTest.cs +++ b/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileReplaceDataStrategyTest.cs @@ -23,15 +23,18 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base; +using Core.Common.Base.Geometry; using NUnit.Framework; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Common.IO.FileImporters; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters; +using Ringtoets.GrassCoverErosionInwards.Utils; namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.FileImporters { @@ -262,5 +265,66 @@ public void UpdateDikeProfilesWithImportedData_CalculationWithOutputAndDikeProfi failureMechanism.DikeProfiles }, affectedObjects); } + + [Test] + public void UpdateDikeProfilesWithImportedData_CalculationWithToBeRemovedDikeProfile_UpdatesSectionResults() + { + // Setup + const string dikeProfileId = "ID of removed profile"; + + var matchingPoint = new Point2D(0, 0); + var removedProfile = new TestDikeProfile(matchingPoint, dikeProfileId); + var affectedCalculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = removedProfile + } + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); + + failureMechanism.AddSection(new FailureMechanismSection("Section", new[] + { + matchingPoint, + new Point2D(10, 10) + })); + + GrassCoverErosionInwardsHelper.UpdateCalculationToSectionResultAssignments( + failureMechanism.SectionResults, + failureMechanism.Calculations + .Cast()); + + DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles; + dikeProfiles.AddRange(new[] + { + removedProfile + }, sourceFilePath); + + // Precondition + GrassCoverErosionInwardsFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults + .ToArray(); + Assert.AreEqual(1, sectionResults.Length); + Assert.AreSame(affectedCalculation, sectionResults[0].Calculation); + + var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfiles, + Enumerable.Empty(), + sourceFilePath); + // Assert + CollectionAssert.AreEquivalent(new IObservable[] + { + dikeProfiles, + affectedCalculation.InputParameters, + sectionResults[0] + }, affectedObjects); + + sectionResults = failureMechanism.SectionResults.ToArray(); + Assert.AreEqual(1, sectionResults.Length); + Assert.IsNull(sectionResults[0].Calculation); + } } } \ No newline at end of file diff --git a/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs b/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs index 6f088ffa950..9b7be174d12 100644 --- a/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs +++ b/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs @@ -642,6 +642,134 @@ public void UpdateDikeProfilesWithImportedData_CalculationWithDikeProfileUpdated Assert.AreSame(affectedCalculation, sectionResults[1].Calculation); } + [Test] + public void UpdateDikeProfilesWithImportedData_CalculationWithToBeRemovedDikeProfile_UpdatesSectionResults() + { + // Setup + const string dikeProfileId = "ID of removed profile"; + + var matchingPoint = new Point2D(0, 0); + var removedProfile = new TestDikeProfile(matchingPoint, dikeProfileId); + var affectedCalculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = removedProfile + } + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(affectedCalculation); + + failureMechanism.AddSection(new FailureMechanismSection("Section", new[] + { + matchingPoint, + new Point2D(10, 10) + })); + + GrassCoverErosionInwardsHelper.UpdateCalculationToSectionResultAssignments( + failureMechanism.SectionResults, + failureMechanism.Calculations + .Cast()); + + DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles; + dikeProfiles.AddRange(new[] + { + removedProfile + }, sourceFilePath); + + // Precondition + GrassCoverErosionInwardsFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults + .ToArray(); + Assert.AreEqual(1, sectionResults.Length); + Assert.AreSame(affectedCalculation, sectionResults[0].Calculation); + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfiles, + Enumerable.Empty(), + sourceFilePath); + // Assert + CollectionAssert.AreEquivalent(new IObservable[] + { + dikeProfiles, + affectedCalculation.InputParameters, + sectionResults[0] + }, affectedObjects); + + sectionResults = failureMechanism.SectionResults.ToArray(); + Assert.AreEqual(1, sectionResults.Length); + Assert.IsNull(sectionResults[0].Calculation); + } + + [Test] + public void UpdateDikeProfilesWithImportedData_CalculationWithOutputAndForeshoreProfileUpdatedWithProfileWithoutGeometry_UpdatesCalculation() + { + // Setup + const string id = "profile ID"; + IEnumerable geometry = new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }; + + var affectedProfile = new TestDikeProfile(geometry, id); + var affectedCalculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = affectedProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + affectedCalculation.InputParameters.UseForeshore = true; + + var profileToUpdateFrom = new TestDikeProfile(Enumerable.Empty(), id); + + var dikeProfiles = new DikeProfileCollection(); + var originalDikeProfiles = new[] + { + affectedProfile + }; + dikeProfiles.AddRange(originalDikeProfiles, sourceFilePath); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + CalculationsGroup = + { + Children = + { + affectedCalculation + } + } + }; + + var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = + strategy.UpdateDikeProfilesWithImportedData(dikeProfiles, + new[] + { + profileToUpdateFrom + }, + sourceFilePath); + + // Assert + Assert.IsFalse(affectedCalculation.HasOutput); + Assert.IsFalse(affectedCalculation.InputParameters.UseForeshore); + AssertDikeProfile(affectedProfile, profileToUpdateFrom); + + CollectionAssert.AreEquivalent(new IObservable[] + { + affectedCalculation, + affectedCalculation.InputParameters, + affectedProfile, + dikeProfiles + }, affectedObjects); + } + /// /// Makes a deep clone of the and modifies /// all its parameters, except the ID. diff --git a/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs b/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs index b3cb7fe2292..9490ebdc8ab 100644 --- a/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs +++ b/Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsDataSynchronizationServiceTest.cs @@ -23,9 +23,11 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base; +using Core.Common.Base.Geometry; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.TestUtil; @@ -209,14 +211,48 @@ public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_Remo } [Test] - public void RemoveAllDikeProfiles_FailureMechanismNull_ThrowsArgumentNullException() + public void RemoveAllDikeProfile_CalculationsNull_ThrowsArgumentNullException() { // Call - TestDelegate call = () => GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles(null); + TestDelegate call = () => + GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles( + null, + new DikeProfileCollection(), + Enumerable.Empty()); // Assert var exception = Assert.Throws(call); - Assert.AreEqual("failureMechanism", exception.ParamName); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void RemoveAllDikeProfile_DikeProfilesNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles( + Enumerable.Empty(), + null, + Enumerable.Empty()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("dikeProfiles", exception.ParamName); + } + + [Test] + public void RemoveAllDikeProfile_SectionResultsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles( + Enumerable.Empty(), + new DikeProfileCollection(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResults", exception.ParamName); } [Test] @@ -238,7 +274,10 @@ public void RemoveAllDikeProfiles_FullyConfiguredFailureMechanism_RemovesAllDike // Call IEnumerable affectedObjects = - GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles(failureMechanism); + GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles( + failureMechanism.Calculations.Cast(), + failureMechanism.DikeProfiles, + failureMechanism.SectionResults); // Assert // Note: To make sure the clear is performed regardless of what is done with @@ -261,35 +300,130 @@ public void RemoveAllDikeProfiles_FullyConfiguredFailureMechanism_RemovesAllDike } [Test] - public void RemoveDikeProfile_FailureMechanismNull_ThrowsArgumentNullException() + public void RemoveAllDikeProfiles_CalculationWithRemovedDikeProfileAndAssignedToSection_ReturnsAllAffectedCalculationsAndClearsDependentData() + { + // Setup + var locationRemovedProfile = new Point2D(0, 0); + var removedProfile = new TestDikeProfile(locationRemovedProfile, "RemovedProfileId"); + + var calculationWitRemovedProfile = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = removedProfile + } + }; + var calculations = new[] + { + calculationWitRemovedProfile + }; + + var dikeProfiles = new DikeProfileCollection(); + dikeProfiles.AddRange(new[] + { + removedProfile + }, "some/path"); + + var sectionResultWithAffectedCalculation = new GrassCoverErosionInwardsFailureMechanismSectionResult( + new FailureMechanismSection("Section", new[] + { + locationRemovedProfile + })) + { + Calculation = calculationWitRemovedProfile + }; + + var sectionResults = new[] + { + sectionResultWithAffectedCalculation + }; + + // Call + IEnumerable affectedObjects = + GrassCoverErosionInwardsDataSynchronizationService.RemoveAllDikeProfiles(calculations, + dikeProfiles, + sectionResults); + + // Assert + CollectionAssert.DoesNotContain(dikeProfiles, removedProfile); + Assert.IsNull(sectionResultWithAffectedCalculation.Calculation); + + var expectedAffectedObjects = new IObservable[] + { + calculationWitRemovedProfile.InputParameters, + sectionResultWithAffectedCalculation, + dikeProfiles + }; + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void RemoveDikeProfile_DikeProfileToRemove_ThrowsArgumentNullException() { // Call TestDelegate call = () => - GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(null, new TestDikeProfile()); + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(null, + Enumerable.Empty(), + new DikeProfileCollection(), + Enumerable.Empty()); // Assert var exception = Assert.Throws(call); - Assert.AreEqual("failureMechanism", exception.ParamName); + Assert.AreEqual("dikeProfileToRemove", exception.ParamName); + } + + [Test] + public void RemoveDikeProfile_CalculationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(new TestDikeProfile(), + null, + new DikeProfileCollection(), + Enumerable.Empty()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); } [Test] - public void RemoveDikeProfile_DikeProfileNull_ThrowsArgumentNullException() + public void RemoveDikeProfile_DikeProfilesNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => - GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(new GrassCoverErosionInwardsFailureMechanism(), null); + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(new TestDikeProfile(), + Enumerable.Empty(), + null, + Enumerable.Empty()); // Assert var exception = Assert.Throws(call); - Assert.AreEqual("dikeProfile", exception.ParamName); + Assert.AreEqual("dikeProfiles", exception.ParamName); } [Test] - public void RemoveDikeProfile_FullyConfiguredFailureMechanism_ReturnsOnlyAffectedCalculations() + public void RemoveDikeProfile_SectionResultsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(new TestDikeProfile(), + Enumerable.Empty(), + new DikeProfileCollection(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResults", exception.ParamName); + } + + [Test] + public void RemoveDikeProfile_VariousCalculationConfigurations_ReturnsOnlyAffectedCalculations() { // Setup GrassCoverErosionInwardsFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); DikeProfile profileToBeCleared = failureMechanism.DikeProfiles[0]; + DikeProfile profileToKeep = failureMechanism.DikeProfiles[1]; GrassCoverErosionInwardsCalculation[] affectedCalculationsWithProfile = failureMechanism.Calculations @@ -299,20 +433,27 @@ public void RemoveDikeProfile_FullyConfiguredFailureMechanism_ReturnsOnlyAffecte GrassCoverErosionInwardsCalculation[] affectedCalculationsWithOutput = affectedCalculationsWithProfile.Where(calc => calc.HasOutput).ToArray(); + GrassCoverErosionInwardsCalculation[] unaffectedCalculationsWithProfile = + failureMechanism.Calculations + .Cast() + .Where(calc => ReferenceEquals(profileToKeep, calc.InputParameters.DikeProfile)) + .ToArray(); + // Pre-condition CollectionAssert.IsNotEmpty(affectedCalculationsWithOutput); // Call IEnumerable affectedObjects = - GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(failureMechanism, profileToBeCleared); + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(profileToBeCleared, + failureMechanism.Calculations.Cast(), + failureMechanism.DikeProfiles, + failureMechanism.SectionResults); // Assert CollectionAssert.DoesNotContain(failureMechanism.DikeProfiles, profileToBeCleared); - foreach (GrassCoverErosionInwardsCalculation calculation in affectedCalculationsWithOutput) - { - Assert.IsFalse(calculation.HasOutput); - } + Assert.True(affectedCalculationsWithOutput.All(calc => !calc.HasOutput)); + Assert.True(unaffectedCalculationsWithProfile.All(calc => calc.InputParameters.DikeProfile != null)); IEnumerable expectedAffectedObjects = affectedCalculationsWithProfile.Select(calc => calc.InputParameters) @@ -325,6 +466,94 @@ public void RemoveDikeProfile_FullyConfiguredFailureMechanism_ReturnsOnlyAffecte CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); } + [Test] + public void RemoveDikeProfile_CalculationWithRemovedDikeProfileAndAssignedToSection_ReturnsOnlyAffectedCalculationsAndClearsDependentData() + { + // Setup + const string profileToBeRemovedId = "RemovedProfileId"; + const string profileToKeepId = "UnaffectedProfileId"; + + var locationRemovedProfile = new Point2D(0, 0); + var removedProfile = new TestDikeProfile(locationRemovedProfile, profileToBeRemovedId); + + var calculationWitRemovedProfile = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = removedProfile + } + }; + + var locationUnaffectedProfile = new Point2D(5, 5); + var unaffectedProfile = new TestDikeProfile(locationUnaffectedProfile, profileToKeepId); + var calculationWithProfileToKeep = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = unaffectedProfile + } + }; + + var calculations = new[] + { + calculationWitRemovedProfile, + calculationWithProfileToKeep + }; + + var dikeProfiles = new DikeProfileCollection(); + dikeProfiles.AddRange(new[] + { + removedProfile, + unaffectedProfile + }, "some/path"); + + var affectedSection = new FailureMechanismSection("Section", new[] + { + locationRemovedProfile, + locationUnaffectedProfile + }); + var sectionResultWithAffectedCalculation = new GrassCoverErosionInwardsFailureMechanismSectionResult(affectedSection) + { + Calculation = calculationWitRemovedProfile + }; + + var unaffectedSection = new FailureMechanismSection("Section2", new[] + { + locationUnaffectedProfile, + new Point2D(10, 10) + }); + var sectionResultWithUnaffectedCalculation = new GrassCoverErosionInwardsFailureMechanismSectionResult(unaffectedSection) + { + Calculation = calculationWithProfileToKeep + }; + + var sectionResults = new[] + { + sectionResultWithUnaffectedCalculation, + sectionResultWithAffectedCalculation + }; + + // Call + IEnumerable affectedObjects = + GrassCoverErosionInwardsDataSynchronizationService.RemoveDikeProfile(removedProfile, + calculations, + dikeProfiles, + sectionResults); + + // Assert + CollectionAssert.DoesNotContain(dikeProfiles, removedProfile); + Assert.AreSame(calculationWithProfileToKeep, sectionResultWithUnaffectedCalculation.Calculation); + Assert.IsNull(sectionResultWithAffectedCalculation.Calculation); + + var expectedAffectedObjects = new IObservable[] + { + calculationWitRemovedProfile.InputParameters, + sectionResultWithAffectedCalculation, + dikeProfiles + }; + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + private static GrassCoverErosionInwardsFailureMechanism CreateFullyConfiguredFailureMechanism() { var testDikeProfile1 = new TestDikeProfile("Profile 1", "ID 1"); diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/DikesOvertopping.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/DikesOvertopping.dll index e89c953b8e3..0acb76d3dc8 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/DikesOvertopping.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/DikesOvertopping.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/DllLinearizedBetaAlpha.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/DllLinearizedBetaAlpha.dll index 48a52505085..0f9059f2d0a 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/DllLinearizedBetaAlpha.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/DllLinearizedBetaAlpha.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.Test.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.Test.dll index 3b8bf703145..59147d08966 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.Test.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.Test.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.TestUtils.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.TestUtils.dll index 0f492f14d77..4b8de239357 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.TestUtils.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.TestUtils.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.dll index 368880f4276..f3fd9ef0f74 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Database.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.DuneErosionWrapper.Tests.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.DuneErosionWrapper.Tests.dll index 687dea6265a..33a255a67d2 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.DuneErosionWrapper.Tests.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.DuneErosionWrapper.Tests.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.DuneErosionWrapper.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.DuneErosionWrapper.dll index 785fd4cdadc..0188004dce8 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.DuneErosionWrapper.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.DuneErosionWrapper.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.IO.Native.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.IO.Native.dll index 6f34f8db984..e83baf44618 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.IO.Native.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.IO.Native.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.IO.TestUtils.Native.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.IO.TestUtils.Native.dll index 589252f66de..35017dc4a57 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.IO.TestUtils.Native.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.IO.TestUtils.Native.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.MacroStability.Wrapper.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.MacroStability.Wrapper.dll index 52087a3281a..1c408d7f372 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.MacroStability.Wrapper.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.MacroStability.Wrapper.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Piping2017Wrapper.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Piping2017Wrapper.dll index 82ed40f9e12..1c6b25fe0fa 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Piping2017Wrapper.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.Piping2017Wrapper.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.PluginShared.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.PluginShared.dll index 192b3649b15..3eea30c419e 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.PluginShared.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/HydraRing.PluginShared.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/MechanismComputation.exe b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/MechanismComputation.exe index e035c19dc28..82042204e5e 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/MechanismComputation.exe and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/MechanismComputation.exe differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/StructuresStructuralFailure2017wrapper.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/StructuresStructuralFailure2017wrapper.dll index 7f0129e4870..ac4b20a0690 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/StructuresStructuralFailure2017wrapper.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/StructuresStructuralFailure2017wrapper.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/dikesOverflow.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/dikesOverflow.dll index 804eda07371..96cd7c540e5 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/dikesOverflow.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/dikesOverflow.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/dllHydraulicDunes.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/dllHydraulicDunes.dll index 4b31aac01b7..d5c73fcec20 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/dllHydraulicDunes.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/dllHydraulicDunes.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/duneErosion.Native.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/duneErosion.Native.dll index 318660fa4c4..2b3c20b7620 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/duneErosion.Native.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/duneErosion.Native.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/exeRingComputation.exe b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/exeRingComputation.exe index 203b73c7b25..ac1ab5ebfee 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/exeRingComputation.exe and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/exeRingComputation.exe differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/feedbackDLL.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/feedbackDLL.dll index 6e74cc9420e..9c6533c5ed8 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/feedbackDLL.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/feedbackDLL.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/hydraring_computation.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/hydraring_computation.dll index d0a909b504b..20af479f7b8 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/hydraring_computation.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/hydraring_computation.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/linearizedBetaAlpha.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/linearizedBetaAlpha.dll index 0be0f132dcd..b8f93bb9735 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/linearizedBetaAlpha.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/linearizedBetaAlpha.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/macroStability.Native.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/macroStability.Native.dll index bdf89efab12..ee179aa4f55 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/macroStability.Native.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/macroStability.Native.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/piping2017.Native.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/piping2017.Native.dll index d065e0caec3..b2118001747 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/piping2017.Native.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/piping2017.Native.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresClosure2017.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresClosure2017.dll index 6bdc798cd0a..917ed9eb720 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresClosure2017.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresClosure2017.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresOvertopping2017.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresOvertopping2017.dll index 279d7c7c983..c175b20b3db 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresOvertopping2017.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresOvertopping2017.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresStructuralFailure2017.Native.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresStructuralFailure2017.Native.dll index 6b17d4200b7..657c73d8b0b 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresStructuralFailure2017.Native.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/structuresStructuralFailure2017.Native.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/winapi.dll b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/winapi.dll index e2c374bc5df..73849d87bea 100644 Binary files a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/winapi.dll and b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/HydraRing/winapi.dll differ diff --git a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/OvertoppingCalculationWaveHeightParser.cs b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/OvertoppingCalculationWaveHeightParser.cs index 5be81aeba37..8c443ac4f9b 100644 --- a/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/OvertoppingCalculationWaveHeightParser.cs +++ b/Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/OvertoppingCalculationWaveHeightParser.cs @@ -83,7 +83,12 @@ private void ReadResult(IDictionary result) { try { - double waveHeight = Convert.ToDouble(result[waveHeightColumn]); + object waveHeightResult = result[waveHeightColumn]; + + double waveHeight = waveHeightResult.GetType() != typeof(DBNull) + ? Convert.ToDouble(waveHeightResult) + : double.NaN; + bool isOvertoppingDominant = Convert.ToBoolean(result[isOvertoppingDominantColumn]); Output = new OvertoppingCalculationWaveHeightOutput(waveHeight, diff --git a/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/OvertoppingCalculationWaveHeightParserTest.cs b/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/OvertoppingCalculationWaveHeightParserTest.cs index 1c3c99580d9..0fa10aa5d9c 100644 --- a/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/OvertoppingCalculationWaveHeightParserTest.cs +++ b/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/OvertoppingCalculationWaveHeightParserTest.cs @@ -101,7 +101,6 @@ public void Parse_WithWorkingDirectoryWithInvalidOutputFile_ThrowsHydraRingFileP [Test] [TestCase("EmptyDatabase")] [TestCase("EmptyTableDesignBeta")] - [TestCase("EmptyTableDesignPointResults")] [TestCase("EmptyTableGoverningWind")] public void Parse_WithDataNotComplete_ThrowsHydraRingFileParserException(string subFolder) { @@ -155,36 +154,35 @@ public void Parse_ErrorWhileReadingFile_ThrowsHydraRingFileParserException() } [Test] - public void Parse_NotAllColumnsHaveResults_ThrowsHydraRingFileParserException() + [TestCase(validFileOvertoppingDominant, 0.265866, true)] + [TestCase("ValidFileOvertoppingNotDominant", 0.000355406, false)] + public void Parse_ValidData_OutputSet(string file, double expectedWaveHeight, bool expectedOvertoppingDominant) { // Setup - string path = Path.Combine(testDirectory, "ValidFileNoWaveHeight"); + string path = Path.Combine(testDirectory, file); var parser = new OvertoppingCalculationWaveHeightParser(); // Call - TestDelegate test = () => parser.Parse(path, 1); + parser.Parse(path, 1); // Assert - var exception = Assert.Throws(test); - Assert.AreEqual("Er is geen resultaat voor overslag en overloop gevonden in de Hydra-Ring uitvoerdatabase.", exception.Message); - Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(expectedWaveHeight, parser.Output.WaveHeight, 1e-11); + Assert.AreEqual(expectedOvertoppingDominant, parser.Output.IsOvertoppingDominant); } [Test] - [TestCase(validFileOvertoppingDominant, 0.265866, true)] - [TestCase("ValidFileOvertoppingNotDominant", 0.000355406, false)] - public void Parse_ValidData_OutputSet(string file, double expectedWaveHeight, bool expectedOvertoppingDominant) + public void Parse_WaveHeightNull_OutputSet() { // Setup - string path = Path.Combine(testDirectory, file); + string path = Path.Combine(testDirectory, "ValidFileWaveHeightNull"); var parser = new OvertoppingCalculationWaveHeightParser(); // Call parser.Parse(path, 1); // Assert - Assert.AreEqual(expectedWaveHeight, parser.Output.WaveHeight, 1e-11); - Assert.AreEqual(expectedOvertoppingDominant, parser.Output.IsOvertoppingDominant); + Assert.IsNaN(parser.Output.WaveHeight); + Assert.IsFalse(parser.Output.IsOvertoppingDominant); } } } \ No newline at end of file diff --git a/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/EmptyTableDesignPointResults/1-output.sqlite b/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/EmptyTableDesignPointResults/1-output.sqlite deleted file mode 100644 index 6856bb04907..00000000000 Binary files a/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/EmptyTableDesignPointResults/1-output.sqlite and /dev/null differ diff --git a/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/ValidFileNoWaveHeight/1-output.sqlite b/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/ValidFileNoWaveHeight/1-output.sqlite deleted file mode 100644 index 2909db66cfe..00000000000 Binary files a/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/ValidFileNoWaveHeight/1-output.sqlite and /dev/null differ diff --git a/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/ValidFileWaveHeightNull/1-output.sqlite b/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/ValidFileWaveHeightNull/1-output.sqlite new file mode 100644 index 00000000000..2d3f81a6350 Binary files /dev/null and b/Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/OvertoppingCalculationWaveHeightParser/ValidFileWaveHeightNull/1-output.sqlite differ