1+ @{
12#if NET9_0_OR_GREATER
2- using Bunit . TestAssets . RenderModes ;
3+ }
34
4- namespace Bunit . Rendering ;
5+ @using Bunit .TestAssets .RenderModes ;
6+ @inherits TestContext
57
6- public class RenderModeTests : TestContext
7- {
8+ @code {
9+ # if NET9_0_OR_GREATER
810 [Fact (DisplayName = " TestRenderer provides RendererInfo" )]
911 public void Test001 ()
1012 {
1113 Renderer .SetRendererInfo (new RendererInfo (" Server" , true ));
1214 var cut = RenderComponent <RendererInfoComponent >();
1315
14- cut . MarkupMatches ( "" "
16+ cut .MarkupMatches (@ "
1517 <p>Is interactive: True</p>
1618 <p>Rendermode: Server</p>
17- """ ) ;
19+ " );
1820 }
1921
2022 [Fact (DisplayName = " Renderer throws exception if RendererInfo is not specified" )]
@@ -39,10 +41,10 @@ public void Test004()
3941 var cut = RenderComponent <ComponentWithoutRenderMode >(
4042 c => c .AddChildContent <ComponentWithWebAssemblyRenderMode >());
4143
42- cut . MarkupMatches ( "" "
44+ cut .MarkupMatches (@ "
4345 <div>Parent assigned render mode: </div>
4446 <div>Assigned render mode: InteractiveWebAssemblyRenderMode</div>
45- """ ) ;
47+ " );
4648 }
4749
4850 [Fact (DisplayName = " Parent and child render mode is specified" )]
@@ -51,10 +53,10 @@ public void Test005()
5153 var cut = RenderComponent <ComponentWithWebAssemblyRenderMode >(
5254 c => c .AddChildContent <ComponentWithServerRenderMode >());
5355
54- cut . MarkupMatches ( "" "
56+ cut .MarkupMatches (@ "
5557 <div>Parent assigned render mode: InteractiveWebAssemblyRenderMode</div>
5658 <div>Assigned render mode: InteractiveServerRenderMode</div>
57- """ ) ;
59+ " );
5860 }
5961
6062 [Fact (DisplayName = " Parent and child render mode is not specified" )]
@@ -63,11 +65,44 @@ public void Test006()
6365 var cut = RenderComponent <ComponentWithoutRenderMode >(
6466 c => c .AddChildContent <ComponentWithoutRenderMode >());
6567
66- cut . MarkupMatches ( "" "
68+ cut .MarkupMatches (@ "
6769 <div>Parent assigned render mode: </div>
6870 <div>Assigned render mode: </div>
69- """ ) ;
70-
71+ " );
72+ }
73+
74+ [Fact (DisplayName = " Parent that sets render mode to children is specified on child" )]
75+ public void Test007 ()
76+ {
77+ var cut = RenderComponent <ComponentWithChildContent >(
78+ p => p .AddChildContent (
79+ @< ComponentThatPrintsAssignedRenderMode @rendermode = " RenderMode.InteractiveServer" / > ));
80+
81+ cut .MarkupMatches (@< p > Assigned Render Mode : InteractiveServerRenderMode < / p > );
82+ }
83+
84+ [Fact (DisplayName = " Assigned Render Mode is inherited all the way down the component hierarchy" )]
85+ public void Test008 ()
86+ {
87+ var cut = RenderComponent <ComponentWithChildContent >(
88+ p => p .AddChildContent (
89+ @< ComponentWithChildContent @rendermode = " RenderMode.InteractiveServer" >
90+ < ComponentThatPrintsAssignedRenderMode / >
91+ < / ComponentWithChildContent > ));
92+
93+ cut .MarkupMatches (@< p > Assigned Render Mode : InteractiveServerRenderMode < / p > );
94+ }
95+
96+ [Fact (DisplayName = " Having a component with section outlet and RenderMode is specifing for child component" )]
97+ public void Test009 ()
98+ {
99+ // See: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/sections?view=aspnetcore-8.0#section-interaction-with-other-blazor-features
100+ var cut = Render (@< SectionOutletComponent / > );
101+
102+ cut .MarkupMatches (@< p > Assigned Render Mode : InteractiveWebAssemblyRenderMode < / p > );
71103 }
104+ #endif
72105}
73- #endif
106+ @{
107+ #endif
108+ }
0 commit comments