TestRoot.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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;
  4. using Avalonia.Controls;
  5. using Avalonia.Input;
  6. using Avalonia.Layout;
  7. using Avalonia.Media;
  8. using Avalonia.Platform;
  9. using Avalonia.Rendering;
  10. using Avalonia.Styling;
  11. using Moq;
  12. namespace Avalonia.UnitTests
  13. {
  14. public class TestRoot : Decorator, IFocusScope, ILayoutRoot, IInputRoot, INameScope, IRenderRoot, IStyleRoot
  15. {
  16. private readonly NameScope _nameScope = new NameScope();
  17. public TestRoot()
  18. {
  19. }
  20. event EventHandler<NameScopeEventArgs> INameScope.Registered
  21. {
  22. add { _nameScope.Registered += value; ++NameScopeRegisteredSubscribers; }
  23. remove { _nameScope.Registered -= value; --NameScopeRegisteredSubscribers; }
  24. }
  25. public event EventHandler<NameScopeEventArgs> Unregistered
  26. {
  27. add { _nameScope.Unregistered += value; ++NameScopeUnregisteredSubscribers; }
  28. remove { _nameScope.Unregistered -= value; --NameScopeUnregisteredSubscribers; }
  29. }
  30. public int NameScopeRegisteredSubscribers { get; private set; }
  31. public int NameScopeUnregisteredSubscribers { get; private set; }
  32. public Size ClientSize { get; set; } = new Size(100, 100);
  33. public Size MaxClientSize { get; set; } = Size.Infinity;
  34. public double LayoutScaling => 1;
  35. public ILayoutManager LayoutManager { get; set; } = new LayoutManager();
  36. public double RenderScaling => 1;
  37. public IRenderer Renderer { get; set; }
  38. public IAccessKeyHandler AccessKeyHandler => null;
  39. public IKeyboardNavigationHandler KeyboardNavigationHandler => null;
  40. public IInputElement PointerOverElement { get; set; }
  41. public IMouseDevice MouseDevice { get; set; }
  42. public bool ShowAccessKeys { get; set; }
  43. public IStyleHost StylingParent { get; set; }
  44. IStyleHost IStyleHost.StylingParent => StylingParent;
  45. public IRenderTarget CreateRenderTarget()
  46. {
  47. var dc = new Mock<IDrawingContextImpl>();
  48. dc.Setup(x => x.CreateLayer(It.IsAny<Size>())).Returns(() =>
  49. {
  50. var layerDc = new Mock<IDrawingContextImpl>();
  51. var layer = new Mock<IRenderTargetBitmapImpl>();
  52. layer.Setup(x => x.CreateDrawingContext(It.IsAny<IVisualBrushRenderer>())).Returns(layerDc.Object);
  53. return layer.Object;
  54. });
  55. var result = new Mock<IRenderTarget>();
  56. result.Setup(x => x.CreateDrawingContext(It.IsAny<IVisualBrushRenderer>())).Returns(dc.Object);
  57. return result.Object;
  58. }
  59. public void Invalidate(Rect rect)
  60. {
  61. }
  62. public Point PointToClient(Point p) => p;
  63. public Point PointToScreen(Point p) => p;
  64. void INameScope.Register(string name, object element)
  65. {
  66. _nameScope.Register(name, element);
  67. }
  68. object INameScope.Find(string name)
  69. {
  70. return _nameScope.Find(name);
  71. }
  72. void INameScope.Unregister(string name)
  73. {
  74. _nameScope.Unregister(name);
  75. }
  76. }
  77. }