Index: Ringtoets.sln =================================================================== diff -u -r33eccadf8ff495010718b9ca6d3e93082dd685b8 -r92827b7879fc5c2544c51a84a7a16c96d9a2103d --- Ringtoets.sln (.../Ringtoets.sln) (revision 33eccadf8ff495010718b9ca6d3e93082dd685b8) +++ Ringtoets.sln (.../Ringtoets.sln) (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -1957,7 +1957,7 @@ {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.Migration.Integration.Test", "Ringtoets\Migration\test\Ringtoets.Migration.Integration.Test\Riskeer.Migration.Integration.Test.csproj", "{ABF98CE1-D311-4835-844A-1D4ED0E6C73D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.Migration.Integration.Test", "Ringtoets\Migration\test\Riskeer.Migration.Integration.Test\Riskeer.Migration.Integration.Test.csproj", "{ABF98CE1-D311-4835-844A-1D4ED0E6C73D}" ProjectSection(ProjectDependencies) = postProject {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo171IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo172IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo173IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo181IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo191IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/Properties/AssemblyInfo.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/Riskeer.Migration.Integration.Test.csproj'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 92827b7879fc5c2544c51a84a7a16c96d9a2103d refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/packages.config'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationIntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationIntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationIntegrationTest.cs (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,170 @@ +// Copyright (C) Stichting Deltares 2018. 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.Collections.ObjectModel; +using System.IO; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Util; +using Riskeer.Migration.Core; +using Riskeer.Migration.Core.TestUtil; + +namespace Riskeer.Migration.Integration.Test +{ + [TestFixture] + public class MigrationIntegrationTest + { + private readonly string latestVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core); + + [Test] + [TestCaseSource(nameof(GetFileNamesWithSpecialCharacters))] + public void GivenProject_WhenSpecialCharacterInPath_DoesNotThrowException(string sourceFile, + string newVersion) + { + // Given + string fileToCopy = Path.Combine(testDataPath, sourceFile); + string sourceFilePath = TestHelper.GetScratchPadPath($"\'[]!`~@#$%^€&()-_=+;, {sourceFile}"); + File.Copy(fileToCopy, sourceFilePath, true); + + // Precondition + Assert.IsTrue(File.Exists(sourceFilePath)); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string name = $"{nameof(GivenProject_WhenSpecialCharacterInPath_DoesNotThrowException)} \'[]!`~@#$%^€&()-_=+;,"; + string targetFilePath = TestHelper.GetScratchPadPath(name); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(name, sourceFile, ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + try + { + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // When + TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + Assert.DoesNotThrow(call); + } + } + finally + { + File.Delete(sourceFilePath); + } + } + + [Test] + public void GivenEmpty164Project_WhenNoChangesMadeAndMigratingToLatestVersion_ThenLogDatabaseContainsMessagesSayingNoChangesMade() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, + "Empty valid Release 16.4.rtd"); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath( + nameof(GivenEmpty164Project_WhenNoChangesMadeAndMigratingToLatestVersion_ThenLogDatabaseContainsMessagesSayingNoChangesMade)); + string logFilePath = TestHelper.GetScratchPadPath( + string.Concat(nameof(GivenEmpty164Project_WhenNoChangesMadeAndMigratingToLatestVersion_ThenLogDatabaseContainsMessagesSayingNoChangesMade), ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // When + migrator.Migrate(fromVersionedFile, latestVersion, targetFilePath); + + using (var reader = new MigrationLogDatabaseReader(logFilePath)) + { + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + Assert.AreEqual(10, messages.Count); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("5", "17.1", "Gevolgen van de migratie van versie 16.4 naar versie 17.1:"), + messages[0]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("5", "17.1", "* Geen aanpassingen."), + messages[1]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", "17.2", "Gevolgen van de migratie van versie 17.1 naar versie 17.2:"), + messages[2]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", "17.2", "* Geen aanpassingen."), + messages[3]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.2", "17.3", "Gevolgen van de migratie van versie 17.2 naar versie 17.3:"), + messages[4]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.2", "17.3", "* Geen aanpassingen."), + messages[5]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", "18.1", "Gevolgen van de migratie van versie 17.3 naar versie 18.1:"), + messages[6]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", "18.1", "* Geen aanpassingen."), + messages[7]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", latestVersion, $"Gevolgen van de migratie van versie 18.1 naar versie {latestVersion}:"), + messages[8]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", latestVersion, "* Geen aanpassingen."), + messages[9]); + } + } + } + + private static IEnumerable GetFileNamesWithSpecialCharacters() + { + foreach (FileToMigrate fileToMigrate in GetFilesToMigrate()) + { + yield return new TestCaseData(fileToMigrate.OriginalPath, fileToMigrate.ToVersion) + .SetName($"Migrate{fileToMigrate.OriginalPath}WithSpecialChars"); + } + } + + private static IEnumerable GetFilesToMigrate() + { + yield return new FileToMigrate("Empty valid Release 16.4.rtd", "17.1"); + yield return new FileToMigrate("Empty valid Release 17.1.rtd", "17.2"); + yield return new FileToMigrate("Empty valid Release 17.2.rtd", "17.3"); + yield return new FileToMigrate("Empty valid Release 17.3.rtd", "18.1"); + yield return new FileToMigrate("Empty valid Release 18.1.rtd", "19.1"); + } + + private class FileToMigrate + { + public FileToMigrate(string path, string toVersion) + { + OriginalPath = path; + ToVersion = toVersion; + } + + public string OriginalPath { get; } + public string ToVersion { get; } + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo171IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo171IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo171IntegrationTest.cs (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,397 @@ +// Copyright (C) Stichting Deltares 2018. 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.ObjectModel; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Migration.Core; +using Riskeer.Migration.Core.TestUtil; + +namespace Riskeer.Migration.Integration.Test +{ + [TestFixture] + public class MigrationTo171IntegrationTest + { + private const string newVersion = "17.1"; + + [Test] + public void Given164Project_WhenUpgradedTo171_ThenProjectAsExpected() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, + "MigrationTestProject164.rtd"); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given164Project_WhenUpgradedTo171_ThenProjectAsExpected)); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Given164Project_WhenUpgradedTo171_ThenProjectAsExpected), ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // When + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + using (var reader = new MigratedDatabaseReader(targetFilePath)) + { + AssertTablesContentMigrated(reader, sourceFilePath); + + AssertDuneErosionFailureMechanism(reader); + AssertClosingStructuresFailureMechanism(reader, sourceFilePath); + AssertGrassCoverErosionInwardsFailureMechanism(reader); + AssertGrassCoverErosionOutwardsFailureMechanism(reader); + AssertHeightStructuresFailureMechanism(reader); + AssertPipingFailureMechanism(reader); + AssertStabilityPointStructuresFailureMechanism(reader); + AssertStabilityStoneCoverFailureMechanism(reader); + AssertWaveImpactAsphaltCoverFailureMechanism(reader); + + AssertHydraulicBoundaryLocations(reader); + AssertDikeProfiles(reader); + AssertForeshoreProfiles(reader); + AssertStochasticSoilModels(reader); + AssertSurfaceLines(reader); + AssertSoilLayers(reader, sourceFilePath); + AssertBackgroundData(reader); + + AssertVersions(reader); + AssertDatabase(reader); + } + + AssertLogDatabase(logFilePath); + } + } + + private static void AssertTablesContentMigrated(MigratedDatabaseReader reader, string sourceFilePath) + { + string[] tables = + { + "AssessmentSectionEntity", + "CalculationGroupEntity", + "CharacteristicPointEntity", + "ClosingStructureEntity", + "ClosingStructuresCalculationEntity", + "ClosingStructuresSectionResultEntity", + "DikeProfileEntity", + "DuneErosionSectionResultEntity", + "FailureMechanismEntity", + "FailureMechanismSectionEntity", + "ForeshoreProfileEntity", + "GrassCoverErosionInwardsCalculationEntity", + "GrassCoverErosionInwardsFailureMechanismMetaEntity", + "GrassCoverErosionInwardsSectionResultEntity", + "GrassCoverErosionOutwardsFailureMechanismMetaEntity", + "GrassCoverErosionOutwardsHydraulicLocationEntity", + "GrassCoverErosionOutwardsSectionResultEntity", + "GrassCoverErosionOutwardsWaveConditionsCalculationEntity", + "GrassCoverSlipOffInwardsSectionResultEntity", + "GrassCoverSlipOffOutwardsSectionResultEntity", + "HeightStructureEntity", + "HeightStructuresCalculationEntity", + "HeightStructuresFailureMechanismMetaEntity", + "HeightStructuresSectionResultEntity", + "HydraulicLocationEntity", + "MacrostabilityInwardsSectionResultEntity", + "MacrostabilityOutwardsSectionResultEntity", + "MicrostabilitySectionResultEntity", + "PipingCalculationEntity", + "PipingFailureMechanismMetaEntity", + "PipingSectionResultEntity", + "PipingStructureSectionResultEntity", + "ProjectEntity", + "SoilLayerEntity", + "SoilProfileEntity", + "StabilityPointStructureEntity", + "StabilityPointStructuresCalculationEntity", + "StabilityPointStructuresFailureMechanismMetaEntity", + "StabilityPointStructuresSectionResultEntity", + "StabilityStoneCoverSectionResultEntity", + "StabilityStoneCoverWaveConditionsCalculationEntity", + "StochasticSoilModelEntity", + "StochasticSoilProfileEntity", + "StrengthStabilityLengthwiseConstructionSectionResultEntity", + "SurfaceLineEntity", + "TechnicalInnovationSectionResultEntity", + "VersionEntity", + "WaterPressureAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverWaveConditionsCalculationEntity" + }; + + foreach (string table in tables) + { + string validateMigratedTable = + $"ATTACH DATABASE[{sourceFilePath}] AS SOURCEPROJECT; " + + $"SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].{table}) " + + $"FROM {table};" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateMigratedTable); + } + } + + private static void AssertDikeProfiles(MigratedDatabaseReader reader) + { + const string validateDikeProfiles = + "SELECT COUNT(DISTINCT(Id)) = COUNT() " + + "FROM DikeProfileEntity " + + "GROUP BY [FailureMechanismEntityId]"; + reader.AssertReturnedDataIsValid(validateDikeProfiles); + } + + private static void AssertForeshoreProfiles(MigratedDatabaseReader reader) + { + const string validateForeshoreProfiles = + "SELECT COUNT() = 0 " + + "FROM ForeshoreProfileEntity " + + "WHERE Id != Name;"; + reader.AssertReturnedDataIsValid(validateForeshoreProfiles); + } + + private static void AssertStochasticSoilModels(MigratedDatabaseReader reader) + { + const string validateStochasticSoilModels = + "SELECT COUNT(DISTINCT(Name)) = COUNT() " + + "FROM StochasticSoilModelEntity;"; + reader.AssertReturnedDataIsValid(validateStochasticSoilModels); + + AssertStochasticSoilProfiles(reader); + } + + private static void AssertStochasticSoilProfiles(MigratedDatabaseReader reader) + { + const string validateStochasticSoilProfiles = + "SELECT " + + "(SELECT COUNT() = (SELECT COUNT() FROM StochasticSoilProfileEntity WHERE [Type] = 1) FROM StochasticSoilProfileEntity) " + + "AND " + + "(SELECT COUNT() = 0 FROM StochasticSoilProfileEntity WHERE [Probability] NOT BETWEEN 0 AND 1 OR [Probability] IS NULL);"; + reader.AssertReturnedDataIsValid(validateStochasticSoilProfiles); + } + + private static void AssertSoilLayers(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSoilLayers = + $"ATTACH DATABASE[{sourceFilePath}] AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].SoilLayerEntity) " + + "FROM SoilLayerEntity AS NEW " + + "LEFT JOIN [SOURCEPROJECT].SoilLayerEntity AS OLD ON NEW.[SoilLayerEntityId] = OLD.[SoilLayerEntityId] " + + "WHERE ((NEW.[DiameterD70CoefficientOfVariation] IS NULL AND OLD.[DiameterD70Deviation] IS NULL) " + + "OR NEW.[DiameterD70CoefficientOfVariation] = ROUND(OLD.[DiameterD70Deviation] / OLD.[DiameterD70Mean], 6)) " + + "AND ((NEW.[PermeabilityCoefficientOfVariation] IS NULL AND OLD.[PermeabilityDeviation] IS NULL) " + + "OR NEW.[PermeabilityCoefficientOfVariation] = ROUND(OLD.[PermeabilityDeviation] / OLD.[PermeabilityMean], 6)); " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSoilLayers); + } + + private static void AssertSurfaceLines(MigratedDatabaseReader reader) + { + const string validateSurfaceLines = + "SELECT COUNT(DISTINCT(Name)) = COUNT() " + + "FROM SurfaceLineEntity;"; + reader.AssertReturnedDataIsValid(validateSurfaceLines); + } + + private static void AssertVersions(MigratedDatabaseReader reader) + { + const string validateVersion = + "SELECT COUNT() = 1 " + + "FROM VersionEntity " + + "WHERE [Version] = \"17.1\";"; + reader.AssertReturnedDataIsValid(validateVersion); + } + + private static void AssertDatabase(MigratedDatabaseReader reader) + { + const string validateForeignKeys = + "PRAGMA foreign_keys;"; + reader.AssertReturnedDataIsValid(validateForeignKeys); + } + + private static void AssertBackgroundData(MigratedDatabaseReader reader) + { + const string validateBackgroundData = + "SELECT COUNT() = " + + "(SELECT COUNT() FROM AssessmentSectionEntity) " + + "FROM BackgroundDataEntity " + + "WHERE [Name] = \"Bing Maps - Satelliet\" " + + "AND [IsVisible] = 1 " + + "AND [Transparency] = 0.0 " + + "AND [BackgroundDataType] = 2 " + + "AND [AssessmentSectionEntityId] IN " + + "(SELECT [AssessmentSectionEntityId] FROM AssessmentSectionEntity);"; + reader.AssertReturnedDataIsValid(validateBackgroundData); + + const string validateBackgroundMetaData = + "SELECT COUNT() = " + + "(SELECT COUNT() FROM BackgroundDataEntity) " + + "FROM BackgroundDataMetaEntity " + + "WHERE [Key] = \"WellKnownTileSource\" " + + "AND [Value] = \"2\" " + + "AND [BackgroundDataEntityId] IN " + + "(SELECT BackgroundDataEntityId FROM BackgroundDataEntity);"; + reader.AssertReturnedDataIsValid(validateBackgroundMetaData); + } + + private static void AssertLogDatabase(string logFilePath) + { + using (var reader = new MigrationLogDatabaseReader(logFilePath)) + { + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + + Assert.AreEqual(6, messages.Count); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("5", newVersion, "Gevolgen van de migratie van versie 16.4 naar versie 17.1:"), + messages[0]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("5", newVersion, "* Alle berekende resultaten zijn verwijderd."), + messages[1]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("5", newVersion, "* Traject: 'assessmentSection'"), + messages[2]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("5", newVersion, " + Toetsspoor: 'Grasbekleding erosie kruin en binnentalud'"), + messages[3]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("5", newVersion, " - De naam van dijkprofiel '1' is veranderd naar '102' en wordt ook gebruikt als ID."), + messages[4]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("5", newVersion, " - De naam van dijkprofiel '10' is veranderd naar '104' en wordt ook gebruikt als ID."), + messages[5]); + } + } + + private static void AssertClosingStructuresFailureMechanism(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateFailureMechanisms = + $"ATTACH DATABASE[{sourceFilePath}] AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].ClosingStructureFailureMechanismMetaEntity) " + + "FROM ClosingStructuresFailureMechanismMetaEntity;" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateFailureMechanisms); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM ClosingStructuresOutputEntity"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertDuneErosionFailureMechanism(MigratedDatabaseReader reader) + { + const string validateFailureMechanisms = + "SELECT COUNT() = (SELECT COUNT() FROM FailureMechanismEntity WHERE FailureMechanismType = 8) " + + "FROM DuneErosionFailureMechanismMetaEntity " + + "WHERE N = 2.0 " + + "AND FailureMechanismEntityId IN " + + "(SELECT FailureMechanismEntityId FROM FailureMechanismEntity WHERE FailureMechanismType = 8);"; + reader.AssertReturnedDataIsValid(validateFailureMechanisms); + } + + private static void AssertGrassCoverErosionInwardsFailureMechanism(MigratedDatabaseReader reader) + { + const string validateFailureMechanisms = + "SELECT COUNT() = 0 " + + "FROM [GrassCoverErosionInwardsFailureMechanismMetaEntity] " + + "WHERE [DikeProfileCollectionSourcePath] != \"\";"; + reader.AssertReturnedDataIsValid(validateFailureMechanisms); + + const string validateCalculations = + "SELECT COUNT() = 0 " + + "FROM [GrassCoverErosionInwardsCalculationEntity] " + + "WHERE [OvertoppingRateCalculationType] != 1;"; + reader.AssertReturnedDataIsValid(validateCalculations); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [GrassCoverErosionInwardsDikeHeightOutputEntity] " + + "JOIN [GrassCoverErosionInwardsOutputEntity];"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertGrassCoverErosionOutwardsFailureMechanism(MigratedDatabaseReader reader) + { + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM GrassCoverErosionOutwardsHydraulicLocationOutputEntity " + + "JOIN GrassCoverErosionOutwardsWaveConditionsOutputEntity"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertHeightStructuresFailureMechanism(MigratedDatabaseReader reader) + { + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM HeightStructuresOutputEntity"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertHydraulicBoundaryLocations(MigratedDatabaseReader reader) + { + const string validateOutputs = + "SELECT COUNT() = 0 " + + "FROM HydraulicLocationOutputEntity"; + reader.AssertReturnedDataIsValid(validateOutputs); + } + + private static void AssertPipingFailureMechanism(MigratedDatabaseReader reader) + { + const string validateFailureMechanisms = + "SELECT COUNT() = 0 " + + "FROM [PipingFailureMechanismMetaEntity] " + + "WHERE [StochasticSoilModelSourcePath] != \"\"" + + "OR [SurfaceLineSourcePath] != \"\";"; + reader.AssertReturnedDataIsValid(validateFailureMechanisms); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM PipingCalculationOutputEntity " + + "JOIN PipingSemiProbabilisticOutputEntity"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertStabilityPointStructuresFailureMechanism(MigratedDatabaseReader reader) + { + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM StabilityPointStructuresOutputEntity"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertStabilityStoneCoverFailureMechanism(MigratedDatabaseReader reader) + { + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM StabilityStoneCoverWaveConditionsOutputEntity"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertWaveImpactAsphaltCoverFailureMechanism(MigratedDatabaseReader reader) + { + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM WaveImpactAsphaltCoverWaveConditionsOutputEntity"; + + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo172IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo172IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo172IntegrationTest.cs (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,1266 @@ +// Copyright (C) Stichting Deltares 2018. 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.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Contribution; +using Riskeer.Migration.Core; +using Riskeer.Migration.Core.TestUtil; + +namespace Riskeer.Migration.Integration.Test +{ + public class MigrationTo172IntegrationTest + { + private const string newVersion = "17.2"; + + [Test] + public void Given171Project_WhenUpgradedTo172_ThenProjectAsExpected() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, + "MigrationTestProject171.rtd"); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given171Project_WhenUpgradedTo172_ThenProjectAsExpected)); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Given171Project_WhenUpgradedTo172_ThenProjectAsExpected), ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // When + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + using (var reader = new MigratedDatabaseReader(targetFilePath)) + { + AssertTablesContentMigrated(reader, sourceFilePath); + + AssertCalculationGroup(reader, sourceFilePath); + + AssertClosingStructuresFailureMechanism(reader); + AssertClosingStructures(reader); + AssertDuneErosionFailureMechanism(reader); + AssertForeshoreProfiles(reader); + + AssertGrassCoverErosionInwardsFailureMechanism(reader); + AssertGrassCoverErosionOutwardsFailureMechanism(reader); + + AssertHeightStructuresFailureMechanism(reader); + AssertHeightStructures(reader); + AssertHydraulicBoundaryLocations(reader); + AssertMacroStabilityInwardsFailureMechanism(reader); + + AssertPipingFailureMechanism(reader, sourceFilePath); + AssertPipingCharacteristicPoints(reader, sourceFilePath); + AssertPipingStochasticSoilProfiles(reader, sourceFilePath); + AssertPipingSoilProfiles(reader, sourceFilePath); + AssertPipingSoilLayers(reader, sourceFilePath); + + AssertStabilityPointStructuresFailureMechanism(reader); + AssertStabilityPointStructures(reader); + + AssertWaveImpactAsphaltCoverFailureMechanism(reader); + AssertStabilityStoneCoverFailureMechanism(reader); + + AssertFailureMechanismSectionResults(reader, "ClosingStructuresSectionResultEntity"); + AssertFailureMechanismSectionResults(reader, "GrassCoverErosionInwardsSectionResultEntity"); + AssertFailureMechanismSectionResults(reader, "HeightStructuresSectionResultEntity"); + AssertFailureMechanismSectionResults(reader, "MacroStabilityInwardsSectionResultEntity"); + AssertFailureMechanismSectionResults(reader, "PipingSectionResultEntity"); + AssertFailureMechanismSectionResults(reader, "StabilityPointStructuresSectionResultEntity"); + + AssertVersions(reader); + AssertDatabase(reader); + } + + AssertLogDatabase(logFilePath); + } + } + + [Test] + [SetCulture("en-US")] + [TestCaseSource(nameof(GetTrajectCombinations))] + public void Given171ProjectOfTrajectWithNorm_WhenMigrated_ThenDatabaseUpdatedAndExpectedLogDatabase(NormType setNormType, + string trajectId, + int signalingReturnPeriod, + int lowerLimitReturnPeriod) + { + // Given + string testName = TestContext.CurrentContext.Test.Name.Replace("\"", string.Empty); + + string sourceFilePath = TestHelper.GetScratchPadPath(string.Concat(testName, "Source", ".sql")); + string targetFilePath = TestHelper.GetScratchPadPath(string.Concat(testName, "Target", ".sql")); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(testName, ".log")); + + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(sourceFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + File.Copy(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, + "Empty valid Release 17.1.rtd"), + sourceFilePath, true + ); + + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + using (var databaseFile = new RingtoetsDatabaseFile(sourceFilePath)) + { + databaseFile.OpenDatabaseConnection(); + + double originalNorm = 1.0 / (setNormType == NormType.Signaling + ? signalingReturnPeriod + : lowerLimitReturnPeriod); + databaseFile.ExecuteQuery("INSERT INTO ProjectEntity ([ProjectEntityId]) VALUES (1);"); + databaseFile.ExecuteQuery("INSERT INTO AssessmentSectionEntity ([ProjectEntityId], [Composition], [Order], [Name], [Id], [Norm]) " + + $"VALUES (1, 1, 0, \"{trajectId}\", \"{trajectId}\", {originalNorm});"); + } + + // When + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + NormType expectedNormType = lowerLimitReturnPeriod == signalingReturnPeriod + ? NormType.Signaling + : setNormType; + + string expectedAssessmentSectionQuery = GetExpectedAssessmentSectionQuery(trajectId, + lowerLimitReturnPeriod, + signalingReturnPeriod, + expectedNormType); + + using (var reader = new MigratedDatabaseReader(targetFilePath)) + { + reader.AssertReturnedDataIsValid(expectedAssessmentSectionQuery); + } + + using (var reader = new MigrationLogDatabaseReader(logFilePath)) + { + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + Assert.AreEqual(5, messages.Count); + + var i = 0; + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", "17.2", "Gevolgen van de migratie van versie 17.1 naar versie 17.2:"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", "17.2", $"* Traject: '{trajectId}'"), + messages[i++]); + + AssertAssessmentSectionNormMigrationMessage(new[] + { + messages[i++], + messages[i++], + messages[i] + }, lowerLimitReturnPeriod, signalingReturnPeriod, expectedNormType); + } + } + } + + [Test] + [SetCulture("en-US")] + [TestCase(2, NormType.LowerLimit, TestName = "Given171ProjectWithNormLargerThenLowerLimit_WhenMigrated_ThenLowerLimitNormSetToNormAndExpectedLogDatabase")] + [TestCase(600, NormType.Signaling, TestName = "Given171ProjectWithNormLessThenLowerLimit_WhenMigrated_ThenSignalingNormSetToNormAndExpectedLogDatabase")] + public void Given171ProjectWithNormNotInList_WhenMigrated_ThenDatabaseUpdatedAndExpectedLogDatabase(int originalReturnPeriod, + NormType expectedNormType) + { + // Given + const string trajectId = "2-1"; + const int signalingReturnPeriod = 1000; + const int lowerLimitReturnPeriod = 300; + + string testName = TestContext.CurrentContext.Test.Name; + + string sourceFilePath = TestHelper.GetScratchPadPath(string.Concat(testName, "Source", ".sql")); + string targetFilePath = TestHelper.GetScratchPadPath(string.Concat(testName, "Target", ".sql")); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(testName, ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(sourceFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + File.Copy(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, + "Empty valid Release 17.1.rtd"), + sourceFilePath, true + ); + + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + using (var databaseFile = new RingtoetsDatabaseFile(sourceFilePath)) + { + databaseFile.OpenDatabaseConnection(); + + double fromNorm = 1.0 / originalReturnPeriod; + databaseFile.ExecuteQuery("INSERT INTO ProjectEntity ([ProjectEntityId]) VALUES (1);"); + databaseFile.ExecuteQuery("INSERT INTO AssessmentSectionEntity ([ProjectEntityId], [Composition], [Order], [Name], [Id], [Norm]) " + + $"VALUES (1, 1, 0, \"{trajectId}\", \"{trajectId}\", {fromNorm});"); + } + + // When + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + int expectedLowerLimitReturnPeriod = expectedNormType == NormType.LowerLimit + ? originalReturnPeriod + : lowerLimitReturnPeriod; + + int expectedSignalingReturnPeriod = expectedNormType == NormType.Signaling + ? originalReturnPeriod + : signalingReturnPeriod; + + string expectedAssessmentSectionQuery = GetExpectedAssessmentSectionQuery(trajectId, + expectedLowerLimitReturnPeriod, + expectedSignalingReturnPeriod, + expectedNormType); + + using (var reader = new MigratedDatabaseReader(targetFilePath)) + { + reader.AssertReturnedDataIsValid(expectedAssessmentSectionQuery); + } + + using (var reader = new MigrationLogDatabaseReader(logFilePath)) + { + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + Assert.AreEqual(5, messages.Count); + + var i = 0; + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", "17.2", "Gevolgen van de migratie van versie 17.1 naar versie 17.2:"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", "17.2", "* Traject: '2-1'"), + messages[i++]); + + AssertAssessmentSectionNormMigrationMessage(new[] + { + messages[i++], + messages[i++], + messages[i] + }, expectedLowerLimitReturnPeriod, expectedSignalingReturnPeriod, expectedNormType); + } + } + } + + private static string GetExpectedAssessmentSectionQuery(string trajectId, + int lowerLimitReturnPeriod, + int signalingReturnPeriod, + NormType normType) + { + return "SELECT COUNT() = 1 " + + "FROM AssessmentSectionEntity " + + $"WHERE [Id] = \"{trajectId}\" " + + $"AND CAST(1.0 / [LowerLimitNorm] AS FLOAT) BETWEEN ({lowerLimitReturnPeriod} - 0.1) AND ({lowerLimitReturnPeriod} + 0.1) " + + $"AND CAST(1.0 / [SignalingNorm] AS FLOAT) BETWEEN ({signalingReturnPeriod} - 0.1) AND ({signalingReturnPeriod} + 0.1) " + + $"AND [NormativeNormType] = {Convert.ToByte(normType)}"; + } + + private static string GetNormTypeString(NormType normType) + { + return normType == NormType.LowerLimit + ? "ondergrens" + : "signaleringswaarde"; + } + + private static IEnumerable GetTrajectCombinations() + { + Array normTypes = Enum.GetValues(typeof(NormType)); + + IEnumerable uniqueTrajectPeriods = GetAllTrajectTestCaseData() + .GroupBy(t => Tuple.Create(t.SignalingReturnPeriod, t.LowerLimitPeriod)) + .Select(t => t.First()); + foreach (AssessmentSectionReturnPeriod data in uniqueTrajectPeriods) + { + foreach (NormType normType in normTypes) + { + yield return new TestCaseData(normType, + data.Id, + data.SignalingReturnPeriod, + data.LowerLimitPeriod) + .SetName("Given171ProjectWithNorm{1}OfTraject{0}_WhenMigrated_ThenDatabaseUpdatedAndExpectedLogDatabase"); + } + } + + yield return new TestCaseData(NormType.Signaling, + "NoValidTrajectId", + 30000, + 30000) + .SetName("Given171ProjectWithNorm{1}OfUnknownTraject_WhenMigrated_ThenDatabaseUpdatedAndExpectedLogDatabase"); + } + + private static IEnumerable GetAllTrajectTestCaseData() + { + yield return new AssessmentSectionReturnPeriod("1-1", 1000, 1000); + yield return new AssessmentSectionReturnPeriod("1-2", 1000, 1000); + yield return new AssessmentSectionReturnPeriod("2-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("2-2", 1000, 1000); + yield return new AssessmentSectionReturnPeriod("3-1", 3000, 3000); + yield return new AssessmentSectionReturnPeriod("3-2", 1000, 1000); + yield return new AssessmentSectionReturnPeriod("4-1", 300, 300); + yield return new AssessmentSectionReturnPeriod("4-2", 1000, 300); + yield return new AssessmentSectionReturnPeriod("5-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("5-2", 3000, 3000); + yield return new AssessmentSectionReturnPeriod("6-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("6-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("6-3", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("6-4", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("6-5", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("6-6", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("6-7", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("7-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("7-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("8-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("8-2", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("8-3", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("8-4", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("8-5", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("8-6", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("8-7", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("9-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("9-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("10-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("10-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("10-3", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("11-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("11-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("11-3", 300, 100); + yield return new AssessmentSectionReturnPeriod("12-1", 1000, 1000); + yield return new AssessmentSectionReturnPeriod("12-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13-2", 3000, 3000); + yield return new AssessmentSectionReturnPeriod("13-3", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13-4", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13-5", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13-6", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13-7", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13-8", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13-9", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("13a-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("13b-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("14-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("14-10", 30000, 30000); + yield return new AssessmentSectionReturnPeriod("14-2", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("14-3", 10000, 10000); + yield return new AssessmentSectionReturnPeriod("14-4", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("14-5", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("14-6", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("14-7", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("14-8", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("14-9", 30000, 30000); + yield return new AssessmentSectionReturnPeriod("15-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("15-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("15-3", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("16-1", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("16-2", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("16-3", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("16-4", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("16-5", 10, 10); // Signaling norm set to LowerLimit + yield return new AssessmentSectionReturnPeriod("17-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("17-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("17-3", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("18-1", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("19-1", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("20-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("20-2", 10000, 10000); + yield return new AssessmentSectionReturnPeriod("20-3", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("20-4", 1000, 300); + yield return new AssessmentSectionReturnPeriod("21-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("21-2", 300, 100); + yield return new AssessmentSectionReturnPeriod("22-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("22-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("23-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("24-1", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("24-2", 1000, 300); + yield return new AssessmentSectionReturnPeriod("24-3", 10000, 10000); + yield return new AssessmentSectionReturnPeriod("25-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("25-2", 1000, 300); + yield return new AssessmentSectionReturnPeriod("25-3", 300, 100); + yield return new AssessmentSectionReturnPeriod("25-4", 300, 300); + yield return new AssessmentSectionReturnPeriod("26-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("26-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("26-3", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("26-4", 1000, 1000); + yield return new AssessmentSectionReturnPeriod("27-1", 3000, 3000); + yield return new AssessmentSectionReturnPeriod("27-2", 10000, 10000); + yield return new AssessmentSectionReturnPeriod("27-3", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("27-4", 1000, 300); + yield return new AssessmentSectionReturnPeriod("28-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("29-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("29-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("29-3", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("29-4", 1000, 1000); + yield return new AssessmentSectionReturnPeriod("30-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("30-2", 100000, 100000); + yield return new AssessmentSectionReturnPeriod("30-3", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("30-4", 1000000, 1000000); + yield return new AssessmentSectionReturnPeriod("31-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("31-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("31-3", 300, 100); + yield return new AssessmentSectionReturnPeriod("32-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("32-2", 1000, 300); + yield return new AssessmentSectionReturnPeriod("32-3", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("32-4", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("33-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("34-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("34-2", 1000, 300); + yield return new AssessmentSectionReturnPeriod("34-3", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("34-4", 1000, 300); + yield return new AssessmentSectionReturnPeriod("34-5", 300, 100); + yield return new AssessmentSectionReturnPeriod("34a-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("35-1", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("35-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("36-1", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("36-2", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("36-3", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("36-4", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("36-5", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("36a-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("37-1", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("38-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("38-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("39-1", 3000, 3000); + yield return new AssessmentSectionReturnPeriod("40-1", 30000, 30000); + yield return new AssessmentSectionReturnPeriod("40-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("41-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("41-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("41-3", 3000, 3000); + yield return new AssessmentSectionReturnPeriod("41-4", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("42-1", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("43-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("43-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("43-3", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("43-4", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("43-5", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("43-6", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("44-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("44-2", 300, 100); + yield return new AssessmentSectionReturnPeriod("44-3", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("45-1", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("45-2", 300, 100); + yield return new AssessmentSectionReturnPeriod("45-3", 300, 100); + yield return new AssessmentSectionReturnPeriod("46-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("47-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("48-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("48-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("48-3", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("49-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("49-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("50-1", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("50-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("51-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("52-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("52-2", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("52-3", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("52-4", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("52a-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("53-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("53-2", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("53-3", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("54-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("55-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("56-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("57-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("58-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("59-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("60-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("61-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("63-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("64-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("65-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("66-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("67-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("68-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("68-2", 300, 100); + yield return new AssessmentSectionReturnPeriod("69-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("70-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("71-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("72-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("73-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("74-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("75-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("76-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("76-2", 300, 100); + yield return new AssessmentSectionReturnPeriod("76a-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("77-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("78-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("78a-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("79-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("80-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("81-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("82-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("83-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("85-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("86-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("87-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("88-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("89-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("90-1", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("91-1", 300, 300); + yield return new AssessmentSectionReturnPeriod("92-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("93-1", 1000, 300); + yield return new AssessmentSectionReturnPeriod("94-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("95-1", 300, 100); + yield return new AssessmentSectionReturnPeriod("201", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("202", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("204a", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("204b", 1000, 300); + yield return new AssessmentSectionReturnPeriod("205", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("206", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("208", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("209", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("210", 100000, 30000); + yield return new AssessmentSectionReturnPeriod("211", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("212", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("213", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("214", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("215", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("216", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("217", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("218", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("219", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("221", 10000, 3000); + yield return new AssessmentSectionReturnPeriod("222", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("223", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("224", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("225", 30000, 10000); + yield return new AssessmentSectionReturnPeriod("226", 3000, 1000); + yield return new AssessmentSectionReturnPeriod("227", 3000, 1000); + } + + private static void AssertTablesContentMigrated(MigratedDatabaseReader reader, string sourceFilePath) + { + string[] tables = + { + "AssessmentSectionEntity", + "ClosingStructureEntity", + "ClosingStructuresCalculationEntity", + "ClosingStructuresSectionResultEntity", + "DikeProfileEntity", + "DuneErosionSectionResultEntity", + "FailureMechanismEntity", + "FailureMechanismSectionEntity", + "ForeshoreProfileEntity", + "GrassCoverErosionInwardsCalculationEntity", + "GrassCoverErosionInwardsFailureMechanismMetaEntity", + "GrassCoverErosionInwardsSectionResultEntity", + "GrassCoverErosionOutwardsFailureMechanismMetaEntity", + "GrassCoverErosionOutwardsHydraulicLocationEntity", + "GrassCoverErosionOutwardsSectionResultEntity", + "GrassCoverErosionOutwardsWaveConditionsCalculationEntity", + "GrassCoverSlipOffInwardsSectionResultEntity", + "GrassCoverSlipOffOutwardsSectionResultEntity", + "HeightStructureEntity", + "HeightStructuresCalculationEntity", + "HeightStructuresFailureMechanismMetaEntity", + "HeightStructuresSectionResultEntity", + "HydraulicLocationEntity", + "MacroStabilityInwardsSectionResultEntity", + "MacrostabilityOutwardsSectionResultEntity", + "MicrostabilitySectionResultEntity", + "PipingCalculationEntity", + "PipingFailureMechanismMetaEntity", + "PipingSectionResultEntity", + "PipingStructureSectionResultEntity", + "ProjectEntity", + "StabilityPointStructureEntity", + "StabilityPointStructuresCalculationEntity", + "StabilityPointStructuresFailureMechanismMetaEntity", + "StabilityPointStructuresSectionResultEntity", + "StabilityStoneCoverSectionResultEntity", + "StabilityStoneCoverWaveConditionsCalculationEntity", + "StochasticSoilModelEntity", + "StrengthStabilityLengthwiseConstructionSectionResultEntity", + "SurfaceLineEntity", + "TechnicalInnovationSectionResultEntity", + "VersionEntity", + "WaterPressureAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverWaveConditionsCalculationEntity" + }; + + foreach (string table in tables) + { + string validateMigratedTable = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + $"SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].{table}) " + + $"FROM {table};" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateMigratedTable); + } + } + + private static void AssertCalculationGroup(MigratedDatabaseReader reader, string sourceFilePath) + { + const string expectedNrOfCalculationGroupsQuery = + "SELECT " + + "COUNT() + " + + "(" + + "SELECT " + + "COUNT() " + + "FROM [SOURCEPROJECT].FailureMechanismEntity " + + "WHERE [FailureMechanismType] = 2" + + ") " + + "FROM [SOURCEPROJECT].CalculationGroupEntity "; + + string validateMigratedTable = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + $"SELECT COUNT() = ({expectedNrOfCalculationGroupsQuery})" + + "FROM CalculationGroupEntity;" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateMigratedTable); + } + + private static void AssertClosingStructuresFailureMechanism(MigratedDatabaseReader reader) + { + const string validateStructuresCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM (SELECT " + + "CASE WHEN " + + "COUNT([ClosingStructureEntityId]) AND [ClosingStructureCollectionSourcePath] IS NULL " + + "OR " + + "[ClosingStructureCollectionSourcePath] IS NOT NULL AND NOT COUNT([ClosingStructureEntityId]) " + + "THEN 1 ELSE 0 END AS [IsInvalid] " + + "FROM [ClosingStructuresFailureMechanismMetaEntity] " + + "LEFT JOIN [ClosingStructureEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateStructuresCollectionSourcePath); + + const string validateForeshoreProfileCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM(" + + "SELECT " + + "CASE WHEN " + + "COUNT([ForeshoreProfileEntityId]) AND [ForeshoreProfileCollectionSourcePath] IS NULL " + + "OR " + + "[ForeshoreProfileCollectionSourcePath] IS NOT NULL AND NOT COUNT([ForeshoreProfileEntityId]) " + + "THEN 1 ELSE 0 END AS [IsInvalid] " + + "FROM [ClosingStructuresFailureMechanismMetaEntity] " + + "LEFT JOIN [ForeshoreProfileEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateForeshoreProfileCollectionSourcePath); + + const string validateCalculations = + "SELECT COUNT() = 0 " + + "FROM [ClosingStructuresCalculationEntity] " + + "WHERE [ShouldIllustrationPointsBeCalculated] != 0;"; + reader.AssertReturnedDataIsValid(validateCalculations); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [ClosingStructuresOutputEntity]"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertClosingStructures(MigratedDatabaseReader reader) + { + const string validateClosingStructures = + "SELECT COUNT(DISTINCT(Id)) = COUNT() " + + "FROM [ClosingStructureEntity] " + + "GROUP BY [FailureMechanismEntityId]"; + reader.AssertReturnedDataIsValid(validateClosingStructures); + } + + private static void AssertDuneErosionFailureMechanism(MigratedDatabaseReader reader) + { + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [DuneLocationOutputEntity]"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertForeshoreProfiles(MigratedDatabaseReader reader) + { + const string validateForeshoreProfiles = + "SELECT COUNT(DISTINCT([Id])) IS COUNT() " + + "FROM [ForeshoreProfileEntity] " + + "GROUP BY [FailureMechanismEntityId]"; + reader.AssertReturnedDataIsValid(validateForeshoreProfiles); + } + + private static void AssertGrassCoverErosionInwardsFailureMechanism(MigratedDatabaseReader reader) + { + const string validateCalculations = + "SELECT COUNT() = 0 " + + "FROM [GrassCoverErosionInwardsCalculationEntity] " + + "WHERE [ShouldDikeHeightIllustrationPointsBeCalculated] != 0 AND " + + "[ShouldOvertoppingRateIllustrationPointsBeCalculated] != 0 AND " + + "[ShouldOvertoppingOutputIllustrationPointsBeCalculated] != 0;"; + reader.AssertReturnedDataIsValid(validateCalculations); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [GrassCoverErosionInwardsDikeHeightOutputEntity] " + + "JOIN [GrassCoverErosionInwardsOutputEntity] " + + "JOIN [GrassCoverErosionInwardsOvertoppingRateOutputEntity];"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertGrassCoverErosionOutwardsFailureMechanism(MigratedDatabaseReader reader) + { + const string validateForeshoreProfileCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM (" + + "SELECT " + + "CASE WHEN " + + "COUNT([ForeshoreProfileEntityId]) AND [ForeshoreProfileCollectionSourcePath] IS NULL " + + "OR " + + "[ForeshoreProfileCollectionSourcePath] IS NOT NULL AND NOT COUNT([ForeshoreProfileEntityId]) " + + "THEN 1 ELSE 0 END AS[IsInvalid] " + + "FROM [GrassCoverErosionOutwardsFailureMechanismMetaEntity] " + + "LEFT JOIN [ForeshoreProfileEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateForeshoreProfileCollectionSourcePath); + + const string validateCalculations = + "SELECT COUNT() = 0 " + + "FROM [GrassCoverErosionOutwardsHydraulicLocationEntity] " + + "WHERE [ShouldWaveHeightIllustrationPointsBeCalculated] != 0 " + + "|| [ShouldDesignWaterLevelIllustrationPointsBeCalculated] != 0;"; + reader.AssertReturnedDataIsValid(validateCalculations); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [GrassCoverErosionOutwardsHydraulicLocationOutputEntity] " + + "JOIN [GrassCoverErosionOutwardsWaveConditionsOutputEntity]"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertHeightStructuresFailureMechanism(MigratedDatabaseReader reader) + { + const string validateStructuresCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM (SELECT " + + "CASE WHEN " + + "COUNT([HeightStructureEntityId]) AND [HeightStructureCollectionSourcePath] IS NULL " + + "OR " + + "[HeightStructureCollectionSourcePath] IS NOT NULL AND NOT COUNT([HeightStructureEntityId]) " + + "THEN 1 ELSE 0 END AS [IsInvalid] " + + "FROM [HeightStructuresFailureMechanismMetaEntity] " + + "LEFT JOIN [HeightStructureEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateStructuresCollectionSourcePath); + + const string validateForeshoreProfileCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM(" + + "SELECT " + + "CASE WHEN " + + "COUNT([ForeshoreProfileEntityId]) AND [ForeshoreProfileCollectionSourcePath] IS NULL " + + "OR " + + "[ForeshoreProfileCollectionSourcePath] IS NOT NULL AND NOT COUNT([ForeshoreProfileEntityId]) " + + "THEN 1 ELSE 0 END AS[IsInvalid] " + + "FROM [HeightStructuresFailureMechanismMetaEntity] " + + "LEFT JOIN [ForeshoreProfileEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateForeshoreProfileCollectionSourcePath); + + const string validateCalculations = + "SELECT COUNT() = 0 " + + "FROM [HeightStructuresCalculationEntity] " + + "WHERE [ShouldIllustrationPointsBeCalculated] != 0;"; + reader.AssertReturnedDataIsValid(validateCalculations); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [HeightStructuresOutputEntity]"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertHeightStructures(MigratedDatabaseReader reader) + { + const string validateHeightStructures = + "SELECT COUNT(DISTINCT(Id)) = COUNT() " + + "FROM [HeightStructureEntity] " + + "GROUP BY [FailureMechanismEntityId]"; + reader.AssertReturnedDataIsValid(validateHeightStructures); + } + + private static void AssertHydraulicBoundaryLocations(MigratedDatabaseReader reader) + { + const string validateCalculations = + "SELECT COUNT() = 0 " + + "FROM [HydraulicLocationEntity] " + + "WHERE [ShouldWaveHeightIllustrationPointsBeCalculated] != 0 " + + "|| [ShouldDesignWaterLevelIllustrationPointsBeCalculated] != 0;"; + reader.AssertReturnedDataIsValid(validateCalculations); + + const string validateOutputs = + "SELECT COUNT() = 0 " + + "FROM [HydraulicLocationOutputEntity]"; + reader.AssertReturnedDataIsValid(validateOutputs); + } + + private static void AssertMacroStabilityInwardsFailureMechanism(MigratedDatabaseReader reader) + { + const string validateFailureMechanisms = + "SELECT COUNT() = (SELECT COUNT() FROM FailureMechanismEntity WHERE FailureMechanismType = 2) " + + "FROM [MacroStabilityInwardsFailureMechanismMetaEntity] " + + "WHERE [A] = 0.033 " + + "AND [StochasticSoilModelCollectionSourcePath] IS NULL " + + "AND [SurfaceLineCollectionSourcePath] IS NULL " + + "AND [FailureMechanismEntityId] IN " + + "(SELECT [FailureMechanismEntityId] FROM [FailureMechanismEntity] WHERE [FailureMechanismType] = 2);"; + reader.AssertReturnedDataIsValid(validateFailureMechanisms); + + const string validateMacroStabilityInwardsFailureMechanismCalculationGroup = + "SELECT COUNT() = 0 " + + "FROM [FailureMechanismEntity] " + + "WHERE [FailureMechanismType] = 2 " + + "AND [CalculationGroupEntityId] IS NULL"; + reader.AssertReturnedDataIsValid(validateMacroStabilityInwardsFailureMechanismCalculationGroup); + } + + private static void AssertPipingFailureMechanism(MigratedDatabaseReader reader, string sourceFilePath) + { + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [PipingCalculationOutputEntity] " + + "LEFT JOIN [PipingSemiProbabilisticOutputEntity] USING(PipingCalculationEntityId) " + + "WHERE [PipingCalculationEntityId] IN( " + + "SELECT [PipingCalculationEntityId] " + + "FROM [PipingCalculationEntity] " + + "WHERE [UseAssessmentLevelManualInput] IS 0);"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + + string validateCalculationOutputsWithManualInput = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = ( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].PipingCalculationOutputEntity " + + "LEFT JOIN [SOURCEPROJECT].PipingSemiProbabilisticOutputEntity USING(PipingCalculationEntityId) " + + "WHERE [PipingCalculationEntityId] IN( " + + "SELECT [PipingCalculationEntityId] " + + "FROM [SOURCEPROJECT].PipingCalculationEntity " + + "WHERE [UseAssessmentLevelManualInput] IS 1 " + + ") " + + ") " + + "FROM [PipingCalculationOutputEntity] " + + "LEFT JOIN [PipingSemiProbabilisticOutputEntity] USING(PipingCalculationEntityId) " + + "WHERE [PipingCalculationEntityId] IN( " + + "SELECT [PipingCalculationEntityId] " + + "FROM [PipingCalculationEntity] " + + "WHERE [UseAssessmentLevelManualInput] IS 1);" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateCalculationOutputsWithManualInput); + } + + private static void AssertPipingCharacteristicPoints(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSoilProfiles = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].CharacteristicPointEntity) " + + "FROM [PipingCharacteristicPointEntity]; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSoilProfiles); + } + + private static void AssertPipingStochasticSoilProfiles(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSoilProfiles = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].StochasticSoilProfileEntity) " + + "FROM [PipingStochasticSoilProfileEntity]; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSoilProfiles); + } + + private static void AssertPipingSoilProfiles(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSoilProfiles = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].SoilProfileEntity) " + + "FROM [PipingSoilProfileEntity] " + + "WHERE [SourceType] IN (1,2);" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSoilProfiles); + } + + private static void AssertPipingSoilLayers(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSoilLayers = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].SoilLayerEntity) " + + "FROM [PipingSoilLayerEntity]; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSoilLayers); + + string validateSoilLayerColors = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].SoilLayerEntity WHERE [Color] = 0) " + + "FROM [PipingSoilLayerEntity] " + + "WHERE [Color] IS NULL;" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSoilLayerColors); + } + + private static void AssertStabilityPointStructuresFailureMechanism(MigratedDatabaseReader reader) + { + const string validateStructuresCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM (SELECT " + + "CASE WHEN " + + "COUNT([StabilityPointStructureEntityId]) AND [StabilityPointStructureCollectionSourcePath] IS NULL " + + "OR " + + "[StabilityPointStructureCollectionSourcePath] IS NOT NULL AND NOT COUNT([StabilityPointStructureEntityId]) " + + "THEN 1 ELSE 0 END AS [IsInvalid] " + + "FROM [StabilityPointStructuresFailureMechanismMetaEntity] " + + "LEFT JOIN [StabilityPointStructureEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateStructuresCollectionSourcePath); + + const string validateForeshoreProfileCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM (" + + "SELECT " + + "CASE WHEN " + + "COUNT([ForeshoreProfileEntityId]) AND [ForeshoreProfileCollectionSourcePath] IS NULL " + + "OR " + + "[ForeshoreProfileCollectionSourcePath] IS NOT NULL AND NOT COUNT([ForeshoreProfileEntityId]) " + + "THEN 1 ELSE 0 END AS [IsInvalid] " + + "FROM [StabilityPointStructuresFailureMechanismMetaEntity] " + + "LEFT JOIN [ForeshoreProfileEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateForeshoreProfileCollectionSourcePath); + + const string validateCalculations = + "SELECT COUNT() = 0 " + + "FROM [StabilityPointStructuresCalculationEntity] " + + "WHERE [ShouldIllustrationPointsBeCalculated] != 0;"; + reader.AssertReturnedDataIsValid(validateCalculations); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [StabilityPointStructuresOutputEntity]"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertStabilityPointStructures(MigratedDatabaseReader reader) + { + const string validateStabilityPointStructures = + "SELECT COUNT(DISTINCT(Id)) = COUNT() " + + "FROM [StabilityPointStructureEntity] " + + "GROUP BY [FailureMechanismEntityId]"; + reader.AssertReturnedDataIsValid(validateStabilityPointStructures); + } + + private static void AssertStabilityStoneCoverFailureMechanism(MigratedDatabaseReader reader) + { + const string validateForeshoreProfileCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM (" + + "SELECT " + + "CASE WHEN " + + "COUNT([ForeshoreProfileEntityId]) AND [ForeshoreProfileCollectionSourcePath] IS NULL " + + "OR " + + "[ForeshoreProfileCollectionSourcePath] IS NOT NULL AND NOT COUNT([ForeshoreProfileEntityId]) " + + "THEN 1 ELSE 0 END AS[IsInvalid] " + + "FROM [StabilityStoneCoverFailureMechanismMetaEntity] " + + "LEFT JOIN [ForeshoreProfileEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateForeshoreProfileCollectionSourcePath); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [StabilityStoneCoverWaveConditionsOutputEntity]"; + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertWaveImpactAsphaltCoverFailureMechanism(MigratedDatabaseReader reader) + { + const string validateForeshoreProfileCollectionSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM (" + + "SELECT " + + "CASE WHEN " + + "COUNT([ForeshoreProfileEntityId]) AND [ForeshoreProfileCollectionSourcePath] IS NULL " + + "OR " + + "[ForeshoreProfileCollectionSourcePath] IS NOT NULL AND NOT COUNT([ForeshoreProfileEntityId]) " + + "THEN 1 ELSE 0 END AS[IsInvalid] " + + "FROM [WaveImpactAsphaltCoverFailureMechanismMetaEntity] " + + "LEFT JOIN [ForeshoreProfileEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateForeshoreProfileCollectionSourcePath); + + const string validateCalculationOutputs = + "SELECT COUNT() = 0 " + + "FROM [WaveImpactAsphaltCoverWaveConditionsOutputEntity]"; + + reader.AssertReturnedDataIsValid(validateCalculationOutputs); + } + + private static void AssertAssessmentSectionNormMigrationMessage(MigrationLogMessage[] messages, + int lowerLimitReturnPeriod, + int signalingReturnPeriod, + NormType normType) + { + Assert.AreEqual(3, messages.Length); + + string lowerLimitLogSuffix = normType == NormType.LowerLimit + ? " (voorheen de waarde van de norm)" + : ""; + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, $" + De ondergrens is gelijk gesteld aan 1/{lowerLimitReturnPeriod}{lowerLimitLogSuffix}."), + messages[0]); + string signalingLogSuffix = normType == NormType.Signaling + ? " (voorheen de waarde van de norm)" + : ""; + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, $" + De signaleringswaarde is gelijk gesteld aan 1/{signalingReturnPeriod}{signalingLogSuffix}."), + messages[1]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, $" + De norm van het dijktraject is gelijk gesteld aan de {GetNormTypeString(normType)}."), + messages[2]); + } + + private static void AssertFailureMechanismSectionResults(MigratedDatabaseReader reader, string sectionResultTable) + { + string validateFailureMechanismSectionResults = + "SELECT COUNT() = 0 " + + $"FROM {sectionResultTable} " + + "WHERE [LayerThree] < 0 OR [LayerThree] > 1"; + + reader.AssertReturnedDataIsValid(validateFailureMechanismSectionResults); + } + + private static void AssertLayerThreeMigrationMessage(MigrationLogMessage[] messages) + { + Assert.AreEqual(2, messages.Length); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het geregistreerde resultaat voor de toets op maat in 'Vak 1' ('5.0') kon niet worden geconverteerd naar een geldige kans en is verwijderd."), + messages[0]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het geregistreerde resultaat voor de toets op maat in 'Vak 2' ('-10.0') kon niet worden geconverteerd naar een geldige kans en is verwijderd."), + messages[1]); + } + + private static void AssertLogDatabase(string logFilePath) + { + using (var reader = new MigrationLogDatabaseReader(logFilePath)) + { + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + + Assert.AreEqual(50, messages.Count); + var i = 0; + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, "Gevolgen van de migratie van versie 17.1 naar versie 17.2:"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, "* Alle berekende resultaten zijn verwijderd, behalve die van het toetsspoor 'Piping' waarbij de waterstand handmatig is ingevuld."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, "* Traject: 'assessmentSection'"), + messages[i++]); + AssertAssessmentSectionNormMigrationMessage(new[] + { + messages[i++], + messages[i++], + messages[i++] + }, 30000, 30000, NormType.Signaling); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Hoogte kunstwerk'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het ID van kunstwerk '10' is veranderd naar '104'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Betrouwbaarheid sluiting kunstwerk'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het ID van kunstwerk '1' is veranderd naar '102'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Golfklappen op asfaltbekleding'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het ID van voorlandprofiel '10' is veranderd naar '10000000000000000000004'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Stabiliteit steenzetting'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het ID van voorlandprofiel '100' is veranderd naar '10000000000000000000006'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Sterkte en stabiliteit puntconstructies'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het ID van kunstwerk '1' is veranderd naar '103'."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, "* Traject: 'Demo traject'"), + messages[i++]); + AssertAssessmentSectionNormMigrationMessage(new[] + { + messages[i++], + messages[i++], + messages[i++] + }, 1000, 30000, NormType.Signaling); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Betrouwbaarheid sluiting kunstwerk'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het ID van kunstwerk '10' is veranderd naar '104'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Sterkte en stabiliteit puntconstructies'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " - Het ID van kunstwerk '10' is veranderd naar '104'."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, "* Traject: 'Empty'"), + messages[i++]); + AssertAssessmentSectionNormMigrationMessage(new[] + { + messages[i++], + messages[i++], + messages[i++] + }, 1000, 1000, NormType.Signaling); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, "* Traject: 'assessmentSectionResults'"), + messages[i++]); + AssertAssessmentSectionNormMigrationMessage(new[] + { + messages[i++], + messages[i++], + messages[i++] + }, 1000, 3000, NormType.Signaling); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Piping'"), + messages[i++]); + AssertLayerThreeMigrationMessage(new[] + { + messages[i++], + messages[i++] + }); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Grasbekleding erosie kruin en binnentalud'"), + messages[i++]); + AssertLayerThreeMigrationMessage(new[] + { + messages[i++], + messages[i++] + }); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Hoogte kunstwerk'"), + messages[i++]); + AssertLayerThreeMigrationMessage(new[] + { + messages[i++], + messages[i++] + }); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Betrouwbaarheid sluiting kunstwerk'"), + messages[i++]); + AssertLayerThreeMigrationMessage(new[] + { + messages[i++], + messages[i++] + }); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Macrostabiliteit binnenwaarts'"), + messages[i++]); + AssertLayerThreeMigrationMessage(new[] + { + messages[i++], + messages[i++] + }); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.1", newVersion, " + Toetsspoor: 'Sterkte en stabiliteit puntconstructies'"), + messages[i++]); + AssertLayerThreeMigrationMessage(new[] + { + messages[i++], + messages[i] + }); + } + } + + private static void AssertVersions(MigratedDatabaseReader reader) + { + const string validateVersion = + "SELECT COUNT() = 1 " + + "FROM [VersionEntity] " + + "WHERE [Version] = \"17.2\";"; + reader.AssertReturnedDataIsValid(validateVersion); + } + + private static void AssertDatabase(MigratedDatabaseReader reader) + { + const string validateForeignKeys = + "PRAGMA foreign_keys;"; + reader.AssertReturnedDataIsValid(validateForeignKeys); + } + + /// + /// Class for combination of an assessment section id with signaling and lower limit return period. + /// + private class AssessmentSectionReturnPeriod + { + /// + /// Creates a new instance of . + /// + /// The assessment section identifier. + /// The signaling return period. + /// The lower limit return period. + public AssessmentSectionReturnPeriod(string id, int signalingReturnPeriod, int lowerLimitPeriod) + { + Id = id; + SignalingReturnPeriod = signalingReturnPeriod; + LowerLimitPeriod = lowerLimitPeriod; + } + + /// + /// Gets the identifier of the assessment section. + /// + public string Id { get; } + + /// + /// Gets the signaling return period which has been defined on the assessment section. + /// + public int SignalingReturnPeriod { get; } + + /// + /// Gets the lower limit return period which has been defined on the assessment section. + /// + public int LowerLimitPeriod { get; } + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo173IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo173IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo173IntegrationTest.cs (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,227 @@ +// Copyright (C) Stichting Deltares 2018. 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.ObjectModel; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Migration.Core; +using Riskeer.Migration.Core.TestUtil; + +namespace Riskeer.Migration.Integration.Test +{ + public class MigrationTo173IntegrationTest + { + private const string newVersion = "17.3"; + + [Test] + public void Given172Project_WhenUpgradedTo173_ThenProjectAsExpected() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, + "MigrationTestProject172.rtd"); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given172Project_WhenUpgradedTo173_ThenProjectAsExpected)); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Given172Project_WhenUpgradedTo173_ThenProjectAsExpected), ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // When + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + using (var reader = new MigratedDatabaseReader(targetFilePath)) + { + AssertTablesContentMigrated(reader, sourceFilePath); + + AssertVersions(reader); + AssertDatabase(reader); + + AssertMacroStabilityInwardsOutput(reader); + } + + AssertLogDatabase(logFilePath); + } + } + + private static void AssertTablesContentMigrated(MigratedDatabaseReader reader, string sourceFilePath) + { + string[] tables = + { + "AssessmentSectionEntity", + "BackgroundDataEntity", + "BackgroundDataMetaEntity", + "CalculationGroupEntity", + "ClosingStructureEntity", + "ClosingStructuresCalculationEntity", + "ClosingStructuresFailureMechanismMetaEntity", + "ClosingStructuresOutputEntity", + "ClosingStructuresSectionResultEntity", + "DikeProfileEntity", + "DuneErosionFailureMechanismMetaEntity", + "DuneErosionSectionResultEntity", + "DuneLocationEntity", + "DuneLocationOutputEntity", + "FailureMechanismEntity", + "FailureMechanismSectionEntity", + "FaultTreeIllustrationPointEntity", + "FaultTreeIllustrationPointStochastEntity", + "FaultTreeSubmechanismIllustrationPointEntity", + "ForeshoreProfileEntity", + "GeneralResultFaultTreeIllustrationPointEntity", + "GeneralResultFaultTreeIllustrationPointStochastEntity", + "GeneralResultSubMechanismIllustrationPointEntity", + "GeneralResultSubMechanismIllustrationPointStochastEntity", + "GrassCoverErosionInwardsCalculationEntity", + "GrassCoverErosionInwardsDikeHeightOutputEntity", + "GrassCoverErosionInwardsFailureMechanismMetaEntity", + "GrassCoverErosionInwardsOutputEntity", + "GrassCoverErosionInwardsOvertoppingRateOutputEntity", + "GrassCoverErosionInwardsSectionResultEntity", + "GrassCoverErosionOutwardsFailureMechanismMetaEntity", + "GrassCoverErosionOutwardsHydraulicLocationEntity", + "GrassCoverErosionOutwardsHydraulicLocationOutputEntity", + "GrassCoverErosionOutwardsSectionResultEntity", + "GrassCoverErosionOutwardsWaveConditionsCalculationEntity", + "GrassCoverErosionOutwardsWaveConditionsOutputEntity", + "GrassCoverSlipOffInwardsSectionResultEntity", + "GrassCoverSlipOffOutwardsSectionResultEntity", + "HeightStructureEntity", + "HeightStructuresCalculationEntity", + "HeightStructuresFailureMechanismMetaEntity", + "HeightStructuresOutputEntity", + "HeightStructuresSectionResultEntity", + "HydraulicLocationEntity", + "HydraulicLocationOutputEntity", + "IllustrationPointResultEntity", + "MacroStabilityInwardsCalculationEntity", + "MacroStabilityInwardsCharacteristicPointEntity", + "MacroStabilityInwardsFailureMechanismMetaEntity", + "MacroStabilityInwardsPreconsolidationStressEntity", + "MacroStabilityInwardsSectionResultEntity", + "MacroStabilityInwardsSoilLayerOneDEntity", + "MacroStabilityInwardsSoilLayerTwoDEntity", + "MacroStabilityInwardsSoilProfileOneDEntity", + "MacroStabilityInwardsSoilProfileTwoDEntity", + "MacroStabilityInwardsSoilProfileTwoDSoilLayerTwoDEntity", + "MacroStabilityInwardsStochasticSoilProfileEntity", + "MacrostabilityOutwardsSectionResultEntity", + "MicrostabilitySectionResultEntity", + "PipingCalculationEntity", + "PipingCalculationOutputEntity", + "PipingCharacteristicPointEntity", + "PipingFailureMechanismMetaEntity", + "PipingSectionResultEntity", + "PipingSemiProbabilisticOutputEntity", + "PipingSoilLayerEntity", + "PipingSoilProfileEntity", + "PipingStochasticSoilProfileEntity", + "PipingStructureSectionResultEntity", + "ProjectEntity", + "StabilityPointStructureEntity", + "StabilityPointStructuresCalculationEntity", + "StabilityPointStructuresFailureMechanismMetaEntity", + "StabilityPointStructuresOutputEntity", + "StabilityPointStructuresSectionResultEntity", + "StabilityStoneCoverFailureMechanismMetaEntity", + "StabilityStoneCoverSectionResultEntity", + "StabilityStoneCoverWaveConditionsCalculationEntity", + "StabilityStoneCoverWaveConditionsOutputEntity", + "StochastEntity", + "StochasticSoilModelEntity", + "StrengthStabilityLengthwiseConstructionSectionResultEntity", + "SubMechanismIllustrationPointEntity", + "SubMechanismIllustrationPointStochastEntity", + "SurfaceLineEntity", + "TechnicalInnovationSectionResultEntity", + "TopLevelFaultTreeIllustrationPointEntity", + "TopLevelSubMechanismIllustrationPointEntity", + "VersionEntity", + "WaterPressureAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverFailureMechanismMetaEntity", + "WaveImpactAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverWaveConditionsCalculationEntity", + "WaveImpactAsphaltCoverWaveConditionsOutputEntity" + }; + + foreach (string table in tables) + { + string validateMigratedTable = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + $"SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].{table}) " + + $"FROM {table};" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateMigratedTable); + } + } + + private static void AssertLogDatabase(string logFilePath) + { + using (var reader = new MigrationLogDatabaseReader(logFilePath)) + { + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + + Assert.AreEqual(2, messages.Count); + var i = 0; + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.2", newVersion, "Gevolgen van de migratie van versie 17.2 naar versie 17.3:"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.2", newVersion, "* Alle berekende resultaten van het toetsspoor 'Macrostabiliteit binnenwaarts' zijn verwijderd."), + messages[i]); + } + } + + private static void AssertVersions(MigratedDatabaseReader reader) + { + const string validateVersion = + "SELECT COUNT() = 1 " + + "FROM [VersionEntity] " + + "WHERE [Version] = \"17.3\";"; + reader.AssertReturnedDataIsValid(validateVersion); + } + + private static void AssertDatabase(MigratedDatabaseReader reader) + { + const string validateForeignKeys = + "PRAGMA foreign_keys;"; + reader.AssertReturnedDataIsValid(validateForeignKeys); + } + + private static void AssertMacroStabilityInwardsOutput(MigratedDatabaseReader reader) + { + const string validateMacroStabilityInwardsCalculationOutput = + "SELECT COUNT() = 0 " + + "FROM [MacroStabilityInwardsCalculationOutputEntity]"; + reader.AssertReturnedDataIsValid(validateMacroStabilityInwardsCalculationOutput); + + const string validateMacroStabilityInwardsSemiProbabiliticOutput = + "SELECT COUNT() = 0 " + + "FROM [MacroStabilityInwardsSemiProbabilisticOutputEntity]"; + reader.AssertReturnedDataIsValid(validateMacroStabilityInwardsSemiProbabiliticOutput); + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo181IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo181IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo181IntegrationTest.cs (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,2578 @@ +// Copyright (C) Stichting Deltares 2018. 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.Collections.ObjectModel; +using System.ComponentModel; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Riskeer.Migration.Core; +using Riskeer.Migration.Core.TestUtil; + +namespace Riskeer.Migration.Integration.Test +{ + public class MigrationTo181IntegrationTest + { + /// + /// Enum to indicate the normative norm type. + /// + private enum NormativeNormType + { + /// + /// Represents the lower limit norm. + /// + LowerLimitNorm = 1, + + /// + /// Represents the signaling norm. + /// + SignalingNorm = 2 + } + + private const string newVersion = "18.1"; + + [Test] + public void Given173Project_WhenUpgradedTo181_ThenProjectAsExpected() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, + "MigrationTestProject173.rtd"); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given173Project_WhenUpgradedTo181_ThenProjectAsExpected)); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Given173Project_WhenUpgradedTo181_ThenProjectAsExpected), ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // When + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + using (var reader = new MigratedDatabaseReader(targetFilePath)) + { + AssertTablesContentMigrated(reader, sourceFilePath); + + AssertVersions(reader); + AssertDatabase(reader); + + AssertAssessmentSection(reader, sourceFilePath); + AssertHydraulicBoundaryLocationsProperties(reader, sourceFilePath); + AssertHydraulicBoundaryLocationsOnAssessmentSection(reader, sourceFilePath); + AssertHydraulicBoundaryLocationsOnGrassCoverErosionOutwardsFailureMechanism(reader, sourceFilePath); + AssertFailureMechanisms(reader, sourceFilePath); + + AssertFailureMechanismRelatedOutput(reader); + AssertPipingOutput(reader, sourceFilePath); + AssertMacroStabilityInwardsOutput(reader, sourceFilePath); + + AssertPipingSoilLayers(reader); + AssertStabilityStoneCoverFailureMechanism(reader); + AssertMacroStabilityOutwardsFailureMechanism(reader); + AssertPipingStructureFailureMechanism(reader); + AssertWaveImpactAsphaltCoverFailureMechanism(reader); + + AssertGrassCoverErosionOutwardsFailureMechanismMetaEntity(reader, sourceFilePath); + + AssertDuneErosionFailureMechanismMetaEntity(reader, sourceFilePath); + AssertDuneLocations(reader, sourceFilePath); + + AssertHeightStructuresSectionResultEntity(reader, sourceFilePath); + AssertClosingStructuresSectionResultEntity(reader, sourceFilePath); + AssertStabilityPointStructuresSectionResultEntity(reader, sourceFilePath); + AssertGrassCoverErosionInwardsSectionResultEntity(reader, sourceFilePath); + + AssertPipingSectionResultEntity(reader, sourceFilePath); + AssertMacroStabilityInwardsSectionResultEntity(reader, sourceFilePath); + + AssertDuneErosionSectionResultEntity(reader, sourceFilePath); + AssertGrassCoverErosionOutwardsSectionResultEntity(reader, sourceFilePath); + AssertStabilityStoneCoverSectionResultEntity(reader, sourceFilePath); + AssertWaveImpactAsphaltCoverSectionResultEntity(reader, sourceFilePath); + + AssertGrassCoverSlipOffInwardsSectionResultEntity(reader, sourceFilePath); + AssertGrassCoverSlipOffOutwardsSectionResultEntity(reader, sourceFilePath); + AssertMacroStabilityOutwardsSectionResultEntity(reader, sourceFilePath); + AssertMicrostabilitySectionResultEntity(reader, sourceFilePath); + AssertPipingStructureSectionResultEntity(reader, sourceFilePath); + AssertStrengthStabilityLengthwiseConstructionSectionResultEntity(reader, sourceFilePath); + AssertTechnicalInnovationSectionResultEntity(reader, sourceFilePath); + AssertWaterPressureAsphaltCoverSectionResultEntity(reader, sourceFilePath); + + AssertWaveConditionsCalculations(reader, sourceFilePath); + + MigratedSerializedDataTestHelper.AssertSerializedMacroStabilityInwardsOutput(reader); + MigratedSerializedDataTestHelper.AssertSerializedDikeProfileRoughnessPoints(reader); + MigratedSerializedDataTestHelper.AssertSerializedSurfaceLine(reader); + MigratedSerializedDataTestHelper.AssertSerializedPoint2DCollection(reader); + + AssertClosingStructure(reader, sourceFilePath); + AssertClosingStructureCalculation(reader, sourceFilePath); + + AssertStabilityPointStructureCalculation(reader, sourceFilePath); + } + + AssertLogDatabase(logFilePath); + } + } + + private static void AssertClosingStructure(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateClosingStructureProbabilityOpenStructureBeforeFlooding = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "SUM([IsInvalid]) = 0 " + + "FROM " + + "( " + + "SELECT " + + "CASE WHEN (NEW.[ProbabilityOpenStructureBeforeFlooding] IS NOT OLD.[ProbabilityOrFrequencyOpenStructureBeforeFlooding] " + + "AND OLD.[ProbabilityOrFrequencyOpenStructureBeforeFlooding] <= 1) " + + "OR (NEW.[ProbabilityOpenStructureBeforeFlooding] IS NOT NULL AND OLD.[ProbabilityOrFrequencyOpenStructureBeforeFlooding] > 1) " + + "THEN 1 " + + "ELSE 0 " + + "END AS [IsInvalid] " + + "FROM ClosingStructureEntity NEW " + + "JOIN [SOURCEPROJECT].ClosingStructureEntity OLD USING (ClosingStructureEntityId) " + + "); " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateClosingStructureProbabilityOpenStructureBeforeFlooding); + + string validateIdenticalApertures = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "SUM([IsInvalid]) = 0 " + + "FROM " + + "( " + + "SELECT " + + "CASE WHEN (NEW.[IdenticalApertures] != OLD.[IdenticalApertures] " + + "AND OLD.[IdenticalApertures] >= 1) " + + "OR (NEW.[IdenticalApertures] != 1 AND OLD.[IdenticalApertures] < 1) " + + "THEN 1 " + + "ELSE 0 " + + "END AS [IsInvalid] " + + "FROM ClosingStructureEntity NEW " + + "JOIN [SOURCEPROJECT].ClosingStructureEntity OLD USING (ClosingStructureEntityId) " + + "); " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateIdenticalApertures); + + string validateClosingStructure = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].ClosingStructureEntity) " + + "FROM ClosingStructureEntity NEW " + + "JOIN [SOURCEPROJECT].ClosingStructureEntity OLD USING(ClosingStructureEntityId) " + + "WHERE NEW.FailureMechanismEntityId = OLD.FailureMechanismEntityId " + + "AND NEW.\"Order\" = OLD.\"Order\"; " + + "AND NEW.Name = OLD.Name " + + "AND NEW.X IS OLD.X " + + "AND NEW.Y IS OLD.Y" + + "AND NEW.StructureNormalOrientation IS OLD.StructureNormalOrientation" + + "AND NEW.StorageStructureAreaMean IS OLD.StorageStructureAreaMean" + + "AND NEW.StorageStructureAreaCoefficientOfVariation IS OLD.StorageStructureAreaCoefficientOfVariation" + + "AND NEW.AllowedLevelIncreaseStorageMean IS OLD.AllowedLevelIncreaseStorageMean" + + "AND NEW.AllowedLevelIncreaseStorageStandardDeviation IS OLD.AllowedLevelIncreaseStorageStandardDeviation" + + "AND NEW.WidthFlowAperturesMean IS OLD.WidthFlowAperturesMean" + + "AND NEW.WidthFlowAperturesStandardDeviation IS OLD.WidthFlowAperturesStandardDeviation" + + "AND NEW.LevelCrestStructureNotClosingMean IS OLD.LevelCrestStructureNotClosingMean" + + "AND NEW.LevelCrestStructureNotClosingStandardDeviation IS OLD.LevelCrestStructureNotClosingStandardDeviation" + + "AND NEW.InsideWaterLevelMean IS OLD.InsideWaterLevelMean" + + "AND NEW.InsideWaterLevelStandardDeviation IS OLD.InsideWaterLevelStandardDeviation" + + "AND NEW.ThresholdHeightOpenWeirMean IS OLD.ThresholdHeightOpenWeirMean" + + "AND NEW.ThresholdHeightOpenWeirStandardDeviation IS OLD.ThresholdHeightOpenWeirStandardDeviation" + + "AND NEW.AreaFlowAperturesMean IS OLD.AreaFlowAperturesMean" + + "AND NEW.AreaFlowAperturesStandardDeviation IS OLD.AreaFlowAperturesStandardDeviation" + + "AND NEW.CriticalOvertoppingDischargeMean IS OLD.CriticalOvertoppingDischargeMean" + + "AND NEW.CriticalOvertoppingDischargeCoefficientOfVariation IS OLD.CriticalOvertoppingDischargeCoefficientOfVariation" + + "AND NEW.FlowWidthAtBottomProtectionMean IS OLD.FlowWidthAtBottomProtectionMean" + + "AND NEW.FlowWidthAtBottomProtectionStandardDeviation IS OLD.FlowWidthAtBottomProtectionStandardDeviation" + + "AND NEW.FailureProbabilityOpenStructure IS OLD.FailureProbabilityOpenStructure" + + "AND NEW.FailureProbabilityReparation IS OLD.FailureProbabilityReparation" + + "AND NEW.InflowModelType IS OLD.InflowModelType;" + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateClosingStructure); + } + + private static void AssertClosingStructureCalculation(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateIdenticalApertures = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCE; " + + "SELECT " + + "SUM([IsInvalid]) = 0 " + + "FROM " + + "( " + + "SELECT " + + "CASE WHEN (NEW.[IdenticalApertures] != OLD.[IdenticalApertures] " + + "AND OLD.[IdenticalApertures] >= 1) " + + "OR (NEW.[IdenticalApertures] != 1 AND OLD.[IdenticalApertures] < 1) " + + "THEN 1 " + + "ELSE 0 " + + "END AS [IsInvalid] " + + "FROM ClosingStructuresCalculationEntity NEW " + + "JOIN [SOURCE].ClosingStructuresCalculationEntity OLD USING (ClosingStructuresCalculationEntityId) " + + "); " + + "DETACH DATABASE SOURCE;"; + reader.AssertReturnedDataIsValid(validateIdenticalApertures); + + string validateClosingStructureCalculation = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCE; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCE].ClosingStructuresCalculationEntity) " + + "FROM ClosingStructuresCalculationEntity NEW " + + "JOIN [SOURCE].ClosingStructuresCalculationEntity OLD USING(ClosingStructuresCalculationEntityId) " + + "WHERE OLD.CalculationGroupEntityId = NEW.CalculationGroupEntityId " + + "AND OLD.ForeshoreProfileEntityId IS NEW.ForeshoreProfileEntityId " + + "AND OLD.HydraulicLocationEntityId IS NEW.HydraulicLocationEntityId " + + "AND OLD.ClosingStructureEntityId IS NEW.ClosingStructureEntityId " + + "AND OLD.\"Order\" = NEW.\"Order\" " + + "AND OLD.Name IS NEW.Name " + + "AND OLD.Comments IS NEW.Comments " + + "AND OLD.UseBreakWater = NEW.UseBreakWater " + + "AND OLD.BreakWaterType = NEW.BreakWaterType " + + "AND OLD.BreakWaterHeight IS NEW.BreakWaterHeight " + + "AND OLD.UseForeshore = NEW.UseForeshore " + + "AND OLD.Orientation IS NEW.Orientation " + + "AND OLD.StructureNormalOrientation IS NEW.StructureNormalOrientation " + + "AND OLD.StorageStructureAreaMean IS NEW.StorageStructureAreaMean " + + "AND OLD.StorageStructureAreaCoefficientOfVariation IS NEW.StorageStructureAreaCoefficientOfVariation " + + "AND OLD.AllowedLevelIncreaseStorageMean IS NEW.AllowedLevelIncreaseStorageMean " + + "AND OLD.AllowedLevelIncreaseStorageStandardDeviation IS NEW.AllowedLevelIncreaseStorageStandardDeviation " + + "AND OLD.WidthFlowAperturesMean IS NEW.WidthFlowAperturesMean " + + "AND OLD.WidthFlowAperturesStandardDeviation IS NEW.WidthFlowAperturesStandardDeviation " + + "AND OLD.LevelCrestStructureNotClosingMean IS NEW.LevelCrestStructureNotClosingMean " + + "AND OLD.LevelCrestStructureNotClosingStandardDeviation IS NEW.LevelCrestStructureNotClosingStandardDeviation " + + "AND OLD.InsideWaterLevelMean IS NEW.InsideWaterLevelMean " + + "AND OLD.InsideWaterLevelStandardDeviation IS NEW.InsideWaterLevelStandardDeviation " + + "AND OLD.ThresholdHeightOpenWeirMean IS NEW.ThresholdHeightOpenWeirMean " + + "AND OLD.ThresholdHeightOpenWeirStandardDeviation IS NEW.ThresholdHeightOpenWeirStandardDeviation " + + "AND OLD.AreaFlowAperturesMean IS NEW.AreaFlowAperturesMean " + + "AND OLD.AreaFlowAperturesStandardDeviation IS NEW.AreaFlowAperturesStandardDeviation " + + "AND OLD.CriticalOvertoppingDischargeMean IS NEW.CriticalOvertoppingDischargeMean " + + "AND OLD.CriticalOvertoppingDischargeCoefficientOfVariation IS NEW.CriticalOvertoppingDischargeCoefficientOfVariation " + + "AND OLD.FlowWidthAtBottomProtectionMean IS NEW.FlowWidthAtBottomProtectionMean " + + "AND OLD.FlowWidthAtBottomProtectionStandardDeviation IS NEW.FlowWidthAtBottomProtectionStandardDeviation " + + "AND OLD.ProbabilityOrFrequencyOpenStructureBeforeFlooding = NEW.ProbabilityOpenStructureBeforeFlooding " + + "AND OLD.FailureProbabilityOpenStructure = NEW.FailureProbabilityOpenStructure " + + "AND OLD.FailureProbabilityReparation = NEW.FailureProbabilityReparation " + + "AND OLD.InflowModelType = NEW.InflowModelType " + + "AND OLD.FailureProbabilityStructureWithErosion = NEW.FailureProbabilityStructureWithErosion " + + "AND OLD.DeviationWaveDirection IS NEW.DeviationWaveDirection " + + "AND OLD.DrainCoefficientMean IS NEW.DrainCoefficientMean " + + "AND OLD.ModelFactorSuperCriticalFlowMean IS NEW.ModelFactorSuperCriticalFlowMean " + + "AND OLD.StormDurationMean IS NEW.StormDurationMean " + + "AND OLD.FactorStormDurationOpenStructure IS NEW.FactorStormDurationOpenStructure " + + "AND OLD.ShouldIllustrationPointsBeCalculated = NEW.ShouldIllustrationPointsBeCalculated;" + + "DETACH DATABASE SOURCE;"; + reader.AssertReturnedDataIsValid(validateClosingStructureCalculation); + } + + private static void AssertStabilityPointStructureCalculation(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateLevellingCount = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCE; " + + "SELECT " + + "SUM([IsInvalid]) = 0 " + + "FROM " + + "( " + + "SELECT " + + "CASE WHEN (NEW.[LevellingCount] != OLD.[LevellingCount] " + + "AND OLD.[LevellingCount] >= 0) " + + "OR (NEW.[LevellingCount] != 0 AND OLD.[LevellingCount] < 0) " + + "THEN 1 " + + "ELSE 0 " + + "END AS [IsInvalid] " + + "FROM StabilityPointStructuresCalculationEntity NEW " + + "JOIN [SOURCE].StabilityPointStructuresCalculationEntity OLD USING (StabilityPointStructuresCalculationEntityId) " + + "); " + + "DETACH DATABASE SOURCE;"; + reader.AssertReturnedDataIsValid(validateLevellingCount); + + string validateVerticalDistance = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCE; " + + "SELECT " + + "SUM([IsInvalid]) = 0 " + + "FROM " + + "( " + + "SELECT " + + "CASE WHEN (NEW.[VerticalDistance] IS NOT OLD.[VerticalDistance] " + + "AND OLD.[VerticalDistance] >= 0) " + + "OR (NEW.[VerticalDistance] IS NOT NULL AND OLD.[VerticalDistance] < 0) " + + "THEN 1 " + + "ELSE 0 " + + "END AS [IsInvalid] " + + "FROM StabilityPointStructuresCalculationEntity NEW " + + "JOIN [SOURCE].StabilityPointStructuresCalculationEntity OLD USING (StabilityPointStructuresCalculationEntityId) " + + "); " + + "DETACH DATABASE SOURCE;"; + reader.AssertReturnedDataIsValid(validateVerticalDistance); + + string validateStabilityPointStructureCalculation = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCE; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCE].StabilityPointStructuresCalculationEntity) " + + "FROM StabilityPointStructuresCalculationEntity NEW " + + "JOIN [SOURCE].StabilityPointStructuresCalculationEntity OLD USING(StabilityPointStructuresCalculationEntityId) " + + "WHERE OLD.CalculationGroupEntityId = NEW.CalculationGroupEntityId " + + "AND OLD.ForeshoreProfileEntityId IS NEW.ForeshoreProfileEntityId " + + "AND OLD.HydraulicLocationEntityId IS NEW.HydraulicLocationEntityId " + + "AND OLD.StabilityPointStructureEntityId IS NEW.StabilityPointStructureEntityId " + + "AND OLD.\"Order\" = NEW.\"Order\" " + + "AND OLD.Name IS NEW.Name " + + "AND OLD.Comments IS NEW.Comments " + + "AND OLD.UseBreakWater = NEW.UseBreakWater " + + "AND OLD.BreakWaterType = NEW.BreakWaterType " + + "AND OLD.BreakWaterHeight IS NEW.BreakWaterHeight " + + "AND OLD.UseForeshore = NEW.UseForeshore " + + "AND OLD.StructureNormalOrientation IS NEW.StructureNormalOrientation " + + "AND OLD.StorageStructureAreaMean IS NEW.StorageStructureAreaMean " + + "AND OLD.StorageStructureAreaCoefficientOfVariation IS NEW.StorageStructureAreaCoefficientOfVariation " + + "AND OLD.AllowedLevelIncreaseStorageMean IS NEw.AllowedLevelIncreaseStorageMean " + + "AND OLD.AllowedLevelIncreaseStorageStandardDeviation IS NEW.AllowedLevelIncreaseStorageStandardDeviation " + + "AND OLD.WidthFlowAperturesMean IS NEW.WidthFlowAperturesMean " + + "AND OLD.WidthFlowAperturesStandardDeviation IS NEW.WidthFlowAperturesStandardDeviation " + + "AND OLD.InsideWaterLevelMean IS NEW.InsideWaterLevelMean " + + "AND OLD.InsideWaterLevelStandardDeviation IS NEW.InsideWaterLevelStandardDeviation " + + "AND OLD.ThresholdHeightOpenWeirMean IS NEW.ThresholdHeightOpenWeirMean " + + "AND OLD.ThresholdHeightOpenWeirStandardDeviation IS NEW.ThresholdHeightOpenWeirStandardDeviation " + + "AND OLD.CriticalOvertoppingDischargeMean IS NEW.CriticalOvertoppingDischargeMean " + + "AND OLD.CriticalOvertoppingDischargeCoefficientOfVariation IS NEW.CriticalOvertoppingDischargeCoefficientOfVariation " + + "AND OLD.FlowWidthAtBottomProtectionMean IS NEW.FlowWidthAtBottomProtectionMean " + + "AND OLD.FlowWidthAtBottomProtectionStandardDeviation IS NEW.FlowWidthAtBottomProtectionStandardDeviation " + + "AND OLD.ConstructiveStrengthLinearLoadModelMean IS NEW.ConstructiveStrengthLinearLoadModelMean " + + "AND OLD.ConstructiveStrengthLinearLoadModelCoefficientOfVariation IS NEW.ConstructiveStrengthLinearLoadModelCoefficientOfVariation " + + "AND OLD.ConstructiveStrengthQuadraticLoadModelMean IS NEW.ConstructiveStrengthQuadraticLoadModelMean " + + "AND OLD.ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation IS NEW.ConstructiveStrengthQuadraticLoadModelCoefficientOfVariation " + + "AND OLD.BankWidthMean IS NEW.BankWidthMean " + + "AND OLD.BankWidthStandardDeviation IS NEW.BankWidthStandardDeviation " + + "AND OLD.InsideWaterLevelFailureConstructionMean IS NEW.InsideWaterLevelFailureConstructionMean " + + "AND OLD.InsideWaterLevelFailureConstructionStandardDeviation IS NEW.InsideWaterLevelFailureConstructionStandardDeviation " + + "AND OLD.EvaluationLevel IS NEW.EvaluationLevel " + + "AND OLD.LevelCrestStructureMean IS NEW.LevelCrestStructureMean " + + "AND OLD.LevelCrestStructureStandardDeviation IS NEW.LevelCrestStructureStandardDeviation " + + "AND OLD.FailureProbabilityRepairClosure = NEW.FailureProbabilityRepairClosure " + + "AND OLD.FailureCollisionEnergyMean IS NEW.FailureCollisionEnergyMean " + + "AND OLD.FailureCollisionEnergyCoefficientOfVariation IS NEW.FailureCollisionEnergyCoefficientOfVariation " + + "AND OLD.ShipMassMean IS NEW.ShipMassMean " + + "AND OLD.ShipMassCoefficientOfVariation IS NEW.ShipMassCoefficientOfVariation " + + "AND OLD.ShipVelocityMean IS NEW.ShipVelocityMean " + + "AND OLD.ShipVelocityCoefficientOfVariation IS NEW.ShipVelocityCoefficientOfVariation " + + "AND OLD.ProbabilityCollisionSecondaryStructure = NEW.ProbabilityCollisionSecondaryStructure " + + "AND OLD.FlowVelocityStructureClosableMean IS NEW.FlowVelocityStructureClosableMean " + + "AND OLD.StabilityLinearLoadModelMean IS NEW.StabilityLinearLoadModelMean " + + "AND OLD.StabilityLinearLoadModelCoefficientOfVariation IS NEW.StabilityLinearLoadModelCoefficientOfVariation " + + "AND OLD.StabilityQuadraticLoadModelMean IS NEW.StabilityQuadraticLoadModelMean " + + "AND OLD.StabilityQuadraticLoadModelCoefficientOfVariation IS NEW.StabilityQuadraticLoadModelCoefficientOfVariation " + + "AND OLD.AreaFlowAperturesMean IS NEW.AreaFlowAperturesMean " + + "AND OLD.AreaFlowAperturesStandardDeviation IS NEW.AreaFlowAperturesStandardDeviation " + + "AND OLD.InflowModelType = NEW.InflowModelType " + + "AND OLD.LoadSchematizationType = NEW.LoadSchematizationType " + + "AND OLD.VolumicWeightWater IS NEW.VolumicWeightWater " + + "AND OLD.StormDurationMean IS NEW.StormDurationMean " + + "AND OLD.FactorStormDurationOpenStructure IS NEW.FactorStormDurationOpenStructure " + + "AND OLD.DrainCoefficientMean IS NEW.DrainCoefficientMean " + + "AND OLD.FailureProbabilityStructureWithErosion = NEW.FailureProbabilityStructureWithErosion " + + "AND OLD.ShouldIllustrationPointsBeCalculated = NEW.ShouldIllustrationPointsBeCalculated;" + + "DETACH DATABASE SOURCE;"; + reader.AssertReturnedDataIsValid(validateStabilityPointStructureCalculation); + } + + private static void AssertTablesContentMigrated(MigratedDatabaseReader reader, string sourceFilePath) + { + string[] tables = + { + "AssessmentSectionEntity", + "BackgroundDataEntity", + "BackgroundDataMetaEntity", + "CalculationGroupEntity", + "ClosingStructureEntity", + "ClosingStructuresCalculationEntity", + "ClosingStructuresFailureMechanismMetaEntity", + "ClosingStructuresSectionResultEntity", + "DikeProfileEntity", + "DuneErosionFailureMechanismMetaEntity", + "DuneErosionSectionResultEntity", + "DuneLocationEntity", + "FailureMechanismEntity", + "FailureMechanismSectionEntity", + "ForeshoreProfileEntity", + "GrassCoverErosionInwardsCalculationEntity", + "GrassCoverErosionInwardsFailureMechanismMetaEntity", + "GrassCoverErosionInwardsSectionResultEntity", + "GrassCoverErosionOutwardsFailureMechanismMetaEntity", + "GrassCoverErosionOutwardsSectionResultEntity", + "GrassCoverErosionOutwardsWaveConditionsCalculationEntity", + "GrassCoverSlipOffInwardsSectionResultEntity", + "GrassCoverSlipOffOutwardsSectionResultEntity", + "HeightStructureEntity", + "HeightStructuresCalculationEntity", + "HeightStructuresFailureMechanismMetaEntity", + "HeightStructuresSectionResultEntity", + "HydraulicLocationEntity", + "IllustrationPointResultEntity", + "MacroStabilityInwardsCalculationEntity", + "MacroStabilityInwardsCharacteristicPointEntity", + "MacroStabilityInwardsFailureMechanismMetaEntity", + "MacroStabilityInwardsPreconsolidationStressEntity", + "MacroStabilityInwardsSectionResultEntity", + "MacroStabilityInwardsSemiProbabilisticOutputEntity", + "MacroStabilityInwardsSoilLayerOneDEntity", + "MacroStabilityInwardsSoilLayerTwoDEntity", + "MacroStabilityInwardsSoilProfileOneDEntity", + "MacroStabilityInwardsSoilProfileTwoDEntity", + "MacroStabilityInwardsSoilProfileTwoDSoilLayerTwoDEntity", + "MacroStabilityInwardsStochasticSoilProfileEntity", + "MacroStabilityOutwardsSectionResultEntity", + "MicrostabilitySectionResultEntity", + "PipingCalculationEntity", + "PipingCharacteristicPointEntity", + "PipingFailureMechanismMetaEntity", + "PipingSectionResultEntity", + "PipingSemiProbabilisticOutputEntity", + "PipingSoilLayerEntity", + "PipingSoilProfileEntity", + "PipingStochasticSoilProfileEntity", + "PipingStructureSectionResultEntity", + "ProjectEntity", + "StabilityPointStructureEntity", + "StabilityPointStructuresCalculationEntity", + "StabilityPointStructuresFailureMechanismMetaEntity", + "StabilityPointStructuresSectionResultEntity", + "StabilityStoneCoverSectionResultEntity", + "StabilityStoneCoverWaveConditionsCalculationEntity", + "StochasticSoilModelEntity", + "StrengthStabilityLengthwiseConstructionSectionResultEntity", + "SurfaceLineEntity", + "TechnicalInnovationSectionResultEntity", + "VersionEntity", + "WaterPressureAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverFailureMechanismMetaEntity", + "WaveImpactAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverWaveConditionsCalculationEntity" + }; + + foreach (string table in tables) + { + string validateMigratedTable = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + $"SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].{table}) " + + $"FROM {table};" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateMigratedTable); + } + } + + private static void AssertLogDatabase(string logFilePath) + { + using (var reader = new MigrationLogDatabaseReader(logFilePath)) + { + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + + Assert.AreEqual(73, messages.Count); + var i = 0; + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, "Gevolgen van de migratie van versie 17.3 naar versie 18.1:"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, "* Alle berekende resultaten zijn verwijderd, behalve die van het toetsspoor 'Piping' en 'Macrostabiliteit binnenwaarts' waarbij de waterstand handmatig is ingevuld."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, "* Traject: 'assessmentSectionResults'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Piping'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Hoogte kunstwerk'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Sterkte en stabiliteit langsconstructies'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Technische innovaties'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Wateroverdruk bij asfaltbekleding'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Betrouwbaarheid sluiting kunstwerk'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Macrostabiliteit binnenwaarts'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Macrostabiliteit buitenwaarts'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Golfklappen op asfaltbekleding'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de gedetailleerde toets van dit toetsspoor konden niet worden " + + "omgezet naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Grasbekleding erosie buitentalud'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de gedetailleerde toets van dit toetsspoor konden niet worden " + + "omgezet naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Grasbekleding afschuiven binnentalud'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de gedetailleerde toets van dit toetsspoor konden niet worden " + + "omgezet naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Grasbekleding afschuiven buitentalud'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de gedetailleerde toets van dit toetsspoor konden niet worden " + + "omgezet naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Microstabiliteit'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de gedetailleerde toets van dit toetsspoor konden niet worden " + + "omgezet naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Piping bij kunstwerk'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten met de waarde 'Voldoende / Niet relevant' voor de eenvoudige toets " + + "van dit toetsspoor zijn omgezet naar 'NVT'."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de gedetailleerde toets van dit toetsspoor konden niet worden " + + "omgezet naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Stabiliteit steenzetting'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de gedetailleerde toets van dit toetsspoor konden niet worden " + + "omgezet naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Duinafslag'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de gedetailleerde toets van dit toetsspoor konden niet worden " + + "omgezet naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - Alle resultaten voor de toets op maat van dit toetsspoor konden niet worden omgezet " + + "naar een geldig resultaat en zijn verwijderd."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, "* Traject: 'PipingSoilLayer'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Piping'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde '-0.125' voor de variatiecoëfficiënt van parameter 'd70' van ondergrondlaag 'DiameterD70Variation' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde '-1.0' voor het gemiddelde van parameter 'Doorlatendheid' van ondergrondlaag 'PermeabilityMean' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde '-1.0e-06' voor het gemiddelde van parameter 'd70' van ondergrondlaag 'DiameterD70Mean' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde '-10.0' voor de standaardafwijking van parameter 'Verzadigd gewicht' van ondergrondlaag 'BelowPhreaticLevelDeviation' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde '-10.0' voor de variatiecoëfficiënt van parameter 'Doorlatendheid' van ondergrondlaag 'PermeabilityVariation' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde '0.0' voor het gemiddelde van parameter 'Verzadigd gewicht' van ondergrondlaag 'BelowPhreaticLevelMean' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde '15.0' voor de verschuiving van parameter 'Verzadigd gewicht' van ondergrondlaag 'BelowPhreaticLevelShift' is ongeldig en is veranderd naar NaN."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, "* Traject: 'Closing Structures Invalid Data'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Betrouwbaarheid sluiting kunstwerk'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde van '-11' van parameter 'Aantal identieke doorstroomopeningen' van berekening 'Invalid Identical Apertures - Negative Value' is ongeldig en is veranderd naar 1."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde van '-11' van parameter 'Aantal identieke doorstroomopeningen' van kunstwerk 'Gemaal Leemans (Negatieve doorstroomopeningen)' is ongeldig en is veranderd naar 1."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde van '0' van parameter 'Aantal identieke doorstroomopeningen' van berekening 'Invalid Identical Apertures' is ongeldig en is veranderd naar 1."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde van '0' van parameter 'Aantal identieke doorstroomopeningen' van kunstwerk 'Gemaal Leemans' is ongeldig en is veranderd naar 1."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde van '1.1' van parameter 'Kans op open staan bij naderend hoogwater' van kunstwerk 'Gemaal Leemans' is ongeldig en is veranderd naar NaN."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, "* Traject: 'Stability Point Structures Data'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " + Toetsspoor: 'Sterkte en stabiliteit puntconstructies'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde van '-0.11' van parameter 'Afstand onderkant wand en teen van de dijk/berm' van berekening 'Invalid Vertical Distance' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", newVersion, " - De waarde van '-30' van parameter 'Aantal nivelleringen per jaar' van berekening 'Invalid Levelling Count' is ongeldig en is veranderd naar 0."), + messages[i]); + } + } + + private static void AssertVersions(MigratedDatabaseReader reader) + { + const string validateVersion = + "SELECT COUNT() = 1 " + + "FROM [VersionEntity] " + + "WHERE [Version] = \"18.1\";"; + reader.AssertReturnedDataIsValid(validateVersion); + } + + private static void AssertDatabase(MigratedDatabaseReader reader) + { + const string validateForeignKeys = + "PRAGMA foreign_keys;"; + reader.AssertReturnedDataIsValid(validateForeignKeys); + } + + private static void AssertFailureMechanisms(MigratedDatabaseReader reader, string sourceFilePath) + { + const string validateFailureMechanismSectionsSourcePath = + "SELECT SUM([IsInvalid]) = 0 " + + "FROM (SELECT " + + "CASE WHEN " + + "COUNT([FailureMechanismSectionEntityId]) AND [FailureMechanismSectionCollectionSourcePath] IS NULL " + + "OR " + + "[FailureMechanismSectionCollectionSourcePath] IS NOT NULL AND NOT COUNT([FailureMechanismSectionEntityId]) " + + "THEN 1 ELSE 0 END AS [IsInvalid] " + + "FROM [FailureMechanismEntity] " + + "LEFT JOIN [FailureMechanismSectionEntity] USING([FailureMechanismEntityId]) " + + "GROUP BY [FailureMechanismEntityId]);"; + reader.AssertReturnedDataIsValid(validateFailureMechanismSectionsSourcePath); + + string validateFailureMechanisms = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].FailureMechanismEntity) " + + "FROM FailureMechanismEntity NEW " + + "JOIN [SOURCEPROJECT].FailureMechanismEntity OLD USING (FailureMechanismEntityId) " + + "WHERE NEW.AssessmentSectionEntityId = OLD.AssessmentSectionEntityId " + + "AND NEW.CalculationGroupEntityId IS OLD.CalculationGroupEntityId " + + "AND NEW.FailureMechanismType = OLD.FailureMechanismType " + + "AND NEW.IsRelevant = OLD.IsRelevant " + + "AND NEW.InputComments IS OLD.InputComments " + + "AND NEW.OutputComments IS OLD.OutputComments " + + "AND NEW.NotRelevantComments IS OLD.NotRelevantComments; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateFailureMechanisms); + } + + private static void AssertPipingSoilLayers(MigratedDatabaseReader reader) + { + const string validateBelowPhreaticLevel = + "SELECT COUNT() = 0 " + + "FROM PipingSoilLayerEntity " + + "WHERE [BelowPhreaticLevelMean] < [BelowPhreaticLevelShift] " + + "OR [BelowPhreaticLevelMean] <= 0 " + + "OR [BelowPhreaticLevelDeviation] < 0;"; + reader.AssertReturnedDataIsValid(validateBelowPhreaticLevel); + + const string validateDiameter70 = + "SELECT COUNT() = 0 " + + "FROM PipingSoilLayerEntity " + + "WHERE [DiameterD70Mean] <= 0 " + + "OR [DiameterD70CoefficientOfVariation] < 0;"; + reader.AssertReturnedDataIsValid(validateDiameter70); + + const string validatePermeability = + "SELECT COUNT() = 0 " + + "FROM PipingSoilLayerEntity " + + "WHERE [PermeabilityMean] <= 0 " + + "OR [PermeabilityCoefficientOfVariation] < 0;"; + reader.AssertReturnedDataIsValid(validatePermeability); + } + + private static void AssertStabilityStoneCoverFailureMechanism(MigratedDatabaseReader reader) + { + const string validateStabilityStoneCoverFailureMechanisms = + "SELECT COUNT() = 0 " + + "FROM [StabilityStoneCoverFailureMechanismMetaEntity] " + + "WHERE [N] IS NOT 4;"; + reader.AssertReturnedDataIsValid(validateStabilityStoneCoverFailureMechanisms); + } + + private static void AssertMacroStabilityOutwardsFailureMechanism(MigratedDatabaseReader reader) + { + const string validateMacroStabilityOutwardsFailureMechanisms = + "SELECT COUNT() = (SELECT COUNT() FROM FailureMechanismEntity WHERE FailureMechanismType = 13) " + + "FROM [MacroStabilityOutwardsFailureMechanismMetaEntity] " + + "WHERE [A] = 0.033 " + + "AND [FailureMechanismEntityId] IN " + + "(SELECT [FailureMechanismEntityId] FROM [FailureMechanismEntity] WHERE [FailureMechanismType] = 13);"; + reader.AssertReturnedDataIsValid(validateMacroStabilityOutwardsFailureMechanisms); + } + + private static void AssertPipingStructureFailureMechanism(MigratedDatabaseReader reader) + { + const string validatePipingStructureFailureMechanisms = + "SELECT COUNT() = (SELECT COUNT() FROM FailureMechanismEntity WHERE FailureMechanismType = 11) " + + "FROM [PipingStructureFailureMechanismMetaEntity] " + + "WHERE [N] = 1.0 " + + "AND [FailureMechanismEntityId] IN " + + "(SELECT [FailureMechanismEntityId] FROM [FailureMechanismEntity] WHERE [FailureMechanismType] = 11);"; + reader.AssertReturnedDataIsValid(validatePipingStructureFailureMechanisms); + } + + private static void AssertWaveImpactAsphaltCoverFailureMechanism(MigratedDatabaseReader reader) + { + const string validateWaveImpactAsphaltCoverFailureMechanisms = + "SELECT COUNT() = 0 " + + "FROM [WaveImpactAsphaltCoverFailureMechanismMetaEntity] " + + "WHERE [DeltaL] IS NOT 1000;"; + reader.AssertReturnedDataIsValid(validateWaveImpactAsphaltCoverFailureMechanisms); + } + + private static void AssertAssessmentSection(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateAssessmentSectionEntities = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].AssessmentSectionEntity) " + + "FROM AssessmentSectionEntity NEW " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity AS OLD USING(AssessmentSectionEntityId) " + + "WHERE NEW.ProjectEntityId = OLD.ProjectEntityId " + + "AND NEW.Id = OLD.Id " + + "AND NEW.Name IS OLD.Name " + + "AND NEW.Comments IS OLD.Comments " + + "AND NEW.LowerLimitNorm = OLD.LowerLimitNorm " + + "AND NEW.SignalingNorm = OLD.SignalingNorm " + + "AND NEW.NormativeNormType = OLD.NormativeNormType " + + "AND NEW.HydraulicDatabaseVersion IS OLD.HydraulicDatabaseVersion " + + "AND NEW.HydraulicDatabaseLocation IS OLD.HydraulicDatabaseLocation " + + "AND NEW.Composition = OLD.Composition " + + "AND NEW.\"Order\" = OLD.\"Order\"; " + + "DETACH DATABASE SOURCEPROJECT;"; + + reader.AssertReturnedDataIsValid(validateAssessmentSectionEntities); + } + + private static void AssertHydraulicBoundaryLocationsProperties(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateMigratedHyraulicBoundaryLocations = $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].HydraulicLocationEntity) " + + "FROM HydraulicLocationEntity NEW " + + "JOIN [SourceProject].HydraulicLocationEntity AS OLD USING(HydraulicLocationEntityId) " + + "WHERE NEW.AssessmentSectionEntityId = OLD.AssessmentSectionEntityId " + + "AND NEW.LocationId = OLD.LocationId " + + "AND NEW.Name = OLD.Name " + + "AND NEW.LocationX = OLD.LocationX " + + "AND NEW.LocationY = OLD.LocationY " + + "AND NEW.\"Order\" = OLD.\"Order\"; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateMigratedHyraulicBoundaryLocations); + + string validateHydraulicLocationCalculationCount = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = 0 " + + "FROM " + + "( " + + "SELECT " + + "COUNT(distinct HydraulicLocationCalculationEntityId) AS NrOfCalculationsPerLocation " + + "FROM [SOURCEPROJECT].HydraulicLocationEntity " + + "LEFT JOIN HydraulicLocationCalculationEntity USING(HydraulicLocationEntityId) " + + "GROUP BY HydraulicLocationEntityId " + + ") " + + "WHERE NrOfCalculationsPerLocation IS NOT 14; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateHydraulicLocationCalculationCount); + + const string validateHydraulicBoundaryCalculationInputValues = "SELECT " + + "COUNT() = 0 " + + "FROM HydraulicLocationCalculationEntity " + + "WHERE ShouldIllustrationPointsBeCalculated != 0 AND ShouldIllustrationPointsBeCalculated != 1"; + reader.AssertReturnedDataIsValid(validateHydraulicBoundaryCalculationInputValues); + + string validateHydraulicLocationCalculationOutputCount = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = 0 " + + "FROM HydraulicLocationOutputEntity; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateHydraulicLocationCalculationOutputCount); + } + + private static void AssertHydraulicBoundaryLocationsOnAssessmentSection(MigratedDatabaseReader reader, string sourceFilePath) + { + var queryGenerator = new HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator(sourceFilePath); + AssertDesignWaterLevelCalculationEntitiesOnAssessmentSection(reader, queryGenerator); + AssertWaveHeightCalculationEntitiesOnAssessmentSection(reader, queryGenerator); + } + + private static void AssertHydraulicBoundaryLocationsOnGrassCoverErosionOutwardsFailureMechanism(MigratedDatabaseReader reader, string sourceFilePath) + { + var queryGenerator = new HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator(sourceFilePath); + + AssertDesignWaterLevelCalculationEntitiesOnGrassCoverErosionOutwardsFailureMechanism(reader, queryGenerator); + AssertWaveHeightCalculationEntitiesOnGrassCoverErosionOutwardsFailureMechanism(reader, queryGenerator); + } + + private static void AssertDuneLocations(MigratedDatabaseReader reader, string sourceFilePath) + { + var queryGenerator = new DuneErosionFailureMechanismValidationQueryGenerator(sourceFilePath); + + reader.AssertReturnedDataIsValid(queryGenerator.GetDuneLocationCalculationsCountValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForMechanismSpecificFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetDuneLocationCalculationsCountValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForMechanismSpecificSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetDuneLocationCalculationsCountValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForMechanismSpecificLowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetDuneLocationCalculationsCountValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForLowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetDuneLocationCalculationsCountValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForLowerFactorizedLimitNorm)); + + string validateDuneLocationOutput = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = 0 " + + "FROM DuneLocationCalculationOutputEntity; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateDuneLocationOutput); + } + + private static void AssertGrassCoverErosionOutwardsFailureMechanismMetaEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateMetaEntity = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].GrassCoverErosionOutwardsFailureMechanismMetaEntity) " + + "FROM GrassCoverErosionOutwardsFailureMechanismMetaEntity NEW " + + "JOIN [SOURCEPROJECT].GrassCoverErosionOutwardsFailureMechanismMetaEntity OLD USING(GrassCoverErosionOutwardsFailureMechanismMetaEntityId) " + + "WHERE new.FailureMechanismEntityId = OLD.FailureMechanismEntityId " + + "AND NEW.N = OLD.N " + + "AND NEW.ForeshoreProfileCollectionSourcePath IS OLD.ForeshoreProfileCollectionSourcePath; " + + "DETACH DATABASE SOURCEPROJECT;"; + + reader.AssertReturnedDataIsValid(validateMetaEntity); + } + + private static void AssertDuneErosionFailureMechanismMetaEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateMetaEntity = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].DuneErosionFailureMechanismMetaEntity) " + + "FROM DuneErosionFailureMechanismMetaEntity NEW " + + "JOIN [SOURCEPROJECT].DuneErosionFailureMechanismMetaEntity OLD USING(DuneErosionFailureMechanismMetaEntityId) " + + "WHERE new.FailureMechanismEntityId = OLD.FailureMechanismEntityId " + + "AND NEW.N = OLD.N; " + + "DETACH DATABASE SOURCEPROJECT;"; + + reader.AssertReturnedDataIsValid(validateMetaEntity); + } + + private static void AssertFailureMechanismRelatedOutput(MigratedDatabaseReader reader) + { + var tables = new[] + { + "ClosingStructuresOutputEntity", + "GrassCoverErosionOutwardsWaveConditionsOutputEntity", + "GrassCoverErosionInwardsDikeHeightOutputEntity", + "GrassCoverErosionInwardsOutputEntity", + "GrassCoverErosionInwardsOvertoppingRateOutputEntity", + "HeightStructuresOutputEntity", + "StabilityPointStructuresOutputEntity", + "StabilityStoneCoverWaveConditionsOutputEntity", + "WaveImpactAsphaltCoverWaveConditionsOutputEntity", + "TopLevelFaultTreeIllustrationPointEntity", + "TopLevelSubMechanismIllustrationPointEntity", + "GeneralResultFaultTreeIllustrationPointEntity", + "GeneralResultFaultTreeIllustrationPointStochastEntity", + "GeneralResultSubMechanismIllustrationPointEntity", + "GeneralResultSubMechanismIllustrationPointStochastEntity", + "SubMechanismIllustrationPointEntity", + "SubMechanismIllustrationPointStochastEntity", + "FaultTreeIllustrationPointEntity", + "FaultTreeIllustrationPointStochastEntity", + "FaultTreeSubmechanismIllustrationPointEntity", + "StochastEntity" + }; + + foreach (string table in tables) + { + string validateMigratedTable = + "SELECT COUNT() = 0 " + + $"FROM {table};" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateMigratedTable); + } + } + + private static void AssertPipingOutput(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateOutputCount = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = " + + "( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].PipingCalculationOutputEntity " + + "JOIN [SOURCEPROJECT].PipingCalculationEntity USING(PipingCalculationEntityId) " + + "WHERE [UseAssessmentLevelManualInput] = 1 " + + ") " + + "FROM PipingCalculationOutputEntity;" + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateOutputCount); + } + + private static void AssertMacroStabilityInwardsOutput(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateOutputCount = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = " + + "( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].MacroStabilityInwardsCalculationOutputEntity " + + "JOIN [SOURCEPROJECT].MacroStabilityInwardsCalculationEntity USING(MacroStabilityInwardsCalculationEntityId) " + + "WHERE [UseAssessmentLevelManualInput] = 1 " + + ") " + + "FROM MacroStabilityInwardsCalculationOutputEntity;" + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateOutputCount); + + string validateOutputContent = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = " + + "(" + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].MacroStabilityInwardsCalculationOutputEntity " + + "JOIN [SOURCEPROJECT].MacroStabilityInwardsCalculationEntity USING(MacroStabilityInwardsCalculationEntityId) " + + "WHERE [UseAssessmentLevelManualInput] = 1 " + + ") " + + "FROM MacroStabilityInwardsCalculationOutputEntity NEW " + + "JOIN [SourceProject].MacroStabilityInwardsCalculationOutputEntity AS OLD USING(MacroStabilityInwardsCalculationOutputEntityId) " + + "WHERE NEW.MacroStabilityInwardsCalculationEntityId = OLD.MacroStabilityInwardsCalculationEntityId " + + "AND NEW.FactorOfStability IS OLD.FactorOfStability " + + "AND NEW.ZValue IS OLD.ZValue " + + "AND NEW.ForbiddenZonesXEntryMin IS OLD.ForbiddenZonesXEntryMin " + + "AND NEW.ForbiddenZonesXEntryMax IS OLD.ForbiddenZonesXEntryMax " + + "AND NEW.SlidingCurveLeftSlidingCircleCenterX IS OLD.SlidingCurveLeftSlidingCircleCenterX " + + "AND NEW.SlidingCurveLeftSlidingCircleCenterY IS OLD.SlidingCurveLeftSlidingCircleCenterY " + + "AND NEW.SlidingCurveLeftSlidingCircleRadius IS OLD.SlidingCurveLeftSlidingCircleRadius " + + "AND NEW.SlidingCurveLeftSlidingCircleIsActive = OLD.SlidingCurveLeftSlidingCircleIsActive " + + "AND NEW.SlidingCurveLeftSlidingCircleNonIteratedForce IS OLD.SlidingCurveLeftSlidingCircleNonIteratedForce " + + "AND NEW.SlidingCurveLeftSlidingCircleIteratedForce IS OLD.SlidingCurveLeftSlidingCircleIteratedForce " + + "AND NEW.SlidingCurveLeftSlidingCircleDrivingMoment IS OLD.SlidingCurveLeftSlidingCircleDrivingMoment " + + "AND NEW.SlidingCurveLeftSlidingCircleResistingMoment IS OLD.SlidingCurveLeftSlidingCircleResistingMoment " + + "AND NEW.SlidingCurveRightSlidingCircleCenterX IS OLD.SlidingCurveRightSlidingCircleCenterX " + + "AND NEW.SlidingCurveRightSlidingCircleCenterY IS OLD.SlidingCurveRightSlidingCircleCenterY " + + "AND NEW.SlidingCurveRightSlidingCircleRadius IS OLD.SlidingCurveRightSlidingCircleRadius " + + "AND NEW.SlidingCurveRightSlidingCircleIsActive = OLD.SlidingCurveRightSlidingCircleIsActive " + + "AND NEW.SlidingCurveRightSlidingCircleNonIteratedForce IS OLD.SlidingCurveRightSlidingCircleNonIteratedForce " + + "AND NEW.SlidingCurveRightSlidingCircleIteratedForce IS OLD.SlidingCurveRightSlidingCircleIteratedForce " + + "AND NEW.SlidingCurveRightSlidingCircleDrivingMoment IS OLD.SlidingCurveRightSlidingCircleDrivingMoment " + + "AND NEW.SlidingCurveRightSlidingCircleResistingMoment IS OLD.SlidingCurveRightSlidingCircleResistingMoment " + + "AND NEW.SlidingCurveNonIteratedHorizontalForce IS OLD.SlidingCurveNonIteratedHorizontalForce " + + "AND NEW.SlidingCurveIteratedHorizontalForce IS OLD.SlidingCurveIteratedHorizontalForce " + + "AND NEW.SlipPlaneLeftGridXLeft IS OLD.SlipPlaneLeftGridXLeft " + + "AND NEW.SlipPlaneLeftGridXRight IS OLD.SlipPlaneLeftGridXRight " + + "AND NEW.SlipPlaneLeftGridNrOfHorizontalPoints = OLD.SlipPlaneLeftGridNrOfHorizontalPoints " + + "AND NEW.SlipPlaneLeftGridZTop IS OLD.SlipPlaneLeftGridZTop " + + "AND NEW.SlipPlaneLeftGridZBottom IS OLD.SlipPlaneLeftGridZBottom " + + "AND NEW.SlipPlaneLeftGridNrOfVerticalPoints = OLD.SlipPlaneLeftGridNrOfVerticalPoints " + + "AND NEW.SlipPlaneRightGridXLeft IS OLD.SlipPlaneRightGridXLeft " + + "AND NEW.SlipPlaneRightGridXRight IS OLD.SlipPlaneRightGridXRight " + + "AND NEW.SlipPlaneRightGridNrOfHorizontalPoints = OLD.SlipPlaneRightGridNrOfHorizontalPoints " + + "AND NEW.SlipPlaneRightGridZTop IS OLD.SlipPlaneRightGridZTop " + + "AND NEW.SlipPlaneRightGridZBottom IS OLD.SlipPlaneRightGridZBottom " + + "AND NEW.SlipPlaneRightGridNrOfVerticalPoints = OLD.SlipPlaneRightGridNrOfVerticalPoints;" + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateOutputContent); + } + + #region Dune Locations + + /// + /// Class to generate queries which can be used to assert if the dune locations are correctly migrated. + /// + private class DuneErosionFailureMechanismValidationQueryGenerator + { + /// + /// Enum to indicate the dune location calculation type. + /// + public enum CalculationType + { + /// + /// Represents the calculations for the mechanism specific factorized signaling norm. + /// + CalculationsForMechanismSpecificFactorizedSignalingNorm = 1, + + /// + /// Represents the calculations for the mechanism specific signaling norm. + /// + CalculationsForMechanismSpecificSignalingNorm = 2, + + /// + /// Represents the calculations for the mechanism specific lower limit norm. + /// + CalculationsForMechanismSpecificLowerLimitNorm = 3, + + /// + /// Represents the calculations for the lower limit norm. + /// + CalculationsForLowerLimitNorm = 4, + + /// + /// Represents the calculations for the factorized lower limit norm. + /// + CalculationsForLowerFactorizedLimitNorm = 5 + } + + private readonly string sourceFilePath; + + /// + /// Creates a new instance of . + /// + /// The file path of the original database. + /// Thrown when + /// is null or empty. + public DuneErosionFailureMechanismValidationQueryGenerator(string sourceFilePath) + { + if (string.IsNullOrWhiteSpace(sourceFilePath)) + { + throw new ArgumentException(@"Sourcefile path cannot be null or empty", + nameof(sourceFilePath)); + } + + this.sourceFilePath = sourceFilePath; + } + + /// + /// Generates a query to validate the number of created dune location calculations per failure mechanism. + /// + /// The type of calculation that should be validated. + /// The query to validate the number of dune location calculations per calculation type. + public string GetDuneLocationCalculationsCountValidationQuery(CalculationType calculationType) + { + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = 0 " + + "FROM " + + "( " + + "SELECT " + + "[DuneErosionFailureMechanismMetaEntityId], " + + "COUNT() AS NewCount, " + + "OldCount " + + GetDuneLocationCalculationsQuery(calculationType) + + "LEFT JOIN " + + "( " + + "SELECT " + + "[DuneErosionFailureMechanismMetaEntityId], " + + "COUNT() as OldCount " + + "FROM [SourceProject].DuneErosionFailureMechanismMetaEntity " + + "JOIN [SourceProject].DuneLocationEntity USING(FailureMechanismEntityId) " + + "GROUP BY DuneErosionFailureMechanismMetaEntityId " + + ") USING(DuneErosionFailureMechanismMetaEntityId) " + + "GROUP BY DuneErosionFailureMechanismMetaEntityId " + + "UNION " + + "SELECT " + + "[DuneErosionFailureMechanismMetaEntityId], " + + "NewCount, " + + "COUNT() AS OldCount " + + "FROM [SourceProject].DuneErosionFailureMechanismMetaEntity " + + "JOIN [SourceProject].DuneLocationEntity USING(FailureMechanismEntityId) " + + "LEFT JOIN " + + "( " + + "SELECT " + + "[DuneErosionFailureMechanismMetaEntityId], " + + "COUNT() as NewCount " + + GetDuneLocationCalculationsQuery(calculationType) + + "GROUP BY DuneErosionFailureMechanismMetaEntityId " + + ") USING(DuneErosionFailureMechanismMetaEntityId) " + + "GROUP BY DuneErosionFailureMechanismMetaEntityId " + + ") " + + "WHERE NewCount IS NOT OldCount; " + + "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) "; + } + } + + #endregion + + #region Serializers + + /// + /// Test helper to assert the migrated values of serialized data. + /// + private static class MigratedSerializedDataTestHelper + { + private const string oldNamespace = "Application.Ringtoets.Storage.Serializers"; + + /// + /// Asserts the migrated serialized data related to macro stability inwards output. + /// + /// The reader to read the migrated database. + /// Thrown when: + /// + /// The namespace is still present. + /// The class name of the serialized data is still present. + /// + public static void AssertSerializedMacroStabilityInwardsOutput(MigratedDatabaseReader reader) + { + const string outputEntity = "MacroStabilityInwardsCalculationOutputEntity"; + + string validateSlidingCurves = + "SELECT " + + "COUNT() = 0 " + + $"FROM {outputEntity} " + + "WHERE LIKE('%MacroStabilityInwardsSliceXmlSerializer%', SlidingCurveSliceXML) " + + $"OR LIKE('%{oldNamespace}%', SlidingCurveSliceXML)"; + + reader.AssertReturnedDataIsValid(validateSlidingCurves); + + string validateTangentLines = + "SELECT " + + "COUNT() = 0 " + + $"FROM {outputEntity} " + + "WHERE LIKE('%TangentLinesXmlSerializer%', SlipPlaneTangentLinesXml) " + + $"OR LIKE('%{oldNamespace}%', SlipPlaneTangentLinesXml)"; + + reader.AssertReturnedDataIsValid(validateTangentLines); + } + + /// + /// Asserts the migrated serialized data related to dike profiles. + /// + /// The reader to read the migrated database. + /// Thrown when: + /// + /// The namespace is still present. + /// The class name of the serialized data is still present. + /// + public static void AssertSerializedDikeProfileRoughnessPoints(MigratedDatabaseReader reader) + { + string validateDikeGeometry = + "SELECT " + + "COUNT() = 0 " + + "FROM DikeProfileEntity " + + "WHERE LIKE('%RoughnessPointXmlSerializer%', DikeGeometryXml) " + + $"OR LIKE('%{oldNamespace}%', DikeGeometryXml)"; + + reader.AssertReturnedDataIsValid(validateDikeGeometry); + } + + /// + /// Asserts the migrated serialized data related to the surface lines. + /// + /// The reader to read the migrated database. + /// Thrown when: + /// + /// The namespace is still present. + /// The class name of the serialized data is still present. + /// + public static void AssertSerializedSurfaceLine(MigratedDatabaseReader reader) + { + string validateSurfaceLinePoints = + "SELECT " + + "COUNT() = 0 " + + "FROM SurfaceLineEntity " + + "WHERE LIKE('%Point3DXmlSerializer%', PointsXml) " + + $"OR LIKE('%{oldNamespace}%', PointsXml)"; + + reader.AssertReturnedDataIsValid(validateSurfaceLinePoints); + } + + /// + /// Asserts the migrated serialized data related to serialized 2D point collections. + /// + /// The reader to read the migrated database. + /// Thrown when: + /// + /// The namespace is still present. + /// The class name of the serialized data is still present. + /// + public static void AssertSerializedPoint2DCollection(MigratedDatabaseReader reader) + { + reader.AssertReturnedDataIsValid(GenerateSerializedPoint2DValidationQuery("AssessmentSectionEntity", "ReferenceLinePointXml")); + reader.AssertReturnedDataIsValid(GenerateSerializedPoint2DValidationQuery("FailureMechanismSectionEntity", "FailureMechanismSectionPointXml")); + reader.AssertReturnedDataIsValid(GenerateSerializedPoint2DValidationQuery("StochasticSoilModelEntity", "StochasticSoilModelSegmentPointXml")); + reader.AssertReturnedDataIsValid(GenerateSerializedPoint2DValidationQuery("DikeProfileEntity", "ForeshoreXml")); + reader.AssertReturnedDataIsValid(GenerateSerializedPoint2DValidationQuery("ForeshoreProfileEntity", "GeometryXml")); + reader.AssertReturnedDataIsValid(GenerateSerializedPoint2DValidationQuery("MacroStabilityInwardsSoilLayerTwoDEntity", "OuterRingXml")); + } + + private static string GenerateSerializedPoint2DValidationQuery(string tableName, + string columnName) + { + return "SELECT " + + "COUNT() = 0 " + + $"FROM {tableName} " + + $"WHERE LIKE('%Point2DXmlSerializer%', {columnName}) " + + $"OR LIKE('%{oldNamespace}%', {columnName})"; + } + } + + #endregion + + #region Failure Mechanism Section Result Entities + + private static void AssertHeightStructuresSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].HeightStructuresSectionResultEntity) " + + "FROM HeightStructuresSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].HeightStructuresSectionResultEntity OLD USING(HeightStructuresSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND NEW.HeightStructuresCalculationEntityId IS OLD.HeightStructuresCalculationEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND ((OLD.LayerThree IS NULL AND NEW.TailorMadeAssessmentResult = 1) " + + "OR (OLD.LayerThree IS NOT NULL AND NEW.TailorMadeAssessmentResult = 3)) " + + "AND NEW.TailorMadeAssessmentProbability IS OLD.LayerThree " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyProbability IS NULL; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertClosingStructuresSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].ClosingStructuresSectionResultEntity) " + + "FROM ClosingStructuresSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].ClosingStructuresSectionResultEntity OLD USING(ClosingStructuresSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND NEW.ClosingStructuresCalculationEntityId IS OLD.ClosingStructuresCalculationEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND ((OLD.LayerThree IS NULL AND NEW.TailorMadeAssessmentResult = 1) " + + "OR (OLD.LayerThree IS NOT NULL AND NEW.TailorMadeAssessmentResult = 3)) " + + "AND NEW.TailorMadeAssessmentProbability IS OLD.LayerThree " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyProbability IS NULL; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertStabilityPointStructuresSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].StabilityPointStructuresSectionResultEntity) " + + "FROM StabilityPointStructuresSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].StabilityPointStructuresSectionResultEntity OLD USING(StabilityPointStructuresSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND NEW.StabilityPointStructuresCalculationEntityId IS OLD.StabilityPointStructuresCalculationEntityId " + + "AND NEW.SimpleAssessmentResult = OLD.LayerOne " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND ((OLD.LayerThree IS NULL AND NEW.TailorMadeAssessmentResult = 1) " + + "OR (OLD.LayerThree IS NOT NULL AND NEW.TailorMadeAssessmentResult = 3)) " + + "AND NEW.TailorMadeAssessmentProbability IS OLD.LayerThree " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyProbability IS NULL; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertGrassCoverErosionInwardsSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].GrassCoverErosionInwardsSectionResultEntity) " + + "FROM GrassCoverErosionInwardsSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].GrassCoverErosionInwardsSectionResultEntity OLD USING(GrassCoverErosionInwardsSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND NEW.GrassCoverErosionInwardsCalculationEntityId IS OLD.GrassCoverErosionInwardsCalculationEntityId " + + "AND NEW.SimpleAssessmentResult = OLD.LayerOne " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND ((OLD.LayerThree IS NULL AND NEW.TailorMadeAssessmentResult = 1) " + + "OR (OLD.LayerThree IS NOT NULL AND NEW.TailorMadeAssessmentResult = 3)) " + + "AND NEW.TailorMadeAssessmentProbability IS OLD.LayerThree " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyProbability IS NULL; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertPipingSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].PipingSectionResultEntity) " + + "FROM PipingSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].PipingSectionResultEntity OLD USING(PipingSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND ((OLD.LayerThree IS NULL AND NEW.TailorMadeAssessmentResult = 1) " + + "OR (OLD.LayerThree IS NOT NULL AND NEW.TailorMadeAssessmentResult = 3)) " + + "AND NEW.TailorMadeAssessmentProbability IS OLD.LayerThree " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyProbability IS NULL; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertMacroStabilityInwardsSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].MacroStabilityInwardsSectionResultEntity) " + + "FROM MacroStabilityInwardsSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].MacroStabilityInwardsSectionResultEntity OLD USING(MacroStabilityInwardsSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND ((OLD.LayerThree IS NULL AND NEW.TailorMadeAssessmentResult = 1) " + + "OR (OLD.LayerThree IS NOT NULL AND NEW.TailorMadeAssessmentResult = 3)) " + + "AND NEW.TailorMadeAssessmentProbability IS OLD.LayerThree " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyProbability IS NULL; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertDuneErosionSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].DuneErosionSectionResultEntity) " + + "FROM DuneErosionSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].DuneErosionSectionResultEntity OLD USING(DuneErosionSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND NEW.SimpleAssessmentResult = OLD.LayerOne " + + "AND NEW.DetailedAssessmentResultForFactorizedSignalingNorm = 1 " + + "AND NEW.DetailedAssessmentResultForSignalingNorm = 1 " + + "AND NEW.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = 1 " + + "AND NEW.DetailedAssessmentResultForLowerLimitNorm = 1 " + + "AND NEW.DetailedAssessmentResultForFactorizedLowerLimitNorm = 1 " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertGrassCoverErosionOutwardsSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].GrassCoverErosionOutwardsSectionResultEntity) " + + "FROM GrassCoverErosionOutwardsSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].GrassCoverErosionOutwardsSectionResultEntity OLD USING(GrassCoverErosionOutwardsSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResultForFactorizedSignalingNorm = 1 " + + "AND NEW.DetailedAssessmentResultForSignalingNorm = 1 " + + "AND NEW.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = 1 " + + "AND NEW.DetailedAssessmentResultForLowerLimitNorm = 1 " + + "AND NEW.DetailedAssessmentResultForFactorizedLowerLimitNorm = 1 " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertStabilityStoneCoverSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].StabilityStoneCoverSectionResultEntity) " + + "FROM StabilityStoneCoverSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].StabilityStoneCoverSectionResultEntity OLD USING(StabilityStoneCoverSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND NEW.SimpleAssessmentResult = OLD.LayerOne " + + "AND NEW.DetailedAssessmentResultForFactorizedSignalingNorm = 1 " + + "AND NEW.DetailedAssessmentResultForSignalingNorm = 1 " + + "AND NEW.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = 1 " + + "AND NEW.DetailedAssessmentResultForLowerLimitNorm = 1 " + + "AND NEW.DetailedAssessmentResultForFactorizedLowerLimitNorm = 1 " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertWaveImpactAsphaltCoverSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].WaveImpactAsphaltCoverSectionResultEntity) " + + "FROM WaveImpactAsphaltCoverSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].WaveImpactAsphaltCoverSectionResultEntity OLD USING(WaveImpactAsphaltCoverSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResultForFactorizedSignalingNorm = 1 " + + "AND NEW.DetailedAssessmentResultForSignalingNorm = 1 " + + "AND NEW.DetailedAssessmentResultForMechanismSpecificLowerLimitNorm = 1 " + + "AND NEW.DetailedAssessmentResultForLowerLimitNorm = 1 " + + "AND NEW.DetailedAssessmentResultForFactorizedLowerLimitNorm = 1 " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertGrassCoverSlipOffInwardsSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].GrassCoverSlipOffInwardsSectionResultEntity) " + + "FROM GrassCoverSlipOffInwardsSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].GrassCoverSlipOffInwardsSectionResultEntity OLD USING (GrassCoverSlipOffInwardsSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertGrassCoverSlipOffOutwardsSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].GrassCoverSlipOffOutwardsSectionResultEntity) " + + "FROM GrassCoverSlipOffOutwardsSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].GrassCoverSlipOffOutwardsSectionResultEntity OLD USING (GrassCoverSlipOffOutwardsSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertMacroStabilityOutwardsSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].MacroStabilityOutwardsSectionResultEntity) " + + "FROM MacroStabilityOutwardsSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].MacroStabilityOutwardsSectionResultEntity OLD USING (MacroStabilityOutwardsSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND NEW.DetailedAssessmentProbability IS OLD.LayerTwoA " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.TailorMadeAssessmentProbability IS NULL " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertMicrostabilitySectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].MicrostabilitySectionResultEntity) " + + "FROM MicrostabilitySectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].MicrostabilitySectionResultEntity OLD USING (MicrostabilitySectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertPipingStructureSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].PipingStructureSectionResultEntity) " + + "FROM PipingStructureSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].PipingStructureSectionResultEntity OLD USING (PipingStructureSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.DetailedAssessmentResult = 1 " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertStrengthStabilityLengthwiseConstructionSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].StrengthStabilityLengthwiseConstructionSectionResultEntity) " + + "FROM StrengthStabilityLengthwiseConstructionSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].StrengthStabilityLengthwiseConstructionSectionResultEntity OLD USING (StrengthStabilityLengthwiseConstructionSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertTechnicalInnovationSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].TechnicalInnovationSectionResultEntity) " + + "FROM TechnicalInnovationSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].TechnicalInnovationSectionResultEntity OLD USING (TechnicalInnovationSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + private static void AssertWaterPressureAsphaltCoverSectionResultEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].WaterPressureAsphaltCoverSectionResultEntity) " + + "FROM WaterPressureAsphaltCoverSectionResultEntity NEW " + + "JOIN [SOURCEPROJECT].WaterPressureAsphaltCoverSectionResultEntity OLD USING (WaterPressureAsphaltCoverSectionResultEntityId) " + + "WHERE NEW.FailureMechanismSectionEntityId = OLD.FailureMechanismSectionEntityId " + + "AND ((OLD.LayerOne = 1 AND NEW.SimpleAssessmentResult = 1) " + + "OR (OLD.LayerOne = 2 AND NEW.SimpleAssessmentResult = 2) " + + "OR (OLD.LayerOne = 3 AND NEW.SimpleAssessmentResult = 4)) " + + "AND NEW.TailorMadeAssessmentResult = 1 " + + "AND NEW.UseManualAssembly = 0 " + + "AND NEW.ManualAssemblyCategoryGroup = 1; " + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResult); + } + + #endregion + + #region Migrated Hydraulic Boundary Locations on Assessment section + + private static void AssertWaveHeightCalculationEntitiesOnAssessmentSection(MigratedDatabaseReader reader, + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator queryGenerator) + { + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaveHeightCalculationsForFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaveHeightCalculationsForSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaveHeightCalculationsForLowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaveHeightCalculationsForFactorizedLowerLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedWaveHeightCalculationsValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedWaveHeightCalculationsValidationQuery(NormativeNormType.SignalingNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaveHeightCalculationsForFactorizedLowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaveHeightCalculationsForFactorizedSignalingNorm)); + } + + private static void AssertDesignWaterLevelCalculationEntitiesOnAssessmentSection(MigratedDatabaseReader reader, + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator queryGenerator) + { + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForLowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForFactorizedLowerLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDesignWaterLevelCalculationsValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDesignWaterLevelCalculationsValidationQuery(NormativeNormType.SignalingNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForFactorizedLowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForFactorizedSignalingNorm)); + } + + /// + /// Class to generate queries which can be used to assert if the hydraulic boundary locations + /// are correctly migrated on the assessment section level. + /// + private class HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator + { + /// + /// Enum to indicate the hydraulic location calculation type. + /// + public enum CalculationType + { + /// + /// Represents the water level calculations for the factorized signaling norm. + /// + WaterLevelCalculationsForFactorizedSignalingNorm = 1, + + /// + /// Represents the water level calculations for the signaling norm. + /// + WaterLevelCalculationsForSignalingNorm = 2, + + /// + /// Represents the water level calculations for the lower limit norm. + /// + WaterLevelCalculationsForLowerLimitNorm = 3, + + /// + /// Represents the water level calculations for the factorized lower limit norm. + /// + WaterLevelCalculationsForFactorizedLowerLimitNorm = 4, + + /// + /// Represents the wave height calculations for the factorized signaling norm. + /// + WaveHeightCalculationsForFactorizedSignalingNorm = 5, + + /// + /// Represents the wave height calculations for the signaling norm. + /// + WaveHeightCalculationsForSignalingNorm = 6, + + /// + /// Represents the wave height calculations for the lower limit norm. + /// + WaveHeightCalculationsForLowerLimitNorm = 7, + + /// + /// Represents the wave height calculations for the factorized lower limit norm. + /// + WaveHeightCalculationsForFactorizedLowerLimitNorm = 8 + } + + private readonly string sourceFilePath; + + /// + /// Creates a new instance of . + /// + /// The file path of the original database. + /// Thrown when + /// is null or empty. + public HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator(string sourceFilePath) + { + if (string.IsNullOrEmpty(sourceFilePath)) + { + throw new ArgumentException(@"Sourcefile path cannot be null or empty", + nameof(sourceFilePath)); + } + + this.sourceFilePath = sourceFilePath; + } + + /// + /// Generates a query to validate the number of created hydraulic boundary location calculations per assessment section. + /// + /// The type of calculation that should be validated. + /// The query to validate the number of hydraulic boundary location calculations per assessment section. + public string GetHydraulicBoundaryLocationCalculationsPerAssessmentSectionCountValidationQuery(CalculationType calculationType) + { + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = 0 " + + "FROM " + + "( " + + "SELECT " + + "ase.AssessmentSectionEntityId, " + + "COUNT() AS NewCount, " + + "OldCount " + + GetHydraulicLocationCalculationsFromCollectionQuery(calculationType) + + "LEFT JOIN " + + "( " + + "SELECT " + + "sourceAse.AssessmentSectionEntityId, " + + "COUNT(distinct HydraulicLocationEntityId) AS OldCount " + + "FROM [SOURCEPROJECT].HydraulicLocationEntity sourceHle " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity sourceAse ON sourceHle.AssessmentSectionEntityId = sourceAse.AssessmentSectionEntityId " + + "GROUP BY sourceAse.AssessmentSectionEntityId " + + ") USING(AssessmentSectionEntityId) " + + "GROUP BY ase.AssessmentSectionEntityId " + + "UNION " + + "SELECT " + + "sourceAse.AssessmentSectionEntityId, " + + "NewCount, " + + "COUNT(distinct HydraulicLocationEntityId) AS OldCount " + + "FROM [SOURCEPROJECT].HydraulicLocationEntity sourceHle " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity sourceAse ON sourceHle.AssessmentSectionEntityId = sourceAse.AssessmentSectionEntityId " + + "LEFT JOIN " + + "( " + + "SELECT " + + "ase.AssessmentSectionEntityId, " + + "COUNT() AS NewCount " + + GetHydraulicLocationCalculationsFromCollectionQuery(calculationType) + + "GROUP BY ase.AssessmentSectionEntityId " + + ") USING(AssessmentSectionEntityId) " + + "GROUP BY sourceAse.AssessmentSectionEntityId " + + ") " + + "WHERE NewCount IS NOT OldCount; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + /// + /// Generates a query to validate if the hydraulic boundary calculation input for the design water level calculations + /// are migrated correctly. + /// + /// The norm type to generate the query for. + /// A query to validate the hydraulic boundary location calculation input for the design water level calculations. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedDesignWaterLevelCalculationsValidationQuery(NormativeNormType normType) + { + CalculationType calculationType = ConvertToDesignWaterLevelCalculationType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = 0 " + + "FROM AssessmentSectionEntity ase " + + "JOIN HydraulicLocationCalculationCollectionEntity hlcce " + + $"ON ase.HydraulicLocationCalculationCollectionEntity{(int) calculationType}Id = hlcce.HydraulicLocationCalculationCollectionEntityId " + + "JOIN HydraulicLocationCalculationEntity NEW USING(HydraulicLocationCalculationCollectionEntityId) " + + "JOIN [SOURCEPROJECT].HydraulicLocationEntity OLD USING(HydraulicLocationEntityId) " + + $"WHERE OLD.ShouldDesignWaterLevelIllustrationPointsBeCalculated != NEW.ShouldIllustrationPointsBeCalculated AND ase.NormativeNormType = {(int) normType}; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + /// + /// Generates a query to validate if the hydraulic boundary calculation input for the wave height calculations + /// are migrated correctly. + /// + /// The norm type to generate the query for. + /// A query to validate the hydraulic boundary location calculation input for the wave height calculations. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedWaveHeightCalculationsValidationQuery(NormativeNormType normType) + { + CalculationType calculationType = ConvertToWaveHeightCalculationType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = 0 " + + "FROM AssessmentSectionEntity ase " + + "JOIN HydraulicLocationCalculationCollectionEntity hlcce " + + $"ON ase.HydraulicLocationCalculationCollectionEntity{(int) calculationType}Id = hlcce.HydraulicLocationCalculationCollectionEntityId " + + "JOIN HydraulicLocationCalculationEntity NEW USING(HydraulicLocationCalculationCollectionEntityId) " + + "JOIN [SOURCEPROJECT].HydraulicLocationEntity OLD USING(HydraulicLocationEntityId) " + + $"WHERE OLD.ShouldWaveHeightIllustrationPointsBeCalculated != NEW.ShouldIllustrationPointsBeCalculated AND ase.NormativeNormType = {(int) normType}; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + /// + /// 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. + public string GetNewCalculationsValidationQuery(CalculationType calculationType) + { + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].HydraulicLocationEntity) " + + GetHydraulicLocationCalculationsFromCollectionQuery(calculationType) + + "WHERE ShouldIllustrationPointsBeCalculated = 0;" + + "DETACH DATABASE SOURCEPROJECT;"; + } + + private static string GetHydraulicLocationCalculationsFromCollectionQuery(CalculationType calculationType) + { + return "FROM AssessmentSectionEntity ase " + + $"JOIN HydraulicLocationCalculationCollectionEntity hlcce ON ase.HydraulicLocationCalculationCollectionEntity{(int) calculationType}Id " + + "= hlcce.HydraulicLocationCalculationCollectionEntityId " + + "JOIN HydraulicLocationCalculationEntity USING(HydraulicLocationCalculationCollectionEntityId) "; + } + + /// + /// Converts the to the corresponding design water level calculation from . + /// + /// The norm type to convert. + /// Returns the converted . + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + private static CalculationType ConvertToDesignWaterLevelCalculationType(NormativeNormType normType) + { + if (!Enum.IsDefined(typeof(NormativeNormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), (int) normType, typeof(NormativeNormType)); + } + + switch (normType) + { + case NormativeNormType.LowerLimitNorm: + return CalculationType.WaterLevelCalculationsForLowerLimitNorm; + case NormativeNormType.SignalingNorm: + return CalculationType.WaterLevelCalculationsForSignalingNorm; + default: + throw new NotSupportedException(); + } + } + + /// + /// Converts the to the corresponding wave height calculation from . + /// + /// The norm type to convert. + /// Returns the converted . + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + private static CalculationType ConvertToWaveHeightCalculationType(NormativeNormType normType) + { + if (!Enum.IsDefined(typeof(NormativeNormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), (int) normType, typeof(NormativeNormType)); + } + + switch (normType) + { + case NormativeNormType.LowerLimitNorm: + return CalculationType.WaveHeightCalculationsForLowerLimitNorm; + case NormativeNormType.SignalingNorm: + return CalculationType.WaveHeightCalculationsForSignalingNorm; + default: + throw new NotSupportedException(); + } + } + } + + #endregion + + #region Migrated Hydraulic Boundary Locations on Grass Cover Erosion Outwards Failure Mechanism + + private static void AssertDesignWaterLevelCalculationEntitiesOnGrassCoverErosionOutwardsFailureMechanism(MigratedDatabaseReader reader, + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator queryGenerator) + { + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerFailureMechanismCountValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerFailureMechanismCountValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaterLevelCalculationsForMechanismSpecificSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerFailureMechanismCountValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDesignWaterLevelCalculationsValidationQuery(NormativeNormType.SignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDesignWaterLevelCalculationsValidationQuery(NormativeNormType.LowerLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm)); + } + + private static void AssertWaveHeightCalculationEntitiesOnGrassCoverErosionOutwardsFailureMechanism(MigratedDatabaseReader reader, + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator queryGenerator) + { + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerFailureMechanismCountValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerFailureMechanismCountValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaveHeightCalculationsForMechanismSpecificSignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetHydraulicBoundaryLocationCalculationsPerFailureMechanismCountValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedWaveHeightCalculationsValidationQuery(NormativeNormType.SignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedWaveHeightCalculationsValidationQuery(NormativeNormType.LowerLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm)); + } + + /// + /// Class to generate queries which can be used to assert if the hydraulic boundary locations + /// are correctly migrated on the grass cover erosion outwards failure mechanism level. + /// + private class HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator + { + /// + /// Enum to indicate the hydraulic location calculation type. + /// + public enum CalculationType + { + /// + /// Represents the water level calculations for the mechanism specific factorized signaling norm. + /// + WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm = 1, + + /// + /// Represents the water level calculations for the mechanism specific signaling norm. + /// + WaterLevelCalculationsForMechanismSpecificSignalingNorm = 2, + + /// + /// Represents the water level calculations for the mechanism specific lower limit norm. + /// + WaterLevelCalculationsForMechanismSpecificLowerLimitNorm = 3, + + /// + /// Represents the wave height calculations for the mechanism specific factorized signaling norm. + /// + WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm = 4, + + /// + /// Represents the wave height calculations for the mechanism specific signaling norm. + /// + WaveHeightCalculationsForMechanismSpecificSignalingNorm = 5, + + /// + /// Represents the wave height calculations for the mechanism specific lower limit norm. + /// + WaveHeightCalculationsForMechanismSpecificLowerLimitNorm = 6 + } + + private readonly string sourceFilePath; + + /// + /// Creates a new instance of . + /// + /// The file path of the original database. + /// Thrown when + /// is null or empty. + public HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator(string sourceFilePath) + { + if (string.IsNullOrWhiteSpace(sourceFilePath)) + { + throw new ArgumentException(@"Sourcefile path cannot be null or empty", + nameof(sourceFilePath)); + } + + this.sourceFilePath = sourceFilePath; + } + + /// + /// Generates a query to validate the number of created hydraulic boundary location calculations per failure mechanism. + /// + /// The type of calculation that should be validated. + /// The query to validate the number of hydraulic boundary location calculations per failure mechanism. + public string GetHydraulicBoundaryLocationCalculationsPerFailureMechanismCountValidationQuery(CalculationType calculationType) + { + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = 0 " + + "FROM " + + "( " + + "SELECT " + + "[FailureMechanismEntityId], " + + "COUNT() AS NewCount, " + + "OldCount " + + GetHydraulicLocationCalculationsFromFailureMechanismQuery(calculationType) + + "LEFT JOIN " + + "( " + + "SELECT " + + "[FailureMechanismEntityId], " + + "COUNT(distinct GrassCoverErosionOutwardsHydraulicLocationEntityId) AS OldCount " + + "FROM [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity " + + "JOIN [SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + "GROUP BY FailureMechanismEntityId " + + ") USING(FailureMechanismEntityId) " + + "GROUP BY FailureMechanismEntityId " + + "UNION " + + "SELECT " + + "[FailureMechanismEntityId], " + + "NewCount, " + + "COUNT(distinct GrassCoverErosionOutwardsHydraulicLocationEntityId) AS OldCount " + + "FROM [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity " + + "JOIN [SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + "LEFT JOIN " + + "( " + + "SELECT " + + "[FailureMechanismEntityId], " + + "COUNT() AS NewCount " + + GetHydraulicLocationCalculationsFromFailureMechanismQuery(calculationType) + + "GROUP BY FailureMechanismEntityId " + + ") USING(FailureMechanismEntityId) " + + "GROUP BY FailureMechanismEntityId" + + ") " + + "WHERE NewCount IS NOT OldCount; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + /// + /// Generates a query to validate if the hydraulic boundary calculation input for the design water level calculations + /// are migrated correctly. + /// + /// The norm type to generate the query for. + /// A query to validate the hydraulic boundary location calculation input for the design water level calculations. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedDesignWaterLevelCalculationsValidationQuery(NormativeNormType normType) + { + CalculationType calculationType = ConvertToDesignWaterLevelCalculationType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = 0 " + + "FROM GrassCoverErosionOutwardsFailureMechanismMetaEntity gceofmme " + + "JOIN HydraulicLocationCalculationCollectionEntity hlcce " + + $"ON gceofmme.HydraulicLocationCalculationCollectionEntity{(int) calculationType}Id = hlcce.HydraulicLocationCalculationCollectionEntityId " + + "JOIN HydraulicLocationCalculationEntity NEW USING(HydraulicLocationCalculationCollectionEntityId) " + + "JOIN HydraulicLocationEntity hl USING(HydraulicLocationEntityId) " + + "JOIN FailureMechanismEntity fm USING(FailureMechanismEntityId) " + + "JOIN AssessmentSectionEntity ase USING(AssessmentSectionEntityId) " + + "JOIN( " + + "SELECT " + + "LocationId, " + + "AssessmentSectionEntityId, " + + "ShouldDesignWaterLevelIllustrationPointsBeCalculated " + + "FROM[SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity " + + "JOIN[SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + ") OLD ON(OLD.LocationId = hl.LocationId AND OLD.AssessmentSectionEntityId = fm.AssessmentSectionEntityId) " + + $"WHERE OLD.ShouldDesignWaterLevelIllustrationPointsBeCalculated != NEW.ShouldIllustrationPointsBeCalculated AND ase.NormativeNormType = {(int) normType}; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + /// + /// Generates a query to validate if the hydraulic boundary calculation input for the wave height calculations + /// are migrated correctly. + /// + /// The norm type to generate the query for. + /// A query to validate the hydraulic boundary location calculation input for the wave height calculations. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedWaveHeightCalculationsValidationQuery(NormativeNormType normType) + { + CalculationType calculationType = ConvertToWaveHeightCalculationType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = 0 " + + "FROM GrassCoverErosionOutwardsFailureMechanismMetaEntity gceofmme " + + "JOIN HydraulicLocationCalculationCollectionEntity hlcce " + + $"ON gceofmme.HydraulicLocationCalculationCollectionEntity{(int) calculationType}Id = hlcce.HydraulicLocationCalculationCollectionEntityId " + + "JOIN HydraulicLocationCalculationEntity NEW USING(HydraulicLocationCalculationCollectionEntityId) " + + "JOIN HydraulicLocationEntity hl USING(HydraulicLocationEntityId) " + + "JOIN FailureMechanismEntity fm USING(FailureMechanismEntityId) " + + "JOIN AssessmentSectionEntity ase USING(AssessmentSectionEntityId) " + + "JOIN( " + + "SELECT " + + "LocationId, " + + "AssessmentSectionEntityId, " + + "ShouldWaveHeightIllustrationPointsBeCalculated " + + "FROM[SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity " + + "JOIN[SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + ") OLD ON(OLD.LocationId = hl.LocationId AND OLD.AssessmentSectionEntityId = fm.AssessmentSectionEntityId) " + + $"WHERE OLD.ShouldWaveHeightIllustrationPointsBeCalculated != NEW.ShouldIllustrationPointsBeCalculated AND ase.NormativeNormType = {(int) normType}; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + /// + /// 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 output. + public string GetNewCalculationsValidationQuery(CalculationType calculationType) + { + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity) " + + GetHydraulicLocationCalculationsFromFailureMechanismQuery(calculationType) + + "WHERE ShouldIllustrationPointsBeCalculated = 0;" + + "DETACH DATABASE SOURCEPROJECT;"; + } + + private static string GetHydraulicLocationCalculationsFromFailureMechanismQuery(CalculationType calculationType) + { + return "FROM GrassCoverErosionOutwardsFailureMechanismMetaEntity gceofmm " + + "JOIN HydraulicLocationCalculationCollectionEntity " + + $"ON gceofmm.HydraulicLocationCalculationCollectionEntity{(int) calculationType}Id = HydraulicLocationCalculationCollectionEntityId " + + "JOIN HydraulicLocationCalculationEntity USING(HydraulicLocationCalculationCollectionEntityId) " + + "JOIN HydraulicLocationEntity hl USING(HydraulicLocationEntityId) " + + "JOIN FailureMechanismEntity fm USING(FailureMechanismEntityId) " + + "JOIN AssessmentSectionEntity USING(AssessmentSectionEntityId) "; + } + + /// + /// Converts the to the corresponding design water level calculation from . + /// + /// The norm type to convert. + /// Returns the converted . + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + private static CalculationType ConvertToDesignWaterLevelCalculationType(NormativeNormType normType) + { + if (!Enum.IsDefined(typeof(NormativeNormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), (int) normType, typeof(NormativeNormType)); + } + + switch (normType) + { + case NormativeNormType.LowerLimitNorm: + return CalculationType.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm; + case NormativeNormType.SignalingNorm: + return CalculationType.WaterLevelCalculationsForMechanismSpecificSignalingNorm; + default: + throw new NotSupportedException(); + } + } + + /// + /// Converts the to the corresponding wave height calculation from . + /// + /// The norm type to convert. + /// Returns the converted . + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + private static CalculationType ConvertToWaveHeightCalculationType(NormativeNormType normType) + { + if (!Enum.IsDefined(typeof(NormativeNormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), (int) normType, typeof(NormativeNormType)); + } + + switch (normType) + { + case NormativeNormType.LowerLimitNorm: + return CalculationType.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm; + case NormativeNormType.SignalingNorm: + return CalculationType.WaveHeightCalculationsForMechanismSpecificSignalingNorm; + default: + throw new NotSupportedException(); + } + } + } + + #endregion + + #region Migrated Wave Condition Calculations + + private static void AssertWaveConditionsCalculations(MigratedDatabaseReader reader, string sourceFilePath) + { + var queryGenerator = new WaveConditionsCalculationValidationQueryGenerator(sourceFilePath); + + reader.AssertReturnedDataIsValid(queryGenerator.GetGrassCoverErosionOutwardsCalculationValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetGrassCoverErosionOutwardsCalculationValidationQuery(NormativeNormType.SignalingNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetStabilityStoneCoverCalculationValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetStabilityStoneCoverCalculationValidationQuery(NormativeNormType.SignalingNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetWaveImpactAsphaltCoverCalculationValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetWaveImpactAsphaltCoverCalculationValidationQuery(NormativeNormType.SignalingNorm)); + } + + /// + /// Class to generate queries which can be used to assert if the wave conditions calculations + /// are correctly migrated. + /// + private class WaveConditionsCalculationValidationQueryGenerator + { + private readonly string sourceFilePath; + + /// + /// Creates a new instance of . + /// + /// The file path of the original database. + /// Thrown when + /// is null or empty. + public WaveConditionsCalculationValidationQueryGenerator(string sourceFilePath) + { + if (string.IsNullOrWhiteSpace(sourceFilePath)) + { + throw new ArgumentException(@"Sourcefile path cannot be null or empty", + nameof(sourceFilePath)); + } + + this.sourceFilePath = sourceFilePath; + } + + /// + /// Generates a query to validate if the grass cover erosion outwards calculations are migrated correctly. + /// + /// The norm type to generate the query for. + /// A query to validate the grass cover erosion outwards calculations. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetGrassCoverErosionOutwardsCalculationValidationQuery(NormativeNormType normType) + { + FailureMechanismCategoryType categoryType = ConvertToFailureMechanismCategoryType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = " + + "(" + + "SELECT COUNT() " + + "FROM[SOURCEPROJECT].GrassCoverErosionOutwardsWaveConditionsCalculationEntity " + + "JOIN[SOURCEPROJECT].CalculationGroupEntity USING(CalculationGroupEntityId) " + + "JOIN[SOURCEPROJECT].FailureMechanismEntity USING(CalculationGroupEntityId) " + + "JOIN[SOURCEPROJECT].AssessmentSectionEntity USING(AssessmentSectionEntityId) " + + $"WHERE NormativeNormType = {(int) normType}" + + ") " + + "FROM GrassCoverErosionOutwardsWaveConditionsCalculationEntity NEW " + + "JOIN CalculationGroupEntity USING(CalculationGroupEntityId) " + + "JOIN FailureMechanismEntity USING(CalculationGroupEntityId) " + + "JOIN AssessmentSectionEntity USING(AssessmentSectionEntityId) " + + "LEFT JOIN HydraulicLocationEntity hl USING(HydraulicLocationEntityId) " + + "JOIN ( " + + "SELECT " + + "[GrassCoverErosionOutwardsWaveConditionsCalculationEntityId], " + + "[LocationId], " + + "[AssessmentSectionEntityId], " + + "calc.CalculationGroupEntityId, " + + "[ForeshoreProfileEntityId], " + + "calc.'Order', " + + "calc.Name, " + + "[Comments], " + + "[UseBreakWater], " + + "[BreakWaterType], " + + "[BreakWaterHeight], " + + "[UseForeshore], " + + "[Orientation], " + + "[UpperBoundaryRevetment], " + + "[LowerBoundaryRevetment], " + + "[UpperBoundaryWaterLevels], " + + "[LowerBoundaryWaterLevels], " + + "[StepSize] " + + "FROM [SOURCEPROJECT].GrassCoverErosionOutwardsWaveConditionsCalculationEntity calc " + + "LEFT JOIN [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity USING(GrassCoverErosionOutwardsHydraulicLocationEntityId) " + + "LEFT JOIN [SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + ") OLD USING(GrassCoverErosionOutwardsWaveConditionsCalculationEntityId) " + + GetCommonWaveConditionsCalculationPropertiesValidationString(normType) + + "AND OLD.LocationId IS hl.LocationId " + + $"AND NEW.CategoryType = {(int) categoryType}; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + /// + /// Generates a query to validate if the stability stone cover calculations are migrated correctly. + /// + /// The norm type to generate the query for. + /// A query to validate the migrated stability stone cover calculations. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetStabilityStoneCoverCalculationValidationQuery(NormativeNormType normType) + { + AssessmentSectionCategoryType categoryType = ConvertToAssessmentSectionCategoryType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = " + + "(" + + "SELECT COUNT() " + + "FROM[SOURCEPROJECT].StabilityStoneCoverWaveConditionsCalculationEntity " + + "JOIN[SOURCEPROJECT].CalculationGroupEntity USING(CalculationGroupEntityId) " + + "JOIN[SOURCEPROJECT].FailureMechanismEntity USING(CalculationGroupEntityId) " + + "JOIN[SOURCEPROJECT].AssessmentSectionEntity USING(AssessmentSectionEntityId) " + + $"WHERE NormativeNormType = {(int) normType}" + + ") " + + "FROM StabilityStoneCoverWaveConditionsCalculationEntity NEW " + + "JOIN [SOURCEPROJECT].StabilityStoneCoverWaveConditionsCalculationEntity OLD USING(StabilityStoneCoverWaveConditionsCalculationEntityId) " + + GetCommonWaveConditionsCalculationPropertiesValidationString(normType) + + "AND NEW.HydraulicLocationEntityId IS OLD.HydraulicLocationEntityId " + + $"AND NEW.CategoryType = {(int) categoryType}; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + /// + /// Generates a query to validate if the wave impact asphalt cover calculations are migrated correctly. + /// + /// The norm type to generate the query for. + /// A query to validate the migrated wave impact asphalt cover calculations. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetWaveImpactAsphaltCoverCalculationValidationQuery(NormativeNormType normType) + { + AssessmentSectionCategoryType categoryType = ConvertToAssessmentSectionCategoryType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = " + + "(" + + "SELECT COUNT() " + + "FROM[SOURCEPROJECT].WaveImpactAsphaltCoverWaveConditionsCalculationEntity " + + "JOIN[SOURCEPROJECT].CalculationGroupEntity USING(CalculationGroupEntityId) " + + "JOIN[SOURCEPROJECT].FailureMechanismEntity USING(CalculationGroupEntityId) " + + "JOIN[SOURCEPROJECT].AssessmentSectionEntity USING(AssessmentSectionEntityId) " + + $"WHERE NormativeNormType = {(int) normType}" + + ") " + + "FROM WaveImpactAsphaltCoverWaveConditionsCalculationEntity NEW " + + "JOIN [SOURCEPROJECT].WaveImpactAsphaltCoverWaveConditionsCalculationEntity OLD USING(WaveImpactAsphaltCoverWaveConditionsCalculationEntityId) " + + GetCommonWaveConditionsCalculationPropertiesValidationString(normType) + + "AND NEW.HydraulicLocationEntityId IS OLD.HydraulicLocationEntityId " + + $"AND NEW.CategoryType = {(int) categoryType}; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + private static string GetCommonWaveConditionsCalculationPropertiesValidationString(NormativeNormType normType) + { + return "JOIN CalculationGroupEntity USING(CalculationGroupEntityId) " + + "JOIN FailureMechanismEntity USING(CalculationGroupEntityId) " + + "JOIN AssessmentSectionEntity ase USING(AssessmentSectionEntityId)" + + $"WHERE ase.NormativeNormType = {(int) normType} " + + "AND NEW.CalculationGroupEntityId = OLD.CalculationGroupEntityId " + + "AND NEW.ForeshoreProfileEntityId IS OLD.ForeshoreProfileEntityId " + + "AND NEW.\"Order\" = OLD.\"Order\" " + + "AND NEW.Name IS OLD.Name " + + "AND NEW.Comments IS OLD.Comments " + + "AND NEW.UseBreakWater = OLD.UseBreakWater " + + "AND NEW.BreakWaterType = OLD.BreakWaterType " + + "AND NEW.BreakWaterHeight IS OLD.BreakWaterHeight " + + "AND NEW.UseForeshore = OLD.UseForeshore " + + "AND NEW.Orientation IS OLD.Orientation " + + "AND NEW.UpperBoundaryRevetment IS OLD.UpperBoundaryRevetment " + + "AND NEW.LowerBoundaryRevetment IS OLD.LowerBoundaryRevetment " + + "AND NEW.UpperBoundaryWaterLevels IS OLD.UpperBoundaryWaterLevels " + + "AND NEW.LowerBoundaryWaterLevels IS OLD.LowerBoundaryWaterLevels " + + "AND NEW.StepSize = OLD.StepSize "; + } + + /// + /// Converts the to the corresponding category type from . + /// + /// The norm type to convert. + /// Returns the converted . + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + private static FailureMechanismCategoryType ConvertToFailureMechanismCategoryType(NormativeNormType normType) + { + if (!Enum.IsDefined(typeof(NormativeNormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), (int) normType, typeof(NormativeNormType)); + } + + switch (normType) + { + case NormativeNormType.SignalingNorm: + return FailureMechanismCategoryType.MechanismSpecificSignalingNorm; + case NormativeNormType.LowerLimitNorm: + return FailureMechanismCategoryType.MechanismSpecificLowerLimitNorm; + default: + throw new NotSupportedException(); + } + } + + /// + /// Converts the to the corresponding category type from . + /// + /// The norm type to convert. + /// Returns the converted . + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + private static AssessmentSectionCategoryType ConvertToAssessmentSectionCategoryType(NormativeNormType normType) + { + if (!Enum.IsDefined(typeof(NormativeNormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), (int) normType, typeof(NormativeNormType)); + } + + switch (normType) + { + case NormativeNormType.SignalingNorm: + return AssessmentSectionCategoryType.SignalingNorm; + case NormativeNormType.LowerLimitNorm: + return AssessmentSectionCategoryType.LowerLimitNorm; + default: + throw new NotSupportedException(); + } + } + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo191IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo191IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo191IntegrationTest.cs (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,355 @@ +// Copyright (C) Stichting Deltares 2018. 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.ObjectModel; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Migration.Core; +using Riskeer.Migration.Core.TestUtil; + +namespace Riskeer.Migration.Integration.Test +{ + public class MigrationTo191IntegrationTest + { + private const string newVersion = "19.1"; + + [Test] + public void Given181Project_WhenUpgradedTo182_ThenProjectAsExpected() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, + "MigrationTestProject181.rtd"); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given181Project_WhenUpgradedTo182_ThenProjectAsExpected)); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Given181Project_WhenUpgradedTo182_ThenProjectAsExpected), ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // When + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Then + using (var reader = new MigratedDatabaseReader(targetFilePath)) + { + AssertTablesContentMigrated(reader, sourceFilePath); + + AssertVersions(reader); + AssertDatabase(reader); + + AssertAssessmentSection(reader,sourceFilePath); + AssertBackgroundData(reader, sourceFilePath); + + AssertPipingSoilLayers(reader); + } + + AssertLogDatabase(logFilePath); + } + } + + private static void AssertAssessmentSection(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateAssessmentSection = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM SOURCEPROJECT.AssessmentSectionEntity) " + + "FROM AssessmentSectionEntity NEW " + + "JOIN SOURCEPROJECT.AssessmentSectionEntity OLD USING(AssessmentSectionEntityId) " + + "WHERE NEW.[ProjectEntityId] = OLD.[ProjectEntityId] " + + "AND NEW.[HydraulicLocationCalculationCollectionEntity1Id] = OLD.[HydraulicLocationCalculationCollectionEntity1Id] " + + "AND NEW.[HydraulicLocationCalculationCollectionEntity2Id] = OLD.[HydraulicLocationCalculationCollectionEntity2Id] " + + "AND NEW.[HydraulicLocationCalculationCollectionEntity3Id] = OLD.[HydraulicLocationCalculationCollectionEntity3Id] " + + "AND NEW.[HydraulicLocationCalculationCollectionEntity4Id] = OLD.[HydraulicLocationCalculationCollectionEntity4Id] " + + "AND NEW.[HydraulicLocationCalculationCollectionEntity5Id] = OLD.[HydraulicLocationCalculationCollectionEntity5Id] " + + "AND NEW.[HydraulicLocationCalculationCollectionEntity6Id] = OLD.[HydraulicLocationCalculationCollectionEntity6Id] " + + "AND NEW.[HydraulicLocationCalculationCollectionEntity7Id] = OLD.[HydraulicLocationCalculationCollectionEntity7Id] " + + "AND NEW.[HydraulicLocationCalculationCollectionEntity8Id] = OLD.[HydraulicLocationCalculationCollectionEntity8Id] " + + "AND NEW.[Id] IS OLD.[Id] " + + "AND NEW.[Name] IS OLD.[Name] " + + "AND NEW.[Comments] IS OLD.[Comments] " + + "AND NEW.[LowerLimitNorm] = OLD.[LowerLimitNorm] " + + "AND NEW.[SignalingNorm] = OLD.[SignalingNorm] " + + "AND NEW.[NormativeNormType] = OLD.[NormativeNormType] " + + "AND NEW.[Composition] = OLD.[Composition] " + + "AND NEW.[ReferenceLinePointXml] IS OLD.[ReferenceLinePointXml] " + + "AND NEW.\"Order\" = OLD.\"Order\"; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateAssessmentSection); + + string validateHydraulicDatabase = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = " + + "( " + + "SELECT COUNT() " + + "FROM SOURCEPROJECT.AssessmentSectionEntity " + + "WHERE HydraulicDatabaseLocation IS NOT NULL " + + ") " + + "FROM HydraulicBoundaryDatabaseEntity NEW " + + "JOIN SOURCEPROJECT.AssessmentSectionEntity OLD USING(AssessmentSectionEntityId) " + + "WHERE NEW.[Version] = OLD.[HydraulicDatabaseVersion] " + + "AND NEW.[FilePath] = OLD.[HydraulicDatabaseLocation] " + + "AND NEW.[HydraulicLocationConfigurationSettingsFilePath] = rtrim(OLD.[HydraulicDatabaseLocation], replace(OLD.[HydraulicDatabaseLocation], '\\', '')) || 'hlcd.sqlite' " + + "AND NEW.[HydraulicLocationConfigurationSettingsScenarioName] = 'Conform WBI2017' " + + "AND NEW.[HydraulicLocationConfigurationSettingsYear] = 2023 " + + "AND NEW.[HydraulicLocationConfigurationSettingsSeaLevel] IS 'Conform WBI2017' " + + "AND NEW.[HydraulicLocationConfigurationSettingsRiverDischarge] IS 'Conform WBI2017' " + + "AND NEW.[HydraulicLocationConfigurationSettingsLakeLevel] IS 'Conform WBI2017' " + + "AND NEW.[HydraulicLocationConfigurationSettingsWindDirection] IS 'Conform WBI2017' " + + "AND NEW.[HydraulicLocationConfigurationSettingsWindSpeed] IS 'Conform WBI2017' " + + "AND NEW.[HydraulicLocationConfigurationSettingsComment] IS 'Gegenereerd door Ringtoets (conform WBI2017)'; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateHydraulicDatabase); + } + + private static void AssertBackgroundData(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateTransparency = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT;" + + "SELECT SUM([IsInvalid]) = 0 " + + "FROM " + + "(" + + "SELECT " + + "CASE WHEN (NEW.[Transparency] = OLD.[Transparency] AND OLD.[Transparency] > 0) " + + "OR (NEW.[Transparency] = 0.6 AND OLD.[Transparency] = 0) " + + "THEN 0 " + + "ELSE 1 " + + "END AS [IsInvalid] " + + "FROM BackgroundDataEntity NEW " + + "JOIN [SOURCEPROJECT].BackgroundDataEntity OLD USING(BackgroundDataEntityId) " + + "); " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateTransparency); + + string validateBackgroundData = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT;" + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].BackgroundDataEntity) " + + "FROM BackgroundDataEntity NEW " + + "JOIN [SOURCEPROJECT].BackgroundDataEntity OLD USING(BackgroundDataEntityId) " + + "WHERE NEW.[AssessmentSectionEntityId] = OLD.[AssessmentSectionEntityId] " + + "AND NEW.[Name] = OLD.[Name] " + + "AND NEW.[IsVisible] = OLD.[IsVisible] " + + "AND NEW.[BackgroundDataType] = OLD.[BackgroundDataType]; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateBackgroundData); + } + + private static void AssertTablesContentMigrated(MigratedDatabaseReader reader, string sourceFilePath) + { + string[] tables = + { + "AssessmentSectionEntity", + "BackgroundDataEntity", + "BackgroundDataMetaEntity", + "CalculationGroupEntity", + "ClosingStructureEntity", + "ClosingStructuresCalculationEntity", + "ClosingStructuresFailureMechanismMetaEntity", + "ClosingStructuresOutputEntity", + "ClosingStructuresSectionResultEntity", + "DikeProfileEntity", + "DuneErosionFailureMechanismMetaEntity", + "DuneErosionSectionResultEntity", + "DuneLocationCalculationCollectionEntity", + "DuneLocationCalculationEntity", + "DuneLocationCalculationOutputEntity", + "DuneLocationEntity", + "FailureMechanismEntity", + "FailureMechanismSectionEntity", + "FaultTreeIllustrationPointEntity", + "FaultTreeIllustrationPointStochastEntity", + "FaultTreeSubmechanismIllustrationPointEntity", + "ForeshoreProfileEntity", + "GeneralResultFaultTreeIllustrationPointEntity", + "GeneralResultFaultTreeIllustrationPointStochastEntity", + "GeneralResultSubMechanismIllustrationPointEntity", + "GeneralResultSubMechanismIllustrationPointStochastEntity", + "GrassCoverErosionInwardsCalculationEntity", + "GrassCoverErosionInwardsDikeHeightOutputEntity", + "GrassCoverErosionInwardsFailureMechanismMetaEntity", + "GrassCoverErosionInwardsOutputEntity", + "GrassCoverErosionInwardsOvertoppingRateOutputEntity", + "GrassCoverErosionInwardsSectionResultEntity", + "GrassCoverErosionOutwardsFailureMechanismMetaEntity", + "GrassCoverErosionOutwardsSectionResultEntity", + "GrassCoverErosionOutwardsWaveConditionsCalculationEntity", + "GrassCoverErosionOutwardsWaveConditionsOutputEntity", + "GrassCoverSlipOffInwardsSectionResultEntity", + "GrassCoverSlipOffOutwardsSectionResultEntity", + "HeightStructureEntity", + "HeightStructuresCalculationEntity", + "HeightStructuresFailureMechanismMetaEntity", + "HeightStructuresOutputEntity", + "HeightStructuresSectionResultEntity", + "HydraulicLocationCalculationCollectionEntity", + "HydraulicLocationCalculationEntity", + "HydraulicLocationEntity", + "HydraulicLocationOutputEntity", + "IllustrationPointResultEntity", + "MacroStabilityInwardsCalculationEntity", + "MacroStabilityInwardsCalculationOutputEntity", + "MacroStabilityInwardsCharacteristicPointEntity", + "MacroStabilityInwardsFailureMechanismMetaEntity", + "MacroStabilityInwardsPreconsolidationStressEntity", + "MacroStabilityInwardsSectionResultEntity", + "MacroStabilityInwardsSoilLayerOneDEntity", + "MacroStabilityInwardsSoilLayerTwoDEntity", + "MacroStabilityInwardsSoilProfileOneDEntity", + "MacroStabilityInwardsSoilProfileTwoDEntity", + "MacroStabilityInwardsSoilProfileTwoDSoilLayerTwoDEntity", + "MacroStabilityInwardsStochasticSoilProfileEntity", + "MacroStabilityOutwardsFailureMechanismMetaEntity", + "MacroStabilityOutwardsSectionResultEntity", + "MicrostabilitySectionResultEntity", + "PipingCalculationEntity", + "PipingCalculationOutputEntity", + "PipingCharacteristicPointEntity", + "PipingFailureMechanismMetaEntity", + "PipingSectionResultEntity", + "PipingSoilLayerEntity", + "PipingSoilProfileEntity", + "PipingStochasticSoilProfileEntity", + "PipingStructureFailureMechanismMetaEntity", + "PipingStructureSectionResultEntity", + "ProjectEntity", + "StabilityPointStructureEntity", + "StabilityPointStructuresCalculationEntity", + "StabilityPointStructuresFailureMechanismMetaEntity", + "StabilityPointStructuresOutputEntity", + "StabilityPointStructuresSectionResultEntity", + "StabilityStoneCoverFailureMechanismMetaEntity", + "StabilityStoneCoverSectionResultEntity", + "StabilityStoneCoverWaveConditionsCalculationEntity", + "StabilityStoneCoverWaveConditionsOutputEntity", + "StochastEntity", + "StochasticSoilModelEntity", + "StrengthStabilityLengthwiseConstructionSectionResultEntity", + "SubMechanismIllustrationPointEntity", + "SubMechanismIllustrationPointStochastEntity", + "SurfaceLineEntity", + "TechnicalInnovationSectionResultEntity", + "TopLevelFaultTreeIllustrationPointEntity", + "TopLevelSubMechanismIllustrationPointEntity", + "VersionEntity", + "WaterPressureAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverFailureMechanismMetaEntity", + "WaveImpactAsphaltCoverSectionResultEntity", + "WaveImpactAsphaltCoverWaveConditionsCalculationEntity", + "WaveImpactAsphaltCoverWaveConditionsOutputEntity" + }; + + foreach (string table in tables) + { + string validateMigratedTable = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + $"SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].{table}) " + + $"FROM {table};" + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateMigratedTable); + } + } + + private static void AssertLogDatabase(string logFilePath) + { + using (var reader = new MigrationLogDatabaseReader(logFilePath)) + { + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + + Assert.AreEqual(10, messages.Count); + var i = 0; + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, "Gevolgen van de migratie van versie 18.1 naar versie 19.1:"), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, "* Traject: 'BackgroundData-DefaultValue'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, " + De waarde voor de transparantie van de achtergrondkaart is aangepast naar 0.60."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, "* Traject: 'PipingSoilLayer'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, " + Toetsspoor: 'Piping'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, " - De waarde '0.0049' voor het gemiddelde van parameter 'Verzadigd gewicht' van ondergrondlaag 'BelowPhreaticLevelMean' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, " - De waarde '4.9e-07' voor het gemiddelde van parameter 'Doorlatendheid' van ondergrondlaag 'PermeabilityMean' is ongeldig en is veranderd naar NaN."), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, " - De waarde '4.9e-07' voor het gemiddelde van parameter 'd70' van ondergrondlaag 'DiameterD70Mean' is ongeldig en is veranderd naar NaN."), + messages[i++]); + + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, "* Traject: 'WithHydraulicDatabase'"), + messages[i++]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("18.1", newVersion, " + Er worden standaardwaarden conform WBI2017 voor de HLCD bestand informatie gebruikt."), + messages[i]); + } + } + + private static void AssertVersions(MigratedDatabaseReader reader) + { + const string validateVersion = + "SELECT COUNT() = 1 " + + "FROM [VersionEntity] " + + "WHERE [Version] = \"19.1\";"; + reader.AssertReturnedDataIsValid(validateVersion); + } + + private static void AssertDatabase(MigratedDatabaseReader reader) + { + const string validateForeignKeys = + "PRAGMA foreign_keys;"; + reader.AssertReturnedDataIsValid(validateForeignKeys); + } + + private static void AssertPipingSoilLayers(MigratedDatabaseReader reader) + { + const string validateBelowPhreaticLevel = + "SELECT COUNT() = 0 " + + "FROM PipingSoilLayerEntity " + + "WHERE [BelowPhreaticLevelMean] < [BelowPhreaticLevelShift] " + + "OR [BelowPhreaticLevelMean] < 0.005;"; + reader.AssertReturnedDataIsValid(validateBelowPhreaticLevel); + + const string validateDiameter70 = + "SELECT COUNT() = 0 " + + "FROM PipingSoilLayerEntity " + + "WHERE [DiameterD70Mean] < 0.0000005;"; + reader.AssertReturnedDataIsValid(validateDiameter70); + + const string validatePermeability = + "SELECT COUNT() = 0 " + + "FROM PipingSoilLayerEntity " + + "WHERE [PermeabilityMean] < 0.0000005;"; + reader.AssertReturnedDataIsValid(validatePermeability); + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/Properties/AssemblyInfo.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/Properties/AssemblyInfo.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/Properties/AssemblyInfo.cs (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,25 @@ +// Copyright (C) Stichting Deltares 2018. 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.Reflection; + +[assembly: AssemblyTitle("Riskeer.Migration.Integration.Test")] +[assembly: AssemblyProduct("Riskeer.Migration.Integration.Test")] \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/Riskeer.Migration.Integration.Test.csproj =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/Riskeer.Migration.Integration.Test.csproj (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/Riskeer.Migration.Integration.Test.csproj (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,75 @@ + + + + {ABF98CE1-D311-4835-844A-1D4ED0E6C73D} + Riskeer.Migration.Integration.Test + Riskeer.Migration.Integration.Test + + + + + ..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll + + + + + ..\..\..\..\packages\System.Data.SQLite.Core.1.0.106.0\lib\net40\System.Data.SQLite.dll + + + + + + + + + + + + + + Copying.licenseheader + + + + + + {e344867e-9ac9-44c8-88a5-8185681679a9} + Core.Common.IO + + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + + + {efd7e662-5b69-4b71-a448-565b64e9c033} + Migration.Core.Storage + + + {d08db9e2-6861-44c8-a725-71a70274cc77} + Migration.Scripts.Data + + + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} + Ringtoets.Common.Data + + + {6A074D65-A81C-4C1C-8E24-F36C916E4ED7} + Ringtoets.Common.Util + + + {fac55b92-e259-43d6-b9a1-5bda6c834359} + Riskeer.Migration.Core + + + {C98D99C5-2ADD-4693-916C-71BF78750412} + Riskeer.Migration.Core.TestUtil + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/packages.config =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/packages.config (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Integration.Test/packages.config (revision 92827b7879fc5c2544c51a84a7a16c96d9a2103d) @@ -0,0 +1,27 @@ + + + + + + \ No newline at end of file