Example #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();
        }
Example #2
0
        public void ShouldMigrate_LatestProjectVersion_ReturnsFalse()
        {
            // Setup
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            mocks.ReplayAll();

            string sourceFilePath = ProjectMigrationTestHelper.GetLatestProjectFilePath();

            var migrator = new ProjectMigrator(inquiryHelper);

            // Call
            MigrationRequired shouldMigrate = migrator.ShouldMigrate(sourceFilePath);

            // Assert
            Assert.AreEqual(MigrationRequired.No, shouldMigrate);
            mocks.VerifyAll();
        }
Example #3
0
        public void ShouldMigrate_FilePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            mocks.ReplayAll();

            var migrator = new ProjectMigrator(inquiryHelper);

            // Call
            void Call() => migrator.ShouldMigrate(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("filePath", exception.ParamName);

            mocks.VerifyAll();
        }
Example #4
0
        public void ShouldMigrate_InvalidFilePath_ThrowsArgumentException(string invalidFilePath)
        {
            // Setup
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.Stub <IInquiryHelper>();

            mocks.ReplayAll();

            var migrator = new ProjectMigrator(inquiryHelper);

            // Call
            void Call() => migrator.ShouldMigrate(invalidFilePath);

            // Assert
            var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(
                Call, "Bronprojectpad moet een geldig projectpad zijn.");

            Assert.AreEqual("filePath", exception.ParamName);

            mocks.VerifyAll();
        }
Example #5
0
        public void ShouldMigrate_OutdatedProjectSupported_AskMigrationConfirmationAndReturnBasedOnConfirmation(bool confirmContinuation)
        {
            // Setup
            string question = "Het project dat u wilt openen is opgeslagen in het formaat van een eerdere versie van Riskeer of Ringtoets." +
                              $"{Environment.NewLine}{Environment.NewLine}" +
                              $"Weet u zeker dat u het bestand wilt migreren naar het formaat van uw huidige Riskeerversie ({currentDatabaseVersion})?";
            var mocks         = new MockRepository();
            var inquiryHelper = mocks.StrictMock <IInquiryHelper>();

            inquiryHelper.Expect(h => h.InquireContinuation(question)).Return(confirmContinuation);
            mocks.ReplayAll();

            string sourceFilePath = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath();

            var migrator = new ProjectMigrator(inquiryHelper);

            // Call
            var shouldMigrate = MigrationRequired.No;

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

            // Assert
            var expectedLogMessages = new List <Tuple <string, LogLevelConstant> >();

            if (!confirmContinuation)
            {
                expectedLogMessages.Add(Tuple.Create($"Het migreren van het projectbestand '{sourceFilePath}' is geannuleerd.",
                                                     LogLevelConstant.Warn));
            }

            TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedLogMessages, expectedLogMessages.Count);

            MigrationRequired expectedResult = confirmContinuation ? MigrationRequired.Yes : MigrationRequired.Aborted;

            Assert.AreEqual(expectedResult, shouldMigrate);

            mocks.VerifyAll();
        }