UserControlTests.cs 1.8 KB

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