FluentExtensions.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Infrastructure;
  3. namespace QuestPDF.LayoutTests.TestEngine;
  4. internal class ExpectedDocumentLayoutDescriptor
  5. {
  6. public List<LayoutTestResult.PageLayoutSnapshot> PageLayouts { get; } = new();
  7. public ExpectedPageLayoutDescriptor Page()
  8. {
  9. var page = new LayoutTestResult.PageLayoutSnapshot();
  10. PageLayouts.Add(page);
  11. return new ExpectedPageLayoutDescriptor(page);
  12. }
  13. }
  14. internal class ExpectedPageLayoutDescriptor
  15. {
  16. private LayoutTestResult.PageLayoutSnapshot PageLayout { get; }
  17. public ExpectedPageLayoutDescriptor(LayoutTestResult.PageLayoutSnapshot pageLayout)
  18. {
  19. PageLayout = pageLayout;
  20. }
  21. public ExpectedPageLayoutDescriptor TakenAreaSize(float width, float height)
  22. {
  23. PageLayout.RequiredArea = new Size(width, height);
  24. return this;
  25. }
  26. public ExpectedPageLayoutDescriptor Content(Action<ExpectedPageContentDescriptor> content)
  27. {
  28. var pageContent = new ExpectedPageContentDescriptor();
  29. content(pageContent);
  30. PageLayout.MockPositions = pageContent.MockPositions;
  31. return this;
  32. }
  33. }
  34. internal class ExpectedPageContentDescriptor
  35. {
  36. public List<LayoutTestResult.MockLayoutPosition> MockPositions { get;} = new();
  37. public ExpectedMockPositionDescriptor Mock(string mockId)
  38. {
  39. var child = new LayoutTestResult.MockLayoutPosition { MockId = mockId };
  40. MockPositions.Add(child);
  41. return new ExpectedMockPositionDescriptor(child);
  42. }
  43. }
  44. internal class ExpectedMockPositionDescriptor
  45. {
  46. private LayoutTestResult.MockLayoutPosition MockLayoutPosition { get; }
  47. public ExpectedMockPositionDescriptor(LayoutTestResult.MockLayoutPosition mockLayoutPosition)
  48. {
  49. MockLayoutPosition = mockLayoutPosition;
  50. }
  51. public ExpectedMockPositionDescriptor Position(float x, float y)
  52. {
  53. MockLayoutPosition.Position = new Position(x, y);
  54. return this;
  55. }
  56. public ExpectedMockPositionDescriptor Size(float width, float height)
  57. {
  58. MockLayoutPosition.Size = new Size(width, height);
  59. return this;
  60. }
  61. }
  62. internal static class ElementExtensions
  63. {
  64. public static MockDescriptor Mock(this IContainer element, string id)
  65. {
  66. var mock = new ElementMock
  67. {
  68. MockId = id
  69. };
  70. element.Element(mock);
  71. return new MockDescriptor(mock);
  72. }
  73. }
  74. internal class MockDescriptor
  75. {
  76. private ElementMock Mock { get; }
  77. public MockDescriptor(ElementMock mock)
  78. {
  79. Mock = mock;
  80. }
  81. public MockDescriptor Size(float width, float height)
  82. {
  83. Mock.TotalWidth = width;
  84. Mock.TotalHeight = height;
  85. return this;
  86. }
  87. }