How to create a testset in a user's non-default project using Rally API Toolkit for .NET?
The code example below is based on v.3.0.1 of Rally API Toolkit for .NET
Setup: the user whose ApiKey is used to authenticate the requests in the code has different default Workspace and Project than those referenced in the code.
TestSet created in the code will be created in Child2 project.
The WS API query below illustrates that the ObjectID of workspace and project used in the code below reference the projects shown above:
https://rally1.rallydev.com/slm/webservice/v2.0/project?workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/<WORKSPACE_OID>&query=(Name = "Child2")
Lines to set project and workspace references as shown below:
String workspaceRef = "/workspace/<WORKSPACE_OID>"; String projectRef = "/project/<PROJECT_OID>";
First, a TestSet is created:
DynamicJsonObject myTestSet = new DynamicJsonObject(); myTestSet["Name"] = "important set " + DateTime.Now; myTestSet["Project"] = projectRef; CreateResult createTestSet = restApi.Create(workspaceRef, "TestSet", myTestSet); myTestSet = restApi.GetByReference(createTestSet.Reference, "FormattedID", "Project"); Console.WriteLine(myTestSet["FormattedID"] + " " + myTestSet["Project"]._refObjectName);
To show how to use the reference to the newly created TestSet, we query for a current iteration. If iteration is found, we update the TestSet:
Request iterationRequest = new Request("Iteration"); iterationRequest.Project = projectRef; iterationRequest.ProjectScopeDown = false; iterationRequest.ProjectScopeUp = false; iterationRequest.Fetch = new List<string>() { "ObjectID", "Name" }; iterationRequest.Query = new Query("(StartDate <= Today)").And(new Query("(EndDate >= Today)")); QueryResult queryResults = restApi.Query(iterationRequest); if (queryResults.TotalResultCount > 0) { Console.WriteLine(queryResults.Results.First()["Name"] + " " + queryResults.Results.First()["ObjectID"]); myTestSet["Iteration"] = queryResults.Results.First()._ref; OperationResult updateResult = restApi.Update(myTestSet["_ref"], myTestSet); }