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); }
private void saveBuildDetailsForSelectedRowsToolStripMenuItem_Click(object sender, EventArgs e) { if (this.dgMaster.SelectedCells.Count == 0) { return; } List <SqlSyncBuildData.BuildRow> rows = new List <SqlSyncBuildData.BuildRow>(); for (int i = 0; i < this.dgMaster.SelectedCells.Count; i++) { SqlSyncBuildData.BuildRow row = (SqlSyncBuildData.BuildRow)((System.Data.DataRowView) this.dgMaster.SelectedCells[i].OwningRow.DataBoundItem).Row; if (!rows.Contains(row)) { rows.Add(row); } } if (DialogResult.OK == saveFileDialog1.ShowDialog()) { try { //Perform a deep copy of the build data... SqlSyncBuildData data = new SqlSyncBuildData(); using (StringReader sr = new StringReader("<?xml version=\"1.0\" standalone=\"yes\"?>" + this.sqlSyncBuildData1.GetXml())) { data.ReadXml(sr); } //Get ID's for selected rows... StringBuilder sb = new StringBuilder("("); foreach (SqlSyncBuildData.BuildRow row in rows) { sb.Append("'" + row.BuildId.ToString() + "',"); } sb.Length = sb.Length - 1; sb.Append(")"); //Filter out any rows that were not selected System.Data.DataView view = data.Build.DefaultView; view.RowFilter = data.Build.BuildIdColumn.ColumnName + " not in " + sb.ToString(); //Delete the non-selected rows from the build data copy object. while (view.Count > 0) { DataRow[] kids = view[0].Row.GetChildRows("Builds_Build"); for (int j = 0; j < kids.Length; j++) { kids[j].Delete(); } view[0].Row.Delete(); } //Save the file... string fileName = saveFileDialog1.FileName; data.AcceptChanges(); data.WriteXml(fileName); if (DialogResult.Yes == MessageBox.Show("Saved history to " + fileName + "\r\nOpen this file?", "Save Complete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { System.Diagnostics.Process.Start(fileName); } } catch (Exception exe) { MessageBox.Show("There was an error saving the history.\r\n" + exe.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }