Copy Code
|
|
---|---|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using TDAPIOLELib; class OtaApiActions { private TDConnection conn; private IReqFactory2 reqF; private IReq reqItem; IBugFactory2 bugF; IBug bugItem; /* Create a connection to an ALM server */ /* Authenticate the user and log on to a project */ public void connectToServer() { conn = new TDConnection(); conn.InitConnectionEx("http://myServer:8080/qcbin"); //Authentication conn.Login("myuser", "mypassword"); //Connect to a project conn.Connect("MY_DOMAIN", "myproject"); } /* Create a pre-authenticated connection to an ALM server */ public void authenticatedConnectToServer() { TDConnection otaConnection = new TDConnection(); // configure connection to add Basic Auth Header at first request otaConnection.SetBasicAuthHeaderMode(TDAPI_BASIC_AUTH_HEADER_MODES.HEADER_MODE_ONCE); // set user credentials otaConnection.SetServerCredentials("Login", "Password"); // init connect to ALM server otaConnection.InitConnection("http://<server URL>/qcbin"); // Connect to a project otaConnection.Connect("MY_DOMAIN", "myproject"); } /* Create a new defect */ public void addBug2Project(uint index) { bugF = (IBugFactory2)conn.BugFactory; bugItem = (IBug)bugF.AddItem(DBNull.Value); DateTime saveNow = DateTime.Now; // Populate the mandatory fields. bugItem.Summary = "This is a summary" + index; bugItem.DetectedBy = "mary_qa"; bugItem.Priority = "2-Medium"; bugItem.Status = "New"; bugItem["BG_DETECTION_DATE"] = saveNow; bugItem["BG_SEVERITY"] = "2-Medium"; bugItem["BG_DESCRIPTION"] = "This is a description" + index; //Post the bug bugItem.Post(); } /* Create a new requirement */ public void addRequirement2Project(uint index) { reqF = (IReqFactory2)conn.ReqFactory; reqItem = (IReq)reqF.AddItem(DBNull.Value); DateTime saveNow = DateTime.Now; //Populate the mandatory fields. reqItem.Name = "CS requirment" + index; reqItem.Type = "Functional"; reqItem.Author = "Eli"; reqItem.Priority = "2-Medium"; //Post the requirement reqItem.Post(); } /* Link bug to requirement*/ public void linkBug2Req(uint index) { LinkFactory linkF; Link linkItem; ILinkable linkableReq; linkableReq = (ILinkable)reqItem; linkF = linkableReq.BugLinkFactory; linkItem = linkF.AddItem(bugItem); linkItem.Comment = "Req" + index + "Linked to Bug" + index; linkItem.Post(); } public void disconnect() { conn.Disconnect(); } } class Tutorial { static void Main() { uint loopIndex; OtaApiActions ota = new OtaApiActions(); ota.connectToServer(); for (loopIndex = 156 ; loopIndex < 265; loopIndex++ ) { ota.addBug2Project(loopIndex); ota.addRequirement2Project(loopIndex); ota.linkBug2Req(loopIndex); } ota.disconnect(); } } |