Question

I have created an application using Rally Rest API Ver 2.0.1.0 in C# that enables my test engineers to modify Rally test data in an automated fashion using CSV files.

I would like the application to be able to find an existing test set, grab the list of test cases in the set, add more test cases to that list, and then update the test set with the new list of test cases.

My problem is that when I get the list of test cases in the test set, Rally only returns 20 test cases even if there are more than 20 test cases in the Test Set.

In order to get the list of test cases in the test set, here is my code (I apologize for not having all declarations, but I think you get the point):

public ArrayList testSetList = new ArrayList(); 

Request requestTS = new Request("TestSet");

requestTS.Project = rallyProjectRef;

requestTS.ProjectScopeDown = false;

requestTS.ProjectScopeUp = false;

requestTS.Fetch = new List<string> { "Name", "ObjectID", "Iteration", "TestCases" };

requestTS.Query = new Query("Name", Query.Operator.Equals, testSetName).And(new Query("Iteration", Query.Operator.Equals, currentIterationRef));

try
{
    QueryResult findTSMatchQueryResult = m.myRestApi.Query(requestTS);
    string currentTestSetRef = "/TestSet/" + findTSMatchQueryResult.Results.First()["ObjectID"];

     string testCasesintheTestSEt = currentTestSetRef + "/TestCases";
     DynamicJsonObject item = m.myRestApi.GetByReference(testCasesintheTestSEt, "TestCase", "ObjectID");
     foreach (var testCaseObject in item["Results"])
     {
         testSetList.Add(testCaseObject);
     }

When looping through the results of the GetByReference method, there are only 20 test case objects returned. Is there a way for me to expand the amount of returned objects using this GetByReference method? Or is there a query I could setup to get me the full list of test case objects in the Test set?

I used the above methodology because I noticed that when "updating" the test cases in a test set using the Update method, Rally will wipe out any existing data, and treat the new test case list as the full set of test cases in the test set. Perhaps there is another means to add test cases to an existing test set without wiping out the existing test cases?

Currently, when trying to update the test cases in a test set, I use the following code, which removes the already existing test cases from the test set if the testCaseList does not already contain the previously existing test cases.

DynamicJsonObject toUpdate = new DynamicJsonObject();
toUpdate["TestCases"] = testCasesList;
try
{
    OperationResult updateOperationResult = m.myRestApi.Update(currentTestSetRef, toUpdate);
    if (updateOperationResult.Success == true)
    {
        return "Added the test case to the test set. ";
    }
    else
    {
        return "Error.  An error occurred trying to update the test case list of the test set. ";
    }
}
catch (Exception)
{
    return "Error.  An exception occurred trying to update the test cases list of the test set. ";
}

Any help would be greatly appreciated.

Was it helpful?

Solution

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.

enter image description here

OTHER TIPS

In other words, the answer to your question is 'No' - theres no way to have GetByReference return all of the test cases in the test set - it returns 20 at a time. In order to get an array of the >20 Test cases in the test set, you have to use the query method above, walking the results, and putting each result into an array.

ArrayList TestCaseList = restApi.GetByReference(TestSet["TestCases"]["_ref"])["Results"];

will only ever return up to 20 results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top