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.
59 lines
2.3 KiB
59 lines
2.3 KiB
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using System;
|
|
using Avalonia.Input;
|
|
using Avalonia.Layout;
|
|
using Avalonia.Platform;
|
|
using Avalonia.Styling;
|
|
using Avalonia.Controls;
|
|
|
|
namespace Avalonia.UnitTests
|
|
{
|
|
public class UnitTestApplication : Application
|
|
{
|
|
private readonly TestServices _services;
|
|
|
|
public UnitTestApplication(TestServices services)
|
|
{
|
|
_services = services ?? new TestServices();
|
|
RegisterServices();
|
|
}
|
|
|
|
public static new UnitTestApplication Current => (UnitTestApplication)Application.Current;
|
|
|
|
public TestServices Services => _services;
|
|
|
|
public static IDisposable Start(TestServices services = null)
|
|
{
|
|
var scope = AvaloniaLocator.EnterScope();
|
|
var app = new UnitTestApplication(services);
|
|
AvaloniaLocator.CurrentMutable.BindToSelf<Application>(app);
|
|
return scope;
|
|
}
|
|
|
|
public override void RegisterServices()
|
|
{
|
|
AvaloniaLocator.CurrentMutable
|
|
.Bind<IAssetLoader>().ToConstant(Services.AssetLoader)
|
|
.Bind<IFocusManager>().ToConstant(Services.FocusManager)
|
|
.BindToSelf<IGlobalStyles>(this)
|
|
.Bind<IInputManager>().ToConstant(Services.InputManager)
|
|
.Bind<IKeyboardDevice>().ToConstant(Services.KeyboardDevice?.Invoke())
|
|
.Bind<ILayoutManager>().ToConstant(Services.LayoutManager)
|
|
.Bind<IRuntimePlatform>().ToConstant(Services.Platform)
|
|
.Bind<IPlatformRenderInterface>().ToConstant(Services.RenderInterface)
|
|
.Bind<IPlatformThreadingInterface>().ToConstant(Services.ThreadingInterface)
|
|
.Bind<IStandardCursorFactory>().ToConstant(Services.StandardCursorFactory)
|
|
.Bind<IStyler>().ToConstant(Services.Styler)
|
|
.Bind<IWindowingPlatform>().ToConstant(Services.WindowingPlatform)
|
|
.Bind<IApplicationLifecycle>().ToConstant(this);
|
|
var styles = Services.Theme?.Invoke();
|
|
|
|
if (styles != null)
|
|
{
|
|
Styles.AddRange(styles);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|