TextStyleTests.cs 1.7 KB

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