33@code {
44 MockJsRuntimeInvokeHandler MockJsRuntime { get ; set ; } = default ! ;
55
6- void Setup ()
6+ void Setup (Fixture fixture )
77 {
8- MockJsRuntime = Services .AddMockJsRuntime ();
8+ MockJsRuntime = fixture . Services .AddMockJsRuntime ();
99 }
1010}
1111
2222 </button >
2323 </div >
2424 </Fragment >
25- </Fixture >
26- @code {
27- void Test001 ()
28- {
29- // Arrange and act
30- var cut = GetComponentUnderTest <Alert >();
25+ @code {
26+ void Test001 (Fixture fixture )
27+ {
28+ // Arrange and act
29+ var cut = fixture .GetComponentUnderTest <Alert >();
3130
32- // Assert
33- IRenderedFragment expected = GetFragment (" expected" );
34- cut .MarkupMatches (expected );
31+ // Assert
32+ IRenderedFragment expected = fixture .GetFragment (" expected" );
33+ cut .MarkupMatches (expected );
34+ }
3535 }
36- }
36+ </ Fixture >
3737
3838<Fixture Setup =" Setup" Test =" Test002"
3939 Description =" Given a component as Child Content,
5050 @testContent
5151 </Paragraph >
5252 </Fragment >
53- </Fixture >
54- @code {
55- string testContent = " .NET Conf: Focus on Blazor is a free ..." ;
56- void Test002 ()
57- {
58- // Arrange and act
59- var cut = GetComponentUnderTest <Alert >();
53+ @code {
54+ string testContent = " .NET Conf: Focus on Blazor is a free ..." ;
55+ void Test002 (Fixture fixture )
56+ {
57+ // Arrange and act
58+ var cut = fixture .GetComponentUnderTest <Alert >();
6059
61- // Assert
62- var actual = cut .Find (" .alert-content > p" ).TextContent .Trim ();
63- Assert .Equal (testContent , actual );
60+ // Assert
61+ var actual = cut .Find (" .alert-content > p" ).TextContent .Trim ();
62+ Assert .Equal (testContent , actual );
6463
65- IRenderedFragment expected = GetFragment ();
66- cut .Find (" .alert-content > p" ).MarkupMatches (expected );
64+ IRenderedFragment expected = fixture .GetFragment ();
65+ cut .Find (" .alert-content > p" ).MarkupMatches (expected );
66+ }
6767 }
68- }
68+ </ Fixture >
6969
7070<Fixture Setup =" Setup" Test =" Test003"
7171 Description =" Given Child Content as input, Alert renders it inside its alert-content element" >
7474 @testContent
7575 </Alert >
7676 </ComponentUnderTest >
77- </ Fixture >
78- @code {
79- void Test003 ()
80- {
81- // Arrange and act
82- var cut = GetComponentUnderTest < Alert >();
83-
84- // Assert
85- // Verify by looking at the content and handling whitespace
86- var actual = cut . Find ( " .alert-content " ). TextContent . Trim ( );
87- Assert . Equal ( testContent , actual );
88-
89- // Verify using semantic comparison of all child nodes inside content
90- cut . Find ( " .alert-content " )
91- . ChildNodes
92- . MarkupMatches ( testContent );
77+ @code {
78+ void Test003 ( Fixture fixture )
79+ {
80+ // Arrange and act
81+ var cut = fixture . GetComponentUnderTest < Alert >();
82+
83+ // Assert
84+ // Verify by looking at the content and handling whitespace
85+ var actual = cut . Find ( " .alert-content " ). TextContent . Trim ();
86+ Assert . Equal ( testContent , actual );
87+
88+ // Verify using semantic comparison of all child nodes inside content
89+ cut . Find ( " .alert- content" )
90+ . ChildNodes
91+ . MarkupMatches ( testContent );
92+ }
9393 }
94- }
94+ </ Fixture >
9595
9696<Fixture Setup =" Setup" Test =" Test004"
9797 Description =" Given a Header as input, Alert renders the header text in the expected element" >
101101 <Fragment >
102102 <h4 class =" alert-heading" >@headerText </h4 >
103103 </Fragment >
104- </Fixture >
105- @code {
106- string headerText = " It is time to focus on Blazor" ;
107- void Test004 ()
108- {
109- // Arrange and Act
110- var cut = GetComponentUnderTest <Alert >();
104+ @code {
105+ string headerText = " It is time to focus on Blazor" ;
106+ void Test004 (Fixture fixture )
107+ {
108+ // Arrange and Act
109+ var cut = fixture .GetComponentUnderTest <Alert >();
111110
112- // Assert
113- string expected = cut .Find (" .alert-heading" ).TextContent ;
114- Assert .Equal (headerText , expected );
111+ // Assert
112+ string expected = cut .Find (" .alert-heading" ).TextContent ;
113+ Assert .Equal (headerText , expected );
115114
116- var expectedMarkup = GetFragment ();
117- cut .Find (" .alert-heading" ).MarkupMatches (expectedMarkup );
115+ var expectedMarkup = fixture .GetFragment ();
116+ cut .Find (" .alert-heading" ).MarkupMatches (expectedMarkup );
117+ }
118118 }
119- }
119+ </ Fixture >
120120
121121<Fixture Setup =" Setup"
122122 Test =" Given_Header_and_Localizer_Alert_Uses_Lozalizer_to_lozalize_Header_text" >
130130 <Fragment >
131131 <h4 class =" alert-heading" >@localizer [headerKey]</h4 >
132132 </Fragment >
133- </Fixture >
134- @code {
135- Localizer localizer = new Localizer () { CultureCode = " Yoda" };
136- string headerKey = " alert-heading" ;
137133
138- void Given_Header_and_Localizer_Alert_Uses_Lozalizer_to_lozalize_Header_text ()
139- {
140- // Arrange and act
141- localizer .Add (headerKey , " Time to focus on Blazor it is." );
142- var cut = GetComponentUnderTest <Alert >();
134+ @code {
135+ Localizer localizer = new Localizer () { CultureCode = " Yoda" };
136+ string headerKey = " alert-heading" ;
137+
138+ void Given_Header_and_Localizer_Alert_Uses_Lozalizer_to_lozalize_Header_text (Fixture fixture )
139+ {
140+ // Arrange and act
141+ localizer .Add (headerKey , " Time to focus on Blazor it is." );
142+ var cut = fixture .GetComponentUnderTest <Alert >();
143143
144- // Assert
145- var expected = cut .Find (" .alert-heading" ).TextContent ;
146- Assert .Equal (localizer [headerKey ], expected );
144+ // Assert
145+ var expected = cut .Find (" .alert-heading" ).TextContent ;
146+ Assert .Equal (localizer [headerKey ], expected );
147147
148- var expectedMarkup = GetFragment ();
149- cut .Find (" .alert-heading" ).MarkupMatches (expectedMarkup );
148+ var expectedMarkup = fixture .GetFragment ();
149+ cut .Find (" .alert-heading" ).MarkupMatches (expectedMarkup );
150+ }
150151 }
151- }
152+ </ Fixture >
152153
153154<Fixture Setup =" Setup" Test =" Test006"
154155 Description =" When dismiss button is clicked, Alert triggers expected callbacks" >
159160 </Alert >
160161
161162 </ComponentUnderTest >
162- </Fixture >
163- @code {
164- DismissingEventArgs ? dismissingEvent = default ;
165- Alert ? dismissedAlert = default ;
163+ @code {
164+ DismissingEventArgs ? dismissingEvent = default ;
165+ Alert ? dismissedAlert = default ;
166166
167- void Test006 ()
168- {
169- // Arrange
170- var cut = GetComponentUnderTest <Alert >();
167+ void Test006 (Fixture fixture )
168+ {
169+ // Arrange
170+ var cut = fixture . GetComponentUnderTest <Alert >();
171171
172- // Act
173- cut .Find (" button" ).Click ();
172+ // Act
173+ cut .Find (" button" ).Click ();
174174
175- // Assert
176- Assert .NotNull (dismissingEvent );
177- Assert .Equal (cut .Instance , dismissedAlert );
175+ // Assert
176+ Assert .NotNull (dismissingEvent );
177+ Assert .Equal (cut .Instance , dismissedAlert );
178+ }
178179 }
179- }
180+ </Fixture >
181+
180182
181183<Fixture Setup =" Setup" Test =" Test007"
182184 Description =" When dismiss button is clicked, Alert trigger css animation and finally removes all markup" >
183185 <ComponentUnderTest >
184-
185- <Alert >
186- </Alert >
187-
186+ <Alert />
188187 </ComponentUnderTest >
189- </Fixture >
190- @code {
191- void Test007 ()
192- {
193- // arrange
194- var plannedInvocation = MockJsRuntime .Setup <object >(" window.transitionFinished" );
195- var cut = GetComponentUnderTest <Alert >();
196188
197- // Act
198- cut .Find (" button" ).Click ();
189+ @code {
190+ void Test007 (Fixture fixture )
191+ {
192+ // arrange
193+ var plannedInvocation = MockJsRuntime .Setup <object >(" window.transitionFinished" );
194+ var cut = fixture .GetComponentUnderTest <Alert >();
199195
200- // Assert that css transition has started
201- Assert . DoesNotContain ( " show " , cut .Find (" .alert " ).ClassList );
196+ // Act
197+ cut .Find (" button " ).Click ( );
202198
203- // Act - complete
204- WaitForNextRender (() =>
205- {
199+ // Assert that css transition has started
200+ Assert .DoesNotContain (" show" , cut .Find (" .alert" ).ClassList );
201+
202+ // Act - complete
206203 plannedInvocation .SetResult (default ! );
207- });
208204
209- // Assert that all markup is gone
210- cut .MarkupMatches (string .Empty );
205+ // Assert that all markup is gone
206+ cut .WaitForAssertion (() => cut .MarkupMatches (string .Empty ));
207+ }
211208 }
212- }
209+ </Fixture >
210+
213211
214212<Fixture Setup =" Setup" Test =" Test008"
215213 Description =" Alert can be dismissed via Dismiss() mehod" >
216214 <ComponentUnderTest >
217215 <Alert @ref =" testAlert" >
218216 </Alert >
219217 </ComponentUnderTest >
220- </Fixture >
221- @code {
222- Alert ? testAlert ;
223- void Test008 ()
224- {
225- // arrange
226- var cut = GetComponentUnderTest <Alert >();
218+ @code {
219+ Alert ? testAlert ;
220+ void Test008 (Fixture fixture )
221+ {
222+ // arrange
223+ var cut = fixture .GetComponentUnderTest <Alert >();
227224
228- // Act
229- testAlert ? .Dismiss ().Wait ();
225+ // Act
226+ testAlert ? .Dismiss ().Wait ();
230227
231- // Assert that all markup is gone
232- cut .MarkupMatches (string .Empty );
233- Assert .False (cut .Instance .IsVisible );
228+ // Assert that all markup is gone
229+ cut .MarkupMatches (string .Empty );
230+ Assert .False (cut .Instance .IsVisible );
231+ }
234232 }
235- }
233+ </ Fixture >
236234
237235<Fixture Setup =" Setup" Test =" Test009"
238236 Description =" Alert renders correctly when all input is provided" >
246244 </CascadingValue >
247245 </ComponentUnderTest >
248246 <Fragment >
249- <div role =" alert" class =" alert alert-info alert-dismissible fade show" >
247+ <div role =" alert" class =" alert alert-info alert-dismissible fade show" >
250248 <h4 class =" alert-heading" >@localizer2 [headerKey]</h4 >
251249 <div class =" alert-content" >
252250 <Paragraph IsLast =" true" >
253251 @testContent
254252 </Paragraph >
255253 </div >
256- <button type =" button" class =" close" aria-label =" Close" >
254+ <button type =" button" class =" close" aria-label =" Close" >
257255 <span aria-hidden =" true" >× ; </span >
258256 </button >
259257 </div >
260258 </Fragment >
261- </Fixture >
262- @code {
263- Localizer localizer2 = new Localizer () { CultureCode = " Yoda" };
259+ @code {
260+ Localizer localizer2 = new Localizer () { CultureCode = " Yoda" };
264261
265- void Test009 ()
266- {
267- // Arrange
268- localizer2 .Add (" alert-heading" , " Time to focus on Blazor it is." );
262+ void Test009 (Fixture fixture )
263+ {
264+ // Arrange
265+ localizer2 .Add (" alert-heading" , " Time to focus on Blazor it is." );
269266
270- // Act
271- var cut = GetComponentUnderTest <Alert >();
267+ // Act
268+ var cut = fixture . GetComponentUnderTest <Alert >();
272269
273- // Assert
274- var expected = GetFragment ();
275- cut .MarkupMatches (expected );
270+ // Assert
271+ var expected = fixture .GetFragment ();
272+ cut .MarkupMatches (expected );
273+ }
276274 }
277- }
275+ </ Fixture >
0 commit comments