csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
8.8 KiB
194 lines
8.8 KiB
using System;
|
|
using Moq;
|
|
using Avalonia.Input;
|
|
using Avalonia.Platform;
|
|
using Avalonia.Styling;
|
|
using Avalonia.Themes.Simple;
|
|
using Avalonia.Rendering;
|
|
using System.Reactive.Concurrency;
|
|
using Avalonia.Animation;
|
|
using Avalonia.Headless;
|
|
using Avalonia.Threading;
|
|
|
|
namespace Avalonia.UnitTests
|
|
{
|
|
public class TestServices
|
|
{
|
|
public static readonly TestServices StyledWindow = new TestServices(
|
|
assetLoader: new StandardAssetLoader(),
|
|
platform: new StandardRuntimePlatform(),
|
|
renderInterface: new HeadlessPlatformRenderInterface(),
|
|
standardCursorFactory: new HeadlessCursorFactoryStub(),
|
|
theme: () => CreateSimpleTheme(),
|
|
dispatcherImpl: new NullDispatcherImpl(),
|
|
fontManagerImpl: new HeadlessFontManagerStub(),
|
|
textShaperImpl: new HeadlessTextShaperStub(),
|
|
windowingPlatform: new MockWindowingPlatform());
|
|
|
|
public static readonly TestServices MockPlatformRenderInterface = new TestServices(
|
|
assetLoader: new StandardAssetLoader(),
|
|
renderInterface: new HeadlessPlatformRenderInterface(),
|
|
fontManagerImpl: new HeadlessFontManagerStub(),
|
|
textShaperImpl: new HeadlessTextShaperStub());
|
|
|
|
public static readonly TestServices MockPlatformWrapper = new TestServices(
|
|
platform: Mock.Of<IRuntimePlatform>());
|
|
|
|
public static readonly TestServices MockThreadingInterface = new TestServices(
|
|
dispatcherImpl: new NullDispatcherImpl());
|
|
|
|
public static readonly TestServices MockWindowingPlatform = new TestServices(
|
|
windowingPlatform: new MockWindowingPlatform());
|
|
|
|
public static readonly TestServices RealFocus = new TestServices(
|
|
keyboardDevice: () => new KeyboardDevice(),
|
|
keyboardNavigation: () => new KeyboardNavigationHandler(),
|
|
inputManager: new InputManager(),
|
|
assetLoader: new StandardAssetLoader(),
|
|
renderInterface: new HeadlessPlatformRenderInterface(),
|
|
fontManagerImpl: new HeadlessFontManagerStub(),
|
|
textShaperImpl: new HeadlessTextShaperStub());
|
|
|
|
public static readonly 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(),
|
|
dispatcherImpl: new NullDispatcherImpl(),
|
|
fontManagerImpl: new HeadlessFontManagerStub(),
|
|
textShaperImpl: new HeadlessTextShaperStub(),
|
|
windowingPlatform: new MockWindowingPlatform());
|
|
|
|
public static readonly TestServices TextServices = new TestServices(
|
|
assetLoader: new StandardAssetLoader(),
|
|
renderInterface: new HeadlessPlatformRenderInterface(),
|
|
fontManagerImpl: new HarfBuzzFontManagerImpl(),
|
|
textShaperImpl: new HarfBuzzTextShaperImpl());
|
|
|
|
public TestServices(
|
|
IAssetLoader assetLoader = null,
|
|
IInputManager inputManager = null,
|
|
Func<IKeyboardDevice> keyboardDevice = null,
|
|
Func<IKeyboardNavigationHandler> keyboardNavigation = null,
|
|
Func<IMouseDevice> mouseDevice = null,
|
|
IRuntimePlatform platform = null,
|
|
IPlatformRenderInterface renderInterface = null,
|
|
IRenderTimer renderLoop = null,
|
|
ICursorFactory standardCursorFactory = null,
|
|
Func<IStyle> theme = null,
|
|
IDispatcherImpl dispatcherImpl = null,
|
|
IFontManagerImpl fontManagerImpl = null,
|
|
ITextShaperImpl textShaperImpl = null,
|
|
IWindowImpl windowImpl = null,
|
|
IWindowingPlatform windowingPlatform = null)
|
|
{
|
|
AssetLoader = assetLoader;
|
|
InputManager = inputManager;
|
|
KeyboardDevice = keyboardDevice;
|
|
KeyboardNavigation = keyboardNavigation;
|
|
MouseDevice = mouseDevice;
|
|
Platform = platform;
|
|
RenderInterface = renderInterface;
|
|
FontManagerImpl = fontManagerImpl;
|
|
TextShaperImpl = textShaperImpl;
|
|
StandardCursorFactory = standardCursorFactory;
|
|
Theme = theme;
|
|
DispatcherImpl = dispatcherImpl;
|
|
WindowImpl = windowImpl;
|
|
WindowingPlatform = windowingPlatform;
|
|
}
|
|
|
|
internal TestServices(
|
|
IGlobalClock globalClock,
|
|
IAssetLoader assetLoader = null,
|
|
IInputManager inputManager = null,
|
|
Func<IKeyboardDevice> keyboardDevice = null,
|
|
Func<IKeyboardNavigationHandler> keyboardNavigation = null,
|
|
Func<IMouseDevice> mouseDevice = null,
|
|
IRuntimePlatform platform = null,
|
|
IPlatformRenderInterface renderInterface = null,
|
|
IRenderTimer renderLoop = null,
|
|
ICursorFactory standardCursorFactory = null,
|
|
Func<IStyle> theme = null,
|
|
IDispatcherImpl dispatcherImpl = null,
|
|
IFontManagerImpl fontManagerImpl = null,
|
|
ITextShaperImpl textShaperImpl = null,
|
|
IWindowImpl windowImpl = null,
|
|
IWindowingPlatform windowingPlatform = null,
|
|
IAccessKeyHandler accessKeyHandler = null
|
|
) : this(assetLoader, inputManager, keyboardDevice,
|
|
keyboardNavigation,
|
|
mouseDevice, platform, renderInterface, renderLoop, standardCursorFactory, theme,
|
|
dispatcherImpl, fontManagerImpl, textShaperImpl, windowImpl, windowingPlatform)
|
|
{
|
|
GlobalClock = globalClock;
|
|
AccessKeyHandler = accessKeyHandler;
|
|
}
|
|
|
|
public IAssetLoader AssetLoader { get; }
|
|
public IInputManager InputManager { get; }
|
|
internal IGlobalClock GlobalClock { get; set; }
|
|
internal IAccessKeyHandler AccessKeyHandler { get; }
|
|
public Func<IKeyboardDevice> KeyboardDevice { get; }
|
|
public Func<IKeyboardNavigationHandler> KeyboardNavigation { get; }
|
|
public Func<IMouseDevice> MouseDevice { get; }
|
|
public IRuntimePlatform Platform { get; }
|
|
public IPlatformRenderInterface RenderInterface { get; }
|
|
public IFontManagerImpl FontManagerImpl { get; }
|
|
public ITextShaperImpl TextShaperImpl { get; }
|
|
public ICursorFactory StandardCursorFactory { get; }
|
|
public Func<IStyle> Theme { get; }
|
|
public IDispatcherImpl DispatcherImpl { get; }
|
|
public IWindowImpl WindowImpl { get; }
|
|
public IWindowingPlatform WindowingPlatform { get; }
|
|
|
|
internal TestServices With(
|
|
IAssetLoader assetLoader = null,
|
|
IInputManager inputManager = null,
|
|
Func<IKeyboardDevice> keyboardDevice = null,
|
|
Func<IKeyboardNavigationHandler> keyboardNavigation = null,
|
|
Func<IMouseDevice> mouseDevice = null,
|
|
IRuntimePlatform platform = null,
|
|
IPlatformRenderInterface renderInterface = null,
|
|
IRenderTimer renderLoop = null,
|
|
IScheduler scheduler = null,
|
|
ICursorFactory standardCursorFactory = null,
|
|
Func<IStyle> theme = null,
|
|
IDispatcherImpl dispatcherImpl = null,
|
|
IFontManagerImpl fontManagerImpl = null,
|
|
ITextShaperImpl textShaperImpl = null,
|
|
IWindowImpl windowImpl = null,
|
|
IWindowingPlatform windowingPlatform = null,
|
|
IGlobalClock globalClock = null,
|
|
IAccessKeyHandler accessKeyHandler = null)
|
|
{
|
|
return new TestServices(
|
|
globalClock ?? GlobalClock,
|
|
assetLoader: assetLoader ?? AssetLoader,
|
|
inputManager: inputManager ?? InputManager,
|
|
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,
|
|
dispatcherImpl: dispatcherImpl ?? DispatcherImpl,
|
|
windowingPlatform: windowingPlatform ?? WindowingPlatform,
|
|
windowImpl: windowImpl ?? WindowImpl,
|
|
accessKeyHandler: accessKeyHandler ?? AccessKeyHandler
|
|
);
|
|
}
|
|
|
|
private static IStyle CreateSimpleTheme()
|
|
{
|
|
return new SimpleTheme();
|
|
}
|
|
}
|
|
}
|
|
|