TextPresenter_Tests.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Linq;
  2. using Avalonia.Controls.Presenters;
  3. using Avalonia.Media;
  4. using Avalonia.UnitTests;
  5. using Xunit;
  6. namespace Avalonia.Controls.UnitTests.Presenters
  7. {
  8. public class TextPresenter_Tests : ScopedTestBase
  9. {
  10. [Fact]
  11. public void TextPresenter_Can_Contain_Null_With_Password_Char_Set()
  12. {
  13. using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
  14. {
  15. var target = new TextPresenter
  16. {
  17. PasswordChar = '*'
  18. };
  19. Assert.NotNull(target.TextLayout);
  20. }
  21. }
  22. [Fact]
  23. public void TextPresenter_Can_Contain_Null_WithOut_Password_Char_Set()
  24. {
  25. using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
  26. {
  27. var target = new TextPresenter();
  28. Assert.NotNull(target.TextLayout);
  29. }
  30. }
  31. [Fact]
  32. public void Text_Presenter_Replaces_Formatted_Text_With_Password_Char()
  33. {
  34. using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
  35. {
  36. var target = new TextPresenter { PasswordChar = '*', Text = "Test" };
  37. target.Measure(Size.Infinity);
  38. Assert.NotNull(target.TextLayout);
  39. var actual = string.Join(null,
  40. target.TextLayout.TextLines.SelectMany(x => x.TextRuns).Select(x => x.Text.ToString()));
  41. Assert.Equal("****", actual);
  42. }
  43. }
  44. [Theory]
  45. [InlineData(FontStretch.Condensed)]
  46. [InlineData(FontStretch.Expanded)]
  47. [InlineData(FontStretch.Normal)]
  48. [InlineData(FontStretch.ExtraCondensed)]
  49. [InlineData(FontStretch.SemiCondensed)]
  50. [InlineData(FontStretch.ExtraExpanded)]
  51. [InlineData(FontStretch.SemiExpanded)]
  52. [InlineData(FontStretch.UltraCondensed)]
  53. [InlineData(FontStretch.UltraExpanded)]
  54. public void TextPresenter_Should_Use_FontStretch_Property(FontStretch fontStretch)
  55. {
  56. using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
  57. {
  58. var presenter = new TextPresenter { FontStretch = fontStretch, Text = "test" };
  59. Assert.NotNull(presenter.TextLayout);
  60. Assert.Equal(1, presenter.TextLayout.TextLines.Count);
  61. Assert.Equal(1, presenter.TextLayout.TextLines[0].TextRuns.Count);
  62. Assert.NotNull(presenter.TextLayout.TextLines[0].TextRuns[0].Properties);
  63. Assert.Equal(fontStretch, presenter.TextLayout.TextLines[0].TextRuns[0].Properties.Typeface.Stretch);
  64. }
  65. }
  66. }
  67. }