public void CleanProjectFileForRemoteExecutionTest_NothingToClean()
        {
            Initialization init = GetInitializationObject();

            //Create the build package...
            SqlSyncBuildData buildData = init.CreateSqlSyncSqlBuildDataObject();

            init.AddInsertScript(ref buildData, true);
            init.AddFailureScript(ref buildData, true, true);
            init.AddFailureScript(ref buildData, true, true);
            foreach (SqlSyncBuildData.ScriptRow row in buildData.Script)
            {
                row.FileName = Path.GetFileName(row.FileName);
            }

            string zipFileName = init.GetTrulyUniqueFile() + ".sbm";
            string path        = Path.GetDirectoryName(zipFileName);

            SqlBuildFileHelper.PackageProjectFileIntoZip(buildData, path, zipFileName, false);

            byte[]           expected = File.ReadAllBytes(zipFileName);
            byte[]           actual;
            SqlSyncBuildData cleanedBuildData;

            actual = SqlBuildFileHelper.CleanProjectFileForRemoteExecution(zipFileName, out cleanedBuildData);
            Assert.IsTrue(cleanedBuildData.GetXml().ToString().Length > 100);
            Assert.AreEqual(buildData.GetXml().ToString().Length, cleanedBuildData.GetXml().ToString().Length);
            Assert.IsTrue(1500 <= actual.Length, string.Format("Actual length of cleaned XML {0}.\r\n{1}", actual.Length.ToString(), cleanedBuildData.GetXml())); //can't get exact length due to variations in guids and dates.
            Assert.IsTrue(expected.Length == actual.Length);

            Assert.IsTrue(cleanedBuildData.ScriptRun.Rows.Count == 0);
            Assert.IsTrue(cleanedBuildData.Build.Rows.Count == 0);
            Assert.IsTrue(cleanedBuildData.CodeReview.Rows.Count == 0);
            Assert.AreEqual(buildData.Script.Rows.Count, cleanedBuildData.Script.Rows.Count);
        }
Beispiel #2
0
        internal static bool RebuildBuildManagerFile(int defaultTimeout, string buildFileName, List <RebuilderData> rebuildData)
        {
            string tempPath = System.IO.Path.GetTempPath() + System.Guid.NewGuid();

            Directory.CreateDirectory(tempPath);
            try
            {
                string projFileName = Path.Combine(tempPath, SqlSync.SqlBuild.XmlFileNames.MainProjectFile);

                for (int i = 0; i < rebuildData.Count; i++)
                {
                    File.WriteAllText(Path.Combine(tempPath, rebuildData[i].ScriptFileName), rebuildData[i].ScriptText);
                }

                SqlSyncBuildData buildData = SqlBuildFileHelper.CreateShellSqlSyncBuildDataObject();
                buildData.AcceptChanges();

                if (!SqlBuildFileHelper.PackageProjectFileIntoZip(buildData, tempPath, buildFileName))
                {
                    return(false);
                }

                if (!ZipHelper.UnpackZipPackage(tempPath, buildFileName, false))
                {
                    return(false);
                }

                for (int i = 0; i < rebuildData.Count; i++)
                {
                    SqlBuildFileHelper.AddScriptFileToBuild(ref buildData,
                                                            projFileName,
                                                            rebuildData[i].ScriptFileName,
                                                            rebuildData[i].Sequence + 1,
                                                            string.Empty,
                                                            true,
                                                            true,
                                                            rebuildData[i].Database,
                                                            false,
                                                            buildFileName,
                                                            false,
                                                            false,
                                                            System.Environment.UserName,
                                                            defaultTimeout,
                                                            rebuildData[i].ScriptId,
                                                            rebuildData[i].Tag);
                }

                SqlBuildFileHelper.SaveSqlBuildProjectFile(ref buildData, projFileName, buildFileName);

                return(true);
            }
            finally
            {
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
            }
        }
        public void CleanProjectFileForRemoteExecutionTest_CleanOutUnitTest()
        {
            Initialization init = GetInitializationObject();

            //Create the build package...
            SqlSyncBuildData buildData = init.CreateSqlSyncSqlBuildDataObject();

            init.AddInsertScript(ref buildData, true);
            init.AddFailureScript(ref buildData, true, true);
            foreach (SqlSyncBuildData.ScriptRow row in buildData.Script)
            {
                row.FileName = Path.GetFileName(row.FileName);
            }

            //Add in code review rows
            buildData.CodeReview.AddCodeReviewRow(
                Guid.NewGuid(),
                buildData.Script[0],
                DateTime.Now,
                "Reviewer",
                1,
                "Comment",
                "12345",
                "AABBCCDD",
                "EEFFGGHHII");

            buildData.AcceptChanges();

            string zipFileName = init.GetTrulyUniqueFile();

            string path            = Path.GetDirectoryName(zipFileName);
            string projectFileName = Path.Combine(path, XmlFileNames.MainProjectFile);

            buildData.WriteXml(projectFileName);
            SqlBuildFileHelper.PackageProjectFileIntoZip(buildData, path, zipFileName, false);

            byte[] expected = File.ReadAllBytes(zipFileName);
            byte[] actual;

            SqlSyncBuildData cleanedBuildData;

            actual = SqlBuildFileHelper.CleanProjectFileForRemoteExecution(zipFileName, out cleanedBuildData);
            Assert.IsTrue(actual.Length >= 1200);  //can't get exact length due to variations in guids and dates.
            Assert.IsTrue(cleanedBuildData.GetXml().ToString().Length > 100);
            Assert.IsTrue(buildData.GetXml().ToString().Length > cleanedBuildData.GetXml().ToString().Length);

            Assert.IsTrue(cleanedBuildData.ScriptRun.Rows.Count == 0);
            Assert.IsTrue(cleanedBuildData.Build.Rows.Count == 0);
            Assert.IsTrue(cleanedBuildData.CodeReview.Rows.Count == 0);
            Assert.AreEqual(buildData.Script.Rows.Count, cleanedBuildData.Script.Rows.Count);
        }
        public void CleanProjectFileForRemoteExecutionTest_CleanOutScriptRunRowsTest()
        {
            Initialization init = GetInitializationObject();

            //Create the build package...
            SqlSyncBuildData buildData = init.CreateSqlSyncSqlBuildDataObject();

            init.AddInsertScript(ref buildData, true);
            init.AddInsertScript(ref buildData, true);
            init.AddInsertScript(ref buildData, true);
            init.AddFailureScript(ref buildData, true, true);
            foreach (SqlSyncBuildData.ScriptRow row in buildData.Script)
            {
                row.FileName = Path.GetFileName(row.FileName);
            }

            buildData.Builds.AddBuildsRow((SqlSyncBuildData.SqlSyncBuildProjectRow)buildData.SqlSyncBuildProject.Rows[0]);
            buildData.Build.AddBuildRow("Script", "Development", DateTime.Now, DateTime.Now, "Server", "Committed", Guid.NewGuid().ToString(), "user", buildData.Builds[0]);
            buildData.ScriptRun.AddScriptRunRow("HASH", "Committed", "FileName", 2.2, DateTime.Now, DateTime.Now, true, "Database", Guid.NewGuid().ToString(), (SqlSyncBuildData.BuildRow)buildData.Build[0]);


            buildData.AcceptChanges();

            string zipFileName = init.GetTrulyUniqueFile();

            string path            = Path.GetDirectoryName(zipFileName);
            string projectFileName = Path.Combine(path, XmlFileNames.MainProjectFile);

            buildData.WriteXml(projectFileName);
            SqlBuildFileHelper.PackageProjectFileIntoZip(buildData, path, zipFileName, false);

            byte[] expected = File.ReadAllBytes(zipFileName);
            byte[] actual;

            SqlSyncBuildData cleanedBuildData;

            actual = SqlBuildFileHelper.CleanProjectFileForRemoteExecution(zipFileName, out cleanedBuildData);
            Assert.IsTrue(2000 <= actual.Length);  //can't get exact length due to variations in guids and dates.
            Assert.IsTrue(cleanedBuildData.GetXml().ToString().Length > 100);
            Assert.IsTrue(buildData.GetXml().ToString().Length > cleanedBuildData.GetXml().ToString().Length);

            Assert.IsTrue(cleanedBuildData.ScriptRun.Rows.Count == 0);
            Assert.IsTrue(cleanedBuildData.Build.Rows.Count == 0);
            Assert.IsTrue(cleanedBuildData.CodeReview.Rows.Count == 0);
            Assert.AreEqual(buildData.Script.Rows.Count, cleanedBuildData.Script.Rows.Count);
        }