@@ -14,59 +14,51 @@ namespace Bunit.RazorTesting
1414 /// </summary>
1515 public abstract class FixtureBase < TFixture > : RazorTestBase
1616 {
17+ /// <inheritdoc/>
18+ public override string ? DisplayName => Description ?? Test ? . Method . Name ?? TestAsync ? . Method . Name ;
19+
1720 /// <summary>
1821 /// Gets or sets the child content of the fragment.
1922 /// </summary>
2023 [ Parameter ] public RenderFragment ChildContent { get ; set ; } = default ! ;
2124
2225 /// <summary>
23- /// Gets or sets the setup action to perform before the <see cref="Test"/> action,
24- /// <see cref="TestAsync"/> action and <see cref="Tests"/> and <see cref="TestsAsync"/> actions are invoked.
26+ /// Gets or sets the setup action to perform before the <see cref="Test"/> action or
27+ /// <see cref="TestAsync"/> action are invoked.
2528 /// </summary>
2629 [ Parameter ] public Action < TFixture > ? Setup { get ; set ; }
2730
2831 /// <summary>
29- /// Gets or sets the asynchronous setup action to perform before the <see cref="Test"/> action,
30- /// <see cref="TestAsync"/> action and <see cref="Tests"/> and <see cref="TestsAsync"/> actions are invoked.
32+ /// Gets or sets the asynchronous setup action to perform before the <see cref="Test"/> action or
33+ /// <see cref="TestAsync"/> action are invoked.
3134 /// </summary>
3235 [ Parameter ] public Func < TFixture , Task > ? SetupAsync { get ; set ; }
3336
3437 /// <summary>
35- /// Gets or sets the first test action to invoke, after the <see cref="Setup"/> action has
36- /// executed (if provided).
37- ///
38- /// Use this to assert against the <see cref="ComponentUnderTest"/> and <see cref="Fragment"/>'s
39- /// defined in the fixture.
38+ /// Gets or sets the test action to invoke, after the <see cref="Setup"/> and <see cref="SetupAsync"/> actions has
39+ /// invoked (if provided).
40+ /// If this is set, then <see cref="TestAsync"/> cannot also be set.
4041 /// </summary>
4142 [ Parameter ] public Action < TFixture > ? Test { get ; set ; }
4243
4344 /// <summary>
44- /// Gets or sets the first test action to invoke, after the <see cref="SetupAsync"/> action has
45- /// executed (if provided).
46- ///
47- /// Use this to assert against the <see cref="ComponentUnderTest"/> and <see cref="Fragment"/>'s
48- /// defined in the fixture.
45+ /// Gets or sets the test action to invoke, after the <see cref="Setup"/> and <see cref="SetupAsync"/> actions has
46+ /// invoked (if provided).
47+ /// If this is set, then <see cref="Test"/> cannot also be set.
4948 /// </summary>
5049 [ Parameter ] public Func < TFixture , Task > ? TestAsync { get ; set ; }
5150
5251 /// <summary>
53- /// Gets or sets the test actions to invoke, one at the time, in the order they are placed
54- /// into the collection, after the <see cref="Setup"/> action and the <see cref="Test"/> action has
55- /// executed (if provided).
56- ///
57- /// Use this to assert against the <see cref="ComponentUnderTest"/> and <see cref="Fragment"/>'s
58- /// defined in the fixture.
52+ /// Obsolete. Methods assigned to this parameter will not be invoked.
5953 /// </summary>
60- [ Parameter ] public IReadOnlyCollection < Action < TFixture > > ? Tests { get ; set ; }
54+ [ Obsolete ( "This feature has been removed since it caused confusion about the state of the fixture being passed to the test methods. Methods assigned to this parameter will not be invoked." ) ]
55+ [ Parameter ]
56+ public IReadOnlyCollection < Action < TFixture > > ? Tests { get ; set ; }
6157
6258 /// <summary>
63- /// Gets or sets the test actions to invoke, one at the time, in the order they are placed
64- /// into the collection, after the <see cref="SetupAsync"/> action and the <see cref="TestAsync"/> action has
65- /// executed (if provided).
66- ///
67- /// Use this to assert against the <see cref="ComponentUnderTest"/> and <see cref="Fragment"/>'s
68- /// defined in the fixture.
59+ /// Obsolete. Methods assigned to this parameter will not be invoked.
6960 /// </summary>
61+ [ Obsolete ( "This feature has been removed since it caused confusion about the state of the fixture being passed to the test methods. Methods assigned to this parameter will not be invoked." ) ]
7062 [ Parameter ]
7163 public IReadOnlyCollection < Func < TFixture , Task > > ? TestsAsync { get ; set ; }
7264
@@ -78,8 +70,13 @@ public override Task SetParametersAsync(ParameterView parameters)
7870 SetupAsync = parameters . GetValueOrDefault < Func < TFixture , Task > > ( nameof ( SetupAsync ) ) ;
7971 Test = parameters . GetValueOrDefault < Action < TFixture > > ( nameof ( Test ) ) ;
8072 TestAsync = parameters . GetValueOrDefault < Func < TFixture , Task > > ( nameof ( TestAsync ) ) ;
81- Tests = parameters . GetValueOrDefault < IReadOnlyCollection < Action < TFixture > > > ( nameof ( Tests ) , Array . Empty < Action < TFixture > > ( ) ) ;
82- TestsAsync = parameters . GetValueOrDefault < IReadOnlyCollection < Func < TFixture , Task > > > ( nameof ( TestsAsync ) , Array . Empty < Func < TFixture , Task > > ( ) ) ;
73+
74+ #pragma warning disable CS0618 // Type or member is obsolete
75+ if ( parameters . TryGetValue < IReadOnlyCollection < Action < TFixture > > > ( "Tests" , out var tests ) )
76+ Tests = tests ;
77+ if ( parameters . TryGetValue < IReadOnlyCollection < Func < TFixture , Task > > > ( "TestsAsync" , out var asyncTests ) )
78+ TestsAsync = asyncTests ;
79+ #pragma warning restore CS0618 // Type or member is obsolete
8380
8481 return base . SetParametersAsync ( parameters ) ;
8582 }
@@ -90,8 +87,16 @@ public override void Validate()
9087 base . Validate ( ) ;
9188 if ( ChildContent is null )
9289 throw new ArgumentException ( $ "No { nameof ( ChildContent ) } specified in the { GetType ( ) . Name } component.") ;
93- if ( Test is null && TestAsync is null && Tests ? . Count == 0 && TestsAsync ? . Count == 0 )
90+ if ( Test is null && TestAsync is null )
9491 throw new ArgumentException ( $ "No test/assertions provided to the { GetType ( ) . Name } component.") ;
92+ if ( Test is { } && TestAsync is { } )
93+ throw new ArgumentException ( $ "Only a single test method can be provided to the { GetType ( ) . Name } component at the time.") ;
94+ #pragma warning disable CS0618 // Type or member is obsolete
95+ if ( Tests is { } )
96+ throw new ArgumentException ( $ "The user of the Tests parameter has been obsoleted, and any methods assigned to it will not longer be invoked.") ;
97+ if ( TestsAsync is { } )
98+ throw new ArgumentException ( $ "The user of the TestsAsync parameter has been obsoleted, and any methods assigned to it will not longer be invoked.") ;
99+ #pragma warning restore CS0618 // Type or member is obsolete
95100 }
96101
97102 /// <inheritdoc/>
@@ -109,12 +114,6 @@ protected virtual async Task Run(TFixture self)
109114
110115 if ( TestAsync is { } )
111116 await TryRunAsync ( TestAsync , self ) . ConfigureAwait ( false ) ;
112-
113- foreach ( var test in Tests ?? Array . Empty < Action < TFixture > > ( ) )
114- TryRun ( test , self ) ;
115-
116- foreach ( var test in TestsAsync ?? Array . Empty < Func < TFixture , Task > > ( ) )
117- await TryRunAsync ( test , self ) . ConfigureAwait ( false ) ;
118117 }
119118 }
120119}
0 commit comments