private void lstTestCase_DragDrop(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Copy; string strTemp = new Random().NextDouble().ToString(); string strData = e.Data.GetData(e.Data.GetFormats()[0]).ToString(); Step s = td.steps["" + strData]; if (s.Cat != StepCategory.TestStep) { strData = "> " + strData; } ((ListBox)sender).Items.Add(new FormatName(strData + "\t\t\t\t\t\t\t\t" + strTemp)); tc.testSteps.Add("" + strData + "\t\t\t\t\t\t\t\t" + strTemp, Step.Copy(s)); isDirty = true; }
public void Load() { testSteps.Clear(); try { processingState = "Loading test case"; XmlDocument xd = new XmlDocument(); xd.Load(xmlFile); processingState = "Checking for test step elements"; XmlNodeList testStepNodes = xd.GetElementsByTagName("TestStep"); if (testStepNodes.Count < 1) { throw new Exception("No test steps found"); } foreach (XmlNode testStepNode in testStepNodes) { processingState = "Retreiving test steps"; if (((XmlElement)testStepNode).GetAttribute("NonGUITestStep") == "true") { Step sn = Step.Copy(form.td.steps["*NonGUITestStep"]); string strTempn = sn.Name + "\t\t\t\t\t\t\t\t" + ran.NextDouble().ToString(); testSteps.Add(strTempn, sn); sn.StepAttributes["TestCaseXml"].Val = XmlFormatter.MakeReadable(((XmlElement)testStepNode).OuterXml); if (((XmlElement)testStepNode).ParentNode.Name == "TestSetup") { form.lstSetup.Items.Add(new FormatName(strTempn)); } if (((XmlElement)testStepNode).ParentNode.Name == "TestExecution") { form.lstExecute.Items.Add(new FormatName(strTempn)); } if (((XmlElement)testStepNode).ParentNode.Name == "TestCleanup") { form.lstCleanup.Items.Add(new FormatName(strTempn)); } continue; } Step s = Step.Copy(form.td.steps["T:" + ((XmlElement)testStepNode).GetAttribute("typeName").Split(',')[0]]); string strTemp = s.Name + "\t\t\t\t\t\t\t\t" + ran.NextDouble().ToString(); testSteps.Add(strTemp, s); if (((XmlElement)testStepNode).ParentNode.Name == "TestSetup") { form.lstSetup.Items.Add(new FormatName(strTemp)); } if (((XmlElement)testStepNode).ParentNode.Name == "TestExecution") { form.lstExecute.Items.Add(new FormatName(strTemp)); } if (((XmlElement)testStepNode).ParentNode.Name == "TestCleanup") { form.lstCleanup.Items.Add(new FormatName(strTemp)); } processingState = "Retreiving attributes for test step: " + s.Name; Dictionary <string, StepAttribute> .Enumerator enumerator = s.StepAttributes.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current.Value.Name == "ValidationStep" || enumerator.Current.Value.Name == "ContextLoaderStep") { continue; } SetAttributeValue(testStepNode, enumerator.Current.Value); } XmlNodeList ctxLoaderStepNodes = ((XmlElement)testStepNode).GetElementsByTagName("ContextLoaderStep"); foreach (XmlNode ctxLoaderStepNode in ctxLoaderStepNodes) { Step s1 = Step.Copy(form.td.steps["T:" + ((XmlElement)ctxLoaderStepNode).GetAttribute("typeName").Split(',')[0]]); processingState = "Retreiving context loader steps for test step: " + s.Name; strTemp = "> " + s1.Name + "\t\t\t\t\t\t\t\t" + ran.NextDouble().ToString(); testSteps.Add("" + strTemp, s1); if (((XmlElement)ctxLoaderStepNode).ParentNode.ParentNode.Name == "TestSetup") { form.lstSetup.Items.Add(new FormatName(strTemp)); } if (((XmlElement)ctxLoaderStepNode).ParentNode.ParentNode.Name == "TestExecution") { form.lstExecute.Items.Add(new FormatName(strTemp)); } if (((XmlElement)ctxLoaderStepNode).ParentNode.ParentNode.Name == "TestCleanup") { form.lstCleanup.Items.Add(new FormatName(strTemp)); } processingState = "Retreiving context loader attributes for test step: " + s1.Name; Dictionary <string, StepAttribute> .Enumerator enumerator1 = s1.StepAttributes.GetEnumerator(); while (enumerator1.MoveNext()) { if (enumerator1.Current.Value.Name == "ValidationStep" || enumerator1.Current.Value.Name == "ContextLoaderStep") { continue; } SetAttributeValue(ctxLoaderStepNode, enumerator1.Current.Value); } } XmlNodeList validationStepNodes = ((XmlElement)testStepNode).GetElementsByTagName("ValidationStep"); foreach (XmlNode validationStepNode in validationStepNodes) { Step s2 = Step.Copy(form.td.steps["T:" + ((XmlElement)validationStepNode).GetAttribute("typeName").Split(',')[0]]); processingState = "Retreiving validation steps for test step: " + s.Name; strTemp = "> " + s2.Name + "\t\t\t\t\t\t\t\t" + ran.NextDouble().ToString(); testSteps.Add("" + strTemp, s2); if (((XmlElement)validationStepNode).ParentNode.ParentNode.Name == "TestSetup") { form.lstSetup.Items.Add(new FormatName(strTemp)); } if (((XmlElement)validationStepNode).ParentNode.ParentNode.Name == "TestExecution") { form.lstExecute.Items.Add(new FormatName(strTemp)); } if (((XmlElement)validationStepNode).ParentNode.ParentNode.Name == "TestCleanup") { form.lstCleanup.Items.Add(new FormatName(strTemp)); } processingState = "Retreiving validation attributes for test step: " + s2.Name; Dictionary <string, StepAttribute> .Enumerator enumerator2 = s2.StepAttributes.GetEnumerator(); while (enumerator2.MoveNext()) { if (enumerator2.Current.Value.Name == "ValidationStep" || enumerator2.Current.Value.Name == "ContextLoaderStep") { continue; } SetAttributeValue(validationStepNode, enumerator2.Current.Value); } } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Error occured while: " + processingState + "\r\n\r\n" + "Actual error:\r\n" + e.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); testSteps.Clear(); form.lstSetup.Items.Clear(); form.lstExecute.Items.Clear(); form.lstCleanup.Items.Clear(); } }