Tests.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using NUnit.Framework;
  6. using QuestPDF.Drawing;
  7. using QuestPDF.Fluent;
  8. using QuestPDF.Infrastructure;
  9. using QuestPDF.ReportSample.Layouts;
  10. namespace QuestPDF.ReportSample
  11. {
  12. public class ReportGeneration
  13. {
  14. private StandardReport Report { get; set; }
  15. [SetUp]
  16. public void SetUp()
  17. {
  18. var model = DataSource.GetReport();
  19. Report = new StandardReport(model);
  20. }
  21. [Test]
  22. public void GenerateAndShowPdf()
  23. {
  24. Settings.DocumentLayoutExceptionThreshold = 10_000;
  25. Settings.EnableCaching = true;
  26. Settings.EnableDebugging = false;
  27. ImagePlaceholder.Solid = true;
  28. var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"test_result.pdf");
  29. Report.GeneratePdf(path);
  30. Process.Start("explorer.exe", path);
  31. }
  32. [Test]
  33. public void GenerateAndShowXps()
  34. {
  35. var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"test_result.xps");
  36. Report.GenerateXps(path);
  37. Process.Start("explorer.exe", path);
  38. }
  39. [Test]
  40. public void Profile()
  41. {
  42. ImagePlaceholder.Solid = true;
  43. var container = new DocumentContainer();
  44. Report.Compose(container);
  45. var content = container.Compose();
  46. var pageContext = new PageContext();
  47. DocumentGenerator.RenderPass(pageContext, new FreeCanvas(), content, null);
  48. DocumentGenerator.RenderPass(pageContext, new FreeCanvas(), content, null);
  49. }
  50. }
  51. }