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);
        }
        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);
        }
        public void CleanProjectFileForRemoteExecutionTest_FileNotExist()
        {
            string fileName = string.Empty;

            byte[]           expected = new byte[0];
            byte[]           actual;
            SqlSyncBuildData cleanedBuildData;

            actual = SqlBuildFileHelper.CleanProjectFileForRemoteExecution(fileName, out cleanedBuildData);
            Assert.IsTrue(actual.Length == 0);
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(81, cleanedBuildData.GetXml().Length); //The size of an "empty" build data object

            Assert.IsTrue(cleanedBuildData.ScriptRun.Rows.Count == 0);
            Assert.IsTrue(cleanedBuildData.Build.Rows.Count == 0);
            Assert.IsTrue(cleanedBuildData.CodeReview.Rows.Count == 0);
        }