Reputation: 81352
I'm trying to update the area of a test case programatically.
The code I have seems logical, but fails with:
An unhandled exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll
Additional information: TF400276: You have tried to set a value for a field of a work item which is not opened or partial opened. You cannot set a value for a field of a work item which is not opened or partial opened.
Here is the code:
private static void Main(string[] args)
{
TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
tpp.ShowDialog();
var tc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
tfsUri,
new UICredentialsProvider());
tc.EnsureAuthenticated();
var wiStore = tc.GetService<TestManagementService>();
var project = wiStore.GetTeamProject(tpp.SelectedProjects[0].Name);
SetAreaPathByTestSuiteID(project, 501);
}
private static void SetAreaPathByTestSuiteID(ITestManagementTeamProject project, int testSuiteID)
{
var testSuite = project.TestSuites.Find(testSuiteID).TestCases;
foreach (ITestSuiteEntry entry in testSuite)
{
ITestCase theCase = entry.TestCase;
theCase.Area = "NewAreaPath"; //Error thrown here
theCase.Save();
}
}
Upvotes: 0
Views: 832
Reputation: 161
You should just call a WorkItem. That's enough if you
testCase.WorkItem.PartialOpen();
if you call
testCase.WorkItem.Open();
then Save, you will to override the steps and parameter value
Upvotes: 0
Reputation: 1274
I know this thread is old, but I'll answer it anyway, in case someone encounters the same problem. To be able to edit a test case, you should call Open() like this:
theCase.WorkItem.Open();
And that's it.
Upvotes: 5