TextStyleTests.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. var spanTextStyle = TextStyle
  22. .Default
  23. .FontFamily("Times New Roman", "Arial", "Calibri")
  24. .Bold()
  25. .Strikethrough()
  26. .BackgroundColor(Colors.Red.Lighten2);
  27. // act
  28. var targetStyle = spanTextStyle.ApplyInheritedStyle(defaultTextStyle).ApplyGlobalStyle();
  29. // assert
  30. var expectedStyle = TextStyle.LibraryDefault with
  31. {
  32. Id = targetStyle.Id, // expect to break when adding new TextStyle properties, so use the real one
  33. Size = 20,
  34. FontFamilies = new[] { "Times New Roman", "Arial", "Calibri", "Microsoft YaHei", "Lato" },
  35. FontWeight = FontWeight.Bold,
  36. BackgroundColor = Colors.Red.Lighten2,
  37. HasStrikethrough = true
  38. };
  39. spanTextStyle.Id.Should().BeGreaterThan(1);
  40. targetStyle.Should().BeEquivalentTo(expectedStyle);
  41. }
  42. }
  43. }