0

I'm able to copy most test cases with this code (trying to copy shared steps to be part of the test case itself) but this one will not copy but I can not see any error message as to why - could anyone suggest anything else to try. See output from Immediate windows. Thanks John.

?targetTestCase.Error
null
?targetTestCase.InvalidProperties
Count = 0
?targetTestCase.IsDirty
true
?targetTestCase.State
"Ready"
?targetTestCase.Reason
"New"

foreach (ITestAction step in testSteps)
        {
            if (step is ITestStep)
            {
                ITestStep sourceStep = (ITestStep)step;
                ITestStep targetStep = targetTestCase.CreateTestStep();
                targetStep.Title = sourceStep.Title;
                targetStep.Description = sourceStep.Description;
                targetStep.ExpectedResult = sourceStep.ExpectedResult;

                //Copy Attachments
                if (sourceStep.Attachments.Count > 0)
                {
                    string attachmentRootFolder = _tfsServiceUtilities.GetAttachmentsFolderPath();
                    string testCaseFolder = _tfsServiceUtilities.CreateDirectory(attachmentRootFolder, "TestCase_" + targetTestCase.Id);
                    //Unique folder path for test step
                    string TestStepAttachementFolder = _tfsServiceUtilities.CreateDirectory(testCaseFolder, "TestStep_" + sourceStep.Id);

                    using (var client = new WebClient())
                    {
                        client.UseDefaultCredentials = true;
                        foreach (ITestAttachment attachment in sourceStep.Attachments)
                        {
                            string attachmentPath = TestStepAttachementFolder + "\\" + attachment.Name;
                            client.DownloadFile(attachment.Uri, attachmentPath);
                            ITestAttachment newAttachment = targetTestCase.CreateAttachment(attachmentPath);
                            newAttachment.Comment = attachment.Comment;
                            targetStep.Attachments.Add(newAttachment);
                        }
                    }
                }
                targetTestCase.Actions.Add(targetStep);
                targetTestCase.Save();
            }

1 Answers1

0

Since this code works for most test cases, this issue may come from the particular test case. In order to narrow down the issue, please try the following items:

  1. Run the code on another client machine to see whether it works.
  2. Try to modify this particular test case using the account API uses, to see whether it can be saved successfully.
  3. Try validate the WorkItem prior to save. The validate() method will return an arraylist of invalid fields.
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39