TestServices.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 System.Reflection;
  5. using Moq;
  6. using Perspex.Input;
  7. using Perspex.Layout;
  8. using Perspex.Platform;
  9. using Perspex.Shared.PlatformSupport;
  10. using Perspex.Styling;
  11. using Perspex.Themes.Default;
  12. using Ploeh.AutoFixture;
  13. using Ploeh.AutoFixture.AutoMoq;
  14. namespace Perspex.UnitTests
  15. {
  16. public class TestServices
  17. {
  18. private static IFixture s_fixture = new Fixture().Customize(new AutoMoqCustomization());
  19. public static readonly TestServices StyledWindow = new TestServices(
  20. assetLoader: new AssetLoader(),
  21. layoutManager: new LayoutManager(),
  22. platformWrapper: new PclPlatformWrapper(),
  23. renderInterface: s_fixture.Create<IPlatformRenderInterface>(),
  24. standardCursorFactory: Mock.Of<IStandardCursorFactory>(),
  25. styler: new Styler(),
  26. theme: () => new DefaultTheme(),
  27. threadingInterface: Mock.Of<IPlatformThreadingInterface>(x => x.CurrentThreadIsLoopThread == true),
  28. windowingPlatform: new MockWindowingPlatform());
  29. public static readonly TestServices MockPlatformWrapper = new TestServices(
  30. platformWrapper: Mock.Of<IPclPlatformWrapper>());
  31. public static readonly TestServices MockStyler = new TestServices(
  32. styler: Mock.Of<IStyler>());
  33. public static readonly TestServices MockThreadingInterface = new TestServices(
  34. threadingInterface: Mock.Of<IPlatformThreadingInterface>(x => x.CurrentThreadIsLoopThread == true));
  35. public static readonly TestServices RealStyler = new TestServices(
  36. styler: new Styler());
  37. public TestServices(
  38. IAssetLoader assetLoader = null,
  39. IInputManager inputManager = null,
  40. ILayoutManager layoutManager = null,
  41. IPclPlatformWrapper platformWrapper = null,
  42. IPlatformRenderInterface renderInterface = null,
  43. IStandardCursorFactory standardCursorFactory = null,
  44. IStyler styler = null,
  45. Func<Styles> theme = null,
  46. IPlatformThreadingInterface threadingInterface = null,
  47. IWindowImpl windowImpl = null,
  48. IWindowingPlatform windowingPlatform = null)
  49. {
  50. AssetLoader = assetLoader;
  51. InputManager = inputManager;
  52. LayoutManager = layoutManager;
  53. PlatformWrapper = platformWrapper;
  54. RenderInterface = renderInterface;
  55. StandardCursorFactory = standardCursorFactory;
  56. Styler = styler;
  57. Theme = theme;
  58. ThreadingInterface = threadingInterface;
  59. WindowImpl = windowImpl;
  60. WindowingPlatform = windowingPlatform;
  61. }
  62. public IAssetLoader AssetLoader { get; }
  63. public IInputManager InputManager { get; }
  64. public ILayoutManager LayoutManager { get; }
  65. public IPclPlatformWrapper PlatformWrapper { get; }
  66. public IPlatformRenderInterface RenderInterface { get; }
  67. public IStandardCursorFactory StandardCursorFactory { get; }
  68. public IStyler Styler { get; }
  69. public Func<Styles> Theme { get; }
  70. public IPlatformThreadingInterface ThreadingInterface { get; }
  71. public IWindowImpl WindowImpl { get; }
  72. public IWindowingPlatform WindowingPlatform { get; }
  73. public TestServices With(
  74. IAssetLoader assetLoader = null,
  75. IInputManager inputManager = null,
  76. ILayoutManager layoutManager = null,
  77. IPclPlatformWrapper platformWrapper = null,
  78. IPlatformRenderInterface renderInterface = null,
  79. IStandardCursorFactory standardCursorFactory = null,
  80. IStyler styler = null,
  81. Func<Styles> theme = null,
  82. IPlatformThreadingInterface threadingInterface = null,
  83. IWindowImpl windowImpl = null,
  84. IWindowingPlatform windowingPlatform = null)
  85. {
  86. return new TestServices(
  87. assetLoader: assetLoader ?? AssetLoader,
  88. inputManager: inputManager ?? InputManager,
  89. layoutManager: layoutManager ?? LayoutManager,
  90. platformWrapper: platformWrapper ?? PlatformWrapper,
  91. renderInterface: renderInterface ?? RenderInterface,
  92. standardCursorFactory: standardCursorFactory ?? StandardCursorFactory,
  93. styler: styler ?? Styler,
  94. theme: theme ?? Theme,
  95. threadingInterface: threadingInterface ?? ThreadingInterface,
  96. windowImpl: windowImpl ?? WindowImpl,
  97. windowingPlatform: windowingPlatform ?? WindowingPlatform);
  98. }
  99. }
  100. }