11using System ;
22using System . Collections . Generic ;
33using System . Threading . Tasks ;
4+
45using Bunit . RazorTesting ;
56using Bunit . Rendering ;
7+
68using Microsoft . AspNetCore . Components ;
79using Microsoft . Extensions . DependencyInjection ;
810
@@ -13,7 +15,7 @@ namespace Bunit
1315 /// define the <see cref="ComponentUnderTest"/> and any <see cref="Fragment"/>'s
1416 /// you might need during testing, and assert against them in the Test methods.
1517 /// </summary>
16- public abstract class FixtureBase < TFixture > : RazorTest
18+ public abstract class FixtureBase < TFixture > : RazorTestBase
1719 {
1820 /// <summary>
1921 /// Gets or sets the child content of the fragment.
@@ -73,24 +75,31 @@ public abstract class FixtureBase<TFixture> : RazorTest
7375 /// <inheritdoc/>
7476 public override Task SetParametersAsync ( ParameterView parameters )
7577 {
76- if ( parameters . TryGetValue < RenderFragment > ( nameof ( ChildContent ) , out RenderFragment childContent ) )
77- ChildContent = childContent ;
78- else
79- throw new InvalidOperationException ( $ "No { nameof ( ChildContent ) } specified in the { GetType ( ) . Name } component.") ;
80-
78+ ChildContent = parameters . GetValueOrDefault < RenderFragment > ( nameof ( ChildContent ) ) ;
8179 Setup = parameters . GetValueOrDefault < Action < TFixture > > ( nameof ( Setup ) ) ;
8280 SetupAsync = parameters . GetValueOrDefault < Func < TFixture , Task > > ( nameof ( SetupAsync ) ) ;
8381 Test = parameters . GetValueOrDefault < Action < TFixture > > ( nameof ( Test ) ) ;
8482 TestAsync = parameters . GetValueOrDefault < Func < TFixture , Task > > ( nameof ( TestAsync ) ) ;
85- Tests = parameters . GetValueOrDefault < IReadOnlyCollection < Action < TFixture > > > ( nameof ( Tests ) ) ;
86- TestsAsync = parameters . GetValueOrDefault < IReadOnlyCollection < Func < TFixture , Task > > > ( nameof ( TestsAsync ) ) ;
83+ Tests = parameters . GetValueOrDefault < IReadOnlyCollection < Action < TFixture > > > ( nameof ( Tests ) , Array . Empty < Action < TFixture > > ( ) ) ;
84+ TestsAsync = parameters . GetValueOrDefault < IReadOnlyCollection < Func < TFixture , Task > > > ( nameof ( TestsAsync ) , Array . Empty < Func < TFixture , Task > > ( ) ) ;
8785
8886 return base . SetParametersAsync ( parameters ) ;
8987 }
9088
89+ /// <inheritdoc/>
90+ public override void Validate ( )
91+ {
92+ base . Validate ( ) ;
93+ if ( ChildContent is null )
94+ throw new ArgumentException ( $ "No { nameof ( ChildContent ) } specified in the { GetType ( ) . Name } component.") ;
95+ if ( Test is null && TestAsync is null && Tests ? . Count == 0 && TestsAsync ? . Count == 0 )
96+ throw new ArgumentException ( $ "No test/assertions provided to the { GetType ( ) . Name } component.") ;
97+ }
98+
9199 /// <inheritdoc/>
92100 protected virtual async Task Run ( TFixture self )
93101 {
102+ Validate ( ) ;
94103 if ( Setup is { } )
95104 TryRun ( Setup , self ) ;
96105
0 commit comments