Pregunta

I am posting this because it might help someone using the VersionOne API SDK Client. I wanted to change the status of a test programmatically, to one of the following categories: Ready, InTesting, Passed, or Failed. I originally tried to change the attribute 'Status.Name' however I would get an error that the attribute is a Read-Only attribute. Another suggestion was to create a new attribute with the same name and that the new attribute would override the previous read-only attribute with the same name. However, it appears that I was looking at it backwards.

internal void TestStatusPassed(string str_TestID)
{
     var testId = Oid.FromToken(str_TestID, _context.MetaModel);
     var query = new Query(testId);
     var testType = _context.MetaModel.GetAssetType("Test");
     var sourceAttribute = testType.GetAttributeDefinition("Status.Name");
     query.Selection.Add(sourceAttribute);
     var result = _context.Services.Retrieve(query);
     var test = result.Assets[0];
     var oldSource = GetValue(test.GetAttribute(sourceAttribute).Value);
     test.SetAttributeValue(sourceAttribute, "Passed");
     _context.Services.Save(test);
 }

This code will throw an exception "Cannot change a read-only attribute"...

¿Fue útil?

Solución

I pulled the XML data for one test from the VersionOne Rest API and noticed a relation named "TestStatus" and then it had a number '9123' assigned to it. So I moved that test manually to 'In Testing' and the "TestStatus" changed to '9121'. Then I moved it to failed and the "TestStatus" changed to '155'. I repeated this with several tests from different testsets and noticed that the numbers for each status were consistent and then changed the code slightly and then I was able to programmatically change the status of each test. I changed "Status.Name" to "Status" and "Passed" to "TestStatus:9123" and now it moves the test into the passed category programmatically.

internal void TestStatusPassed(string str_TestID)
{
     var testId = Oid.FromToken(str_TestID, _context.MetaModel);
     var query = new Query(testId);
     var testType = _context.MetaModel.GetAssetType("Test");
     var sourceAttribute = testType.GetAttributeDefinition("Status");
     query.Selection.Add(sourceAttribute);
     var result = _context.Services.Retrieve(query);
     var test = result.Assets[0];
     var oldSource = GetValue(test.GetAttribute(sourceAttribute).Value);
     test.SetAttributeValue(sourceAttribute, "TestStatus:9123");
     _context.Services.Save(test);
 }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top