TextStyleTests.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections.Generic;
  2. using FluentAssertions;
  3. using NUnit.Framework;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Helpers;
  6. using QuestPDF.Infrastructure;
  7. namespace QuestPDF.UnitTests
  8. {
  9. [TestFixture]
  10. public class TextStyleTests
  11. {
  12. [Test]
  13. public void ApplyInheritedAndGlobalStyle()
  14. {
  15. // arrange
  16. var defaultTextStyle = TextStyle
  17. .Default
  18. .FontSize(20)
  19. .FontFamily("Arial", "Microsoft YaHei")
  20. .BackgroundColor(Colors.Green.Lighten2)
  21. .EnableFontFeature(FontFeatures.StandardLigatures);
  22. var spanTextStyle = TextStyle
  23. .Default
  24. .FontFamily("Times New Roman", "Arial", "Calibri")
  25. .Bold()
  26. .Strikethrough()
  27. .BackgroundColor(Colors.Red.Lighten2)
  28. .DisableFontFeature(FontFeatures.StandardLigatures)
  29. .EnableFontFeature(FontFeatures.Kerning);
  30. // act
  31. var targetStyle = spanTextStyle.ApplyInheritedStyle(defaultTextStyle).ApplyGlobalStyle();
  32. // assert
  33. var expectedStyle = TextStyle.LibraryDefault with
  34. {
  35. Id = targetStyle.Id, // expect to break when adding new TextStyle properties, so use the real one
  36. Size = 20,
  37. FontFamilies = new[] { "Times New Roman", "Arial", "Calibri", "Microsoft YaHei", "Lato" },
  38. FontWeight = FontWeight.Bold,
  39. BackgroundColor = Colors.Red.Lighten2,
  40. FontFeatures = new[]
  41. {
  42. (FontFeatures.Kerning, true),
  43. (FontFeatures.StandardLigatures, false)
  44. },
  45. HasStrikethrough = true
  46. };
  47. spanTextStyle.Id.Should().BeGreaterThan(1);
  48. targetStyle.Should().BeEquivalentTo(expectedStyle);
  49. }
  50. }
  51. }