UserControlTests.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Linq;
  2. using Avalonia.Controls.Presenters;
  3. using Avalonia.Controls.Primitives;
  4. using Avalonia.Controls.Templates;
  5. using Avalonia.Styling;
  6. using Avalonia.UnitTests;
  7. using Xunit;
  8. namespace Avalonia.Controls.UnitTests
  9. {
  10. public class UserControlTests
  11. {
  12. [Fact]
  13. public void Should_Be_Styled_As_UserControl()
  14. {
  15. using (UnitTestApplication.Start(TestServices.RealStyler))
  16. {
  17. var target = new UserControl();
  18. var root = new TestRoot
  19. {
  20. Styles =
  21. {
  22. new Style(x => x.OfType<UserControl>())
  23. {
  24. Setters =
  25. {
  26. new Setter(TemplatedControl.TemplateProperty, GetTemplate())
  27. }
  28. }
  29. },
  30. Child = target,
  31. };
  32. Assert.NotNull(target.Template);
  33. }
  34. }
  35. private FuncControlTemplate GetTemplate()
  36. {
  37. return new FuncControlTemplate<UserControl>((parent, scope) =>
  38. {
  39. return new Border
  40. {
  41. Background = new Media.SolidColorBrush(0xffffffff),
  42. Child = new ContentPresenter
  43. {
  44. Name = "PART_ContentPresenter",
  45. [~ContentPresenter.ContentProperty] = parent[~ContentControl.ContentProperty],
  46. }.RegisterInNameScope(scope)
  47. };
  48. });
  49. }
  50. }
  51. }