10 changed files with 173 additions and 4 deletions
@ -0,0 +1,19 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net6.0</TargetFramework> |
||||
|
<IsTestProject>true</IsTestProject> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="..\..\build\UnitTests.NetCore.targets" /> |
||||
|
<Import Project="..\..\build\UnitTests.NetFX.props" /> |
||||
|
<Import Project="..\..\build\Moq.props" /> |
||||
|
<Import Project="..\..\build\XUnit.props" /> |
||||
|
<Import Project="..\..\build\Rx.props" /> |
||||
|
<Import Project="..\..\build\SharedVersion.props" /> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Avalonia.Themes.Simple\Avalonia.Themes.Simple.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Headless\Avalonia.Headless.XUnit\Avalonia.Headless.XUnit.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Skia\Avalonia.Skia\Avalonia.Skia.csproj" /> |
||||
|
</ItemGroup> |
||||
|
</Project> |
||||
@ -0,0 +1,37 @@ |
|||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Layout; |
||||
|
using Avalonia.Threading; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Avalonia.Headless.XUnit.Tests; |
||||
|
|
||||
|
public class InputTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Should_Click_Button_On_Window() |
||||
|
{ |
||||
|
var buttonClicked = false; |
||||
|
var button = new Button |
||||
|
{ |
||||
|
HorizontalAlignment = HorizontalAlignment.Stretch, |
||||
|
VerticalAlignment = VerticalAlignment.Stretch |
||||
|
}; |
||||
|
|
||||
|
button.Click += (_, _) => buttonClicked = true; |
||||
|
|
||||
|
var window = new Window |
||||
|
{ |
||||
|
Width = 100, |
||||
|
Height = 100, |
||||
|
Content = button |
||||
|
}; |
||||
|
window.Show(); |
||||
|
|
||||
|
Dispatcher.UIThread.RunJobs(); |
||||
|
|
||||
|
((IHeadlessWindow)window.PlatformImpl!).MouseDown(new Point(50, 50), 0); |
||||
|
((IHeadlessWindow)window.PlatformImpl!).MouseUp(new Point(50, 50), 0); |
||||
|
|
||||
|
Assert.True(buttonClicked); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Layout; |
||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Media.Imaging; |
||||
|
using Avalonia.Threading; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Avalonia.Headless.XUnit.Tests; |
||||
|
|
||||
|
public class RenderingTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Should_Render_Last_Frame_To_Bitmap() |
||||
|
{ |
||||
|
var window = new Window |
||||
|
{ |
||||
|
Content = new ContentControl |
||||
|
{ |
||||
|
HorizontalAlignment = HorizontalAlignment.Stretch, |
||||
|
VerticalAlignment = VerticalAlignment.Stretch, |
||||
|
Padding = new Thickness(4), |
||||
|
Content = new PathIcon |
||||
|
{ |
||||
|
Data = StreamGeometry.Parse("M0,9 L10,0 20,9 19,10 10,2 1,10 z") |
||||
|
} |
||||
|
}, |
||||
|
SizeToContent = SizeToContent.WidthAndHeight |
||||
|
}; |
||||
|
window.Show(); |
||||
|
|
||||
|
Dispatcher.UIThread.RunJobs(); |
||||
|
AvaloniaHeadlessPlatform.ForceRenderTimerTick(); |
||||
|
|
||||
|
var frame = ((IHeadlessWindow)window.PlatformImpl!).GetLastRenderedFrame(); |
||||
|
Assert.NotNull(frame); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using Avalonia.Headless.XUnit; |
||||
|
using Avalonia.Headless.XUnit.Tests; |
||||
|
using Avalonia.Themes.Simple; |
||||
|
using Xunit; |
||||
|
|
||||
|
[assembly: AvaloniaTestFramework(typeof(TestApplication))] |
||||
|
[assembly: CollectionBehavior(DisableTestParallelization = true)] |
||||
|
|
||||
|
namespace Avalonia.Headless.XUnit.Tests; |
||||
|
|
||||
|
public class TestApplication : Application |
||||
|
{ |
||||
|
public TestApplication() |
||||
|
{ |
||||
|
Styles.Add(new SimpleTheme()); |
||||
|
} |
||||
|
|
||||
|
public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<TestApplication>() |
||||
|
.UseSkia() |
||||
|
.UseHeadless(new AvaloniaHeadlessPlatformOptions |
||||
|
{ |
||||
|
UseHeadlessDrawing = false |
||||
|
}); |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Avalonia.Threading; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Avalonia.Headless.XUnit.Tests; |
||||
|
|
||||
|
public class ThreadingTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Should_Be_On_Dispatcher_Thread() |
||||
|
{ |
||||
|
Dispatcher.UIThread.VerifyAccess(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task DispatcherTimer_Works_On_The_Same_Thread() |
||||
|
{ |
||||
|
var currentThread = Thread.CurrentThread; |
||||
|
var tcs = new TaskCompletionSource(); |
||||
|
|
||||
|
DispatcherTimer.RunOnce(() => |
||||
|
{ |
||||
|
Assert.Equal(currentThread, Thread.CurrentThread); |
||||
|
|
||||
|
tcs.SetResult(); |
||||
|
}, TimeSpan.FromTicks(1)); |
||||
|
|
||||
|
await tcs.Task; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue