views:

42

answers:

1

In the Quality Center OTA API how can you delete steps from a test. When I delete steps using the RemoveItem method of the DesignStepFactory, they still remain - I've tried deleting by both ID and step reference:

Test test = _qcAccess.AddTest(folderId);
test.Name = "Test 1";
test.Post();

DesignStepFactory factory = (DesignStepFactory) test.DesignStepFactory;
DesignStep step = (DesignStep)factory.AddItem(1);
step.StepName = "Step1";
step.Post();

Test test2 = _qcAccess.FindExistingTest((int)test.ID);
DesignStepFactory factory2 = (DesignStepFactory) test2.DesignStepFactory;
Assert.Equal(1, test2.DesStepsNum);

factory2.RemoveItem(factory2[0]);
test2.Post();

Test test3= _qcAccess.FindExistingTest((int)test.ID);
Assert.Equal(0, test3.DesStepsNum); // test fails here, DesStepsNumb is still 1 

According to the OTA API documentation

RemoveItem Method

Description: Removes item from the database. Removal takes place immediately, without a Post.

Syntax:

Public Sub RemoveItem(ByVal ItemKey As Variant)

ItemKey:

The Step.ID (long), a reference to the Step Object or a Variant array of Step.IDs.Step.IDs.

So it looks like it should work. FYI this is for QC10.

Any thoughts?

A: 

The fix is to use List("") to retrieve the list of steps, it appears using the indexed accessor on the factory returns invalid step instances, where the ID is just the index of the element, and all properties are null.

Test test = _qcAccess.AddTest(folderId);
test.Name = "Test 1";
test.Post();

DesignStepFactory factory = (DesignStepFactory) test.DesignStepFactory;
DesignStep step = (DesignStep)factory.AddItem(1);
step.StepName = "Step1";
step.Post();
test.Post();

Test test2 = _qcAccess.FindExistingTest((int)test.ID);
DesignStepFactory factory2 = (DesignStepFactory)test2.DesignStepFactory;
Assert.Equal(1, test2.DesStepsNum);

var list = factory2.NewList(""); // get a list
factory2.RemoveItem(list[1]); // note: list indexing starts at 1 (ugh!)
test2.Post();

Test test3 = _qcAccess.FindExistingTest((int)test.ID);
Assert.Equal(0, test3.DesStepsNum);
Bittercoder