public string SaveReportAs(Report report, string fileName, string format, IProgressMonitor progressMonitor) { var file = string.Empty; using (progressMonitor.BeginTask("Generating report", 100)) { var folderName = Path.GetDirectoryName(fileName); var reportContainer = new FileSystemReportContainer(folderName, Path.GetFileNameWithoutExtension(fileName)); var reportWriter = reportManager.CreateReportWriter(report, reportContainer); if (progressMonitor.IsCanceled) throw new OperationCanceledException(); // Delete the report if it already exists reportContainer.DeleteReport(); if (progressMonitor.IsCanceled) throw new OperationCanceledException(); progressMonitor.Worked(10); // Format the report var reportFormatterOptions = new ReportFormatterOptions(); using (var subProgressMonitor = progressMonitor.CreateSubProgressMonitor(90)) reportManager.Format(reportWriter, format, reportFormatterOptions, subProgressMonitor); if (progressMonitor.IsCanceled) throw new OperationCanceledException(); if (reportWriter.ReportDocumentPaths.Count > 0) file = Path.Combine(folderName, reportWriter.ReportDocumentPaths[0]); } return file; }
public void TestStepFinished_Test() { var testStepRun = new TestStepRun(new TestStepData("root", "name", "fullName", "root")) { TestLog = new StructuredDocument() }; testStepRun.TestLog.Attachments.Add(new TextAttachment("name", "contentType", "text").ToAttachmentData()); var report = new Report { TestPackageRun = new TestPackageRun(), TestModel = new TestModelData() }; report.TestPackageRun.RootTestStepRun = testStepRun; testController.Stub(x => x.ReadReport(null)).IgnoreArguments().Do((Action<ReadAction<Report>>)(action => action(report))); testTreeModel.Stub(x => x.Root).Return(new TestTreeNode("root", "root")); var flag = false; executionLogController.ExecutionLogUpdated += (sender, e) => { Assert.Count(1, e.TestStepRuns); flag = true; }; var testData = new TestData("root", "name", "fullName") { IsTestCase = true }; executionLogController.Handle(new TestStepFinished(testData, null)); Assert.IsTrue(flag); }
private static string GenerateReportName(Report report, string reportNameFormat) { DateTime reportTime = report.TestPackageRun != null ? report.TestPackageRun.StartTime : DateTime.Now; return String.Format(CultureInfo.InvariantCulture, reportNameFormat, reportTime.ToString(@"yyyyMMdd"), reportTime.ToString(@"HHmmss")); }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <param name="logStreamName">The log stream name.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// <paramref name="testStepRun"/> or <paramref name="logStreamName"/> is null.</exception> protected TestStepLogStreamEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName) : base(report, test, testStepRun) { if (logStreamName == null) throw new ArgumentNullException("logStreamName"); this.logStreamName = logStreamName; }
public static List<AnnotationData> GetAnnotations(Report report) { var list = new List<AnnotationData>(); list.AddRange(GetAnnotationsWithType(report, AnnotationType.Error)); list.AddRange(GetAnnotationsWithType(report, AnnotationType.Warning)); list.AddRange(GetAnnotationsWithType(report, AnnotationType.Info)); return list; }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <param name="logStreamName">The log stream name.</param> /// <param name="sectionName">The name of the section that was started.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// <paramref name="testStepRun"/>, <paramref name="logStreamName"/>, or <paramref name="sectionName"/> is null.</exception> public TestStepLogStreamBeginSectionBlockEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName, string sectionName) : base(report, test, testStepRun, logStreamName) { if (sectionName == null) throw new ArgumentNullException("sectionName"); this.sectionName = sectionName; }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <param name="attachment">The attachment.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// <paramref name="testStepRun"/> or <paramref name="attachment"/> is null.</exception> public TestStepLogAttachEventArgs(Report report, TestData test, TestStepRun testStepRun, Attachment attachment) : base(report, test, testStepRun) { if (attachment == null) throw new ArgumentNullException("attachment"); this.attachment = attachment; }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <param name="logStreamName">The log stream name.</param> /// <param name="attachmentName">The name of the attachment that was embedded.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// <paramref name="testStepRun"/>, <paramref name="logStreamName"/>, or <paramref name="attachmentName"/> is null.</exception> public TestStepLogStreamEmbedEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName, string attachmentName) : base(report, test, testStepRun, logStreamName) { if (attachmentName == null) throw new ArgumentNullException("attachmentName"); this.attachmentName = attachmentName; }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="success">True if test exploration was successful.</param> /// <param name="report">The report, including test model data on success.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/> is null.</exception> public ExploreFinishedEventArgs(bool success, Report report) : base(success) { if (report == null) throw new ArgumentNullException("report"); this.report = report; }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <param name="lifecyclePhase">The lifecycle phase name.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// <paramref name="testStepRun"/>, or <paramref name="lifecyclePhase"/> is null.</exception> public TestStepLifecyclePhaseChangedEventArgs(Report report, TestData test, TestStepRun testStepRun, string lifecyclePhase) : base(report, test, testStepRun) { if (lifecyclePhase == null) throw new ArgumentNullException("lifecyclePhase"); this.lifecyclePhase = lifecyclePhase; }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <param name="logStreamName">The log stream name.</param> /// <param name="text">The text that was written.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// <paramref name="testStepRun"/> or <paramref name="logStreamName"/> is null.</exception> public TestStepLogStreamWriteEventArgs(Report report, TestData test, TestStepRun testStepRun, string logStreamName, string text) : base(report, test, testStepRun, logStreamName) { if (text == null) throw new ArgumentNullException("text"); this.text = text; }
public void GetAndSetTestModel() { Report report = new Report(); Assert.IsNull(report.TestModel); TestModelData value = new TestModelData(); report.TestModel = value; Assert.AreSame(value, report.TestModel); }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="annotation">The annotation that was added.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/> is null.</exception> public AnnotationDiscoveredEventArgs(Report report, AnnotationData annotation) { if (report == null) throw new ArgumentNullException("report"); if (annotation == null) throw new ArgumentNullException("annotation"); this.report = report; this.annotation = annotation; }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test at the top of the subtree that was added.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/> is null.</exception> public TestDiscoveredEventArgs(Report report, TestData test) { if (report == null) throw new ArgumentNullException("report"); if (test == null) throw new ArgumentNullException("test"); this.report = report; this.test = test; }
public void GetAndSetPackageRun() { Report report = new Report(); Assert.IsNull(report.TestPackageRun); TestPackageRun value = new TestPackageRun(); report.TestPackageRun = value; Assert.AreSame(value, report.TestPackageRun); }
public void GenerateReport_Test() { var report = new Report(); var reportOptions = new ReportOptions("reportDirectory", "reportNameFormat"); reportController.GenerateReport(report, reportOptions, MockProgressMonitor.Instance); reportService.AssertWasCalled(rs => rs.SaveReportAs(Arg.Is(report), Arg<string>.Is.Anything, Arg.Is("xml"), Arg<IProgressMonitor>.Is.Anything)); }
public void GetAndSetPackageConfig() { Report report = new Report(); Assert.IsNull(report.TestModel); TestPackageData value = new TestPackageData(); report.TestPackage = value; Assert.AreSame(value, report.TestPackage); }
private static IEnumerable<AnnotationData> GetAnnotationsWithType(Report report, AnnotationType type) { if (report.TestModel == null) yield break; foreach (AnnotationData annotation in report.TestModel.Annotations) { if (annotation.Type == type) yield return annotation; } }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <param name="metadataKey">The metadata key.</param> /// <param name="metadataValue">The metadata value.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// <paramref name="testStepRun"/>, <paramref name="metadataKey"/> or <paramref name="metadataValue" /> is null.</exception> public TestStepMetadataAddedEventArgs(Report report, TestData test, TestStepRun testStepRun, string metadataKey, string metadataValue) : base(report, test, testStepRun) { if (metadataKey == null) throw new ArgumentNullException("metadataKey"); if (metadataValue == null) throw new ArgumentNullException("metadataValue"); this.metadataKey = metadataKey; this.metadataValue = metadataValue; }
public void ShowReport_Test() { var report = new Report(); const string reportType = "test"; const string reportName = "reportName"; reportService.Stub(rs => rs.SaveReportAs(Arg.Is(report), Arg<string>.Is.Anything, Arg.Is(reportType), Arg<IProgressMonitor>.Is.Anything)).Return(reportName); Assert.AreEqual(reportName, reportController.ShowReport(report, reportType, MockProgressMonitor.Instance)); }
public static void AreEqual(Report expected, Report actual) { if (expected == null) { Assert.IsNull(actual); return; } AreEqual(expected.TestPackage, actual.TestPackage); ModelAssert.AreEqual(expected.TestModel, actual.TestModel); AreEqual(expected.TestPackageRun, actual.TestPackageRun); }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// or <paramref name="testStepRun"/> is null.</exception> protected TestStepEventArgs(Report report, TestData test, TestStepRun testStepRun) { if (report == null) throw new ArgumentNullException("report"); if (test == null) throw new ArgumentNullException("test"); if (testStepRun == null) throw new ArgumentNullException("testStepRun"); this.report = report; this.test = test; this.testStepRun = testStepRun; }
/// <summary> /// Creates a report writer for the specified report. /// </summary> /// <param name="report">The report.</param> /// <param name="reportContainer">The report container.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/> or <paramref name="reportContainer"/> is null.</exception> public DefaultReportWriter(Report report, IReportContainer reportContainer) { if (report == null) throw new ArgumentNullException(@"report"); if (reportContainer == null) throw new ArgumentNullException(@"reportContainer"); this.report = report; this.reportContainer = reportContainer; reportDocumentPaths = new List<string>(); attachmentPathResolver = new AttachmentPathResolver(reportContainer); }
public void RoundTripXmlSerialization() { XmlSerializer serializer = new XmlSerializer(typeof(Report)); StringWriter writer = new StringWriter(); Report report = new Report(); report.TestPackageRun = new TestPackageRun(); report.TestPackageRun.RootTestStepRun = new TestStepRun(new TestStepData("456", "abc", "456:abc", "testId")); report.TestPackageRun.RootTestStepRun.Children.Add(new TestStepRun(new TestStepData("child", "child", "child", "child"))); serializer.Serialize(writer, report); Report deserializedReport = (Report) serializer.Deserialize(new StringReader(writer.ToString())); ReportAssert.AreEqual(report, deserializedReport); }
public void Execute_should_call_GenerateReport_on_ReportController() { var testController = MockRepository.GenerateStub<ITestController>(); var report = new Report(); testController.Stub(tc => tc.ReadReport(null)).IgnoreArguments().Do( (Action<ReadAction<Report>>)(action => action(report))); var reportController = MockRepository.GenerateStub<IReportController>(); var reportOptions = new ReportOptions("", ""); var generateReportCommand = new GenerateReportCommand(testController, reportController) { ReportOptions = reportOptions }; var progressMonitor = MockProgressMonitor.Instance; generateReportCommand.Execute(progressMonitor); reportController.AssertWasCalled(rc => rc.GenerateReport(report, reportOptions, progressMonitor)); }
/// <inheritdoc /> public Report Merge(IProgressMonitor progressMonitor) { if (progressMonitor == null) throw new ArgumentNullException("progressMonitor"); using (progressMonitor.BeginTask("Merging reports.", 1)) { var report = new Report { TestModel = MergeTestModelData(), TestPackageRun = MergeTestPackageRun(), TestPackage = MergeTestPackageData(), }; report.LogEntries.AddRange(MergeLogEntries()); return report; } }
public void Format() { var mockPreferenceStore = MockRepository.GenerateStub<IPreferenceStore>(); var mockPreferenceManager = MockRepository.GenerateStub<IPreferenceManager>(); var mockPreferenceSet = MockRepository.GenerateStub<IPreferenceSet>(); mockPreferenceManager.Stub(x => x.LocalUserPreferences).Return(mockPreferenceStore); mockPreferenceStore.Stub(x => x["Gallio.Reports"]).Return(mockPreferenceSet); mockPreferenceSet.Stub(x => x.Read<bool>(null)).IgnoreArguments().Return(false); mockPreferenceSet.Stub(x => x.Read<int>(null)).IgnoreArguments().Return(2000); var fakeReportPreferenceManager = new ReportPreferenceManager(mockPreferenceManager); var mockReportWriter = MockRepository.GenerateStub<IReportWriter>(); var mockReportContainer = MockRepository.GenerateStub<IReportContainer>(); var mockProgressMonitor = NullProgressMonitor.CreateInstance(); var output = new StringBuilder(); var stream = new StringStream(output); var fakeReport = new Report(); mockReportWriter.Stub(x => x.Report).Return(fakeReport); mockReportWriter.Stub(x => x.ReportContainer).Return(mockReportContainer); mockReportContainer.Stub(x => x.ReportName).Return("output"); mockReportContainer.Stub(x => x.OpenWrite(null, null, null)).IgnoreArguments().Return(stream); fakeReport.TestPackageRun = new TestPackageRun(); fakeReport.TestPackageRun.RootTestStepRun = new TestStepRun(new TestStepData("", "", "", "")); fakeReport.TestPackageRun.Statistics.RunCount = 123; var formatter = new VtlReportFormatter(fakeReportPreferenceManager, "ext", MimeTypes.PlainText, new DirectoryInfo("content"), "Gallio.Tests.Reports.SampleTemplate.vm", EmptyArray<string>.Instance, false); formatter.VelocityEngineFactory = new ResourceVelocityEngineFactory(); formatter.Format(mockReportWriter, new ReportFormatterOptions(), mockProgressMonitor); Assert.AreEqual("This is the test report (123)", output.ToString()); }
public void ExecutionLog_should_be_updated_when_test_selection_changes() { var testStepRun = new TestStepRun(new TestStepData("rootStep", "name", "fullName", "root")); var selectedTests = new List<TestTreeNode> { new TestTreeNode("name", "rootStep") }; var report = new Report { TestPackageRun = new TestPackageRun(), TestModel = new TestModelData() }; report.TestPackageRun.RootTestStepRun = testStepRun; testController.Stub(x => x.ReadReport(Arg<ReadAction<Report>>.Is.Anything)) .Do((Action<ReadAction<Report>>)(action => action(report))); testTreeModel.Stub(x => x.Root).Return(new TestTreeNode("root", "name")); var flag = false; executionLogController.ExecutionLogUpdated += delegate { flag = true; }; executionLogController.Handle(new TestSelectionChanged(selectedTests)); Assert.IsTrue(flag); }
/// <summary> /// Initializes the event arguments. /// </summary> /// <param name="report">The report.</param> /// <param name="test">The test data.</param> /// <param name="testStepRun">The test step run.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/>, <paramref name="test"/> /// or <paramref name="testStepRun"/> is null.</exception> public TestStepFinishedEventArgs(Report report, TestData test, TestStepRun testStepRun) : base(report, test, testStepRun) { }
public void TaskExposesResultsReturnedByLauncher() { var task = new StubbedGallioTask(); task.ResultProperty = "ExitCode"; task.StatisticsPropertiesPrefix = "Stats."; task.SetRunLauncherAction(launcher => { var report = new Report(); report.TestPackageRun = new TestPackageRun(); report.TestPackageRun.Statistics.AssertCount = 42; report.TestPackageRun.Statistics.Duration = 1.5; report.TestPackageRun.Statistics.FailedCount = 5; report.TestPackageRun.Statistics.InconclusiveCount = 11; report.TestPackageRun.Statistics.PassedCount = 21; report.TestPackageRun.Statistics.SkippedCount = 1; report.TestPackageRun.Statistics.StepCount = 30; report.TestPackageRun.Statistics.TestCount = 28; var result = new TestLauncherResult(report); result.SetResultCode(ResultCode.Failure); return result; }); Assert.Throws<BuildException>(task.InternalExecute); Assert.AreEqual(ResultCode.Failure.ToString(), task.Properties["ExitCode"]); Assert.AreEqual("42", task.Properties["Stats.AssertCount"]); Assert.AreEqual("1.5", task.Properties["Stats.Duration"]); Assert.AreEqual("5", task.Properties["Stats.FailedCount"]); Assert.AreEqual("11", task.Properties["Stats.InconclusiveCount"]); Assert.AreEqual("21", task.Properties["Stats.PassedCount"]); Assert.AreEqual("1", task.Properties["Stats.SkippedCount"]); Assert.AreEqual("30", task.Properties["Stats.StepCount"]); Assert.AreEqual("28", task.Properties["Stats.TestCount"]); }