1+ using Xunit ;
2+ using Bunit ;
3+ using System . Collections . Generic ;
4+ using Microsoft . AspNetCore . Components ;
5+ using Microsoft . AspNetCore . Components . Web ;
6+ using Microsoft . Extensions . DependencyInjection ;
7+
8+ namespace Bunit . Docs . Samples
9+ {
10+ public class RenderTreeTest
11+ {
12+ [ Fact ]
13+ public void PrintCascadingValueTest ( )
14+ {
15+ using var ctx = new TestContext ( ) ;
16+
17+ // Add a cascading value to the test contexts root render tree.
18+ ctx . RenderTree . Add < CascadingValue < string > > ( parameters => parameters
19+ . Add ( p => p . Value , "FOO" )
20+ ) ;
21+
22+ // The component will be rendered as a chld of last
23+ // component added to the RenderTree property.
24+ var cut = ctx . RenderComponent < PrintCascadingValue > ( ) ;
25+
26+ // Verify that the cascading value was passed correctly.
27+ cut . MarkupMatches ( $ "Cascading value: FOO") ;
28+ }
29+
30+ [ Fact ]
31+ public void PrintCascadingValue2Test ( )
32+ {
33+ using var ctx = new TestContext ( ) ;
34+
35+ // Add a cascading value to the test contexts root render tree.
36+ ctx . RenderTree . TryAdd < CascadingValue < string > > ( parameters => parameters
37+ . Add ( p => p . Value , "BAR?" )
38+ ) ;
39+
40+ // The component will be rendered as a chld of last
41+ // component added to the RenderTree property.
42+ var cut = ctx . RenderComponent < PrintCascadingValue > ( ) ;
43+
44+ // Verify that the cascading value was passed correctly.
45+ cut . MarkupMatches ( $ "Cascading value: BAR?") ;
46+ }
47+ }
48+ }
0 commit comments