Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/MigrationTo181IntegrationTest.cs =================================================================== diff -u -r1007f8dac7b8420a93101ff3470bf28b07a37fe7 -r6dce1253e4bce745b1f158fec8cf0264bee650df --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/MigrationTo181IntegrationTest.cs (.../MigrationTo181IntegrationTest.cs) (revision 1007f8dac7b8420a93101ff3470bf28b07a37fe7) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/MigrationTo181IntegrationTest.cs (.../MigrationTo181IntegrationTest.cs) (revision 6dce1253e4bce745b1f158fec8cf0264bee650df) @@ -724,6 +724,16 @@ DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForLowerLimitNorm)); reader.AssertReturnedDataIsValid(queryGenerator.GetDuneLocationCalculationsCountValidationQuery( DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForLowerFactorizedLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDuneLocationCalculationOutputValidationQuery(NormativeNormType.SignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDuneLocationCalculationOutputValidationQuery(NormativeNormType.LowerLimitNorm)); + + reader.AssertReturnedDataIsValid(DuneErosionFailureMechanismValidationQueryGenerator.GetNewDuneLocationCalculationOutputValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForMechanismSpecificFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(DuneErosionFailureMechanismValidationQueryGenerator.GetNewDuneLocationCalculationOutputValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForLowerLimitNorm)); + reader.AssertReturnedDataIsValid(DuneErosionFailureMechanismValidationQueryGenerator.GetNewDuneLocationCalculationOutputValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForLowerFactorizedLimitNorm)); } private static void AssertGrassCoverErosionOutwardsFailureMechanismMetaEntity(MigratedDatabaseReader reader, string sourceFilePath) @@ -1431,7 +1441,7 @@ /// Generates a query to validate the new hydraulic boundary location calculation outputs that are not based on migrated data. /// /// The type of calculation on which the output should be validated. - /// The query to validate the hydraulic boundary location calculation input. + /// The query to validate the hydraulic boundary location calculation output. public static string GetNewCalculationOutputsValidationQuery(CalculationType calculationType) { return "SELECT " + @@ -1789,7 +1799,7 @@ /// Generates a query to validate the new hydraulic boundary location calculations that are not based on migrated data. /// /// The type of calculation on which the input should be validated. - /// The query to validate the hydraulic boundary location calculation input. + /// The query to validate the hydraulic boundary location calculation output. public string GetNewCalculationsValidationQuery(CalculationType calculationType) { return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + @@ -1942,7 +1952,7 @@ /// /// Represents the calculations for the factorized lower limit norm. /// - CalculationsForLowerFactorizedLimitNorm = 5, + CalculationsForLowerFactorizedLimitNorm = 5 } private readonly string sourceFilePath; @@ -1980,10 +1990,7 @@ "[DuneErosionFailureMechanismMetaEntityId], " + "COUNT() as NewCount, " + "OldCount " + - "FROM DuneErosionFailureMechanismMetaEntity fme " + - "JOIN DuneLocationCalculationCollectionEntity " + - $"ON DuneLocationCalculationCollectionEntityId = fme.DuneLocationCalculationCollectionEntity{(int)calculationType}Id " + - "JOIN DuneLocationCalculationEntity USING (DuneLocationCalculationCollectionEntityId) " + + GetDuneLocationCalculationsQuery(calculationType) + "LEFT JOIN " + "( " + "SELECT " + @@ -1998,6 +2005,88 @@ "WHERE OldCount IS NOT NewCount; " + "DETACH DATABASE SOURCEPROJECT;"; } + + /// + /// Generates a query to validate the new dune location outputs that are not based on migrated data. + /// + /// The type of calculation on which the output should be validated. + /// The query to validate the dune location output. + public static string GetNewDuneLocationCalculationOutputValidationQuery(CalculationType calculationType) + { + return "SELECT COUNT() = 0 " + + GetDuneLocationCalculationsQuery(calculationType) + + "JOIN DuneLocationOutputEntity USING(DuneLocationCalculationEntityId);"; + } + + /// + /// Generates a query to validate if the dune location outputs are migrated correctly to the + /// corresponding calculation entities. + /// + /// The norm type to generate the query for. + /// A query to validate the dune location outputs. + /// Thrown when + /// is an invalid value of . + /// Thrown when is an unsupported value, + /// but is unsupported. + public string GetMigratedDuneLocationCalculationOutputValidationQuery(NormativeNormType normType) + { + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = ( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].DuneLocationOutputEntity " + + "JOIN [SOURCEPROJECT].DuneLocationEntity USING(DuneLocationEntityId) " + + "JOIN [SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity USING(AssessmentSectionEntityId) " + + $"WHERE NormativeNormType = {(int)normType} " + + ") " + + GetDuneLocationCalculationsQuery(ConvertToCalculationType(normType)) + + "JOIN DuneLocationOutputEntity NEW USING(DuneLocationCalculationEntityId) " + + "JOIN [SOURCEPROJECT].DuneLocationOutputEntity OLD USING(DuneLocationOutputEntityId) " + + "WHERE NEW.WaterLevel IS OLD.WaterLevel " + + "AND NEW.WaveHeight IS OLD.WaveHeight " + + "AND NEW.WavePeriod IS OLD.WavePeriod " + + "AND NEW.TargetProbability IS OLD.TargetProbability " + + "AND NEW.TargetReliability IS OLD.TargetReliability " + + "AND NEW.CalculatedProbability IS OLD.CalculatedProbability " + + "AND NEW.CalculatedReliability IS OLD.CalculatedReliability " + + "AND NEW.CalculationConvergence = OLD.CalculationConvergence; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + private static string GetDuneLocationCalculationsQuery(CalculationType calculationType) + { + return "FROM DuneErosionFailureMechanismMetaEntity fme " + + "JOIN DuneLocationCalculationCollectionEntity ON " + + $"DuneLocationCalculationCollectionEntityId = fme.DuneLocationCalculationCollectionEntity{(int) calculationType}Id " + + "JOIN DuneLocationCalculationEntity USING(DuneLocationCalculationCollectionEntityId) "; + } + + /// + /// Converts the to the corresponding calculation from . + /// + /// The norm type to convert. + /// Returns the converted . + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but is unsupported. + private static CalculationType ConvertToCalculationType(NormativeNormType normType) + { + if (!Enum.IsDefined(typeof(NormativeNormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), (int)normType, typeof(NormativeNormType)); + } + + switch (normType) + { + case NormativeNormType.LowerLimitNorm: + return CalculationType.CalculationsForMechanismSpecificLowerLimitNorm; + case NormativeNormType.SignalingNorm: + return CalculationType.CalculationsForMechanismSpecificSignalingNorm; + default: + throw new NotSupportedException(); + } + } } #endregion