// 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 Application.Ringtoets.Migration.Core; using Application.Ringtoets.Storage.TestUtil; using Core.Common.TestUtil; using NUnit.Framework; namespace Application.Ringtoets.Storage.Test.IntegrationTests { 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); AssertHydraRingPreprocessor(reader); } AssertLogDatabase(logFilePath); } } private static void AssertTablesContentMigrated(MigratedDatabaseReader reader, string sourceFilePath) { var tables = new[] { "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", "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", "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, "* Geen aanpassingen."), 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 AssertHydraRingPreprocessor(MigratedDatabaseReader reader) { const string validatePreprocessorSettings = "SELECT COUNT() = 0 " + "FROM [HydraRingPreprocessorEntity];"; reader.AssertReturnedDataIsValid(validatePreprocessorSettings); } } }