11using System ;
22using System . Collections . Generic ;
3+ using System . Threading . Tasks ;
34using Microsoft . AspNetCore . Components ;
45
56namespace Egil . RazorComponents . Testing
@@ -12,20 +13,29 @@ namespace Egil.RazorComponents.Testing
1213 public class Fixture : FragmentBase
1314 {
1415 private Action _setup = NoopTestMethod ;
16+ private Func < Task > _setupAsync = NoopAsyncTestMethod ;
1517 private Action _test = NoopTestMethod ;
18+ private Func < Task > _testAsync = NoopAsyncTestMethod ;
1619 private IReadOnlyCollection < Action > _tests = Array . Empty < Action > ( ) ;
20+ private IReadOnlyCollection < Func < Task > > _testsAsync = Array . Empty < Func < Task > > ( ) ;
1721
1822 /// <summary>
1923 /// A description or name for the test that will be displayed if the test fails.
2024 /// </summary>
2125 [ Parameter ] public string ? Description { get ; set ; }
2226
2327 /// <summary>
24- /// Gets or sets the setup action to perform before the <see cref="Test"/> action
25- /// and <see cref="Tests"/> actions are invoked.
28+ /// Gets or sets the setup action to perform before the <see cref="Test"/> action,
29+ /// <see cref="TestAsync"/> action and <see cref="Tests"/> and <see cref="TestsAsync "/> actions are invoked.
2630 /// </summary>
2731 [ Parameter ] public Action Setup { get => _setup ; set => _setup = value ?? NoopTestMethod ; }
2832
33+ /// <summary>
34+ /// Gets or sets the asynchronous setup action to perform before the <see cref="Test"/> action,
35+ /// <see cref="TestAsync"/> action and <see cref="Tests"/> and <see cref="TestsAsync"/> actions are invoked.
36+ /// </summary>
37+ [ Parameter ] public Func < Task > SetupAsync { get => _setupAsync ; set => _setupAsync = value ?? NoopAsyncTestMethod ; }
38+
2939 /// <summary>
3040 /// Gets or sets the first test action to invoke, after the <see cref="Setup"/> action has
3141 /// executed (if provided).
@@ -35,6 +45,15 @@ public class Fixture : FragmentBase
3545 /// </summary>
3646 [ Parameter ] public Action Test { get => _test ; set => _test = value ?? NoopTestMethod ; }
3747
48+ /// <summary>
49+ /// Gets or sets the first test action to invoke, after the <see cref="SetupAsync"/> action has
50+ /// executed (if provided).
51+ ///
52+ /// Use this to assert against the <see cref="ComponentUnderTest"/> and <see cref="Fragment"/>'s
53+ /// defined in the <see cref="Fixture"/>.
54+ /// </summary>
55+ [ Parameter ] public Func < Task > TestAsync { get => _testAsync ; set => _testAsync = value ?? NoopAsyncTestMethod ; }
56+
3857 /// <summary>
3958 /// Gets or sets the test actions to invoke, one at the time, in the order they are placed
4059 /// into the collection, after the <see cref="Setup"/> action and the <see cref="Test"/> action has
@@ -45,6 +64,18 @@ public class Fixture : FragmentBase
4564 /// </summary>
4665 [ Parameter ] public IReadOnlyCollection < Action > Tests { get => _tests ; set => _tests = value ?? Array . Empty < Action > ( ) ; }
4766
67+ /// <summary>
68+ /// Gets or sets the test actions to invoke, one at the time, in the order they are placed
69+ /// into the collection, after the <see cref="SetupAsync"/> action and the <see cref="TestAsync"/> action has
70+ /// executed (if provided).
71+ ///
72+ /// Use this to assert against the <see cref="ComponentUnderTest"/> and <see cref="Fragment"/>'s
73+ /// defined in the <see cref="Fixture"/>.
74+ /// </summary>
75+ [ Parameter ] public IReadOnlyCollection < Func < Task > > TestsAsync { get => _testsAsync ; set => _testsAsync = value ?? Array . Empty < Func < Task > > ( ) ; }
76+
4877 private static void NoopTestMethod ( ) { }
78+
79+ private static Task NoopAsyncTestMethod ( ) => Task . CompletedTask ;
4980 }
5081}
0 commit comments