Fixed unit tests
This commit is contained in:
Родитель
7fdb960f57
Коммит
0941b4da6f
|
@ -0,0 +1,43 @@
|
|||
using Avalonia.Media;
|
||||
using Avalonia.Platform;
|
||||
|
||||
using Moq;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AvaloniaEdit.AvaloniaMocks
|
||||
{
|
||||
public class MockFontManagerImpl : IFontManagerImpl
|
||||
{
|
||||
private readonly string _defaultFamilyName;
|
||||
|
||||
public MockFontManagerImpl(string defaultFamilyName = "Default")
|
||||
{
|
||||
_defaultFamilyName = defaultFamilyName;
|
||||
}
|
||||
|
||||
public string GetDefaultFontFamilyName()
|
||||
{
|
||||
return _defaultFamilyName;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetInstalledFontFamilyNames(bool checkForUpdates = false)
|
||||
{
|
||||
return new[] { _defaultFamilyName };
|
||||
}
|
||||
|
||||
public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, FontFamily fontFamily,
|
||||
CultureInfo culture, out Typeface fontKey)
|
||||
{
|
||||
fontKey = new Typeface(_defaultFamilyName);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IGlyphTypefaceImpl CreateGlyphTypeface(Typeface typeface)
|
||||
{
|
||||
return new MockGlyphTypeface();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
using Avalonia.Platform;
|
||||
|
||||
using System;
|
||||
|
||||
namespace AvaloniaEdit.AvaloniaMocks
|
||||
{
|
||||
public class MockGlyphTypeface : IGlyphTypefaceImpl
|
||||
{
|
||||
public short DesignEmHeight => 10;
|
||||
public int Ascent => 2;
|
||||
public int Descent => 10;
|
||||
public int LineGap { get; }
|
||||
public int UnderlinePosition { get; }
|
||||
public int UnderlineThickness { get; }
|
||||
public int StrikethroughPosition { get; }
|
||||
public int StrikethroughThickness { get; }
|
||||
public bool IsFixedPitch { get; }
|
||||
|
||||
public ushort GetGlyph(uint codepoint)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ushort[] GetGlyphs(ReadOnlySpan<uint> codepoints)
|
||||
{
|
||||
return new ushort[codepoints.Length];
|
||||
}
|
||||
|
||||
public int GetGlyphAdvance(ushort glyph)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public int[] GetGlyphAdvances(ReadOnlySpan<ushort> glyphs)
|
||||
{
|
||||
var advances = new int[glyphs.Length];
|
||||
|
||||
for (var i = 0; i < advances.Length; i++)
|
||||
{
|
||||
advances[i] = 8;
|
||||
}
|
||||
|
||||
return advances;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
|
@ -74,7 +74,8 @@ namespace AvaloniaEdit.AvaloniaMocks
|
|||
IPlatformThreadingInterface threadingInterface = null,
|
||||
IWindowImpl windowImpl = null,
|
||||
IWindowingPlatform windowingPlatform = null,
|
||||
PlatformHotkeyConfiguration platformHotkeyConfiguration = null)
|
||||
PlatformHotkeyConfiguration platformHotkeyConfiguration = null,
|
||||
IFontManagerImpl fontManagerImpl = null)
|
||||
{
|
||||
AssetLoader = assetLoader;
|
||||
FocusManager = focusManager;
|
||||
|
@ -93,6 +94,7 @@ namespace AvaloniaEdit.AvaloniaMocks
|
|||
WindowImpl = windowImpl;
|
||||
WindowingPlatform = windowingPlatform;
|
||||
PlatformHotkeyConfiguration = platformHotkeyConfiguration;
|
||||
FontManagerImpl = fontManagerImpl;
|
||||
}
|
||||
|
||||
public IAssetLoader AssetLoader { get; }
|
||||
|
@ -112,6 +114,7 @@ namespace AvaloniaEdit.AvaloniaMocks
|
|||
public IWindowImpl WindowImpl { get; }
|
||||
public IWindowingPlatform WindowingPlatform { get; }
|
||||
public PlatformHotkeyConfiguration PlatformHotkeyConfiguration { get; }
|
||||
public IFontManagerImpl FontManagerImpl { get; }
|
||||
|
||||
public TestServices With(
|
||||
IAssetLoader assetLoader = null,
|
||||
|
@ -130,7 +133,9 @@ namespace AvaloniaEdit.AvaloniaMocks
|
|||
Func<Styles> theme = null,
|
||||
IPlatformThreadingInterface threadingInterface = null,
|
||||
IWindowImpl windowImpl = null,
|
||||
IWindowingPlatform windowingPlatform = null)
|
||||
IWindowingPlatform windowingPlatform = null,
|
||||
PlatformHotkeyConfiguration platformHotkeyConfiguration = null,
|
||||
IFontManagerImpl fontManagerImpl = null)
|
||||
{
|
||||
return new TestServices(
|
||||
assetLoader: assetLoader ?? AssetLoader,
|
||||
|
@ -148,7 +153,9 @@ namespace AvaloniaEdit.AvaloniaMocks
|
|||
theme: theme ?? Theme,
|
||||
threadingInterface: threadingInterface ?? ThreadingInterface,
|
||||
windowingPlatform: windowingPlatform ?? WindowingPlatform,
|
||||
windowImpl: windowImpl ?? WindowImpl);
|
||||
windowImpl: windowImpl ?? WindowImpl,
|
||||
platformHotkeyConfiguration: platformHotkeyConfiguration ?? PlatformHotkeyConfiguration,
|
||||
fontManagerImpl: fontManagerImpl ?? FontManagerImpl);
|
||||
}
|
||||
|
||||
private static Styles CreateDefaultTheme()
|
||||
|
|
|
@ -56,7 +56,8 @@ namespace AvaloniaEdit.AvaloniaMocks
|
|||
.Bind<ICursorFactory>().ToConstant(Services.StandardCursorFactory)
|
||||
.Bind<IStyler>().ToConstant(Services.Styler)
|
||||
.Bind<IWindowingPlatform>().ToConstant(Services.WindowingPlatform)
|
||||
.Bind<PlatformHotkeyConfiguration>().ToConstant(Services.PlatformHotkeyConfiguration);
|
||||
.Bind<PlatformHotkeyConfiguration>().ToConstant(Services.PlatformHotkeyConfiguration)
|
||||
.Bind<IFontManagerImpl>().ToConstant(Services.FontManagerImpl);
|
||||
var styles = Services.Theme?.Invoke();
|
||||
|
||||
if (styles != null)
|
||||
|
|
|
@ -32,7 +32,8 @@ namespace AvaloniaEdit.Editing
|
|||
using (UnitTestApplication.Start(new TestServices(
|
||||
renderInterface: new MockPlatformRenderInterface(),
|
||||
platform: new MockRuntimePlatform(),
|
||||
platformHotkeyConfiguration: new MockPlatformHotkeyConfiguration())))
|
||||
platformHotkeyConfiguration: new MockPlatformHotkeyConfiguration(),
|
||||
fontManagerImpl: new MockFontManagerImpl())))
|
||||
{
|
||||
TextArea textArea = new TextArea();
|
||||
textArea.Document = new TextDocument("1\n2\n3\n4th line");
|
||||
|
@ -51,7 +52,8 @@ namespace AvaloniaEdit.Editing
|
|||
using (UnitTestApplication.Start(new TestServices(
|
||||
renderInterface: new MockPlatformRenderInterface(),
|
||||
platform: new MockRuntimePlatform(),
|
||||
platformHotkeyConfiguration: new MockPlatformHotkeyConfiguration())))
|
||||
platformHotkeyConfiguration: new MockPlatformHotkeyConfiguration(),
|
||||
fontManagerImpl: new MockFontManagerImpl())))
|
||||
{
|
||||
TextArea textArea = new TextArea();
|
||||
textArea.Document = new TextDocument("1\n2\n3\n4th line");
|
||||
|
@ -70,7 +72,8 @@ namespace AvaloniaEdit.Editing
|
|||
using (UnitTestApplication.Start(new TestServices(
|
||||
renderInterface: new MockPlatformRenderInterface(),
|
||||
platform: new MockRuntimePlatform(),
|
||||
platformHotkeyConfiguration: new MockPlatformHotkeyConfiguration())))
|
||||
platformHotkeyConfiguration: new MockPlatformHotkeyConfiguration(),
|
||||
fontManagerImpl: new MockFontManagerImpl())))
|
||||
{
|
||||
TextArea textArea = new TextArea();
|
||||
TextDocument newDocument = new TextDocument();
|
||||
|
|
Загрузка…
Ссылка в новой задаче