TextStyleTests.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using FluentAssertions;
  2. using NUnit.Framework;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.UnitTests
  7. {
  8. [TestFixture]
  9. public class TextStyleTests
  10. {
  11. [Test]
  12. public void ApplyInheritedAndGlobalStyle()
  13. {
  14. // arrange
  15. var defaultTextStyle = TextStyle
  16. .Default
  17. .FontSize(20)
  18. .FontFamily("Arial")
  19. .BackgroundColor(Colors.Green.Lighten2)
  20. .Fallback(y => y
  21. .FontFamily("Microsoft YaHei")
  22. .Underline()
  23. .NormalWeight()
  24. .BackgroundColor(Colors.Blue.Lighten2));
  25. var spanTextStyle = TextStyle
  26. .Default
  27. .FontFamily("Times New Roman")
  28. .Bold()
  29. .Strikethrough()
  30. .BackgroundColor(Colors.Red.Lighten2);
  31. // act
  32. var targetStyle = spanTextStyle.ApplyInheritedStyle(defaultTextStyle).ApplyGlobalStyle();
  33. // assert
  34. var expectedStyle = TextStyle.LibraryDefault with
  35. {
  36. Size = 20,
  37. FontFamily = "Times New Roman",
  38. FontWeight = FontWeight.Bold,
  39. BackgroundColor = Colors.Red.Lighten2,
  40. HasStrikethrough = true,
  41. Fallback = TextStyle.LibraryDefault with
  42. {
  43. Size = 20,
  44. FontFamily = "Microsoft YaHei",
  45. FontWeight = FontWeight.Bold,
  46. BackgroundColor = Colors.Red.Lighten2,
  47. HasUnderline = true,
  48. HasStrikethrough = true
  49. }
  50. };
  51. targetStyle.Should().BeEquivalentTo(expectedStyle);
  52. }
  53. }
  54. }