UnitTestApplication.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) The Perspex 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 Perspex.Input;
  5. using Perspex.Layout;
  6. using Perspex.Platform;
  7. using Perspex.Styling;
  8. namespace Perspex.UnitTests
  9. {
  10. public class UnitTestApplication : Application
  11. {
  12. public UnitTestApplication(TestServices services)
  13. {
  14. Services = services ?? new TestServices();
  15. RegisterServices();
  16. Styles = Services.Theme?.Invoke();
  17. }
  18. public static new UnitTestApplication Current => (UnitTestApplication)Application.Current;
  19. public TestServices Services { get; }
  20. public static IDisposable Start(TestServices services = null)
  21. {
  22. var scope = PerspexLocator.EnterScope();
  23. var app = new UnitTestApplication(services);
  24. return scope;
  25. }
  26. protected override void RegisterServices()
  27. {
  28. PerspexLocator.CurrentMutable
  29. .Bind<IAssetLoader>().ToConstant(Services.AssetLoader)
  30. .BindToSelf<IGlobalStyles>(this)
  31. .Bind<IInputManager>().ToConstant(Services.InputManager)
  32. .Bind<ILayoutManager>().ToConstant(Services.LayoutManager)
  33. .Bind<IPclPlatformWrapper>().ToConstant(Services.PlatformWrapper)
  34. .Bind<IPlatformRenderInterface>().ToConstant(Services.RenderInterface)
  35. .Bind<IPlatformThreadingInterface>().ToConstant(Services.ThreadingInterface)
  36. .Bind<IStandardCursorFactory>().ToConstant(Services.StandardCursorFactory)
  37. .Bind<IStyler>().ToConstant(Services.Styler)
  38. .Bind<IWindowingPlatform>().ToConstant(Services.WindowingPlatform);
  39. }
  40. }
  41. }