Beispiel #1
0
        public void RunMigrationScriptError_Test()
        {
            bool executed = false;

            UnityCache.RegisterInstance <IFaustAccessor>(new Fakes.StubIFaustAccessor
            {
                ExecuteSqlCommandStringUserContext = (command, userContext) =>
                {
                    executed = true;
                    throw new Exception();
                }
            });

            FaustMigrationScript script = new FaustMigrationScript
            {
                ReleaseNumber = 1,
                ScriptName    = "UnitTestScript",
                Commands      = new string[] { "Command 1" }
            };

            FaustMigrationHistory result = new FaustEngine().RunMigrationScript(script, new UserContext());

            Assert.IsTrue(executed);
            Assert.IsFalse(result.Successful.Value);
            Assert.IsNotNull(result);
        }
Beispiel #2
0
        public void SaveMigrationsHistoryUpdate_Test()
        {
            bool created = false;
            bool updated = false;

            UnityCache.RegisterInstance <IFaustMigrationsHistoryAccessor>(new Fakes.StubIFaustMigrationsHistoryAccessor
            {
                FindManyFaustMigrationHistoryUserContext = (history, userContext) =>
                {
                    return(new FaustMigrationHistory[] { new FaustMigrationHistory() });
                },
                CreateFaustMigrationHistoryUserContext = (history, userContext) =>
                {
                    created = true;
                    return(new FaustMigrationHistory());
                },
                UpdateFaustMigrationHistoryUserContext = (history, userContext) =>
                {
                    updated = true;
                    return(new FaustMigrationHistory());
                }
            });

            new FaustEngine().SaveMigrationsHistory(new FaustMigrationHistory[] { new FaustMigrationHistory() }, new UserContext());

            Assert.IsFalse(created);
            Assert.IsTrue(updated);
        }
Beispiel #3
0
        public void BasicTest()
        {
            bool initialized  = false;
            bool debugDeleted = false;
            bool gotScripts   = false;
            bool ranScript    = false;
            bool savedHistory = false;

            UnityCache.RegisterInstance <IFaustMigrationsHistoryAccessor>(new Fakes.StubIFaustMigrationsHistoryAccessor
            {
                InitializeUserContext = (userContext) =>
                {
                    initialized = true;
                },
                DeleteDebugEntriesUserContext = (userContext) =>
                {
                    debugDeleted = true;
                    return(new FaustMigrationHistory[] { });
                }
            });

            UnityCache.RegisterInstance <IFaustEngine>(new Fakes.StubIFaustEngine
            {
                GetReleaseMigrationScriptsDirectoryInfoUserContext = (releaseDir, userContext) =>
                {
                    gotScripts = true;
                    return(new FaustMigrationScript[] { new FaustMigrationScript() });
                },
                RunMigrationScriptFaustMigrationScriptUserContext = (script, userContext) =>
                {
                    ranScript = true;
                    return(new FaustMigrationHistory());
                },
                SaveMigrationsHistoryFaustMigrationHistoryArrayUserContext = (histories, userContext) =>
                {
                    savedHistory = true;
                }
            });

            new FaustManager().RunMigration("unitTest");

            Assert.IsTrue(initialized);
            Assert.IsTrue(debugDeleted);
            Assert.IsTrue(gotScripts);
            Assert.IsTrue(ranScript);
            Assert.IsTrue(savedHistory);
        }
Beispiel #4
0
        public void GetReleaseMigrationScripts_TestFindOne()
        {
            bool foundMany = false;

            UnityCache.RegisterInstance <IFaustMigrationsHistoryAccessor>(new Fakes.StubIFaustMigrationsHistoryAccessor
            {
                FindManyFaustMigrationHistoryUserContext = (history, userContext) => {
                    foundMany = true;
                    return(new FaustMigrationHistory[] {});
                }
            });

            DirectoryInfo releaseDir = new DirectoryInfo(@"..\..\migrations\UnitTest\001");

            FaustMigrationScript[] results = new FaustEngine().GetReleaseMigrationScripts(releaseDir, new UserContext());

            Assert.IsTrue(foundMany);
            Assert.AreEqual(1, results.Length);
        }