Rally SOAP API - 如何向TestCaseResult添加附件

时间:2012-04-29 14:31:52

标签: c# soap rally

我已经想出如何向TestCase,Defect对象添加附件,但是我不能使用相同的机制将测试结果文件附加到TestCaseResult对象。我收到“验证错误:Attachment.attachments [0]不应为null”的错误消息。我在创建测试结果期间尝试附加以及更新现有的,先前创建的测试结果。如果不支持将测试结果文件附加到TestCaseResult,我会感到惊讶,因为这是常见的主流行为。感谢。

我的代码:

private Attachment createAttachment(string resultsFile)         {             byte [] bytes = readFileAsByteArray(resultsFile);

        // Create attachment content;
        AttachmentContent attachmentContent = new AttachmentContent();
        attachmentContent.Content = bytes;
        attachmentContent.Workspace = this.m_targetWorkspace;
        CreateResult result = m_rallyService.create(attachmentContent);
        attachmentContent = (AttachmentContent)result.Object;
        //attachmentContent = (AttachmentContent)this.m_rallyService.read(attachmentContent, this.m_targetWorkspace);


        Attachment attachment = new Attachment();
        attachment.ContentType = "application / vnd.openxmlformats - officedocument.wordprocessingml.document";
        attachment.Content = attachmentContent;
        attachment.Name = "Bubba.docx";
        attachment.Size = bytes.Length;
        attachment.SizeSpecified = true;
        attachment.User = this.m_rallyUser;
        //attachment.Artifact = testResult;
        attachment.Workspace = this.m_targetWorkspace;

        result = m_rallyService.create(attachment);
        attachment = (Attachment)result.Object;
        //attachment = (Attachment)this.m_rallyService.read(attachment, this.m_targetWorkspace);

        return attachment;
    }

4 个答案:

答案 0 :(得分:1)

现在,它现在有效。 Attachment对象现在有一个属性TestCaseResult,在设置时,将附件附加到创建的结果。我修改过的代码:

   private Attachment createAttachment(TestCaseResult testCaseResult, string resultsFile)
    {
        byte[] bytes = readFileAsByteArray(resultsFile);

        // Create attachment content;
        AttachmentContent attachmentContent = new AttachmentContent();
        attachmentContent.Content = bytes;
        attachmentContent.Workspace = this.m_targetWorkspace;
        CreateResult result = m_rallyService.create(attachmentContent);
        attachmentContent = (AttachmentContent)result.Object;

        // Create attachment.
        Attachment attachment = new Attachment();

        // Microsoft Word document.
        attachment.ContentType = "application / vnd.openxmlformats - officedocument.wordprocessingml.document";
        attachment.Content = attachmentContent;

        // Parse out file name.
        string[] parts = resultsFile.Split(new char[] { '\\' });
        attachment.Name = parts[parts.Length - 1];

        attachment.Size = bytes.Length;
        attachment.SizeSpecified = true;
        attachment.User = this.m_rallyUser;
        attachment.TestCaseResult = testCaseResult;
        attachment.Workspace = this.m_targetWorkspace;

        result = m_rallyService.create(attachment);
        attachment = (Attachment)result.Object;

        return attachment;
      }

答案 1 :(得分:0)

不幸的是,您在Rally Webservices API中遇到了已知的缺陷。拉力赛产品开发正在努力解决问题 - 我建议提交拉力赛支持案例(rallysupport@rallydev.com),因为这会将您的查询与缺陷相关联,并且会在修复后通知您。 / p>

答案 2 :(得分:0)

自5/26/2012拉力赛代码发布以来,此缺陷已修复。

答案 3 :(得分:0)

如果附件属于test_case_result,则应使用attachment.artifact:

Artifact
Required    false
Note    The artifact this attachment belongs to.
One-To-One Relationship Artifact

为什么我们需要Attachment.TestCaseResult而不是简单的Attachment.Artifact?

TestCaseResult    
Required    false
Note    Associated Test Case Result
One-To-One Relationship TestCaseResult