public void SessionEndedShouldReturnAttachments() { var attachment = new AttachmentSet(new Uri("my://custom/datacollector"), "CustomDataCollector"); attachment.Attachments.Add(new UriDataAttachment(new Uri("my://filename.txt"), "filename.txt")); this.mockDataCollectionAttachmentManager.Setup(x => x.GetAttachments(It.IsAny <DataCollectionContext>())).Returns(new List <AttachmentSet>() { attachment }); this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings); var sessionStartEventArgs = new SessionStartEventArgs(); this.dataCollectionManager.SessionStarted(sessionStartEventArgs); var result = this.dataCollectionManager.SessionEnded(); Assert.IsTrue(result[0].Attachments[0].Uri.ToString().Contains("filename.txt")); }
public void GetCombinedAttachmentSetsShouldReturnCombinedAttachments() { Collection <AttachmentSet> Attachments1 = new Collection <AttachmentSet>(); AttachmentSet attachmentset1 = new AttachmentSet(new Uri("DataCollection://Attachment/v1"), "AttachmentV1"); attachmentset1.Attachments.Add(new UriDataAttachment(new Uri("DataCollection://Attachment/v11"), "AttachmentV1-Attachment1")); Attachments1.Add(attachmentset1); Collection <AttachmentSet> Attachments2 = new Collection <AttachmentSet>(); AttachmentSet attachmentset2 = new AttachmentSet(new Uri("DataCollection://Attachment/v1"), "AttachmentV1"); attachmentset2.Attachments.Add(new UriDataAttachment(new Uri("DataCollection://Attachment/v12"), "AttachmentV1-Attachment2")); Attachments2.Add(attachmentset2); var result = DataCollectionTestRunEventsHandler.GetCombinedAttachmentSets(Attachments1, Attachments2); Assert.AreEqual(1, result.Count); Assert.AreEqual(2, result.First().Attachments.Count); }
public void TestRunCompleteHandlerShouldReturnIfUriAttachmentIsNull() { // Initialize var attachmentSet = new AttachmentSet(new Uri("test://uri"), "Blame"); var attachmentSetList = new List <AttachmentSet> { attachmentSet }; // Initialize Blame Logger var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); this.blameLogger.Initialize(loggerEvents, (string)null); // Setup and Raise event loggerEvents.CompleteTestRun(null, false, true, null, new Collection <AttachmentSet>(attachmentSetList), new TimeSpan(1, 0, 0, 0)); // Verify Call this.mockBlameReaderWriter.Verify(x => x.ReadTestSequence(It.IsAny <string>()), Times.Never); }
public void AttachmentInformationShouldBeWrittenToConsoleIfAttachmentsArePresent() { var attachmentSet = new AttachmentSet(new Uri("test://uri"), "myattachmentset"); var uriDataAttachment = new UriDataAttachment(new Uri("file://server/filename.ext"), "description"); attachmentSet.Attachments.Add(uriDataAttachment); var uriDataAttachment1 = new UriDataAttachment(new Uri("file://server/filename1.ext"), "description"); attachmentSet.Attachments.Add(uriDataAttachment1); var attachmentSetList = new List <AttachmentSet>(); attachmentSetList.Add(attachmentSet); var testRunCompleteEventArgs = new TestRunCompleteEventArgs(null, false, false, null, new Collection <AttachmentSet>(attachmentSetList), new TimeSpan(1, 0, 0, 0)); // Raise an event on mock object raised to register test case count and mark Outcome as Outcome.Failed this.testRunRequest.Raise(m => m.OnRunCompletion += null, testRunCompleteEventArgs); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.AttachmentOutputFormat, uriDataAttachment.Uri.LocalPath), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.AttachmentOutputFormat, uriDataAttachment1.Uri.LocalPath), OutputLevel.Information), Times.Once()); }
public void AfterTestRunEndShouldReturnAttachments() { var attachments = new Collection <AttachmentSet>(); var dispName = "MockAttachments"; var uri = new Uri("Mock://Attachments"); var attachmentSet = new AttachmentSet(uri, dispName); attachments.Add(attachmentSet); this.mockDataCollectionRequestSender.Attachments = attachments; var result = this.proxyDataCollectionManager.AfterTestRunEnd(false, null); Assert.IsTrue(this.mockDataCollectionRequestSender.sendAfterTestRunStartAndGetResult); Assert.IsNotNull(result); Assert.AreEqual(result.Count, 1); Assert.IsNotNull(result[0]); Assert.AreEqual(result[0].DisplayName, dispName); Assert.AreEqual(uri, result[0].Uri); }
public async Task HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested() { var attachmentSet = new AttachmentSet(new Uri("//badrui//"), string.Empty); attachmentSet.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa.coverage"), "coverage")); CancellationTokenSource cts = new CancellationTokenSource(); cts.Cancel(); Collection <AttachmentSet> attachment = new Collection <AttachmentSet> { attachmentSet, attachmentSet }; await Assert.ThrowsExceptionAsync <OperationCanceledException>(async() => await coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, cts.Token)); Assert.AreEqual(2, attachment.Count); mockProgressReporter.Verify(p => p.Report(It.IsAny <int>()), Times.Never); }
public ICollection <AttachmentSet> HandleDataCollectionAttachmentSets(ICollection <AttachmentSet> dataCollectionAttachments) { if (dataCollectionAttachments != null && dataCollectionAttachments.Any()) { var codeCoverageFiles = dataCollectionAttachments.Select(coverageAttachment => coverageAttachment.Attachments[0].Uri.LocalPath).ToArray(); var outputFile = MergeCodeCoverageFiles(codeCoverageFiles); var attachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName); if (!string.IsNullOrEmpty(outputFile)) { attachmentSet.Attachments.Add(new UriDataAttachment(new Uri(outputFile), CoverageFriendlyName)); return(new Collection <AttachmentSet> { attachmentSet }); } // In case merging fails(esp in dotnet core we cannot merge), so return filtered list of Code Coverage Attachments return(dataCollectionAttachments); } return(new Collection <AttachmentSet>()); }
public async Task HandleDataCollectionAttachmentSetsShouldReturnInputIfOnlySeveralLogsAttachmentAnd1Report() { var attachmentSet = new AttachmentSet(new Uri("datacollector://microsoft/CodeCoverage/2.0"), string.Empty); attachmentSet.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa.coverage"), "coverage")); var attachmentSet1 = new AttachmentSet(new Uri("datacollector://microsoft/CodeCoverage/2.0"), string.Empty); attachmentSet1.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa.logs"), "coverage")); attachmentSet1.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\bb.logs"), "coverage")); Collection <AttachmentSet> attachment = new Collection <AttachmentSet> { attachmentSet, attachmentSet1 }; ICollection <AttachmentSet> resultAttachmentSets = await coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 2); Assert.IsTrue(resultAttachmentSets.First().Attachments.Count == 1); Assert.IsTrue(resultAttachmentSets.Last().Attachments.Count == 2); }
public Task <ICollection <AttachmentSet> > ProcessAttachmentSetsAsync(ICollection <AttachmentSet> attachments, IProgress <int> progressReporter, IMessageLogger logger, CancellationToken cancellationToken) { if (attachments != null && attachments.Any()) { var codeCoverageFiles = attachments.Select(coverageAttachment => coverageAttachment.Attachments[0].Uri.LocalPath).ToArray(); var outputFile = MergeCodeCoverageFiles(codeCoverageFiles, progressReporter, cancellationToken); var attachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName); if (!string.IsNullOrEmpty(outputFile)) { attachmentSet.Attachments.Add(new UriDataAttachment(new Uri(outputFile), CoverageFriendlyName)); return(Task.FromResult((ICollection <AttachmentSet>) new Collection <AttachmentSet> { attachmentSet })); } // In case merging fails(esp in dotnet core we cannot merge), so return filtered list of Code Coverage Attachments return(Task.FromResult(attachments)); } return(Task.FromResult((ICollection <AttachmentSet>) new Collection <AttachmentSet>())); }
// Returns a list of collector entry private CollectorDataEntry ToCollectorEntry(AttachmentSet attachmentSet, Guid testResultExecutionId, TestRun testRun, string trxFileDirectory) { string runDirectoryName = Path.Combine(trxFileDirectory, testRun.RunConfiguration.RunDeploymentRootDirectory); string inDirectory = Path.Combine(runDirectoryName, "In"); string targetDirectory = inDirectory; if (!testResultExecutionId.Equals(Guid.Empty)) { targetDirectory = Path.Combine(inDirectory, testResultExecutionId.ToString()); } targetDirectory = Path.Combine(targetDirectory, Environment.MachineName); if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } List <IDataAttachment> uriDataAttachments = new List <IDataAttachment>(); foreach (ObjectModel.UriDataAttachment uriDataAttachment in attachmentSet.Attachments) { if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose("TrxLogger: ToCollectorEntry: Got attachment " + uriDataAttachment.Uri + " with description " + uriDataAttachment.Description); } string sourceFile = uriDataAttachment.Uri.LocalPath; var rooted = (Path.GetFullPath(sourceFile) == sourceFile); Debug.Assert(Path.IsPathRooted(sourceFile), "Source file is not rooted"); // copy the source file to the target location string targetFileName = trxFileHelper.GetNextIterationFileName(targetDirectory, Path.GetFileName(sourceFile), false); try { CopyFile(sourceFile, targetFileName); // Add the target file name to the collector files list. // (Trx viewer automatically adds In\ to the collected file. string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(targetFileName)); Uri sourceFileUri = new Uri(fileName, UriKind.Relative); TrxObjectModel.UriDataAttachment dataAttachment = new TrxObjectModel.UriDataAttachment(uriDataAttachment.Description, sourceFileUri, trxFileHelper); uriDataAttachments.Add(dataAttachment); } catch (Exception ex) { if (EqtTrace.IsErrorEnabled) { EqtTrace.Error("Trxlogger: ToCollectorEntry: " + ex); } } } return(new CollectorDataEntry( attachmentSet.Uri, attachmentSet.DisplayName, Environment.MachineName, Environment.MachineName, false, uriDataAttachments)); }
public TestResult RunTest(TestCase tc, IRunContext runContext) { TestResult tr = new TestResult(tc); XmlDocument rs = new XmlDocument(); rs.LoadXml(runContext.RunSettings.SettingsXml); XmlNodeList nodes = rs.SelectNodes("//TestRunParameters/Parameter"); string parameters = ""; // "-eval:g_testSetParams.g_browserLibrary='Chrome HTML'" foreach (XmlNode node in nodes) { string key = node.Attributes["name"].Value; string value = "" + node.Attributes["value"].Value; if (key.StartsWith("g_")) { parameters += " \"-eval:g_testSetParams." + key + "=\'" + value + "\'\""; } } XmlNodeList maxCpuCount = rs.SelectNodes("//RunConfiguration/MaxCpuCount"); if (maxCpuCount.Count > 0) { log.Debug("Parallel execution is turned ON"); parameters += " \"-eval:g_testSetParams.g_showExecutionMonitor=''\""; } string path = tc.Source; Directory.SetCurrentDirectory(Path.GetDirectoryName(path)); path = path.Replace("%SMARTESTUDIO%", GetRapisePath()); path = path.Replace("%ENGINE%", System.IO.Path.Combine(GetRapiseEnginePath(), "\\..")); string executorLine = "\"" + System.IO.Path.Combine(GetRapiseEnginePath(), "SeSExecutor.js") + "\"" + " \"" + path + "\"" + parameters; this.timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH_mm_ss"); Process myProc = Process.Start("cscript.exe", executorLine); myProc.WaitForExit(); log.Debug("Exit code: " + myProc.ExitCode); this.testFolderPath = System.IO.Path.GetDirectoryName(path); this.testCaseResultDirectory = Path.Combine(runContext.TestRunDirectory, tc.FullyQualifiedName + "_" + this.timestamp); Directory.CreateDirectory(this.testCaseResultDirectory); var attachmentSet = new AttachmentSet(new Uri(RapiseTestAdapter.ExecutorUri), "Attachments"); RegisterAttachment(tc, "summary.log", "output", attachmentSet); RegisterAttachment(tc, "err.log", "error", attachmentSet); RegisterAttachment(tc, "last.tap", "tap_report", attachmentSet); RegisterAttachment(tc, "last.trp", "trp_report", attachmentSet); string trpPath = System.IO.Path.Combine(testFolderPath, "last.trp"); if (System.IO.File.Exists(trpPath)) { string trpString = "<report>" + File.ReadAllText(trpPath) + "</report>"; XmlDocument trpXml = new XmlDocument(); trpXml.LoadXml(trpString); XmlNode sfn = trpXml.SelectSingleNode("//log[@name='Screen flow']/data"); if (sfn != null) { string htmlPath = sfn.Attributes["url"].Value; if (!string.IsNullOrEmpty(htmlPath)) { string screenFlowPath = Path.GetDirectoryName(htmlPath); string zipFileName = "screen_flow_" + tc.FullyQualifiedName + "_" + this.timestamp + ".zip"; string zipFilePath = Path.Combine(this.testCaseResultDirectory, zipFileName); ZipFile.CreateFromDirectory(screenFlowPath, zipFilePath); Uri zipFileUri = new Uri(zipFilePath, UriKind.Absolute); attachmentSet.Attachments.Add(new UriDataAttachment(zipFileUri, zipFileName)); } } } tr.Attachments.Add(attachmentSet); tr.Outcome = myProc.ExitCode == 0 ? TestOutcome.Passed : TestOutcome.Failed; return(tr); }
private void RegisterAttachment(TestCase tc, string fileName, string friendlyFileNameWithoutExtension, AttachmentSet attachmentSet) { string filePath = System.IO.Path.Combine(this.testFolderPath, fileName); if (System.IO.File.Exists(filePath)) { string attachmentFilePath = Path.Combine(this.testCaseResultDirectory, friendlyFileNameWithoutExtension + "_" + tc.FullyQualifiedName + "_" + this.timestamp + Path.GetExtension(fileName)); File.Copy(filePath, attachmentFilePath); Uri fileUri = new Uri(attachmentFilePath, UriKind.Absolute); attachmentSet.Attachments.Add(new UriDataAttachment(fileUri, friendlyFileNameWithoutExtension)); } }
public AttachmentSetDrop(AttachmentSet attachmentSet) { _attachmentSet = attachmentSet; }
public FileAttachmentSet(AttachmentSet set, string rootDirectory) { Uri = set.Uri; DisplayName = set.DisplayName; Attachments = set.Attachments.Select(a => new FileDataAttachment(a, rootDirectory)).ToList(); }