public void InferScriptTagFromFileNameTest_NoCRMatch() { string scriptFileName = @"C:\mypath\path2\No CR test script.sql"; List <string> regexFormats = ScriptTagProcessingTest.regex; string expected = ""; string actual; actual = ScriptTagProcessing.InferScriptTagFromFileName(scriptFileName, regexFormats); Assert.AreEqual(expected, actual); }
public void InferScriptTagFromFileNameTest_SuccessWithNumberAndSpace() { string scriptFileName = @"C:\mypath\path2\CR# 2123456-test script.sql"; List <string> regexFormats = ScriptTagProcessingTest.regex; string expected = "CR2123456"; string actual; actual = ScriptTagProcessing.InferScriptTagFromFileName(scriptFileName, regexFormats); Assert.AreEqual(expected, actual); }
public void InferScriptTagTest_NoTagInferenceSource() { TagInferenceSource source = TagInferenceSource.None; List <string> regexFormats = ScriptTagProcessingTest.regex; string scriptName = "CR 343423 Test Script.sql"; string scriptPath = @"C:\test"; string expected = string.Empty; string actual; actual = ScriptTagProcessing.InferScriptTag(source, regexFormats, scriptName, scriptPath); Assert.AreEqual(expected, actual); }
public void InferScriptTagTest_NullRegexListSet() { string scriptPathAndName = @"C:\mypath\path2\CR2123456-test script.sql"; string scriptContents = Properties.Resources.TagFromContents; List <string> regexFormats = null; TagInferenceSource source = TagInferenceSource.TextOverName; string expected = ""; string actual; actual = ScriptTagProcessing.InferScriptTag(scriptPathAndName, scriptContents, regexFormats, source); Assert.AreEqual(expected, actual); }
public void InferScriptTagTest_TextOverName_GetFromName() { string scriptPathAndName = @"C:\mypath\path2\CR2123456-test script.sql"; string scriptContents = "This is content that doesn't have a single tag in it."; List <string> regexFormats = ScriptTagProcessingTest.regex; TagInferenceSource source = TagInferenceSource.TextOverName; string expected = "CR2123456"; string actual; actual = ScriptTagProcessing.InferScriptTag(scriptPathAndName, scriptContents, regexFormats, source); Assert.AreEqual(expected, actual); }
public void InferScriptTagTest_NameOverText_GetFromText() { string scriptPathAndName = @"C:\mypath\path2\test script.sql"; string scriptContents = Properties.Resources.TagFromContents; List <string> regexFormats = ScriptTagProcessingTest.regex; TagInferenceSource source = TagInferenceSource.NameOverText; string expected = "CR987654"; string actual; actual = ScriptTagProcessing.InferScriptTag(scriptPathAndName, scriptContents, regexFormats, source); Assert.AreEqual(expected, actual); }
public void InferScriptTagTest_FileDoesntExist() { TagInferenceSource source = TagInferenceSource.TextOverName; List <string> regexFormats = ScriptTagProcessingTest.regex; string scriptName = Path.GetTempPath() + Guid.NewGuid().ToString(); string scriptPath = Path.GetDirectoryName(scriptName); string expected = ""; string actual; actual = ScriptTagProcessing.InferScriptTag(source, regexFormats, scriptName, scriptPath); Assert.AreEqual(expected, actual); }
public void InferScriptTagTest_SourceIsNone() { string scriptPathAndName = @"C:\mypath\path2\NothingHereCR2123456-test script.sql"; string scriptContents = @"There is nothing here that should match either the CR number 1234 content match or the P number 1234 content match"; List <string> regexFormats = ScriptTagProcessingTest.regex; TagInferenceSource source = TagInferenceSource.None; string expected = ""; string actual; actual = ScriptTagProcessing.InferScriptTag(scriptPathAndName, scriptContents, regexFormats, source); Assert.AreEqual(expected, actual); }
public void InferScriptTagTest_TextOverNameNothingFound() { TagInferenceSource source = TagInferenceSource.ScriptName; List <string> regexFormats = ScriptTagProcessingTest.regex; string scriptName = Path.GetTempPath() + @"empty tagless test me.sql"; File.WriteAllText(scriptName, "This doesn't have a tag in it"); string scriptPath = Path.GetDirectoryName(scriptName); string expected = ""; string actual; actual = ScriptTagProcessing.InferScriptTag(source, regexFormats, scriptName, scriptPath); Assert.AreEqual(expected, actual); }
public void InferScriptTagTest_NullRegex() { TagInferenceSource source = TagInferenceSource.ScriptName; List <string> regexFormats = null; string scriptName = Path.GetTempPath() + @"CR 123456 test me.sql"; File.WriteAllText(scriptName, Properties.Resources.TagFromContents); string scriptPath = Path.GetDirectoryName(scriptName); string expected = string.Empty; string actual; actual = ScriptTagProcessing.InferScriptTag(source, regexFormats, scriptName, scriptPath); if (File.Exists(scriptName)) { File.Delete(scriptName); } Assert.AreEqual(expected, actual); }
public bool ValidateValues(string scriptContents, string scriptName) { int minValue = EnterpriseConfigHelper.GetMinumumScriptTimeout(this.parentFileName, SqlSync.Properties.Settings.Default.DefaultMinimumScriptTimeout); if (ScriptSettingValidation.CheckScriptTimeoutValue(txtScriptTimeout.Text, minValue) != ScriptTimeoutValidationResult.Ok) { txtScriptTimeout_Leave(null, EventArgs.Empty); return(false); } bool showMessage = false; if (txtBuildOrder.Enabled == true) { if (txtBuildOrder.Text.Length != 0) { try { Double.Parse(txtBuildOrder.Text); } catch { showMessage = true; } } else { showMessage = true; } } if (ddDatabaseList.Enabled == true) { if (ddDatabaseList.SelectedDatabase.Length == 0) { showMessage = true; } } if (showMessage) { MessageBox.Show("A Target Database and Build Sequence number are required", "Missing Values", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (this.tagRequired && cbTag.Text.Length == 0 && cbTag.SelectedValue == null) { bool alertOnTag = true; if (ddInfer.Text != null && ddInfer.Text.ToString() != "None") { TagInferenceSource source; switch (ddInfer.Text) { case "Name/Script": source = TagInferenceSource.NameOverText; break; case "Script Only": source = TagInferenceSource.ScriptText; break; case "Name Only": source = TagInferenceSource.ScriptName; break; case "Script/Name": default: source = TagInferenceSource.TextOverName; break; } List <string> regex = new List <string>(SqlSync.Properties.Settings.Default.TagInferenceRegexList.Cast <string>()); string tag = ScriptTagProcessing.InferScriptTag(scriptName, scriptContents, regex, source); if (tag.Length > 0) { cbTag.Text = tag; alertOnTag = false; } } if (alertOnTag) { string message = "A Target Database, Build Sequence number and Tag are required"; if (SqlSync.Properties.Settings.Default.RequireScriptTagsMessage != null) { message = SqlSync.Properties.Settings.Default.RequireScriptTagsMessage; } MessageBox.Show(message, "Missing Tag Value", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } return(true); }
private void NewBuildScriptForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { switch (ddInfer.Text) { case "Name/Script": this.TagInferSource = TagInferenceSource.NameOverText; break; case "Script Only": this.TagInferSource = TagInferenceSource.ScriptText; break; case "Name Only": this.TagInferSource = TagInferenceSource.ScriptName; break; case "Script/Name": this.TagInferSource = TagInferenceSource.TextOverName; break; default: this.TagInferSource = TagInferenceSource.None; break; } if (this.DialogResult != DialogResult.OK) { return; } List <string> regexTag = new List <string>(SqlSync.Properties.Settings.Default.TagInferenceRegexList.Cast <string>()); if (this.TagInferSource != TagInferenceSource.None) { if (this.fullPathAndFileName.Length > 0) { this.scriptTag = ScriptTagProcessing.InferScriptTag(this.TagInferSource, regexTag, Path.GetFileName(this.fullPathAndFileName), Path.GetDirectoryName(this.fullPathAndFileName)); } else { this.scriptTag = ScriptTagProcessing.InferScriptTag(this.TagInferSource, regexTag, this.FileName, this.baseFilePath); } } if (this.scriptRows == null || this.scriptRows.Length == 0) { return; } for (int i = 0; i < this.scriptRows.Length; i++) { if (this.scriptTimeoutChanged) { this.scriptRows[i].ScriptTimeOut = Int32.Parse(this.txtScriptTimeout.Text); } if (this.chkAllowMultipleRuns.CheckState != CheckState.Indeterminate) { this.scriptRows[i].AllowMultipleRuns = this.chkAllowMultipleRuns.Checked; } if (this.chkRollBackBuild.CheckState != CheckState.Indeterminate) { this.scriptRows[i].CausesBuildFailure = this.chkRollBackBuild.Checked; } if (this.chkRollBackScript.CheckState != CheckState.Indeterminate) { this.scriptRows[i].RollBackOnError = this.chkRollBackScript.Checked; } if (this.chkStripTransactions.CheckState != CheckState.Indeterminate) { this.scriptRows[i].StripTransactionText = this.chkStripTransactions.Checked; } if (this.ddDatabaseList.Enabled && this.selectedDatabaseChanged) { this.scriptRows[i].Database = this.ddDatabaseList.SelectedDatabase; } if (this.tagSelectionChanged) { this.scriptRows[i].Tag = cbTag.SelectedValue == null ? cbTag.Text : cbTag.SelectedValue.ToString(); } else if ((this.cbTag.BackColor != multipleTagsColor || this.inferSourceChanged) && cbTag.SelectedValue == null && cbTag.Text.Length == 0 && this.TagInferSource != TagInferenceSource.None) //A new add that doesn't have a tag set AND infer is set... { string tmpTag = ScriptTagProcessing.InferScriptTag(this.TagInferSource, regexTag, Path.GetFileName(this.scriptRows[i].FileName), Path.GetDirectoryName(this.scriptRows[i].FileName)); if (tmpTag.Length > 0) { this.scriptRows[i].Tag = tmpTag; } else { this.scriptRows[i].Tag = "Default"; } } } }