Search code examples
c#.netdatetimerally

Rally API - Create TestCaseResult - DateTime issue


I'm using the Rally soap API to create a new TestCaseResult against a test case that has been previously created, but I get an error when I create the result:

'Validation error: TestCaseResult.Date should not be null'

Not sure why this should be the case - can you help?

private Boolean createTestResultForTest(String aResult, String aTestCase)
{
    TestCaseResult myTestCaseResult = new TestCaseResult();
    myTestCaseResult.Build = "1";
    DateTime myDate = DateTime.Now;
    myTestCaseResult.Date = myDate;
    String myQuery = "(FormattedID = " + aTestCase + ")";
    QueryResult myTestCaseReturn = m_rallyService.query(m_workspace, "TestCase", myQuery, "", true, 0, 100);
    long mycount = myTestCaseReturn.TotalResultCount;
    if (mycount > 0)
    {
        TestCase myTestCase = (TestCase)myTestCaseReturn.Results[0];
        myTestCaseResult.TestCase = myTestCase;
    }
    else
    {
        return false;
    }
    myTestCaseResult.Verdict = aResult;


    CreateResult myCreateTestResultResult = m_rallyService.create(myTestCaseResult);
    if (hasErrors(myCreateTestResultResult))
    {
        updateStatus("Could not create test result for test case:" + myTestCaseResult.TestCase.Name);
        printWarningsErrors(myCreateTestResultResult);
        return false;
    }
    else
    {
        myTestCaseResult = (TestCaseResult)myCreateTestResultResult.Object;
        myTestCaseResult = (TestCaseResult)m_rallyService.read(myTestCaseResult);
        updateStatus("Created TestCaseResult: " + myTestCaseResult.TestCase.Name + ", ref = " + myTestCaseResult.@ref);
    }
    return true;
}

Solution

  • I believe you've run into a known bug with Rally's SOAP API that I had forgotten about until just now. Basically the bug is that even when you specify a valid Date/Time object on your TestCaseResult, the SOAP serializer doesn't recognize this unless you also set a specific flag to be true, i.e.:

    myTestCaseResult.DateSpecified = true;

    Please set this flag, and re-run your code - it should work now :)