/// <summary> /// The initialize test run. /// </summary> /// <param name="testSuiteType"> /// The test suite type. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public static bool InitializeTestRun(TestSuiteTypes.Types testSuiteType) { bool success = false; XmlDocument settings = new XmlDocument(); settings.Load(Directory.GetCurrentDirectory() + "\\settings.xml"); XmlNodeList nodeList = settings.SelectNodes("/settings/reports"); DISEHHelper disHelper; TestlabHelper testlabHelper; if (nodeList != null) { foreach (XmlNode node in nodeList) { string disehServerName = node["share"].InnerText; string disehUser = node["user"].InnerText; string disehPwd = node["password"].InnerText; disHelper = new DISEHHelper(disehServerName, disehUser, disehPwd); } } nodeList = settings.SelectNodes("/settings/testconfig"); string testlabShare = string.Empty; string testlabJobLocation = string.Empty; string testlabUser = string.Empty; string testlabPwd = string.Empty; string pathtoExe = string.Empty; string vmName = string.Empty; if (nodeList != null) { foreach (XmlNode node in nodeList) { testlabShare = node["share"].InnerText; testlabJobLocation = node["path"].InnerText; testlabUser = node["user"].InnerText; testlabPwd = node["password"].InnerText; pathtoExe = node["pathtoexe"].InnerText; } } nodeList = settings.SelectNodes("/settings/vm"); if (nodeList != null) { foreach (XmlNode node in nodeList) { var xmlElement = node["name"]; if (xmlElement != null) { vmName = xmlElement.InnerText; } } } testlabHelper = new TestlabHelper(testlabShare, testlabUser, testlabUser, testlabJobLocation, vmName, pathtoExe); if (testlabHelper.MoveJobXMLToExeDir()) { testRun = new TestRun(); Type[] types = Assembly.GetAssembly(typeof(ITestResultItem)).GetTypes(); ITestResultItem instance = null; foreach (Type t in types) { if (typeof(ITestResultItem).IsAssignableFrom(t)) { if (t.Name.Equals(testSuiteType + "TestResultItem")) { instance = Activator.CreateInstance(t) as ITestResultItem; break; } } } testRun.TestResultItem = instance; testlabHelper.WriteStatusFileToTestlab(TestStatus.Status.Running); success = true; } else { testlabHelper.WriteStatusFileToTestlab(TestStatus.Status.ConfigNotCopied); } return(success); }
/// <summary> /// Persists the specified test run. /// </summary> /// <param name="testRun">The test run.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public bool Persist(TestRun testRun) { bool success = true; StreamWriter w = File.AppendText(this.logFile); try { string jobInfo = "Select runs_on_vm from Jobs where id = @jobID"; SqlCommand command = new SqlCommand(jobInfo, this.con); command.Parameters.AddWithValue("@jobID", testRun.JobID); command.ExecuteNonQuery(); Report.Info("QUERY: Select runs_on_vm from Jobs where id = " + testRun.JobID); Log("Select runs_on_vm from Jobs where id = " + testRun.JobID, w); SqlDataReader reader = command.ExecuteReader(); int virtualMachineId = 0; while (reader.Read()) { virtualMachineId = reader.GetInt32(reader.GetOrdinal("runs_on_vm")); Log("VM ID " + virtualMachineId, w); Report.Info("VM ID " + virtualMachineId); } reader.Close(); string insertTestEnv = "Insert into TestEnvironment (pamtool_id, wirings_id, vmware_id, testsystem_id) values (@pamtoolID, @wiringID, @vmwareID, @testsystemID)"; command = new SqlCommand(insertTestEnv, this.con); command.Parameters.AddWithValue("@pamtoolID", testRun.PAMTool.ID); command.Parameters.AddWithValue("@wiringID", testRun.WiringID); command.Parameters.AddWithValue("@vmwareID", virtualMachineId); command.Parameters.AddWithValue("@testsystemID", testRun.SystemID); Report.Info("QUERY: Insert into TestEnvironment (pamtool_id, wirings_id, vmware_id, testsystem_id) values (" + testRun.PAMTool.ID + ", " + testRun.WiringID + ", " + virtualMachineId + "," + testRun.SystemID + ")"); Log("Insert into TestEnvironment (pamtool_id, wirings_id, vmware_id) values (" + testRun.PAMTool.ID + ", " + testRun.WiringID + ", " + virtualMachineId + ", " + testRun.SystemID + ")", w); int insertedRows = command.ExecuteNonQuery(); Log(command.CommandText, w); if (insertedRows == 1) { command.CommandText = "SELECT IDENT_CURRENT('TestEnvironment')"; command.ExecuteNonQuery(); int testEnvId = Convert.ToInt32(command.ExecuteScalar()); Log("NEW TEST ENV ID " + testEnvId, w); int employeeId = Convert.ToInt32(testRun.Tester); int testRunInsert = 0; if (employeeId != 0) { string insertTestRun = "Insert into TestRuns (device_iid, testcase_id, date_execution, tester, testenv_id, job_id) values (@deviceIID, @testcaseID, GETDATE(), @tester, @testenvID, @jobID)"; command = new SqlCommand(insertTestRun, this.con); command.Parameters.AddWithValue("@deviceIID", testRun.Device.IID); command.Parameters.AddWithValue("@testcaseID", testRun.TestCaseID); command.Parameters.AddWithValue("@tester", employeeId); command.Parameters.AddWithValue("@testenvID", testEnvId); command.Parameters.AddWithValue("@jobID", testRun.JobID); testRunInsert += command.ExecuteNonQuery(); Report.Info("Insert into TestRuns (device_iid, testcase_id, date_execution, tester, testenv_id, job_id) values (" + testRun.Device.IID + ", " + testRun.TestCaseID + ", " + employeeId + ", " + testEnvId + ", " + testRun.JobID + ")"); Log("Insert into TestRuns (device_iid, testcase_id, date_execution, tester, testenv_id, job_id) values (" + testRun.Device.IID + ", " + testRun.TestCaseID + ", " + employeeId + ", " + testEnvId + ", " + testRun.JobID + ")", w); if (testRunInsert == 1) { command.CommandText = "SELECT IDENT_CURRENT('TestRuns')"; command.ExecuteNonQuery(); this.testRunId = Convert.ToInt32(command.ExecuteScalar()); } else { success = false; } if (this.testRunId != 0) { ITestResultItem testResult = testRun.TestResultItem; int resultCount = testRun.TestResultItem.GetResults().Count; int insertedResults = 0; foreach (NameValueCollection col in testRun.TestResultItem.GetResults()) { string insertTestRunFunc = "Insert into TestRunFunctions (testrun_id, function_name, description) values (@testrunID, @functionName, @description)"; command = new SqlCommand(insertTestRunFunc, this.con); command.Parameters.AddWithValue("@testrunID", this.testRunId); command.Parameters.AddWithValue("@functionName", col.Get("function")); command.Parameters.AddWithValue("@description", col.Get("description")); insertedResults += command.ExecuteNonQuery(); Report.Info("Insert into TestRunFunctions (testrun_id, function_name, description) values (" + this.testRunId + ", " + col.Get("function") + ", " + col.Get("description") + ")"); Log("Insert into TestRunFunctions (testrun_id, function_name, description) values (" + this.testRunId + ", " + col.Get("function") + ", " + col.Get("description") + ")", w); command.CommandText = "SELECT IDENT_CURRENT('TestRunFunctions')"; command.ExecuteNonQuery(); int testRunFunctionId = Convert.ToInt32(command.ExecuteScalar()); string insertTesRunResult = "Insert into TestRunResults (resulttype_id, result_value, testrunfunction_id) values (@resulttypeID, @resultValue, @testrunfunctionID)"; command = new SqlCommand(insertTesRunResult, this.con); command.Parameters.AddWithValue("@resulttypeID", testResult.ResultType()); command.Parameters.AddWithValue("@resultValue", col.Get("duration")); command.Parameters.AddWithValue("@testrunfunctionID", testRunFunctionId); command.ExecuteNonQuery(); Report.Info("Insert into TestRunResults (resulttype_id, result_value, testrunfunction_id) values (" + testResult.ResultType() + ", " + col.Get("duration") + ", " + testRunFunctionId + ")"); Log("Insert into TestRunResults (resulttype_id, result_value, testrunfunction_id) values (" + testResult.ResultType() + ", " + col.Get("duration") + ", " + testRunFunctionId + ")", w); } if (insertedResults != resultCount) { success = false; } } else { success = false; } } } else { success = false; } } catch (Exception ex) { Log(ex.Message, w); } return(success); }