TestRoot.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. private readonly IRenderTarget _renderTarget = Mock.Of<IRenderTarget>(
  18. x => x.CreateDrawingContext(It.IsAny<IVisualBrushRenderer>()) == Mock.Of<IDrawingContextImpl>());
  19. public TestRoot()
  20. {
  21. }
  22. event EventHandler<NameScopeEventArgs> INameScope.Registered
  23. {
  24. add { _nameScope.Registered += value; ++NameScopeRegisteredSubscribers; }
  25. remove { _nameScope.Registered -= value; --NameScopeRegisteredSubscribers; }
  26. }
  27. public event EventHandler<NameScopeEventArgs> Unregistered
  28. {
  29. add { _nameScope.Unregistered += value; ++NameScopeUnregisteredSubscribers; }
  30. remove { _nameScope.Unregistered -= value; --NameScopeUnregisteredSubscribers; }
  31. }
  32. public int NameScopeRegisteredSubscribers { get; private set; }
  33. public int NameScopeUnregisteredSubscribers { get; private set; }
  34. public Size ClientSize { get; set; } = new Size(100, 100);
  35. public Size MaxClientSize { get; set; } = Size.Infinity;
  36. public double LayoutScaling => 1;
  37. public double RenderScaling => 1;
  38. public ILayoutManager LayoutManager => AvaloniaLocator.Current.GetService<ILayoutManager>();
  39. public IRenderTarget RenderTarget => null;
  40. public IRenderer Renderer { get; set; }
  41. public IAccessKeyHandler AccessKeyHandler => null;
  42. public IKeyboardNavigationHandler KeyboardNavigationHandler => null;
  43. public IInputElement PointerOverElement { get; set; }
  44. public IMouseDevice MouseDevice { get; set; }
  45. public bool ShowAccessKeys { get; set; }
  46. public IStyleHost StylingParent { get; set; }
  47. IStyleHost IStyleHost.StylingParent => StylingParent;
  48. public IRenderTarget CreateRenderTarget() => _renderTarget;
  49. public void Invalidate(Rect rect)
  50. {
  51. }
  52. public Point PointToClient(Point p) => p;
  53. public Point PointToScreen(Point p) => p;
  54. void INameScope.Register(string name, object element)
  55. {
  56. _nameScope.Register(name, element);
  57. }
  58. object INameScope.Find(string name)
  59. {
  60. return _nameScope.Find(name);
  61. }
  62. void INameScope.Unregister(string name)
  63. {
  64. _nameScope.Unregister(name);
  65. }
  66. }
  67. }