Exemplo n.º 1
0
        public void Migrate_VersionedFileVersionNotSupported_ThrowsCriticalMigrationException()
        {
            // Setup
            const string fromLocation     = "fromLocation";
            const string toVersion        = "toVersion";
            const string toLocation       = "location";
            const string incorrectVersion = "not supported";

            var mockRepository = new MockRepository();
            var comparer       = mockRepository.Stub <IComparer>();
            var versionedFile  = mockRepository.Stub <IVersionedFile>();

            versionedFile.Expect(vf => vf.Location).Return(fromLocation);
            versionedFile.Expect(vf => vf.GetVersion()).Return(incorrectVersion);
            mockRepository.ReplayAll();

            var migrator = new SimpleVersionedFileMigrator(comparer);

            // Call
            TestDelegate call = () => migrator.Migrate(versionedFile, toVersion, toLocation);

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

            Assert.AreEqual($"Het migreren van een projectbestand met versie '{incorrectVersion}' naar versie '{toVersion}' is niet ondersteund.", exception.Message);
            mockRepository.VerifyAll();
        }
Exemplo n.º 2
0
        public void IsVersionSupported_ValidFromVersion_ReturnsIfSupported(string fromVersion, bool shouldSupport)
        {
            // Setup
            var mockRepository = new MockRepository();
            var comparer       = mockRepository.Stub <IComparer>();

            mockRepository.ReplayAll();

            const string toVersion = "1";
            var          migrator  = new SimpleVersionedFileMigrator(comparer)
            {
                CreateScripts =
                {
                    new TestCreateScript(toVersion)
                },
                UpgradeScripts =
                {
                    new TestUpgradeScript("true", toVersion)
                }
            };

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

            // Assert
            Assert.AreEqual(shouldSupport, isSupported);
            mockRepository.VerifyAll();
        }
Exemplo n.º 3
0
        public void NeedsMigrate_ValidVersionedFile_ReturnsIfNeedsMigrate(string fromVersion, string toVersion, bool shouldMigrate)
        {
            // Setup
            var mockRepository = new MockRepository();
            var versionedFile  = mockRepository.Stub <IVersionedFile>();

            versionedFile.Expect(vf => vf.GetVersion()).Return(fromVersion);
            mockRepository.ReplayAll();

            var migrator = new SimpleVersionedFileMigrator(new SimpleVersionComparer())
            {
                CreateScripts =
                {
                    new TestCreateScript(toVersion)
                },
                UpgradeScripts =
                {
                    new TestUpgradeScript(fromVersion, toVersion)
                }
            };

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

            // Assert
            Assert.AreEqual(shouldMigrate, needsMigrate);
            mockRepository.VerifyAll();
        }
Exemplo n.º 4
0
        public void IsVersionSupported_FromVersionIsNullOrWhiteSpace_ReturnsFalse(string fromVersion)
        {
            // Setup
            var mockRepository = new MockRepository();
            var comparer       = mockRepository.Stub <IComparer>();

            mockRepository.ReplayAll();
            var migrator = new SimpleVersionedFileMigrator(comparer);

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

            // Assert
            Assert.IsFalse(isSupported);
            mockRepository.VerifyAll();
        }
Exemplo n.º 5
0
        public void NeedsMigrate_VersionedFileNull_ThrowsArgumentNullException()
        {
            // Setup
            var mockRepository = new MockRepository();
            var comparer       = mockRepository.Stub <IComparer>();

            mockRepository.ReplayAll();
            var migrator = new SimpleVersionedFileMigrator(comparer);

            // Call
            TestDelegate call = () => migrator.NeedsMigrate(null, "");

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("versionedFile", paramName);
            mockRepository.VerifyAll();
        }
Exemplo n.º 6
0
        public void Migrate_ValidMigrationFileInUse_ThrowsCriticalMigrationException()
        {
            // Setup
            const string fromVersion  = "fromVersion";
            const string fromLocation = "fromLocation";
            const string toVersion    = "toVersion";

            string toLocation = TestHelper.GetScratchPadPath(nameof(Migrate_ValidMigrationFileInUse_ThrowsCriticalMigrationException));

            var mockRepository = new MockRepository();
            var comparer       = mockRepository.Stub <IComparer>();
            var versionedFile  = mockRepository.Stub <IVersionedFile>();

            versionedFile.Stub(vf => vf.Location).Return(fromLocation);
            versionedFile.Expect(vf => vf.GetVersion()).Return(fromVersion);
            mockRepository.ReplayAll();

            using (var fileDisposeHelper = new FileDisposeHelper(toLocation))
            {
                fileDisposeHelper.LockFiles();
                var migrator = new SimpleVersionedFileMigrator(comparer)
                {
                    CreateScripts =
                    {
                        new TestCreateScript(toVersion)
                    },
                    UpgradeScripts =
                    {
                        new TestUpgradeScript(fromVersion, toVersion)
                    }
                };

                // Call
                TestDelegate call = () => migrator.Migrate(versionedFile, toVersion, toLocation);

                // 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 '{toLocation}'.",
                                      exception.Message);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 7
0
        public void Migrate_ValidChainingMigration_CreatesNewVersion()
        {
            // Setup
            const string fromLocation = "fromLocation";
            const string fromVersion  = "0";
            const string toVersion    = "2";

            string toLocation = TestHelper.GetScratchPadPath(nameof(Migrate_ValidChainingMigration_CreatesNewVersion));

            var mockRepository = new MockRepository();
            var versionedFile  = mockRepository.Stub <IVersionedFile>();

            versionedFile.Stub(vf => vf.Location).Return(fromLocation);
            versionedFile.Expect(vf => vf.GetVersion()).Return(fromVersion);
            mockRepository.ReplayAll();

            var migrator = new SimpleVersionedFileMigrator(new SimpleVersionComparer())
            {
                CreateScripts =
                {
                    new TestCreateScript("1"),
                    new TestCreateScript(toVersion)
                },
                UpgradeScripts =
                {
                    new TestUpgradeScript(fromVersion, "1"),
                    new TestUpgradeScript("1",         toVersion)
                }
            };

            // Call
            migrator.Migrate(versionedFile, toVersion, toLocation);

            // Assert
            Assert.IsTrue(File.Exists(toLocation), $"File at location {toLocation} has not been created");
            File.Delete(toLocation);

            mockRepository.VerifyAll();
        }
Exemplo n.º 8
0
        public void Migrate_NewFileLocationNull_ThrowsArgumentNullException()
        {
            // Setup
            var mockRepository = new MockRepository();
            var comparer       = mockRepository.Stub <IComparer>();
            var versionedFile  = mockRepository.Stub <IVersionedFile>();

            mockRepository.ReplayAll();

            const string toVersion = "toVersion";

            var migrator = new SimpleVersionedFileMigrator(comparer);

            // Call
            TestDelegate call = () => migrator.Migrate(versionedFile, toVersion, null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("newFileLocation", paramName);
            mockRepository.VerifyAll();
        }
Exemplo n.º 9
0
        public void Migrate_NewFileLocationEqualToVersionedFileLocation_ThrowsCriticalMigrationException()
        {
            // Setup
            const string toVersion  = "toVersion";
            const string toLocation = "location";

            var mockRepository = new MockRepository();
            var comparer       = mockRepository.Stub <IComparer>();
            var versionedFile  = mockRepository.Stub <IVersionedFile>();

            versionedFile.Expect(vf => vf.Location).Return(toLocation);
            mockRepository.ReplayAll();

            var migrator = new SimpleVersionedFileMigrator(comparer);

            // Call
            TestDelegate call = () => migrator.Migrate(versionedFile, toVersion, toLocation);

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

            Assert.AreEqual("Het doelprojectpad moet anders zijn dan het bronprojectpad.", exception.Message);
            mockRepository.VerifyAll();
        }