TestApp.cs 1.7 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 Moq;
  4. using Perspex.Controls.UnitTests;
  5. using Perspex.Layout;
  6. using Perspex.Platform;
  7. using Perspex.Shared.PlatformSupport;
  8. using Perspex.Themes.Default;
  9. using Ploeh.AutoFixture;
  10. using Ploeh.AutoFixture.AutoMoq;
  11. namespace Perspex.LeakTests
  12. {
  13. internal class TestApp : Application
  14. {
  15. private TestApp()
  16. {
  17. RegisterServices();
  18. var fixture = new Fixture().Customize(new AutoMoqCustomization());
  19. var windowImpl = new Mock<IWindowImpl>();
  20. var renderInterface = fixture.Create<IPlatformRenderInterface>();
  21. var threadingInterface = Mock.Of<IPlatformThreadingInterface>(x =>
  22. x.CurrentThreadIsLoopThread == true);
  23. PerspexLocator.CurrentMutable
  24. .Bind<IAssetLoader>().ToConstant(new AssetLoader())
  25. .Bind<ILayoutManager>().ToConstant(new LayoutManager())
  26. .Bind<IPclPlatformWrapper>().ToConstant(new PclPlatformWrapper())
  27. .Bind<IPlatformRenderInterface>().ToConstant(renderInterface)
  28. .Bind<IPlatformThreadingInterface>().ToConstant(threadingInterface)
  29. .Bind<IStandardCursorFactory>().ToConstant(new Mock<IStandardCursorFactory>().Object)
  30. .Bind<IWindowingPlatform>().ToConstant(new WindowingPlatformMock(() => windowImpl.Object));
  31. Styles = new DefaultTheme();
  32. }
  33. public static void Initialize()
  34. {
  35. if (Current == null)
  36. {
  37. new TestApp();
  38. }
  39. }
  40. }
  41. }