using System; using System.Reactive.Concurrency; using Avalonia.Animation; using Avalonia.Harfbuzz; using Avalonia.Headless; using Avalonia.Input; using Avalonia.Platform; using Avalonia.Rendering; using Avalonia.Styling; using Avalonia.Themes.Simple; using Avalonia.Threading; using Moq; namespace Avalonia.UnitTests { public class TestServices { public static TestServices StyledWindow => new TestServices( assetLoader: new StandardAssetLoader(), platform: new StandardRuntimePlatform(), renderInterface: new HeadlessPlatformRenderInterface(), standardCursorFactory: new HeadlessCursorFactoryStub(), theme: () => CreateSimpleTheme(), fontManagerImpl: new TestFontManager(), textShaperImpl: new HarfBuzzTextShaper(), windowingPlatform: new MockWindowingPlatform()); public static TestServices MockPlatformRenderInterface => new TestServices( assetLoader: new StandardAssetLoader(), renderInterface: new HeadlessPlatformRenderInterface(), fontManagerImpl: new TestFontManager(), textShaperImpl: new HarfBuzzTextShaper()); public static TestServices MockPlatformWrapper => new TestServices( platform: Mock.Of()); public static TestServices MockThreadingInterface => new TestServices( assetLoader: new StandardAssetLoader()); public static TestServices MockWindowingPlatform => new TestServices( windowingPlatform: new MockWindowingPlatform()); public static TestServices RealFocus => new TestServices( keyboardDevice: () => new KeyboardDevice(), keyboardNavigation: () => new KeyboardNavigationHandler(), inputManager: new InputManager(), assetLoader: new StandardAssetLoader(), renderInterface: new HeadlessPlatformRenderInterface(), fontManagerImpl: new TestFontManager(), textShaperImpl: new HarfBuzzTextShaper()); public static TestServices FocusableWindow => new TestServices( keyboardDevice: () => new KeyboardDevice(), keyboardNavigation: () => new KeyboardNavigationHandler(), inputManager: new InputManager(), assetLoader: new StandardAssetLoader(), platform: new StandardRuntimePlatform(), renderInterface: new HeadlessPlatformRenderInterface(), standardCursorFactory: new HeadlessCursorFactoryStub(), theme: () => CreateSimpleTheme(), fontManagerImpl: new TestFontManager(), textShaperImpl: new HarfBuzzTextShaper(), windowingPlatform: new MockWindowingPlatform()); public static TestServices TextServices => new TestServices( assetLoader: new StandardAssetLoader(), renderInterface: new HeadlessPlatformRenderInterface(), fontManagerImpl: new TestFontManager(), textShaperImpl: new HarfBuzzTextShaper()); internal TestServices( IAssetLoader? assetLoader = null, IInputManager? inputManager = null, IGlobalClock? globalClock = null, Func? keyboardDevice = null, Func? keyboardNavigation = null, Func? mouseDevice = null, IRuntimePlatform? platform = null, IPlatformRenderInterface? renderInterface = null, ICursorFactory? standardCursorFactory = null, Func? theme = null, IFontManagerImpl? fontManagerImpl = null, ITextShaperImpl? textShaperImpl = null, IWindowImpl? windowImpl = null, IWindowingPlatform? windowingPlatform = null, Func? accessKeyHandler = null) { AssetLoader = assetLoader; InputManager = inputManager; GlobalClock = globalClock; AccessKeyHandler = accessKeyHandler; KeyboardDevice = keyboardDevice; KeyboardNavigation = keyboardNavigation; MouseDevice = mouseDevice; Platform = platform; RenderInterface = renderInterface; FontManagerImpl = fontManagerImpl; TextShaperImpl = textShaperImpl; StandardCursorFactory = standardCursorFactory; Theme = theme; WindowImpl = windowImpl; WindowingPlatform = windowingPlatform; } public IAssetLoader? AssetLoader { get; } public IInputManager? InputManager { get; } internal IGlobalClock? GlobalClock { get; set; } internal Func? AccessKeyHandler { get; } public Func? KeyboardDevice { get; } internal Func? KeyboardNavigation { get; } public Func? MouseDevice { get; } public IRuntimePlatform? Platform { get; } public IPlatformRenderInterface? RenderInterface { get; } public IFontManagerImpl? FontManagerImpl { get; } public ITextShaperImpl? TextShaperImpl { get; } public ICursorFactory? StandardCursorFactory { get; } public Func? Theme { get; } public IWindowImpl? WindowImpl { get; } public IWindowingPlatform? WindowingPlatform { get; } internal TestServices With( IAssetLoader? assetLoader = null, IInputManager? inputManager = null, IGlobalClock? globalClock = null, Func? accessKeyHandler = null, Func? keyboardDevice = null, Func? keyboardNavigation = null, Func? mouseDevice = null, IRuntimePlatform? platform = null, IPlatformRenderInterface? renderInterface = null, IRenderTimer? renderLoop = null, IScheduler? scheduler = null, ICursorFactory? standardCursorFactory = null, Func? theme = null, IFontManagerImpl? fontManagerImpl = null, ITextShaperImpl? textShaperImpl = null, IWindowImpl? windowImpl = null, IWindowingPlatform? windowingPlatform = null) { return new TestServices( assetLoader: assetLoader ?? AssetLoader, inputManager: inputManager ?? InputManager, globalClock: globalClock ?? GlobalClock, accessKeyHandler: accessKeyHandler ?? AccessKeyHandler, keyboardDevice: keyboardDevice ?? KeyboardDevice, keyboardNavigation: keyboardNavigation ?? KeyboardNavigation, mouseDevice: mouseDevice ?? MouseDevice, platform: platform ?? Platform, renderInterface: renderInterface ?? RenderInterface, fontManagerImpl: fontManagerImpl ?? FontManagerImpl, textShaperImpl: textShaperImpl ?? TextShaperImpl, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, theme: theme ?? Theme, windowingPlatform: windowingPlatform ?? WindowingPlatform, windowImpl: windowImpl ?? WindowImpl); } private static IStyle CreateSimpleTheme() { return new SimpleTheme(); } } }