/// <inheritdoc /> public void Format(IReportWriter reportWriter, string formatterName, ReportFormatterOptions formatterOptions, IProgressMonitor progressMonitor) { if (reportWriter == null) { throw new ArgumentNullException(@"reportWriter"); } if (formatterName == null) { throw new ArgumentNullException(@"formatterName"); } if (formatterOptions == null) { throw new ArgumentNullException(@"formatterOptions"); } if (progressMonitor == null) { throw new ArgumentNullException(@"progressMonitor"); } IReportFormatter formatter = GetReportFormatter(formatterName); if (formatter == null) { throw new InvalidOperationException(String.Format("There is no report formatter named '{0}'.", formatterName)); } formatter.Format(reportWriter, formatterOptions, progressMonitor); }
private string FormatResults(params IFeatureResult[] results) { using (var memory = new MemoryStream()) { _subject.Format(memory, results); return(Encoding.UTF8.GetString(memory.ToArray())); } }
// Method Injection: передача обязательных зависимостей метода public void SendReport(Report report, IReportFormatter formatter) { Logger.Info("Sending report..."); var formattedReport = formatter.Format(report); _reportSender.SendReport(formattedReport); Logger.Info("Report has been sent"); }
/// <inheritdoc /> public override void Format(IReportWriter reportWriter, ReportFormatterOptions formatterOptions, IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask("Formatting report.", 10)) { using (MultipartMimeReportContainer archiveContainer = new MultipartMimeReportContainer(reportWriter.ReportContainer)) { string archivePath = archiveContainer.ReportName + ".mht"; reportWriter.AddReportDocumentPath(archivePath); archiveContainer.OpenArchive(archivePath); progressMonitor.Worked(0.5); DefaultReportWriter archiveWriter = new DefaultReportWriter(reportWriter.Report, archiveContainer); using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(9)) htmlReportFormatter.Format(archiveWriter, formatterOptions, subProgressMonitor); archiveContainer.CloseArchive(); progressMonitor.Worked(0.5); } } }
public void FormatWritesTheArchivedReport() { IReportWriter reportWriter = Mocks.StrictMock <IReportWriter>(); IReportContainer reportContainer = Mocks.StrictMock <IReportContainer>(); IReportFormatter htmlReportFormatter = Mocks.StrictMock <IReportFormatter>(); IProgressMonitor progressMonitor = NullProgressMonitor.CreateInstance(); var reportFormatterOptions = new ReportFormatterOptions(); string reportPath = SpecialPathPolicy.For <MHtmlReportFormatterTest>().CreateTempFileWithUniqueName().FullName; using (Stream tempFileStream = File.OpenWrite(reportPath)) { using (Mocks.Record()) { SetupResult.For(reportWriter.ReportContainer).Return(reportContainer); SetupResult.For(reportWriter.Report).Return(new Report()); Expect.Call(reportContainer.EncodeFileName(null)) .Repeat.Any() .IgnoreArguments() .Do((Gallio.Common.GallioFunc <string, string>) delegate(string value) { return(value); }); SetupResult.For(reportContainer.ReportName).Return("Foo"); Expect.Call(reportContainer.OpenWrite("Foo.mht", MimeTypes.MHtml, new UTF8Encoding(false))) .Return(tempFileStream); reportWriter.AddReportDocumentPath("Foo.mht"); Expect.Call(delegate { htmlReportFormatter.Format(null, null, null); }) .Constraints(Is.NotNull(), Is.Same(reportFormatterOptions), Is.NotNull()) .Do((FormatDelegate) delegate(IReportWriter innerReportWriter, ReportFormatterOptions innerFormatterOptions, IProgressMonitor innerProgressMonitor) { using (StreamWriter contentWriter = new StreamWriter(innerReportWriter.ReportContainer.OpenWrite("Foo.html", MimeTypes.Html, Encoding.UTF8))) contentWriter.Write("<html><body>Some HTML</body></html>"); using (StreamWriter contentWriter = new StreamWriter(innerReportWriter.ReportContainer.OpenWrite( innerReportWriter.ReportContainer.EncodeFileName("Foo\\Attachment 1%.txt"), MimeTypes.PlainText, Encoding.UTF8))) contentWriter.Write("An attachment."); using (StreamWriter contentWriter = new StreamWriter(innerReportWriter.ReportContainer.OpenWrite("Foo.css", null, null))) contentWriter.Write("#Some CSS."); }); } using (Mocks.Playback()) { MHtmlReportFormatter formatter = new MHtmlReportFormatter(htmlReportFormatter); formatter.Format(reportWriter, reportFormatterOptions, progressMonitor); string reportContents = File.ReadAllText(reportPath); TestLog.AttachPlainText("MHTML Report", reportContents); Assert.Contains(reportContents, "MIME-Version: 1.0"); Assert.Contains(reportContents, "Content-Type: multipart/related; type=\"text/html\"; boundary="); Assert.Contains(reportContents, "This is a multi-part message in MIME format."); Assert.Contains(reportContents, "text/html"); Assert.Contains(reportContents, "Content-Location: file:///Foo.html"); Assert.Contains(reportContents, Convert.ToBase64String(Encoding.UTF8.GetBytes("<html><body>Some HTML</body></html>"), Base64FormattingOptions.InsertLineBreaks)); Assert.Contains(reportContents, "text/plain"); Assert.Contains(reportContents, "Content-Location: file:///Foo/Attachment_1%25.txt"); Assert.Contains(reportContents, Convert.ToBase64String(Encoding.UTF8.GetBytes("An attachment."), Base64FormattingOptions.InsertLineBreaks)); Assert.Contains(reportContents, "text/css"); Assert.Contains(reportContents, "Content-Location: file:///Foo.css"); Assert.Contains(reportContents, Convert.ToBase64String(Encoding.UTF8.GetBytes("#Some CSS."), Base64FormattingOptions.InsertLineBreaks)); File.Delete(reportPath); } } }
public string FormatWith(IReportFormatter formatter) { return(formatter.Format(this)); }