public List <CollectorDataEntry> ToCollectionEntries(IEnumerable <ObjectModel.AttachmentSet> attachmentSets, TestRun testRun, string trxFileDirectory) { List <CollectorDataEntry> collectorEntries = new List <CollectorDataEntry>(); if (attachmentSets == null) { EqtTrace.Info($"Converter.ToCollectionEntries: Received {nameof(attachmentSets)} as null returning empty collection entries."); return(collectorEntries); } if (EqtTrace.IsInfoEnabled) { EqtTrace.Info($"Converter.ToCollectionEntries: Converting attachmentSets {string.Join(",", attachmentSets)} to collection entries."); } foreach (var attachmentSet in attachmentSets) { if (attachmentSet.Uri.AbsoluteUri.StartsWith(Constants.DataCollectorUriPrefix, StringComparison.OrdinalIgnoreCase)) { CollectorDataEntry collectorEntry = ToCollectorEntry(attachmentSet, Guid.Empty, testRun, trxFileDirectory); collectorEntries.Add(collectorEntry); } } return(collectorEntries); }
/// <summary> /// Creates a Gallio attachement from any VSTS collector data. /// </summary> /// <param name="collectorEntry">A VSTS data collector.</param> /// <returns>Gallio attachment instance.</returns> private static Attachment CreateAttachmentData(CollectorDataEntry collectorEntry) { Attachment attachment = null; var vstsAttachment = (UriDataAttachment)collectorEntry.Attachments[0]; if (vstsAttachment != null) { //var file = vstsAttachment.Uri.Segments.Last(); //var fileEx = file.Substring(file.Length - 7, 7); var file = new FileInfo(vstsAttachment.Uri.Segments.Last()); var fileEx = file.Extension; switch (fileEx) { case ".png": attachment = GetImageAttachment(vstsAttachment); break; case ".jpg": attachment = GetImageAttachment(vstsAttachment); break; case ".gif": attachment = GetImageAttachment(vstsAttachment); break; case ".txt": attachment = GetTextAttachment(vstsAttachment); break; case ".xml": attachment = GetXmlAttachment(vstsAttachment); break; case ".htm": attachment = GetHtmlAttachment(vstsAttachment); break; default: attachment = GetBinaryAttachment(vstsAttachment, fileEx); break; } } return(attachment); }
internal static List <CollectorDataEntry> ToCollectionEntries(IEnumerable <ObjectModel.AttachmentSet> attachmentSets, TestRun testRun, string trxFileDirectory) { List <CollectorDataEntry> collectorEntries = new List <CollectorDataEntry>(); if (attachmentSets == null) { return(collectorEntries); } foreach (var attachmentSet in attachmentSets) { if (attachmentSet.Uri.AbsoluteUri.StartsWith(TrxLogger.DataCollectorUriPrefix, StringComparison.OrdinalIgnoreCase)) { CollectorDataEntry collectorEntry = ToCollectorEntry(attachmentSet, Guid.Empty, testRun, trxFileDirectory); collectorEntries.Add(collectorEntry); } } return(collectorEntries); }
/// <summary> /// Updates test result attachments. /// </summary> /// <param name="rockSteadyTestResult"></param> /// <param name="testResult"></param> /// <param name="testRun"></param> /// <param name="trxFileDirectory"></param> /// <param name="addAttachments"></param> private void UpdateTestResultAttachments(ObjectModel.TestResult rockSteadyTestResult, TrxObjectModel.TestResult testResult, TestRun testRun, string trxFileDirectory, bool addAttachments) { if (rockSteadyTestResult.Attachments == null || rockSteadyTestResult.Attachments.Count == 0) { return; } // the testResult needs to have the testRun property set. Otherwise Data Collector entries can't be added. testResult.SetTestRun(testRun); // result files List <string> resultFiles = new List <string>(); // data collection files List <CollectorDataEntry> collectorEntries = new List <CollectorDataEntry>(); foreach (AttachmentSet attachmentSet in rockSteadyTestResult.Attachments) { try { // If the attachment is from data collector if (attachmentSet.Uri.AbsoluteUri.StartsWith(Constants.DataCollectorUriPrefix, StringComparison.OrdinalIgnoreCase)) { CollectorDataEntry collectorEntry = ToCollectorEntry(attachmentSet, testResult.Id.ExecutionId, testRun, trxFileDirectory); collectorEntries.Add(collectorEntry); } else { IList <string> testResultFiles = ToResultFiles(attachmentSet, testResult.Id.ExecutionId, testRun, trxFileDirectory); resultFiles.AddRange(testResultFiles); } } catch (Exception e) { string errorMsg = string.Format( CultureInfo.CurrentCulture, TrxLoggerResources.FailureToAttach, attachmentSet.DisplayName, e.GetType().ToString(), e); if (EqtTrace.IsErrorEnabled) { EqtTrace.Error("Converter: UpdateTestResultAttachments: " + errorMsg); } StringBuilder stdErr = new StringBuilder(testResult.StdErr); stdErr.AppendLine(errorMsg); testResult.StdErr = stdErr.ToString(); testResult.Outcome = TrxObjectModel.TestOutcome.Error; } } if (addAttachments) { if (resultFiles.Count > 0) { testResult.AddResultFiles(resultFiles); } if (collectorEntries.Count > 0) { testResult.AddCollectorDataEntries(collectorEntries); } } }
/// <summary> /// Creates a Gallio attachement from any VSTS collector data. /// </summary> /// <param name="collectorEntry">A VSTS data collector.</param> /// <returns>Gallio attachment instance.</returns> private static Attachment CreateAttachmentData(CollectorDataEntry collectorEntry) { Attachment attachment = null; var vstsAttachment = (UriDataAttachment)collectorEntry.Attachments[0]; if (vstsAttachment != null) { //var file = vstsAttachment.Uri.Segments.Last(); //var fileEx = file.Substring(file.Length - 7, 7); var file = new FileInfo(vstsAttachment.Uri.Segments.Last()); var fileEx = file.Extension; switch(fileEx) { case ".png": attachment = GetImageAttachment(vstsAttachment); break; case ".jpg": attachment = GetImageAttachment(vstsAttachment); break; case ".gif": attachment = GetImageAttachment(vstsAttachment); break; case ".txt": attachment = GetTextAttachment(vstsAttachment); break; case ".xml": attachment = GetXmlAttachment(vstsAttachment); break; case ".htm": attachment = GetHtmlAttachment(vstsAttachment); break; default : attachment = GetBinaryAttachment(vstsAttachment, fileEx); break; } } return attachment; }