コード例 #1
0
        public void Migrate_TargetFileNotWritable_ThrowsCriticalDatabaseMigrationException()
        {
            // Setup
            const string newVersion        = "17.1";
            string       sourceFilePath    = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
            var          fromVersionedFile = new ProjectVersionedFile(sourceFilePath);

            string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_TargetFileNotWritable_ThrowsCriticalDatabaseMigrationException));
            var    migrator       = new ProjectFileMigrator();

            using (new FileDisposeHelper(targetFilePath))
            {
                FileAttributes attributes = File.GetAttributes(targetFilePath);
                File.SetAttributes(targetFilePath, attributes | FileAttributes.ReadOnly);

                try
                {
                    // Call
                    TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath);

                    // Assert
                    var exception = Assert.Throws <CriticalMigrationException>(call);
                    StringAssert.StartsWith("Het gemigreerde projectbestand is aangemaakt op '",
                                            exception.Message);
                    StringAssert.EndsWith($"', maar er is een onverwachte fout opgetreden tijdens het verplaatsen naar '{targetFilePath}'.",
                                          exception.Message);
                    Assert.IsInstanceOf <UnauthorizedAccessException>(exception.InnerException);
                }
                finally
                {
                    File.SetAttributes(targetFilePath, attributes);
                }
            }
        }
コード例 #2
0
        public void Given172Project_WhenUpgradedTo173_ThenProjectAsExpected()
        {
            // Given
            string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Migration.Core,
                                                               "MigrationTestProject172.rtd");
            var fromVersionedFile = new ProjectVersionedFile(sourceFilePath);

            string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given172Project_WhenUpgradedTo173_ThenProjectAsExpected));
            string logFilePath    = TestHelper.GetScratchPadPath(string.Concat(nameof(Given172Project_WhenUpgradedTo173_ThenProjectAsExpected), ".log"));
            var    migrator       = new ProjectFileMigrator
            {
                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);
                }
        }
コード例 #3
0
        public void Migrate_ValidFilesWithLogFile_SavesFileAtNewLocation()
        {
            // Setup
            const string newVersion        = "17.1";
            string       sourceFilePath    = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
            var          fromVersionedFile = new ProjectVersionedFile(sourceFilePath);

            string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_ValidFilesWithLogFile_SavesFileAtNewLocation));
            string logFilePath    = TestHelper.GetScratchPadPath(string.Concat(nameof(Migrate_ValidFilesWithLogFile_SavesFileAtNewLocation), ".log"));
            var    migrator       = new ProjectFileMigrator
            {
                LogPath = logFilePath
            };

            using (new FileDisposeHelper(logFilePath))
                using (new FileDisposeHelper(targetFilePath))
                {
                    // Call
                    migrator.Migrate(fromVersionedFile, newVersion, targetFilePath);

                    // Assert
                    var toVersionedFile = new ProjectVersionedFile(targetFilePath);
                    Assert.AreEqual(newVersion, toVersionedFile.GetVersion());
                }
        }
コード例 #4
0
        public void Constructor_ReturnsExpectedValues()
        {
            // Call
            var migrator = new ProjectFileMigrator();

            // Assert
            Assert.IsInstanceOf <VersionedFileMigrator>(migrator);
        }
コード例 #5
0
        private static void MigrateFile(string sourceFilePath, string targetFilePath)
        {
            string newVersion        = ProjectVersionHelper.GetCurrentDatabaseVersion();
            var    fromVersionedFile = new ProjectVersionedFile(sourceFilePath);
            var    migrator          = new ProjectFileMigrator();

            migrator.Migrate(fromVersionedFile, newVersion, targetFilePath);
        }
コード例 #6
0
        private static void MigrateCommand(string filePath, string toFilePath)
        {
            ValidateMigrationArguments(filePath, toFilePath);
            var migrator   = new ProjectFileMigrator();
            var sourceFile = new ProjectVersionedFile(filePath);

            migrator.Migrate(sourceFile, currentDatabaseVersion, toFilePath);
            System.Console.WriteLine(Resources.CommandMigrate_Successful_Migration_From_Location_0_To_Location_1_Version_2,
                                     filePath, toFilePath, currentDatabaseVersion);
        }
コード例 #7
0
        public void IsVersionSupported_UnsupportedVersion_ReturnsFalse(string fromVersion)
        {
            // Setup
            var migrator = new ProjectFileMigrator();

            // Call
            bool isSupported = migrator.IsVersionSupported(fromVersion);

            // Assert
            Assert.IsFalse(isSupported);
        }
コード例 #8
0
        public void NeedsMigrate_NeedsMigrate_ReturnsTrue()
        {
            // Setup
            string sourceFilePath = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
            var    versionedFile  = new ProjectVersionedFile(sourceFilePath);
            var    migrator       = new ProjectFileMigrator();

            // Call
            bool needsMigrate = migrator.NeedsMigrate(versionedFile, "17.1");

            // Assert
            Assert.IsTrue(needsMigrate);
        }
コード例 #9
0
        public void Given164Project_WhenUpgradedTo171_ThenProjectAsExpected()
        {
            // Given
            string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Migration.Core,
                                                               "MigrationTestProject164.rtd");
            var fromVersionedFile = new ProjectVersionedFile(sourceFilePath);

            string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given164Project_WhenUpgradedTo171_ThenProjectAsExpected));
            string logFilePath    = TestHelper.GetScratchPadPath(string.Concat(nameof(Given164Project_WhenUpgradedTo171_ThenProjectAsExpected), ".log"));
            var    migrator       = new ProjectFileMigrator
            {
                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);
                }
        }
コード例 #10
0
        public void Migrate_UnsupportedVersion_ThrowsCriticalDatabaseMigrationException()
        {
            // Setup
            string sourceFilePath    = ProjectMigrationTestHelper.GetOutdatedUnSupportedProjectFilePath();
            var    fromVersionedFile = new ProjectVersionedFile(sourceFilePath);

            string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_UnsupportedVersion_ThrowsCriticalDatabaseMigrationException));
            var    migrator       = new ProjectFileMigrator();

            // Call
            TestDelegate call = () => migrator.Migrate(fromVersionedFile, "17.1", targetFilePath);

            // Assert
            string message = Assert.Throws <CriticalMigrationException>(call).Message;

            Assert.AreEqual("Het migreren van een projectbestand met versie '8' naar versie '17.1' is niet ondersteund.", message);
        }
コード例 #11
0
        public void Migrate_TargetFilePathEqualsSourcePath_ThrowsCriticalDatabaseMigrationException()
        {
            // Setup
            const string newVersion        = "17.1";
            string       sourceFilePath    = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
            var          fromVersionedFile = new ProjectVersionedFile(sourceFilePath);
            var          migrator          = new ProjectFileMigrator();

            // Call
            TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, sourceFilePath);

            // Assert
            var exception = Assert.Throws <CriticalMigrationException>(call);

            Assert.AreEqual("Het doelprojectpad moet anders zijn dan het bronprojectpad.",
                            exception.Message);
        }
コード例 #12
0
ファイル: ProjectMigrator.cs プロジェクト: Deltares/Riskeer
        /// <summary>
        /// Creates a new instance of <see cref="ProjectMigrator"/>.
        /// </summary>
        /// <param name="inquiryHelper">Object responsible for inquiring the data.</param>
        public ProjectMigrator(IInquiryHelper inquiryHelper)
        {
            if (inquiryHelper == null)
            {
                throw new ArgumentNullException(nameof(inquiryHelper));
            }

            migrationLogPath = Path.Combine(SettingsHelper.Instance.GetLocalUserTemporaryDirectory(),
                                            "RiskeerMigrationLog.sqlite");

            this.inquiryHelper = inquiryHelper;
            fileMigrator       = new ProjectFileMigrator
            {
                LogPath = migrationLogPath
            };
            fileFilter = new FileFilterGenerator(Resources.RiskeerProject_FileExtension,
                                                 Resources.Project_TypeDescription);
        }
コード例 #13
0
        private static void IsVersionSupportedCommand(string location)
        {
            ValidateIsVersionSupportedArgument(location);

            var    versionedFile = new ProjectVersionedFile(location);
            var    migrator      = new ProjectFileMigrator();
            string version       = versionedFile.GetVersion();

            bool isSupported = migrator.IsVersionSupported(version);

            if (isSupported)
            {
                System.Console.WriteLine(Resources.CommandSupported_File_Able_To_Migrate_To_Version_0, currentDatabaseVersion);
            }
            else
            {
                ConsoleHelper.WriteErrorLine(MigrationCoreStorageResources.Migrate_From_Version_0_To_Version_1_Not_Supported,
                                             version, currentDatabaseVersion);
            }
        }
コード例 #14
0
        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 ProjectVersionedFile(sourceFilePath);

            string name           = $"{nameof(GivenProject_WhenSpecialCharacterInPath_DoesNotThrowException)} \'[]!`~@#$%^€&()-_=+;,";
            string targetFilePath = TestHelper.GetScratchPadPath(name);
            string logFilePath    = TestHelper.GetScratchPadPath(string.Concat(name, sourceFile, ".log"));
            var    migrator       = new ProjectFileMigrator
            {
                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);
            }
        }
コード例 #15
0
        public void Migrate_ValidFilesWithNonExistingLogFile_ThrowsCriticalDatabaseMigrationException()
        {
            // Setup
            const string newVersion        = "17.1";
            string       sourceFilePath    = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
            var          fromVersionedFile = new ProjectVersionedFile(sourceFilePath);

            string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_ValidFilesWithNonExistingLogFile_ThrowsCriticalDatabaseMigrationException));
            string logFilePath    = TestHelper.GetScratchPadPath(string.Concat(nameof(Migrate_ValidFilesWithNonExistingLogFile_ThrowsCriticalDatabaseMigrationException), ".log"));
            var    migrator       = new ProjectFileMigrator
            {
                LogPath = logFilePath
            };

            using (new FileDisposeHelper(targetFilePath))
            {
                // Call
                TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath);

                // Assert
                var exception = Assert.Throws <CriticalMigrationException>(call);
                Assert.IsInstanceOf <SQLiteException>(exception.InnerException);
            }
        }
コード例 #16
0
        public void GivenEmpty164Project_WhenNoChangesMadeAndMigratingToLatestVersion_ThenLogDatabaseContainsMessagesSayingNoChangesMade()
        {
            // Given
            string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Migration.Core,
                                                               "Empty valid Release 16.4.rtd");
            var fromVersionedFile = new ProjectVersionedFile(sourceFilePath);

            string targetFilePath = TestHelper.GetScratchPadPath(
                nameof(GivenEmpty164Project_WhenNoChangesMadeAndMigratingToLatestVersion_ThenLogDatabaseContainsMessagesSayingNoChangesMade));
            string logFilePath = TestHelper.GetScratchPadPath(
                string.Concat(nameof(GivenEmpty164Project_WhenNoChangesMadeAndMigratingToLatestVersion_ThenLogDatabaseContainsMessagesSayingNoChangesMade), ".log"));
            var migrator = new ProjectFileMigrator
            {
                LogPath = logFilePath
            };

            using (new FileDisposeHelper(logFilePath))
                using (new FileDisposeHelper(targetFilePath))
                {
                    // When
                    migrator.Migrate(fromVersionedFile, latestVersion, targetFilePath);

                    using (var reader = new MigrationLogDatabaseReader(logFilePath))
                    {
                        ReadOnlyCollection <MigrationLogMessage> messages = reader.GetMigrationLogMessages();
                        Assert.AreEqual(16, messages.Count);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("5", "17.1", "Gevolgen van de migratie van versie 16.4 naar versie 17.1:"),
                            messages[0]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("5", "17.1", "* Geen aanpassingen."),
                            messages[1]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("17.1", "17.2", "Gevolgen van de migratie van versie 17.1 naar versie 17.2:"),
                            messages[2]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("17.1", "17.2", "* Geen aanpassingen."),
                            messages[3]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("17.2", "17.3", "Gevolgen van de migratie van versie 17.2 naar versie 17.3:"),
                            messages[4]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("17.2", "17.3", "* Geen aanpassingen."),
                            messages[5]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("17.3", "18.1", "Gevolgen van de migratie van versie 17.3 naar versie 18.1:"),
                            messages[6]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("17.3", "18.1", "* Geen aanpassingen."),
                            messages[7]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("18.1", "19.1", "Gevolgen van de migratie van versie 18.1 naar versie 19.1:"),
                            messages[8]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("18.1", "19.1", "* Geen aanpassingen."),
                            messages[9]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("19.1", "21.1", "Gevolgen van de migratie van versie 19.1 naar versie 21.1:"),
                            messages[10]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("19.1", "21.1", "* Geen aanpassingen."),
                            messages[11]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("21.1", "22.1", "Gevolgen van de migratie van versie 21.1 naar versie 22.1:"),
                            messages[12]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("21.1", "22.1", "* De oorspronkelijke faalmechanismen zijn omgezet naar het nieuwe formaat.\r\n* Alle toetsoordelen zijn verwijderd."),
                            messages[13]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("22.1", $"{latestVersion}", $"Gevolgen van de migratie van versie 22.1 naar versie {latestVersion}:"),
                            messages[14]);
                        MigrationLogTestHelper.AssertMigrationLogMessageEqual(
                            new MigrationLogMessage("22.1", $"{latestVersion}", "* Geen aanpassingen."),
                            messages[15]);
                    }
                }
        }