Complete interface implementations, fix errors, uncomment tests, etc ...
This commit is contained in:
Daniel 2021-11-18 11:17:00 +01:00
Родитель 5e6572d17c
Коммит 450518726b
8 изменённых файлов: 145 добавлений и 20 удалений

Просмотреть файл

@ -4,6 +4,8 @@ using System.IO;
using Avalonia;
using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.Visuals.Media.Imaging;
using Moq;
namespace AvaloniaEdit.AvaloniaMocks
@ -12,6 +14,12 @@ namespace AvaloniaEdit.AvaloniaMocks
{
public IEnumerable<string> InstalledFontNames => throw new NotImplementedException();
public bool SupportsIndividualRoundRects => throw new NotImplementedException();
public AlphaFormat DefaultAlphaFormat => throw new NotImplementedException();
public PixelFormat DefaultPixelFormat => throw new NotImplementedException();
public IFormattedTextImpl CreateFormattedText(
string text,
Typeface typeface,
@ -81,5 +89,70 @@ namespace AvaloniaEdit.AvaloniaMocks
{
throw new NotImplementedException();
}
public IFormattedTextImpl CreateFormattedText(string text, Typeface typeface, double fontSize, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList<FormattedTextStyleSpan> spans)
{
return Mock.Of<IFormattedTextImpl>();
}
public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children)
{
throw new NotImplementedException();
}
public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2)
{
throw new NotImplementedException();
}
public IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat format, AlphaFormat alphaFormat)
{
throw new NotImplementedException();
}
public IWriteableBitmapImpl LoadWriteableBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IWriteableBitmapImpl LoadWriteableBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IWriteableBitmapImpl LoadWriteableBitmap(string fileName)
{
throw new NotImplementedException();
}
public IWriteableBitmapImpl LoadWriteableBitmap(Stream stream)
{
throw new NotImplementedException();
}
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
public IBitmapImpl LoadBitmap(PixelFormat format, AlphaFormat alphaFormat, IntPtr data, PixelSize size, Vector dpi, int stride)
{
throw new NotImplementedException();
}
public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun, out double width)
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Platform;
namespace AvaloniaEdit.AvaloniaMocks
{
public class MockRuntimePlatform : IRuntimePlatform
{
IUnmanagedBlob IRuntimePlatform.AllocBlob(int size)
{
throw new NotImplementedException();
}
RuntimePlatformInfo IRuntimePlatform.GetRuntimeInfo()
{
return new RuntimePlatformInfo();
}
IDisposable IRuntimePlatform.StartSystemTimer(TimeSpan interval, Action tick)
{
throw new NotImplementedException();
}
}
}

Просмотреть файл

@ -34,6 +34,8 @@ namespace AvaloniaEdit.AvaloniaMocks
public Matrix Transform { get; }
public double ContourLength => throw new NotImplementedException();
public IStreamGeometryImpl Clone()
{
return this;
@ -70,6 +72,21 @@ namespace AvaloniaEdit.AvaloniaMocks
return new MockStreamGeometryImpl(transform, _context);
}
public bool TryGetPointAtDistance(double distance, out Point point)
{
throw new NotImplementedException();
}
public bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent)
{
throw new NotImplementedException();
}
public bool TryGetSegment(double startDistance, double stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry)
{
throw new NotImplementedException();
}
class MockStreamGeometryContext : IStreamGeometryContextImpl
{
private List<Point> points = new List<Point>();

Просмотреть файл

@ -17,14 +17,19 @@ namespace AvaloniaEdit.AvaloniaMocks
public IWindowImpl CreateWindow()
{
return _windowImpl?.Invoke() ?? Mock.Of<IWindowImpl>(x => x.Scaling == 1);
return _windowImpl?.Invoke() ?? Mock.Of<IWindowImpl>(x => x.RenderScaling == 1);
}
public IEmbeddableWindowImpl CreateEmbeddableWindow()
public IWindowImpl CreateEmbeddableWindow()
{
throw new NotImplementedException();
}
public IPopupImpl CreatePopup() => _popupImpl?.Invoke() ?? Mock.Of<IPopupImpl>(x => x.Scaling == 1);
public ITrayIconImpl CreateTrayIcon()
{
throw new NotImplementedException();
}
public IPopupImpl CreatePopup() => _popupImpl?.Invoke() ?? Mock.Of<IPopupImpl>(x => x.RenderScaling == 1);
}
}

Просмотреть файл

@ -19,10 +19,10 @@ namespace AvaloniaEdit.AvaloniaMocks
{
public static readonly TestServices StyledWindow = new TestServices(
assetLoader: new AssetLoader(),
layoutManager: new LayoutManager(),
layoutManager: new LayoutManager(null),
platform: new AppBuilder().RuntimePlatform,
renderInterface: new MockPlatformRenderInterface(),
standardCursorFactory: Mock.Of<IStandardCursorFactory>(),
standardCursorFactory: Mock.Of<ICursorFactory>(),
styler: new Styler(),
theme: () => CreateDefaultTheme(),
threadingInterface: Mock.Of<IPlatformThreadingInterface>(x => x.CurrentThreadIsLoopThread == true),
@ -50,7 +50,7 @@ namespace AvaloniaEdit.AvaloniaMocks
inputManager: new InputManager());
public static readonly TestServices RealLayoutManager = new TestServices(
layoutManager: new LayoutManager());
layoutManager: new LayoutManager(null));
public static readonly TestServices RealStyler = new TestServices(
styler: new Styler());
@ -67,7 +67,7 @@ namespace AvaloniaEdit.AvaloniaMocks
IPlatformRenderInterface renderInterface = null,
IRenderLoop renderLoop = null,
IScheduler scheduler = null,
IStandardCursorFactory standardCursorFactory = null,
ICursorFactory standardCursorFactory = null,
IStyler styler = null,
Func<Styles> theme = null,
IPlatformThreadingInterface threadingInterface = null,
@ -102,7 +102,7 @@ namespace AvaloniaEdit.AvaloniaMocks
public IRuntimePlatform Platform { get; }
public IPlatformRenderInterface RenderInterface { get; }
public IScheduler Scheduler { get; }
public IStandardCursorFactory StandardCursorFactory { get; }
public ICursorFactory StandardCursorFactory { get; }
public IStyler Styler { get; }
public Func<Styles> Theme { get; }
public IPlatformThreadingInterface ThreadingInterface { get; }
@ -121,7 +121,7 @@ namespace AvaloniaEdit.AvaloniaMocks
IPlatformRenderInterface renderInterface = null,
IRenderLoop renderLoop = null,
IScheduler scheduler = null,
IStandardCursorFactory standardCursorFactory = null,
ICursorFactory standardCursorFactory = null,
IStyler styler = null,
Func<Styles> theme = null,
IPlatformThreadingInterface threadingInterface = null,
@ -154,11 +154,6 @@ namespace AvaloniaEdit.AvaloniaMocks
new DefaultTheme(),
};
var loader = new AvaloniaXamlLoader();
var baseLight = (IStyle)loader.Load(
new Uri("resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"));
result.Add(baseLight);
return result;
}
@ -168,6 +163,7 @@ namespace AvaloniaEdit.AvaloniaMocks
x.CreateFormattedText(
It.IsAny<string>(),
It.IsAny<Typeface>(),
It.IsAny<double>(),
It.IsAny<TextAlignment>(),
It.IsAny<TextWrapping>(),
It.IsAny<Size>(),

Просмотреть файл

@ -52,7 +52,7 @@ namespace AvaloniaEdit.AvaloniaMocks
.Bind<IPlatformRenderInterface>().ToConstant(Services.RenderInterface)
.Bind<IPlatformThreadingInterface>().ToConstant(Services.ThreadingInterface)
.Bind<IScheduler>().ToConstant(Services.Scheduler)
.Bind<IStandardCursorFactory>().ToConstant(Services.StandardCursorFactory)
.Bind<ICursorFactory>().ToConstant(Services.StandardCursorFactory)
.Bind<IStyler>().ToConstant(Services.Styler)
.Bind<IWindowingPlatform>().ToConstant(Services.WindowingPlatform);
var styles = Services.Theme?.Invoke();

Просмотреть файл

@ -29,7 +29,9 @@ namespace AvaloniaEdit.Editing
[Test]
public void ClearCaretAndSelectionOnDocumentChange()
{
using (UnitTestApplication.Start(new TestServices(renderInterface: new MockPlatformRenderInterface())))
using (UnitTestApplication.Start(new TestServices(
renderInterface: new MockPlatformRenderInterface(),
platform: new MockRuntimePlatform())))
{
TextArea textArea = new TextArea();
textArea.Document = new TextDocument("1\n2\n3\n4th line");
@ -45,7 +47,9 @@ namespace AvaloniaEdit.Editing
[Test]
public void SetDocumentToNull()
{
using (UnitTestApplication.Start(new TestServices(renderInterface: new MockPlatformRenderInterface())))
using (UnitTestApplication.Start(new TestServices(
renderInterface: new MockPlatformRenderInterface(),
platform: new MockRuntimePlatform())))
{
TextArea textArea = new TextArea();
textArea.Document = new TextDocument("1\n2\n3\n4th line");
@ -61,7 +65,9 @@ namespace AvaloniaEdit.Editing
[Test]
public void CheckEventOrderOnDocumentChange()
{
using (UnitTestApplication.Start(new TestServices(renderInterface: new MockPlatformRenderInterface())))
using (UnitTestApplication.Start(new TestServices(
renderInterface: new MockPlatformRenderInterface(),
platform: new MockRuntimePlatform())))
{
TextArea textArea = new TextArea();
TextDocument newDocument = new TextDocument();

Просмотреть файл

@ -35,7 +35,7 @@ namespace AvaloniaEdit.Highlighting
highlighter = new DocumentHighlighter(document, HighlightingManager.Instance.GetDefinition("C#"));
}
[Test, Ignore("")]
[Test]
public void FullDocumentTest()
{
var segment = new TextSegment { StartOffset = 0, Length = document.TextLength };
@ -45,7 +45,7 @@ namespace AvaloniaEdit.Highlighting
"text = <span style=\"color: #191970; font-weight: bold; \">SomeMethod</span>();", html);
}
[Test, Ignore("")]
[Test]
public void PartOfHighlightedWordTest()
{
var segment = new TextSegment { StartOffset = 1, Length = 3 };