@ -11,15 +11,17 @@ namespace Avalonia.Headless.XUnit;
internal class AvaloniaTestCaseRunner : XunitTestCaseRunner
internal class AvaloniaTestCaseRunner : XunitTestCaseRunner
{
{
private readonly HeadlessUnitTestSession _ session ;
private readonly Action ? _ onAfterTestInvoked ;
private readonly Action ? _ onAfterTestInvoked ;
public AvaloniaTestCaseRunner (
public AvaloniaTestCaseRunner (
Action ? onAfterTestInvoked ,
HeadlessUnitTestSession session , Action ? onAfterTestInvoked ,
IXunitTestCase testCase , string displayName , string skipReason , object [ ] constructorArguments ,
IXunitTestCase testCase , string displayName , string skipReason , object [ ] constructorArguments ,
object [ ] testMethodArguments , IMessageBus messageBus , ExceptionAggregator aggregator ,
object [ ] testMethodArguments , IMessageBus messageBus , ExceptionAggregator aggregator ,
CancellationTokenSource cancellationTokenSource ) : base ( testCase , displayName , skipReason , constructorArguments ,
CancellationTokenSource cancellationTokenSource ) : base ( testCase , displayName , skipReason , constructorArguments ,
testMethodArguments , messageBus , aggregator , cancellationTokenSource )
testMethodArguments , messageBus , aggregator , cancellationTokenSource )
{
{
_ session = session ;
_ onAfterTestInvoked = onAfterTestInvoked ;
_ onAfterTestInvoked = onAfterTestInvoked ;
}
}
@ -29,43 +31,46 @@ internal class AvaloniaTestCaseRunner : XunitTestCaseRunner
CancellationTokenSource cancellationTokenSource )
CancellationTokenSource cancellationTokenSource )
{
{
var afterTest = ( ) = > Dispatcher . UIThread . RunJobs ( ) ;
var afterTest = ( ) = > Dispatcher . UIThread . RunJobs ( ) ;
return session . Dispatch ( async ( ) = >
{
var runner = new AvaloniaTestCaseRunner ( session , afterTest , testCase , displayName ,
var runner = new AvaloniaTestCaseRunner ( afterTest , testCase , displayName ,
skipReason , constructorArguments , testMethodArguments , messageBus , aggregator , cancellationTokenSource ) ;
skipReason , constructorArguments , testMethodArguments , messageBus , aggregator , cancellationTokenSource ) ;
return runner . RunAsync ( ) ;
return await runner . RunAsync ( ) ;
} , cancellationTokenSource . Token ) ;
}
}
protected override XunitTestRunner CreateTestRunner ( ITest test , IMessageBus messageBus , Type testClass ,
protected override XunitTestRunner CreateTestRunner ( ITest test , IMessageBus messageBus , Type testClass ,
object [ ] constructorArguments ,
object [ ] constructorArguments ,
MethodInfo testMethod , object [ ] testMethodArguments , string skipReason ,
MethodInfo testMethod , object [ ] testMethodArguments , string skipReason ,
IReadOnlyList < BeforeAfterTestAttribute > beforeAfterAttributes ,
IReadOnlyList < BeforeAfterTestAttribute > beforeAfterAttributes ,
ExceptionAggregator aggregator , CancellationTokenSource cancellationTokenSource )
ExceptionAggregator aggregator , CancellationTokenSource cancellationTokenSource )
{
{
return new AvaloniaTestRunner ( _ onAfterTestInvoked , test , messageBus , testClass , constructorArguments ,
return new AvaloniaTestRunner ( _ session , _ onAfterTestInvoked , test , messageBus , testClass , constructorArguments ,
testMethod , testMethodArguments , skipReason , beforeAfterAttributes , aggregator , cancellationTokenSource ) ;
testMethod , testMethodArguments , skipReason , beforeAfterAttributes , aggregator , cancellationTokenSource ) ;
}
}
private class AvaloniaTestRunner : XunitTestRunner
private class AvaloniaTestRunner : XunitTestRunner
{
{
private readonly HeadlessUnitTestSession _ session ;
private readonly Action ? _ onAfterTestInvoked ;
private readonly Action ? _ onAfterTestInvoked ;
public AvaloniaTestRunner (
public AvaloniaTestRunner (
Action ? onAfterTestInvoked ,
HeadlessUnitTestSession session , Action ? onAfterTestInvoked ,
ITest test , IMessageBus messageBus , Type testClass , object [ ] constructorArguments , MethodInfo testMethod ,
ITest test , IMessageBus messageBus , Type testClass , object [ ] constructorArguments , MethodInfo testMethod ,
object [ ] testMethodArguments , string skipReason ,
object [ ] testMethodArguments , string skipReason ,
IReadOnlyList < BeforeAfterTestAttribute > beforeAfterAttributes , ExceptionAggregator aggregator ,
IReadOnlyList < BeforeAfterTestAttribute > beforeAfterAttributes , ExceptionAggregator aggregator ,
CancellationTokenSource cancellationTokenSource ) : base ( test , messageBus , testClass , constructorArguments ,
CancellationTokenSource cancellationTokenSource ) : base ( test , messageBus , testClass , constructorArguments ,
testMethod , testMethodArguments , skipReason , beforeAfterAttributes , aggregator , cancellationTokenSource )
testMethod , testMethodArguments , skipReason , beforeAfterAttributes , aggregator , cancellationTokenSource )
{
{
_ session = session ;
_ onAfterTestInvoked = onAfterTestInvoked ;
_ onAfterTestInvoked = onAfterTestInvoked ;
}
}
protected override Task < decimal > InvokeTestMethodAsync ( ExceptionAggregator aggregator )
protected override Task < decimal > InvokeTestMethodAsync ( ExceptionAggregator aggregator )
{
{
return new AvaloniaTestInvoker ( _ onAfterTestInvoked , Test , MessageBus , TestClass , ConstructorArguments ,
return _ session . Dispatch (
TestMethod , TestMethodArguments , BeforeAfterAttributes , aggregator , CancellationTokenSource ) . RunAsync ( ) ;
( ) = > new AvaloniaTestInvoker ( _ onAfterTestInvoked , Test , MessageBus , TestClass ,
ConstructorArguments , TestMethod , TestMethodArguments , BeforeAfterAttributes , aggregator ,
CancellationTokenSource ) . RunAsync ( ) ,
CancellationTokenSource . Token ) ;
}
}
}
}