TextStyleTests.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  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", "Microsoft YaHei")
  19. .BackgroundColor(Colors.Green.Lighten2)
  20. .EnableFontFeature(FontFeatures.StandardLigatures);
  21. var spanTextStyle = TextStyle
  22. .Default
  23. .FontFamily("Times New Roman", "Arial", "Calibri")
  24. .Bold()
  25. .Strikethrough()
  26. .BackgroundColor(Colors.Red.Lighten2)
  27. .DisableFontFeature(FontFeatures.StandardLigatures)
  28. .EnableFontFeature(FontFeatures.Kerning);
  29. // act
  30. var targetStyle = spanTextStyle.ApplyInheritedStyle(defaultTextStyle).ApplyGlobalStyle();
  31. // assert
  32. var expectedStyle = TextStyle.LibraryDefault with
  33. {
  34. Id = targetStyle.Id, // expect to break when adding new TextStyle properties, so use the real one
  35. Size = 20,
  36. FontFamilies = new[] { "Times New Roman", "Arial", "Calibri", "Microsoft YaHei", "Lato" },
  37. FontWeight = FontWeight.Bold,
  38. BackgroundColor = Colors.Red.Lighten2,
  39. FontFeatures = new[]
  40. {
  41. (FontFeatures.Kerning, true),
  42. (FontFeatures.StandardLigatures, false)
  43. },
  44. HasStrikethrough = true
  45. };
  46. Assert.That(targetStyle, Is.Not.Null);
  47. Assert.That(targetStyle.Id, Is.GreaterThan(1));
  48. Assert.That(targetStyle.ToString(), Is.EqualTo(expectedStyle.ToString()));
  49. }
  50. }
  51. }