Example Title |
Copy Code
|
---|---|
public Test AddAndEditTest(String testName, String testType = "SYSTEM-TEST", SubjectNode containingFolder) { try { TestFactory testF; SubjectNode SubjRoot; TDFilter tFilter; List tList; String qTName; VCS versionCtl; bool bIsLocked; String strLockedBy; String tempStr = String.Empty; Test objTest = null; testF = (TestFactory)containingFolder.TestFactory; //Check if the test already exists tFilter = testF.Filter; qTName = "\"" + testName + "\""; tFilter["TS_NAME"] = qTName; tList = tFilter.NewList(); foreach (Test aT in tList) { if (aT.Name == testName) { objTest = aT; break; } } //If test does not exist, create it if (objTest == null) { objTest = testF.AddItem(DBNull.Value); objTest.Name = testName; objTest.Type = testType; objTest.Post(); } versionCtl = objTest.VCS; versionCtl.Refresh(); bIsLocked = versionCtl.IsLocked; strLockedBy = versionCtl.LockedBy; //After POST, Test is checked in. tempStr = String.Format("Version is locked: {0}", bIsLocked); Debug.Print(tempStr); //Is locked: False tempStr = String.Format("Version locked by: \"{0}\"", strLockedBy); Debug.Print(tempStr); //Is locked by: "" versionCtl.CheckOut(Convert.ToString("-1"), "To change state", true); versionCtl.Refresh(); bIsLocked = versionCtl.IsLocked; strLockedBy = versionCtl.LockedBy; tempStr = String.Format("Version is locked: {0}", bIsLocked); Debug.Print(tempStr); //Is locked: True tempStr = String.Format("Version locked by: \"{0}\"", strLockedBy); Debug.Print(tempStr); //Is locked by: "User1" //Take an arbitrary field to change. tempStr = String.Format("Status: \"{0}\"", objTest["TS_STATUS"]); Debug.Print(tempStr); objTest["TS_STATUS"] = "Ready"; objTest.Post(); versionCtl.CheckIn("", "Changed status"); versionCtl.Refresh(); bIsLocked = versionCtl.IsLocked; strLockedBy = versionCtl.LockedBy; tempStr = String.Format("Version is locked: {0}", bIsLocked); Debug.Print(tempStr); //Is locked: False tempStr = String.Format("Version locked by: \"{0}\"", strLockedBy); Debug.Print(tempStr); //Is locked by: "" return objTest; } catch (Exception) { return null; } } |