public string Run() { StringWriter textWriter = new StringWriter(); textWriter.NewLine = "\n"; Console.SetOut(textWriter); Assert.IsFalse(RuntimeAccessor.IsInitialized); TestLog.AttachPlainText("Attachment1", "Text"); using (TestLog.BeginSection("Test Section")) { TestLog.WriteLine("Foo"); TestLog.EmbedExisting("Attachment1"); } return(textWriter.ToString()); }
public void AttachedResources() { TestLog.WriteLine("Attached image."); TestLog.AttachImage("Image", Resources.MbUnitLogo); TestLog.WriteLine("Attached plain text."); TestLog.AttachPlainText("Plain Text", "This is some plain text.\nLalalala..."); TestLog.WriteLine("Attached XML."); TestLog.AttachXml("XML", "<life><universe><everything>42</everything></universe></life>"); TestLog.WriteLine("Attached XHTML."); TestLog.AttachXHtml("XHtml", "<p>Some <b>XHTML</b> markup.<br/>With a line break.</p>"); TestLog.WriteLine("Attached HTML."); TestLog.AttachHtml("Html", "<p>Some <b>HTML</b> markup.<br>With a line break.</p>"); TestLog.WriteLine("Attached binary data."); TestLog.Attach(new BinaryAttachment("Binary", "application/octet-stream", new byte[] { 67, 65, 66, 66, 65, 71, 69 })); TestLog.Write("Attached video."); TestLog.AttachVideo("Video", video); }
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); } } }