Index: Application/Ringtoets/test/Application.Ringtoets.Integration.Test/Application.Ringtoets.Integration.Test.csproj =================================================================== diff -u -r892cd3a8986d39a1e8a4ae33290f469bda616172 -r2fff0d73cd7b654907005611f81e276b4cb36e45 --- Application/Ringtoets/test/Application.Ringtoets.Integration.Test/Application.Ringtoets.Integration.Test.csproj (.../Application.Ringtoets.Integration.Test.csproj) (revision 892cd3a8986d39a1e8a4ae33290f469bda616172) +++ Application/Ringtoets/test/Application.Ringtoets.Integration.Test/Application.Ringtoets.Integration.Test.csproj (.../Application.Ringtoets.Integration.Test.csproj) (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -7,16 +7,34 @@ + + ..\..\..\..\packages\Fluent.Ribbon.3.4.0\lib\net40\Fluent.dll + + + ..\..\..\..\packages\Fluent.Ribbon.3.4.0\lib\net40\Microsoft.Windows.Shell.dll + ..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll True + + + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + + + + ..\..\..\..\packages\Fluent.Ribbon.3.4.0\lib\net40\System.Windows.Interactivity.dll + + + + @@ -30,9 +48,45 @@ + + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} + Core.Common.Base + + + {30E4C2AE-719E-4D70-9FA9-668A9767FBFA} + Core.Common.Gui + {d749ee4c-ce50-4c17-bf01-9a953028c126} Core.Common.TestUtil + + {efd7e662-5b69-4b71-a448-565b64e9c033} + Migration.Core.Storage + + + {d08db9e2-6861-44c8-a725-71a70274cc77} + Migration.Scripts.Data + + + {6A074D65-A81C-4C1C-8E24-F36C916E4ED7} + Ringtoets.Common.Util + + + {11F1F874-45AF-43E4-8AE5-15A5C9593E28} + Ringtoets.Integration.Data + + + {FAC55B92-E259-43D6-B9A1-5BDA6C834359} + Ringtoets.Migration.Core + + + {AC4F7F48-F674-4E32-AB35-9C726605F684} + Ringtoets.Migration + + + {50963F12-448C-41BA-A62C-CDB0AB8D21E0} + Ringtoets.Storage.Core + \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Integration.Test/StorageMigrationIntegrationTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Integration.Test/StorageMigrationIntegrationTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Integration.Test/StorageMigrationIntegrationTest.cs (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -0,0 +1,176 @@ +// Copyright (C) Stichting Deltares 2017. 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.IO; +using System.Threading; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Settings; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Util; +using Ringtoets.Integration.Data; +using Ringtoets.Migration; +using Ringtoets.Migration.Core; +using Ringtoets.Storage.Core; + +namespace Application.Ringtoets.Integration.Test +{ + [TestFixture] + public class StorageMigrationIntegrationTest + { + private readonly string workingDirectory = TestHelper.GetScratchPadPath(nameof(StorageMigrationIntegrationTest)); + private DirectoryDisposeHelper directoryDisposeHelper; + + [Test] + [TestCaseSource(typeof(RingtoetsProjectMigrationTestHelper), nameof(RingtoetsProjectMigrationTestHelper.GetAllOutdatedSupportedProjectFileVersions))] + [Apartment(ApartmentState.STA)] + public void GivenRingtoetsGuiWithStorageSql_WhenRunWithMigratedFile_MigratedProjectSet(string version) + { + string sourceFilePath = GetTestProjectFilePath(version); + string targetFilePath = Path.Combine(workingDirectory, nameof(GivenRingtoetsGuiWithStorageSql_WhenRunWithMigratedFile_MigratedProjectSet)); + MigrateFile(sourceFilePath, targetFilePath); + + // Given + var projectStore = new StorageSqLite(); + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + mocks.ReplayAll(); + + var projectMigrator = new RingtoetsProjectMigrator(inquiryHelper); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RingtoetsProjectFactory(), new GuiCoreSettings())) + { + // When + gui.Run(targetFilePath); + + // Then + Assert.AreEqual(targetFilePath, gui.ProjectFilePath); + Assert.NotNull(gui.Project); + string expectedProjectName = Path.GetFileNameWithoutExtension(targetFilePath); + Assert.AreEqual(expectedProjectName, gui.Project.Name); + Assert.AreEqual("description", gui.Project.Description); + Assert.IsInstanceOf(gui.Project); + } + + mocks.VerifyAll(); + } + + [Test] + [TestCaseSource(typeof(RingtoetsProjectMigrationTestHelper), nameof(RingtoetsProjectMigrationTestHelper.GetAllOutdatedSupportedProjectFileVersions))] + [Apartment(ApartmentState.STA)] + public void GivenRingtoetsGui_WhenRunWithUnmigratedFileAndInquireContinuation_MigratedProjectSet(string version) + { + // Given + string sourceFilePath = GetTestProjectFilePath(version); + string targetFilePath = Path.Combine(workingDirectory, nameof(GivenRingtoetsGui_WhenRunWithUnmigratedFileAndInquireContinuation_MigratedProjectSet)); + + var projectStore = new StorageSqLite(); + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + inquiryHelper.Expect(helper => helper.InquireContinuation(null)) + .IgnoreArguments() + .Return(true); + inquiryHelper.Expect(helper => helper.GetTargetFileLocation(null, null)) + .IgnoreArguments() + .Return(targetFilePath); + mocks.ReplayAll(); + + var projectMigrator = new RingtoetsProjectMigrator(inquiryHelper); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RingtoetsProjectFactory(), new GuiCoreSettings())) + { + // When + gui.Run(sourceFilePath); + + // Then + Assert.AreEqual(targetFilePath, gui.ProjectFilePath); + string expectedProjectName = Path.GetFileNameWithoutExtension(targetFilePath); + Assert.AreEqual(expectedProjectName, gui.Project.Name); + Assert.AreEqual("description", gui.Project.Description); + Assert.IsInstanceOf(gui.Project); + } + + mocks.VerifyAll(); + } + + [Test] + [TestCaseSource(typeof(RingtoetsProjectMigrationTestHelper), nameof(RingtoetsProjectMigrationTestHelper.GetAllOutdatedSupportedProjectFileVersions))] + [Apartment(ApartmentState.STA)] + public void GivenRingtoetsGui_WhenRunWithUnmigratedFileAndNoInquireContinuation_MigratedProjectNotSet(string version) + { + // Given + string sourceFilePath = GetTestProjectFilePath(version); + var projectStore = new StorageSqLite(); + var mocks = new MockRepository(); + var inquiryHelper = mocks.Stub(); + inquiryHelper.Expect(helper => helper.InquireContinuation(null)) + .IgnoreArguments() + .Return(false); + mocks.ReplayAll(); + + var projectMigrator = new RingtoetsProjectMigrator(inquiryHelper); + + using (var gui = new GuiCore(new MainWindow(), projectStore, projectMigrator, new RingtoetsProjectFactory(), new GuiCoreSettings())) + { + // When + gui.Run(sourceFilePath); + + // Then + Assert.IsNull(gui.ProjectFilePath); + Assert.AreEqual("Project", gui.Project.Name); + Assert.IsEmpty((string) gui.Project.Description); + } + + mocks.VerifyAll(); + } + + [OneTimeSetUp] + public void SetUp() + { + directoryDisposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(StorageMigrationIntegrationTest)); + } + + [OneTimeTearDown] + public void TearDown() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + directoryDisposeHelper.Dispose(); + } + + private static void MigrateFile(string sourceFilePath, string targetFilePath) + { + string newVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + } + + private static string GetTestProjectFilePath(string versionNumber) + { + return TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration.Core, $"MigrationTestProject{versionNumber}.rtd"); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Integration.Test/packages.config =================================================================== diff -u -ra1fa1538918813373bcc864f0bce092bf28fd0ce -r2fff0d73cd7b654907005611f81e276b4cb36e45 --- Application/Ringtoets/test/Application.Ringtoets.Integration.Test/packages.config (.../packages.config) (revision a1fa1538918813373bcc864f0bce092bf28fd0ce) +++ Application/Ringtoets/test/Application.Ringtoets.Integration.Test/packages.config (.../packages.config) (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -22,5 +22,7 @@ All rights reserved. --> + + \ No newline at end of file Index: Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationIntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationIntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationIntegrationTest.cs (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -0,0 +1,161 @@ +// Copyright (C) Stichting Deltares 2017. 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.Migration.Core; + +namespace Ringtoets.Migration.Integration.Test +{ + [TestFixture] + public class MigrationIntegrationTest + { + private const string latestVersion = "18.1"; + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Application.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.Application.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(8, 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", latestVersion, $"Gevolgen van de migratie van versie 17.3 naar versie {latestVersion}:"), + messages[6]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual( + new MigrationLogMessage("17.3", latestVersion, "* Geen aanpassingen."), + messages[7]); + } + } + } + + 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"); + } + + 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/Ringtoets.Migration.Integration.Test/MigrationTo171IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo171IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo171IntegrationTest.cs (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -0,0 +1,396 @@ +// Copyright (C) Stichting Deltares 2017. 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 Ringtoets.Migration.Core; + +namespace Ringtoets.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.Application.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) + { + var tables = new[] + { + "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/Ringtoets.Migration.Integration.Test/MigrationTo172IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo172IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo172IntegrationTest.cs (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -0,0 +1,1265 @@ +// Copyright (C) Stichting Deltares 2017. 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 Ringtoets.Migration.Core; + +namespace Ringtoets.Migration.Integration.Test +{ + public class MigrationTo172IntegrationTest + { + private const string newVersion = "17.2"; + + [Test] + public void Given171Project_WhenUpgradedTo172_ThenProjectAsExpected() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.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.Application.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.Application.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((object) 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) + { + var tables = new[] + { + "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 het toetspeil 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/Ringtoets.Migration.Integration.Test/MigrationTo173IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo173IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo173IntegrationTest.cs (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -0,0 +1,226 @@ +// Copyright (C) Stichting Deltares 2017. 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 Ringtoets.Migration.Core; + +namespace Ringtoets.Migration.Integration.Test +{ + public class MigrationTo173IntegrationTest + { + private const string newVersion = "17.3"; + + [Test] + public void Given172Project_WhenUpgradedTo173_ThenProjectAsExpected() + { + // Given + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.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/Ringtoets.Migration.Integration.Test/MigrationTo181IntegrationTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo181IntegrationTest.cs (revision 0) +++ Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/MigrationTo181IntegrationTest.cs (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -0,0 +1,2384 @@ +// Copyright (C) Stichting Deltares 2017. 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 Ringtoets.Migration.Core; + +namespace Ringtoets.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.Application.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); + + AssertPipingSoilLayers(reader); + AssertHydraRingPreprocessor(reader); + AssertStabilityStoneCoverFailureMechanism(reader); + AssertMacroStabilityOutwardsFailureMechanism(reader); + AssertPipingStructureFailureMechanism(reader); + AssertWaveImpactAsphaltCoverFailureMechanism(reader); + AssertGrassCoverErosionInwardsOutput(reader, sourceFilePath); + AssertClosingStructuresOutput(reader, sourceFilePath); + AssertHeightStructuresOutput(reader, sourceFilePath); + AssertStabilityPointStructuresOutput(reader, sourceFilePath); + + 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); + } + + 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", + "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", + "HydraulicLocationEntity", + "IllustrationPointResultEntity", + "MacroStabilityInwardsCalculationEntity", + "MacroStabilityInwardsCalculationOutputEntity", + "MacroStabilityInwardsCharacteristicPointEntity", + "MacroStabilityInwardsFailureMechanismMetaEntity", + "MacroStabilityInwardsPreconsolidationStressEntity", + "MacroStabilityInwardsSectionResultEntity", + "MacroStabilityInwardsSemiProbabilisticOutputEntity", + "MacroStabilityInwardsSoilLayerOneDEntity", + "MacroStabilityInwardsSoilLayerTwoDEntity", + "MacroStabilityInwardsSoilProfileOneDEntity", + "MacroStabilityInwardsSoilProfileTwoDEntity", + "MacroStabilityInwardsSoilProfileTwoDSoilLayerTwoDEntity", + "MacroStabilityInwardsStochasticSoilProfileEntity", + "MacroStabilityOutwardsSectionResultEntity", + "MicrostabilitySectionResultEntity", + "PipingCalculationEntity", + "PipingCalculationOutputEntity", + "PipingCharacteristicPointEntity", + "PipingFailureMechanismMetaEntity", + "PipingSectionResultEntity", + "PipingSemiProbabilisticOutputEntity", + "PipingSoilLayerEntity", + "PipingSoilProfileEntity", + "PipingStochasticSoilProfileEntity", + "PipingStructureSectionResultEntity", + "ProjectEntity", + "StabilityPointStructureEntity", + "StabilityPointStructuresCalculationEntity", + "StabilityPointStructuresFailureMechanismMetaEntity", + "StabilityPointStructuresOutputEntity", + "StabilityPointStructuresSectionResultEntity", + "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(61, 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, "* 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]); + } + } + + 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 AssertHydraRingPreprocessor(MigratedDatabaseReader reader) + { + const string validatePreprocessorSettings = + "SELECT COUNT() = 0 " + + "FROM [HydraRingPreprocessorEntity];"; + reader.AssertReturnedDataIsValid(validatePreprocessorSettings); + } + + 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 AssertGrassCoverErosionInwardsOutput(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateGrassCoverErosionInwardsOutputEntities = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].GrassCoverErosionInwardsOutputEntity) " + + "FROM GrassCoverErosionInwardsOutputEntity NEW " + + "JOIN [SOURCEPROJECT].GrassCoverErosionInwardsOutputEntity OLD USING(GrassCoverErosionInwardsOutputEntityId) " + + "WHERE NEW.GrassCoverErosionInwardsCalculationEntityId = OLD.GrassCoverErosionInwardsCalculationEntityId " + + "AND NEW.GeneralResultFaultTreeIllustrationPointEntityId IS OLD.GeneralResultFaultTreeIllustrationPointEntityId " + + "AND NEW.IsOvertoppingDominant = OLD.IsOvertoppingDominant " + + "AND NEW.WaveHeight IS OLD.WaveHeight " + + "AND NEW.Reliability IS OLD.Reliability;" + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateGrassCoverErosionInwardsOutputEntities); + } + + private static void AssertClosingStructuresOutput(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateClosingStructuresOutputEntities = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].ClosingStructuresOutputEntity) " + + "FROM ClosingStructuresOutputEntity NEW " + + "JOIN [SOURCEPROJECT].ClosingStructuresOutputEntity OLD USING(ClosingStructuresOutputEntityId) " + + "WHERE NEW.ClosingStructuresCalculationEntityId = OLD.ClosingStructuresCalculationEntityId " + + "AND NEW.GeneralResultFaultTreeIllustrationPointEntityId IS OLD.GeneralResultFaultTreeIllustrationPointEntityId " + + "AND NEW.Reliability IS OLD.Reliability;" + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateClosingStructuresOutputEntities); + } + + private static void AssertHeightStructuresOutput(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateHeightStructuresOutputEntities = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].HeightStructuresOutputEntity) " + + "FROM HeightStructuresOutputEntity NEW " + + "JOIN [SOURCEPROJECT].HeightStructuresOutputEntity OLD USING(HeightStructuresOutputEntityId) " + + "WHERE NEW.HeightStructuresCalculationEntityId = OLD.HeightStructuresCalculationEntityId " + + "AND NEW.GeneralResultFaultTreeIllustrationPointEntityId IS OLD.GeneralResultFaultTreeIllustrationPointEntityId " + + "AND NEW.Reliability IS OLD.Reliability;" + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateHeightStructuresOutputEntities); + } + + private static void AssertStabilityPointStructuresOutput(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateStabilityPointStructuresOutputEntities = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = (SELECT COUNT() FROM [SOURCEPROJECT].StabilityPointStructuresOutputEntity) " + + "FROM StabilityPointStructuresOutputEntity NEW " + + "JOIN [SOURCEPROJECT].StabilityPointStructuresOutputEntity OLD ON OLD.StabilityPointStructuresOutputEntity = NEW.StabilityPointStructuresOutputEntityId " + + "WHERE NEW.StabilityPointStructuresCalculationEntityId = OLD.StabilityPointStructuresCalculationEntityId " + + "AND NEW.GeneralResultFaultTreeIllustrationPointEntityId IS OLD.GeneralResultFaultTreeIllustrationPointEntityId " + + "AND NEW.Reliability IS OLD.Reliability;" + + "DETACH DATABASE SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateStabilityPointStructuresOutputEntities); + } + + 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.ReferenceLinePointXml IS OLD.ReferenceLinePointXml " + + "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() = " + + "( " + + "SELECT COUNT() + " + + "( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationOutputEntity " + + ") " + + "FROM [SOURCEPROJECT].HydraulicLocationOutputEntity " + + ") " + + "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)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDuneLocationCalculationOutputValidationQuery(NormativeNormType.SignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDuneLocationCalculationOutputValidationQuery(NormativeNormType.LowerLimitNorm)); + + reader.AssertReturnedDataIsValid(DuneErosionFailureMechanismValidationQueryGenerator.GetNewDuneLocationCalculationOutputValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForMechanismSpecificFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(DuneErosionFailureMechanismValidationQueryGenerator.GetNewDuneLocationCalculationOutputValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForLowerLimitNorm)); + reader.AssertReturnedDataIsValid(DuneErosionFailureMechanismValidationQueryGenerator.GetNewDuneLocationCalculationOutputValidationQuery( + DuneErosionFailureMechanismValidationQueryGenerator.CalculationType.CalculationsForLowerFactorizedLimitNorm)); + } + + private static void AssertGrassCoverErosionOutwardsFailureMechanismMetaEntity(MigratedDatabaseReader reader, string sourceFilePath) + { + 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); + } + + #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;"; + } + + /// + /// Generates a query to validate the new dune location outputs that are not based on migrated data. + /// + /// The type of calculation on which the output should be validated. + /// The query to validate the dune location output. + public static string GetNewDuneLocationCalculationOutputValidationQuery(CalculationType calculationType) + { + return "SELECT COUNT() = 0 " + + GetDuneLocationCalculationsQuery(calculationType) + + "JOIN DuneLocationCalculationOutputEntity USING(DuneLocationCalculationEntityId);"; + } + + /// + /// Generates a query to validate if the dune location outputs are migrated correctly to the + /// corresponding calculation entities. + /// + /// The norm type to generate the query for. + /// A query to validate the dune location outputs. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedDuneLocationCalculationOutputValidationQuery(NormativeNormType normType) + { + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = ( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].DuneLocationOutputEntity " + + "JOIN [SOURCEPROJECT].DuneLocationEntity USING(DuneLocationEntityId) " + + "JOIN [SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity USING(AssessmentSectionEntityId) " + + $"WHERE NormativeNormType = {(int) normType} " + + ") " + + GetDuneLocationCalculationsQuery(ConvertToCalculationType(normType)) + + "JOIN DuneLocationCalculationOutputEntity NEW USING(DuneLocationCalculationEntityId) " + + "JOIN [SOURCEPROJECT].DuneLocationOutputEntity OLD ON OLD.DuneLocationOutputEntityId = NEW.DuneLocationCalculationOutputEntityId " + + "WHERE NEW.WaterLevel IS OLD.WaterLevel " + + "AND NEW.WaveHeight IS OLD.WaveHeight " + + "AND NEW.WavePeriod IS OLD.WavePeriod " + + "AND NEW.TargetProbability IS OLD.TargetProbability " + + "AND NEW.TargetReliability IS OLD.TargetReliability " + + "AND NEW.CalculatedProbability IS OLD.CalculatedProbability " + + "AND NEW.CalculatedReliability IS OLD.CalculatedReliability " + + "AND NEW.CalculationConvergence = OLD.CalculationConvergence; " + + "DETACH DATABASE SOURCEPROJECT;"; + } + + private static string GetDuneLocationCalculationsQuery(CalculationType calculationType) + { + return "FROM DuneErosionFailureMechanismMetaEntity fme " + + "JOIN DuneLocationCalculationCollectionEntity ON " + + $"DuneLocationCalculationCollectionEntityId = fme.DuneLocationCalculationCollectionEntity{(int) calculationType}Id " + + "JOIN DuneLocationCalculationEntity USING(DuneLocationCalculationCollectionEntityId) "; + } + + /// + /// Converts the to the corresponding calculation from . + /// + /// The norm type to convert. + /// Returns the converted . + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + private static CalculationType ConvertToCalculationType(NormativeNormType normType) + { + if (!Enum.IsDefined(typeof(NormativeNormType), normType)) + { + throw new InvalidEnumArgumentException(nameof(normType), (int) normType, typeof(NormativeNormType)); + } + + switch (normType) + { + case NormativeNormType.LowerLimitNorm: + return CalculationType.CalculationsForMechanismSpecificLowerLimitNorm; + case NormativeNormType.SignalingNorm: + return CalculationType.CalculationsForMechanismSpecificSignalingNorm; + default: + throw new NotSupportedException(); + } + } + } + + #endregion + + #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.UseManualAssemblyProbability = 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.UseManualAssemblyProbability = 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.UseManualAssemblyProbability = 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.UseManualAssemblyProbability = 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.UseManualAssemblyProbability = 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.UseManualAssemblyProbability = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.UseManualAssemblyCategoryGroup = 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.GetMigratedWaveHeightCalculationOutputsValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedWaveHeightCalculationOutputsValidationQuery(NormativeNormType.SignalingNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaveHeightCalculationsForFactorizedLowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaveHeightCalculationsForFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.GetNewCalculationOutputsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForFactorizedLowerLimitNorm)); + reader.AssertReturnedDataIsValid(HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.GetNewCalculationOutputsValidationQuery( + 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.GetMigratedDesignWaterLevelCalculationOutputsValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDesignWaterLevelCalculationOutputsValidationQuery(NormativeNormType.SignalingNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForFactorizedLowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.GetNewCalculationOutputsValidationQuery( + HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.CalculationType.WaterLevelCalculationsForFactorizedLowerLimitNorm)); + reader.AssertReturnedDataIsValid(HydraulicLocationCalculationOnAssessmentSectionValidationQueryGenerator.GetNewCalculationOutputsValidationQuery( + 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 location calculation outputs related to the design water level calculations + /// are migrated correctly to the corresponding calculation entities. + /// + /// The norm type to generate the query for. + /// A query to validate the hydraulic boundary location calculation outputs. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedDesignWaterLevelCalculationOutputsValidationQuery(NormativeNormType normType) + { + CalculationType calculationType = ConvertToDesignWaterLevelCalculationType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = " + + "( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].HydraulicLocationOutputEntity sourceHlo " + + "JOIN [SOURCEPROJECT].HydraulicLocationEntity USING(HydraulicLocationEntityId) " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity sourceAse USING(AssessmentSectionEntityId) " + + $"WHERE sourceHlo.HydraulicLocationOutputType = 1 AND sourceAse.NormativeNormType = {(int) normType} " + + ") " + + GetHydraulicLocationCalculationsFromCollectionQuery(calculationType) + + GetHydraulicLocationCalculationOutputValidationSubQuery() + + "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 if the hydraulic boundary location calculation outputs related to the wave height calculations + /// are migrated correctly to the corresponding calculation entities. + /// + /// The norm type to generate the query for. + /// A query to validate the hydraulic boundary location calculation outputs. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedWaveHeightCalculationOutputsValidationQuery(NormativeNormType normType) + { + CalculationType calculationType = ConvertToDesignWaterLevelCalculationType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = " + + "( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].HydraulicLocationOutputEntity sourceHlo " + + "JOIN [SOURCEPROJECT].HydraulicLocationEntity USING(HydraulicLocationEntityId) " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity sourceAse USING(AssessmentSectionEntityId) " + + $"WHERE sourceHlo.HydraulicLocationOutputType = 2 AND sourceAse.NormativeNormType = {(int) normType} " + + ") " + + GetHydraulicLocationCalculationsFromCollectionQuery(calculationType) + + GetHydraulicLocationCalculationOutputValidationSubQuery() + + "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;"; + } + + /// + /// Generates a query to validate the new hydraulic boundary location calculation outputs that are not based on migrated data. + /// + /// The type of calculation on which the output should be validated. + /// The query to validate the hydraulic boundary location calculation output. + public static string GetNewCalculationOutputsValidationQuery(CalculationType calculationType) + { + return "SELECT " + + "COUNT() = 0 " + + GetHydraulicLocationCalculationsFromCollectionQuery(calculationType) + + "JOIN HydraulicLocationOutputEntity USING(HydraulicLocationCalculationEntityId); "; + } + + 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) "; + } + + private static string GetHydraulicLocationCalculationOutputValidationSubQuery() + { + return "JOIN HydraulicLocationOutputEntity NEW USING(HydraulicLocationCalculationEntityId) " + + "JOIN [SOURCEPROJECT].HydraulicLocationOutputEntity OLD ON " + + "NEW.GeneralResultSubMechanismIllustrationPointEntityId IS OLD.GeneralResultSubMechanismIllustrationPointEntityId " + + "AND NEW.Result IS OLD.Result " + + "AND NEW.TargetProbability IS OLD.TargetProbability " + + "AND NEW.TargetReliability IS OLD.TargetReliability " + + "AND NEW.CalculatedProbability IS OLD.CalculatedProbability " + + "AND NEW.CalculatedReliability IS OLD.CalculatedReliability " + + "AND NEW.CalculationConvergence = OLD.CalculationConvergence; "; + } + + /// + /// 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.GetMigratedDesignWaterLevelCalculationOutputsValidationQuery(NormativeNormType.SignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDesignWaterLevelCalculationsValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedDesignWaterLevelCalculationOutputsValidationQuery(NormativeNormType.LowerLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.GetNewCalculationOutputsValidationQuery( + 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.GetMigratedWaveHeightCalculationOutputsValidationQuery(NormativeNormType.SignalingNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedWaveHeightCalculationsValidationQuery(NormativeNormType.LowerLimitNorm)); + reader.AssertReturnedDataIsValid(queryGenerator.GetMigratedWaveHeightCalculationOutputsValidationQuery(NormativeNormType.LowerLimitNorm)); + + reader.AssertReturnedDataIsValid(queryGenerator.GetNewCalculationsValidationQuery( + HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.CalculationType.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm)); + reader.AssertReturnedDataIsValid(HydraulicLocationOnGrassCoverErosionOutwardsFailureMechanismValidationQueryGenerator.GetNewCalculationOutputsValidationQuery( + 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 location calculation outputs related to the design water level calculations + /// are migrated correctly to the corresponding calculation entities. + /// + /// The norm type to generate the query for. + /// A query to validate the hydraulic boundary location calculation outputs. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedDesignWaterLevelCalculationOutputsValidationQuery(NormativeNormType normType) + { + CalculationType calculationType = ConvertToDesignWaterLevelCalculationType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = ( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationOutputEntity " + + "JOIN [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity USING(GrassCoverErosionOutwardsHydraulicLocationEntityId) " + + "JOIN [SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity USING(AssessmentSectionEntityId) " + + $"WHERE HydraulicLocationOutputType = 1 AND NormativeNormType = {(int) normType}" + + ") " + + GetHydraulicLocationCalculationsFromFailureMechanismQuery(calculationType) + + GetHydraulicLocationCalculationOutputValidationSubQuery() + + "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 if the hydraulic boundary location calculation outputs related to the wave height calculations + /// are migrated correctly to the corresponding calculation entities. + /// + /// The norm type to generate the query for. + /// A query to validate the hydraulic boundary location calculation outputs. + /// Thrown when + /// is an invalid value of . + /// Thrown when is a valid value, + /// but unsupported. + public string GetMigratedWaveHeightCalculationOutputsValidationQuery(NormativeNormType normType) + { + CalculationType calculationType = ConvertToWaveHeightCalculationType(normType); + + return $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT " + + "COUNT() = ( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationOutputEntity " + + "JOIN [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity USING(GrassCoverErosionOutwardsHydraulicLocationEntityId) " + + "JOIN [SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + "JOIN [SOURCEPROJECT].AssessmentSectionEntity USING(AssessmentSectionEntityId) " + + $"WHERE HydraulicLocationOutputType = 2 AND NormativeNormType = {(int) normType}" + + ") " + + GetHydraulicLocationCalculationsFromFailureMechanismQuery(calculationType) + + GetHydraulicLocationCalculationOutputValidationSubQuery() + + "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;"; + } + + /// + /// Generates a query to validate the new hydraulic boundary location calculation outputs that are not based on migrated data. + /// + /// The type of calculation on which the output should be validated. + /// The query to validate the hydraulic boundary location calculation input. + public static string GetNewCalculationOutputsValidationQuery(CalculationType calculationType) + { + return "SELECT " + + "COUNT() = 0 " + + GetHydraulicLocationCalculationsFromFailureMechanismQuery(calculationType) + + "JOIN HydraulicLocationOutputEntity USING(HydraulicLocationCalculationEntityId); "; + } + + 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) "; + } + + private static string GetHydraulicLocationCalculationOutputValidationSubQuery() + { + return "JOIN HydraulicLocationOutputEntity NEW USING(HydraulicLocationCalculationEntityId) " + + "JOIN ( " + + "SELECT " + + "LocationId, " + + "AssessmentSectionEntityId, " + + "GeneralResultSubMechanismIllustrationPointEntityId, " + + "Result, " + + "TargetProbability, " + + "TargetReliability, " + + "CalculatedProbability, " + + "CalculatedReliability, " + + "CalculationConvergence " + + "FROM [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationOutputEntity " + + "JOIN [SOURCEPROJECT].GrassCoverErosionOutwardsHydraulicLocationEntity USING(GrassCoverErosionOutwardsHydraulicLocationEntityId) " + + "JOIN [SOURCEPROJECT].FailureMechanismEntity USING(FailureMechanismEntityId) " + + ") OLD ON (fm.AssessmentSectionEntityId = OLD.AssessmentSectionEntityId AND OLD.LocationId = hl.LocationId)" + + "WHERE NEW.GeneralResultSubMechanismIllustrationPointEntityId IS OLD.GeneralResultSubMechanismIllustrationPointEntityId " + + "AND NEW.Result IS OLD.Result " + + "AND NEW.TargetProbability IS OLD.TargetProbability " + + "AND NEW.TargetReliability IS OLD.TargetReliability " + + "AND NEW.CalculatedProbability IS OLD.CalculatedProbability " + + "AND NEW.CalculatedReliability IS OLD.CalculatedReliability " + + "AND NEW.CalculationConvergence = OLD.CalculationConvergence; "; + } + + /// + /// 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/Ringtoets.Migration.Integration.Test/Ringtoets.Migration.Integration.Test.csproj =================================================================== diff -u -r9999a33582eb7e1d3b07b76e4fcce9e972adccc0 -r2fff0d73cd7b654907005611f81e276b4cb36e45 --- Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/Ringtoets.Migration.Integration.Test.csproj (.../Ringtoets.Migration.Integration.Test.csproj) (revision 9999a33582eb7e1d3b07b76e4fcce9e972adccc0) +++ Ringtoets/Migration/test/Ringtoets.Migration.Integration.Test/Ringtoets.Migration.Integration.Test.csproj (.../Ringtoets.Migration.Integration.Test.csproj) (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -14,6 +14,11 @@ + + + + + @@ -22,4 +27,30 @@ + + + {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 + + + {FAC55B92-E259-43D6-B9A1-5BDA6C834359} + Ringtoets.Migration.Core + + \ No newline at end of file Fisheye: Tag 2fff0d73cd7b654907005611f81e276b4cb36e45 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/IntegrationTests/MigrationIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2fff0d73cd7b654907005611f81e276b4cb36e45 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/IntegrationTests/MigrationTo171IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2fff0d73cd7b654907005611f81e276b4cb36e45 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/IntegrationTests/MigrationTo172IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2fff0d73cd7b654907005611f81e276b4cb36e45 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/IntegrationTests/MigrationTo173IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2fff0d73cd7b654907005611f81e276b4cb36e45 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/IntegrationTests/MigrationTo181IntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2fff0d73cd7b654907005611f81e276b4cb36e45 refers to a dead (removed) revision in file `Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/IntegrationTests/StorageMigrationIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Ringtoets.Storage.Core.Test.csproj =================================================================== diff -u -r125245b3cf2272af5a432c198b99ba27cc3d1da3 -r2fff0d73cd7b654907005611f81e276b4cb36e45 --- Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Ringtoets.Storage.Core.Test.csproj (.../Ringtoets.Storage.Core.Test.csproj) (revision 125245b3cf2272af5a432c198b99ba27cc3d1da3) +++ Ringtoets/Storage/test/Ringtoets.Storage.Core.Test/Ringtoets.Storage.Core.Test.csproj (.../Ringtoets.Storage.Core.Test.csproj) (revision 2fff0d73cd7b654907005611f81e276b4cb36e45) @@ -84,12 +84,6 @@ - - - - - -