public ScriptSynchronizerTests(MongoDatabase logDatabase)
        {
            if (logDatabase == null) throw new ArgumentNullException("logDatabase");

            _logDatabase = logDatabase;
            _scriptRunner = new Mock<IScriptRunner>();
            _executionLog = new Mock<IUserInteraction>();
            _systemUnderTest = CreateSystemUnderTest();
        }
Ejemplo n.º 2
0
        private static void Synchronize(MongoScriptRunner scriptRunner, IUserInteraction userInteraction, CmdLine cmdLine,
            MongoUrlBuilder mongoUrlBuilder)
        {
            var client = CreateMongoClient(mongoUrlBuilder);
            var filter = new CategoryMatcher();

            try
            {
                System.Console.Out.WriteLine("Running scripts from {0} on database {1}", cmdLine.SourceDir, mongoUrlBuilder.DatabaseName);

                var synchronizer = new ScriptSynchronizer(client.GetServer().GetDatabase(mongoUrlBuilder.DatabaseName), cmdLine.LogCollection, scriptRunner, userInteraction);
                var sourceScripts = new FileScriptEnumerator(cmdLine.SourceDir)
                    .AllScripts()
                    .Where(script => filter.IsMatch(script.Name, cmdLine.Environment))
                    .ToArray();
                var scriptLog = GetScriptLog(mongoUrlBuilder, cmdLine).ToArray();
                bool wasAborted = synchronizer.Synchronize(scriptLog, sourceScripts);
                if (wasAborted)
                {
                    System.Console.Out.WriteLine("Aborting...");
                    Environment.Exit(0);
                }
            }
            finally
            {
                client.GetServer().Disconnect();
            }
        }