コード例 #1
0
        public void FormatWritesTheReportWithTheSpecifiedAttachmentContentDisposition()
        {
            IProgressMonitor progressMonitor = Mocks.Stub<IProgressMonitor>();
            IReportWriter writer = Mocks.StrictMock<IReportWriter>();

            using (Mocks.Record())
            {
                writer.SaveReport(AttachmentContentDisposition.Link, progressMonitor);
            }

            using (Mocks.Playback())
            {
                XmlReportFormatter formatter = new XmlReportFormatter();
                ReportFormatterOptions options = new ReportFormatterOptions();
                options.AddProperty(XmlReportFormatter.AttachmentContentDispositionOption, AttachmentContentDisposition.Link.ToString());

                formatter.Format(writer, options, progressMonitor);
            }
        }
コード例 #2
0
        public void FormatWritesTheTransformedReport()
        {
            string resourcePath = Path.Combine(Path.GetDirectoryName(AssemblyUtils.GetAssemblyLocalPath(GetType().Assembly)), @"..\Reports");

            IReportWriter reportWriter = Mocks.StrictMock<IReportWriter>();
            IReportContainer reportContainer = Mocks.StrictMock<IReportContainer>();
            IProgressMonitor progressMonitor = NullProgressMonitor.CreateInstance();

            string reportPath = SpecialPathPolicy.For<XsltReportFormatter>().CreateTempFileWithUniqueName().FullName;
            using (Stream tempFileStream = File.OpenWrite(reportPath))
            {
                using (Mocks.Record())
                {
                    SetupResult.For(reportWriter.ReportContainer).Return(reportContainer);

                    reportWriter.SerializeReport(null, AttachmentContentDisposition.Link);
                    LastCall.Constraints(Is.NotNull(), Is.Equal(AttachmentContentDisposition.Link))
                        .Do((SerializeReportDelegate)delegate(XmlWriter writer, AttachmentContentDisposition contentDisposition)
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.InnerXml = "<report>The report.</report>";
                            doc.Save(writer);
                        });

                    SetupResult.For(reportContainer.ReportName).Return("Foo");
                    Expect.Call(reportContainer.OpenWrite("Foo.ext", MimeTypes.PlainText, new UTF8Encoding(false)))
                        .Return(tempFileStream);
                    reportWriter.AddReportDocumentPath("Foo.ext");

                    Expect.Call(reportContainer.OpenWrite(@"Foo\MbUnitLogo.png", MimeTypes.Png, null)).Return(new MemoryStream());

                    reportWriter.SaveReportAttachments(null);
                    LastCall.Constraints(Is.NotNull());
                }

                using (Mocks.Playback())
                {
                    XsltReportFormatter formatter = new XsltReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo(resourcePath), "Diagnostic.xslt", new string[] { "MbUnitLogo.png" });
                    var reportFormatterOptions = new ReportFormatterOptions();
                    reportFormatterOptions.AddProperty(XsltReportFormatter.AttachmentContentDispositionOption, AttachmentContentDisposition.Link.ToString());

                    formatter.Format(reportWriter, reportFormatterOptions, progressMonitor);

                    string reportContents = File.ReadAllText(reportPath);
                    TestLog.EmbedXml("Diagnostic report contents", reportContents);
                    Assert.Contains(reportContents, "<resourceRoot>Foo</resourceRoot>");
                    Assert.Contains(reportContents, "The report.");

                    File.Delete(reportPath);
                }
            }
        }