Ejemplo n.º 1
0
        public void ShouldMigrate_OutdatedProjectUnsupported_ReturnsNotSupportedAndGeneratesLogMessages()
        {
            // Setup
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            mocks.ReplayAll();

            string sourceFilePath = ProjectMigrationTestHelper.GetOutdatedUnSupportedProjectFilePath();
            var    versionedFile  = new ProjectVersionedFile(sourceFilePath);
            string fileVersion    = versionedFile.GetVersion();

            var migrator      = new ProjectMigrator(inquiryHelper);
            var shouldMigrate = MigrationRequired.Yes;

            // Call
            void Call() => shouldMigrate = migrator.ShouldMigrate(sourceFilePath);

            // Assert
            var expectedMessage = $"Het migreren van een projectbestand met versie '{fileVersion}' naar versie '{currentDatabaseVersion}' is niet ondersteund.";

            TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage);
            Assert.AreEqual(MigrationRequired.NotSupported, shouldMigrate);

            mocks.VerifyAll();
        }
        private static IEnumerable <TestCaseData> ProjectFilesToMigrate()
        {
            string unsupportedProjectFilePath = ProjectMigrationTestHelper.GetOutdatedUnSupportedProjectFilePath();
            var    unsupportedVersionedFile   = new ProjectVersionedFile(unsupportedProjectFilePath);
            string unsupportedVersion         = unsupportedVersionedFile.GetVersion();

            string supportedProjectFilePath = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();
            var    supportedVersionedFile   = new ProjectVersionedFile(supportedProjectFilePath);
            string supportedVersion         = supportedVersionedFile.GetVersion();

            yield return(new TestCaseData(unsupportedProjectFilePath, unsupportedVersion, false).SetName("UnsupportedProjectVersion"));

            yield return(new TestCaseData(supportedProjectFilePath, supportedVersion, true).SetName("SupportedProjectVersion"));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void Migrate_UnsupportedSourceFileVersion_MigrationFailsAndLogsError()
        {
            // Setup
            string sourceFilePath = ProjectMigrationTestHelper.GetOutdatedUnSupportedProjectFilePath();
            string targetFile     = $"{nameof(ProjectMigratorTest)}." +
                                    $"{nameof(Migrate_UnsupportedSourceFileVersion_MigrationFailsAndLogsError)}";
            string targetFilePath = Path.Combine(TestHelper.GetScratchPadPath(), testDirectory, targetFile);

            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            mocks.ReplayAll();

            var logDirectory = $"{nameof(Migrate_UnsupportedSourceFileVersion_MigrationFailsAndLogsError)}_log";

            using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), logDirectory))
                using (new UseCustomSettingsHelper(new TestSettingsHelper
                {
                    TempPath = TestHelper.GetScratchPadPath(logDirectory)
                }))
                {
                    var migrator = new ProjectMigrator(inquiryHelper);

                    var migrationSuccessful = true;

                    // Call
                    void Call() => migrationSuccessful = migrator.Migrate(sourceFilePath, targetFilePath);

                    // Assert
                    TestHelper.AssertLogMessages(Call, messages =>
                    {
                        string[] msgs = messages.ToArray();
                        Assert.AreEqual(1, msgs.Length);
                        StringAssert.StartsWith($"Het migreren van het projectbestand '{sourceFilePath}' is mislukt: ", msgs[0]);
                    });
                    Assert.IsFalse(migrationSuccessful);

                    string logPath = Path.Combine(TestHelper.GetScratchPadPath(logDirectory), "RiskeerMigrationLog.sqlite");
                    Assert.IsFalse(File.Exists(logPath));
                }

            mocks.VerifyAll();
        }