On any request you may set a Limit on request to a number that is high enough, for example:
requestTS.Limit = 1000;
For more information on request members see documentation here.
As far as adding a new test case to the existing collection of test cases on a test set, you are correct about the object model that in WS API there is no TestSet attribute on TestCase. Here is a full code that adds a test case to the existing collection of 23 test cases on this test set, and all 23 are returned before the collection is updated.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Rally.RestApi;
using Rally.RestApi.Response;
namespace addTCtoTS
{
class Program
{
static void Main(string[] args)
{
RallyRestApi restApi;
restApi = new RallyRestApi("user@co.com", "secret", "https://rally1.rallydev.com", "v2.0");
String projectRef = "/project/222";
Request testSetRequest = new Request("TestSet");
testSetRequest.Project = projectRef;
testSetRequest.Fetch = new List<string>()
{
"Name",
"FormattedID",
"TestCases"
};
testSetRequest.Query = new Query("FormattedID", Query.Operator.Equals, "TS22");
QueryResult queryTestSetResults = restApi.Query(testSetRequest);
String tsRef = queryTestSetResults.Results.First()._ref;
String tsName = queryTestSetResults.Results.First().Name;
Console.WriteLine(tsName + " " + tsRef);
DynamicJsonObject testSet = restApi.GetByReference(tsRef, "FormattedID", "TestCases");
String testCasesCollectionRef = testSet["TestCases"]._ref;
Console.WriteLine(testCasesCollectionRef);
ArrayList testCasesList = new ArrayList();
foreach (var ts in queryTestSetResults.Results)
{
Request tcRequest = new Request(ts["TestCases"]);
QueryResult queryTestCasesResult = restApi.Query(tcRequest);
foreach (var tc in queryTestCasesResult.Results)
{
var tName = tc["Name"];
var tFormattedID = tc["FormattedID"];
Console.WriteLine("Test Case: " + tName + " " + tFormattedID);
DynamicJsonObject aTC = new DynamicJsonObject();
aTC["_ref"] = tc["_ref"];
testCasesList.Add(aTC); //add each test case in the collection to array 'testCasesList'
}
}
Console.WriteLine("count of elements in the array before adding a new tc:" + testCasesList.Count);
DynamicJsonObject anotherTC = new DynamicJsonObject();
anotherTC["_ref"] = "/testcase/123456789"; //any existing test to add to the collection
testCasesList.Add(anotherTC);
Console.WriteLine("count of elements in the array:" + testCasesList.Count);
testSet["TestCases"] = testCasesList;
OperationResult updateResult = restApi.Update(tsRef, testSet);
}
}
}
The code is available in this github repo.