public void MarkAsExecutedTest()
        {
            var databaseMock = new Mock <IDatabase>();
            var fileMock     = new Mock <IFileSystemAccess>();

            fileMock.Setup(f => f.FileExists(It.IsAny <string>())).Returns(true);

            var file = new SQLFile("\\0001.diff.sql", databaseMock.Object, fileMock.Object);

            databaseMock.Setup(c => c.ExecuteCommandNonQuery(SQLTemplates.AddExecutedFileSql(new DatabaseVersion("\\Test\\0001" + SQLTemplates.DiffFile), FileType.Diff, "Exported from this database"))).Verifiable();

            file.MarkAsExecuted();

            databaseMock.VerifyAll();
        }
Пример #2
0
        /// <summary>
        /// Executes all statements in an transaction.
        /// </summary>
        /// <exception cref="TeamworkConnectionException">Is thrown when an error occurred while executing the SQL Statements.</exception>
        public void ExecuteInTransaction()
        {
            try
            {
                // execute statements which dont support transaction at the beginning
                foreach (var statement in this.SQLStatements.Where(s => !s.SupportsTransaction && !s.IsTeamworkSchema))
                {
                    statement.Execute();
                }

                var sb = new StringBuilder();
                foreach (var statement in this.SQLStatements.Where(s => s.SupportsTransaction && !s.IsTeamworkSchema))
                {
                    sb.AppendLine(statement.SQL);
                }

                // execute other statements in transaction
                var sql = sb.ToString();
                this.database.ExecuteCommandNonQuery(sql);

                if (this.FileType == FileType.UndoDiff)
                {
                    this.database.ExecuteCommandNonQuery(SQLTemplates.RemoveVersion(this.Version));
                }

                this.database.ExecuteCommandNonQuery(SQLTemplates.AddExecutedFileSql(this.Version, this.FileType));
            }
            catch (NpgsqlException ex)
            {
                try
                {
                    this.database.ExecuteCommandNonQuery(SQLTemplates.AddExecutionHistorySql(this.Version, this.FileType, ex.Message));
                }
                catch (Exception innerEx)
                {
                    Log.Warn("Error while inserting execution history", innerEx);
                }

                Log.Warn(string.Format("File {0} contains errors", this.FileName));
                throw new TeamworkConnectionException(this, ex.Message, ex);
            }

            Log.Info(string.Format("File {0} executed successfully", this.FileName));
        }
Пример #3
0
 public void MarkAsExecuted()
 {
     this.database.ExecuteCommandNonQuery(SQLTemplates.AddExecutedFileSql(this.Version, this.FileType, "Exported from this database"));
     this.database.UpdateData();
 }