0

I am trying to upload attachments using TFS API Following is the code snippet :

    result.State = TestResultState.Completed;
    result.RunBy = identity;

    var attachment = result.CreateAttachment(logFilePath);
    run.Attachments.Add(attachment);

The code doesn't throw any error. Also i see that IAttachmentOwner.AttachmentUploadCompleted Event has been raised indicating it is completed. Yet I am not able to see the uploaded attachments on my TFSWebPortal. Am I missing something here ?

P.S : First question here. Please feel free to correct me.

1 Answers1

0

You can get it works with the following code:

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfsservername:8080/tfs/DefaultCollection"));
        ITestManagementTeamProject project = tfs.GetService<ITestManagementService>().GetTeamProject("projectName");

        foreach (ITestPlan p in project.TestPlans.Query("Select * From TestPlan"))
        {
            ITestRun testRun = p.CreateTestRun(false);
            var testPoints = p.QueryTestPoints("SELECT * from TestPoint");
            foreach (ITestPoint testPoint in testPoints)
            {
                testRun.AddTestPoint(testPoint, null);
            }
            testRun.Save();

            ITestCaseResultCollection results = testRun.QueryResults();

            foreach (ITestCaseResult result in results)
            {
                result.Attachments.Add(result.CreateAttachment(@"C:\Users\visong\Pictures\000.jpg"));
                result.Outcome = TestOutcome.Warning;
                result.State = TestResultState.Completed; 
                results.Save(true);
            }

            testRun.Save();
            testRun.Refresh();
        }

Then you should be able to find the attachement in the test result you're working with in MTM.

Vicky - MSFT
  • 4,970
  • 1
  • 14
  • 22
  • Thank you for your reply. Actually, it had uploaded in the MTM, Is there a way to see it in the TFS Webaccess ? – EverLearner Aug 14 '15 at 18:46
  • @EverLearner, I can't figure out one method to check attachment in TFS web access. However, does the ITestAttachment.Uri work? You can use URI to retrieve the contents of the attachment. – Vicky - MSFT Aug 17 '15 at 02:22