TextStyleTests.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 Font()
  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. .Bold()
  28. .Strikethrough()
  29. .BackgroundColor(Colors.Red.Lighten2);
  30. // act
  31. var targetStyle = spanTextStyle.ApplyInheritedStyle(defaultTextStyle).ApplyGlobalStyle();
  32. // assert
  33. var expectedStyle = TextStyle.LibraryDefault with
  34. {
  35. Size = 20,
  36. FontFamily = "Arial",
  37. FontWeight = FontWeight.Bold,
  38. BackgroundColor = Colors.Red.Lighten2,
  39. HasStrikethrough = true,
  40. Fallback = TextStyle.LibraryDefault with
  41. {
  42. Size = 20,
  43. FontFamily = "Microsoft YaHei",
  44. FontWeight = FontWeight.Bold,
  45. BackgroundColor = Colors.Red.Lighten2,
  46. HasUnderline = true,
  47. HasStrikethrough = true
  48. }
  49. };
  50. targetStyle.Should().BeEquivalentTo(expectedStyle);
  51. }
  52. }
  53. }