MockPlatformRenderInterface.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Avalonia.Media;
  5. using Avalonia.Platform;
  6. using Avalonia.Media.Imaging;
  7. using Avalonia.Rendering;
  8. using Moq;
  9. namespace Avalonia.UnitTests
  10. {
  11. public class MockPlatformRenderInterface : IPlatformRenderInterface
  12. {
  13. public IGeometryImpl CreateEllipseGeometry(Rect rect)
  14. {
  15. return Mock.Of<IGeometryImpl>();
  16. }
  17. public IGeometryImpl CreateLineGeometry(Point p1, Point p2)
  18. {
  19. return Mock.Of<IGeometryImpl>();
  20. }
  21. public IGeometryImpl CreateRectangleGeometry(Rect rect)
  22. {
  23. return Mock.Of<IGeometryImpl>(x => x.Bounds == rect);
  24. }
  25. class MockRenderTarget : IRenderTarget
  26. {
  27. public void Dispose()
  28. {
  29. }
  30. public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
  31. {
  32. var m = new Mock<IDrawingContextImpl>();
  33. m.Setup(c => c.CreateLayer(It.IsAny<Size>()))
  34. .Returns(() =>
  35. {
  36. var r = new Mock<IDrawingContextLayerImpl>();
  37. r.Setup(r => r.CreateDrawingContext(It.IsAny<IVisualBrushRenderer>()))
  38. .Returns(CreateDrawingContext(null));
  39. return r.Object;
  40. }
  41. );
  42. return m.Object;
  43. }
  44. }
  45. public IRenderTarget CreateRenderTarget(IEnumerable<object> surfaces)
  46. {
  47. return new MockRenderTarget();
  48. }
  49. public IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi)
  50. {
  51. return Mock.Of<IRenderTargetBitmapImpl>();
  52. }
  53. public IStreamGeometryImpl CreateStreamGeometry()
  54. {
  55. return new MockStreamGeometryImpl();
  56. }
  57. public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children)
  58. {
  59. return Mock.Of<IGeometryImpl>();
  60. }
  61. public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2)
  62. {
  63. return Mock.Of<IGeometryImpl>();
  64. }
  65. public IWriteableBitmapImpl CreateWriteableBitmap(
  66. PixelSize size,
  67. Vector dpi,
  68. PixelFormat format,
  69. AlphaFormat alphaFormat)
  70. {
  71. throw new NotImplementedException();
  72. }
  73. public IBitmapImpl LoadBitmap(Stream stream)
  74. {
  75. return Mock.Of<IBitmapImpl>();
  76. }
  77. public IWriteableBitmapImpl LoadWriteableBitmapToWidth(Stream stream, int width,
  78. BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  79. {
  80. throw new NotImplementedException();
  81. }
  82. public IWriteableBitmapImpl LoadWriteableBitmapToHeight(Stream stream, int height,
  83. BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  84. {
  85. throw new NotImplementedException();
  86. }
  87. public IWriteableBitmapImpl LoadWriteableBitmap(string fileName)
  88. {
  89. throw new NotImplementedException();
  90. }
  91. public IWriteableBitmapImpl LoadWriteableBitmap(Stream stream)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. public IBitmapImpl LoadBitmap(string fileName)
  96. {
  97. return Mock.Of<IBitmapImpl>();
  98. }
  99. public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  100. {
  101. return Mock.Of<IBitmapImpl>();
  102. }
  103. public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  104. {
  105. return Mock.Of<IBitmapImpl>();
  106. }
  107. public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  108. {
  109. return Mock.Of<IBitmapImpl>();
  110. }
  111. public IBitmapImpl LoadBitmap(
  112. PixelFormat format,
  113. AlphaFormat alphaFormat,
  114. IntPtr data,
  115. PixelSize size,
  116. Vector dpi,
  117. int stride)
  118. {
  119. throw new NotImplementedException();
  120. }
  121. public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun)
  122. {
  123. return Mock.Of<IGlyphRunImpl>();
  124. }
  125. public IGeometryImpl BuildGlyphRunGeometry(GlyphRun glyphRun)
  126. {
  127. return Mock.Of<IGeometryImpl>();
  128. }
  129. public IGlyphRunBuffer AllocateGlyphRun(GlyphTypeface glyphTypeface, float fontRenderingEmSize, int length)
  130. {
  131. return Mock.Of<IGlyphRunBuffer>();
  132. }
  133. public IHorizontalGlyphRunBuffer AllocateHorizontalGlyphRun(GlyphTypeface glyphTypeface, float fontRenderingEmSize, int length)
  134. {
  135. return Mock.Of<IHorizontalGlyphRunBuffer>();
  136. }
  137. public IPositionedGlyphRunBuffer AllocatePositionedGlyphRun(GlyphTypeface glyphTypeface, float fontRenderingEmSize, int length)
  138. {
  139. return Mock.Of<IPositionedGlyphRunBuffer>();
  140. }
  141. public bool SupportsIndividualRoundRects { get; set; }
  142. public AlphaFormat DefaultAlphaFormat => AlphaFormat.Premul;
  143. public PixelFormat DefaultPixelFormat => PixelFormat.Rgba8888;
  144. }
  145. }