Write() public method

Writes the given contents into the migration script file.
public Write ( MigrationScriptContents contents ) : void
contents MigrationScriptContents
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Creates a blank migration script with the given name.
        /// </summary>
        /// <param name="migrationName">name of the migration script</param>
        /// <returns>The path to the new migration script.</returns>
        public string CreateBlankScript(string migrationName)
        {
            long version = GetNewVersionNumber();
            var path = GetPath(null);
            path = Path.Combine(path, version + "_" + SanitizeMigrationName(migrationName) + ".sql");

            var contents = new MigrationScriptContents(null, null);

            var file = new MigrationScriptFile(path);
            file.Write(contents);

            return path;
        }
        /// <summary>
        /// Creates a blank migration script with the given name.
        /// </summary>
        /// <param name="migrationName">name of the migration script</param>
        /// <returns>The path to the new migration script.</returns>
        public string CreateBlankScript(string migrationName)
        {
            long version = GetNewVersionNumber();
            var  path    = GetPath(null);

            path = Path.Combine(path, version + "_" + SanitizeMigrationName(migrationName) + ".sql");

            var contents = new MigrationScriptContents(null, null);

            var file = new MigrationScriptFile(path);

            file.Write(contents);

            return(path);
        }
        /// <summary>
        /// Creates a blank migration script with the given name.
        /// </summary>
        /// <returns>The path to the new migration script.</returns>
        public string CreateBlankScript(GenerateScriptCommandArgs args)
        {
            long version = GetNewVersionNumber(args);
            var  path    = GetPath(null, args);

            path = Path.Combine(path, version + "_" + SanitizeMigrationName(args.MigrationName) + ".sql");

            var setup = new System.Text.StringBuilder();

            setup.AppendLine("SET XACT_ABORT ON;");
            setup.AppendLine("");
            setup.Append("-- TODO: Replace with script implementation");

            var contents = new MigrationScriptContents(setup.ToString(), null);

            var file = new MigrationScriptFile(path);

            file.Write(contents);

            return(path);
        }
        public void Read_should_parse_file_contents_correctly()
        {
            //  arrange
            var tempFilePath = Path.GetTempFileName();
            using (DisposableFile.Watch(tempFilePath))
            {
                var file = new MigrationScriptFile(tempFilePath);
                const string setupText = "my setup text";
                const string teardownText = "my teardown text";
                file.Write(new MigrationScriptContents(setupText, teardownText));

                //  act
                var contents = file.Read();

                //  assert
                Assert.AreEqual(setupText, contents.Setup.Trim(), "setup does not match");
                Assert.AreEqual(teardownText, contents.Teardown.Trim(), "teardown does not match");
            }
        }