- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable RenderMode cascading to the Component
1 parent
05010c2
commit 1514e0c
Showing
7 changed files
with
139 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#if NET9_0_OR_GREATER | ||
using Bunit.TestAssets.RenderModes; | ||
|
||
namespace Bunit.Rendering; | ||
|
||
public class RenderModeTests : TestContext | ||
{ | ||
[Fact(DisplayName = "TestRenderer provides RendererInfo")] | ||
public void Test001() | ||
{ | ||
Renderer.SetRendererInfo(new RendererInfo("Server", true)); | ||
var cut = RenderComponent<RendererInfoComponent>(); | ||
|
||
cut.MarkupMatches(""" | ||
<p>Is interactive: True</p> | ||
<p>Rendermode: Server</p> | ||
"""); | ||
} | ||
|
||
[Fact(DisplayName = "Renderer throws exception if RendererInfo is not specified")] | ||
public void Test002() | ||
{ | ||
Action act = () => RenderComponent<RendererInfoComponent>(); | ||
|
||
act.ShouldThrow<MissingRendererInfoException>(); | ||
} | ||
|
||
[Fact(DisplayName = "Renderer should set the RenderModeAttribute on the component")] | ||
public void Test003() | ||
{ | ||
var cut = RenderComponent<ComponentWithServerRenderMode>(); | ||
|
||
cut.MarkupMatches("<div>Assigned render mode: InteractiveServerRenderMode</div>"); | ||
} | ||
|
||
[Fact(DisplayName = "The AssignedRenderMode is based on the RenderModeAttribute in the component hierarchy where parent component has no RenderMode")] | ||
public void Test004() | ||
{ | ||
var cut = RenderComponent<ComponentWithoutRenderMode>( | ||
c => c.AddChildContent<ComponentWithWebAssemblyRenderMode>()); | ||
|
||
cut.MarkupMatches(""" | ||
<div>Parent assigned render mode: </div> | ||
<div>Assigned render mode: InteractiveWebAssemblyRenderMode</div> | ||
"""); | ||
} | ||
|
||
[Fact(DisplayName = "Parent and child render mode is specified")] | ||
public void Test005() | ||
{ | ||
var cut = RenderComponent<ComponentWithWebAssemblyRenderMode>( | ||
c => c.AddChildContent<ComponentWithServerRenderMode>()); | ||
|
||
cut.MarkupMatches(""" | ||
<div>Parent assigned render mode: InteractiveWebAssemblyRenderMode</div> | ||
<div>Assigned render mode: InteractiveServerRenderMode</div> | ||
"""); | ||
} | ||
|
||
[Fact(DisplayName = "Parent and child render mode is not specified")] | ||
public void Test006() | ||
{ | ||
var cut = RenderComponent<ComponentWithoutRenderMode>( | ||
c => c.AddChildContent<ComponentWithoutRenderMode>()); | ||
|
||
cut.MarkupMatches(""" | ||
<div>Parent assigned render mode: </div> | ||
<div>Assigned render mode: </div> | ||
"""); | ||
|
||
} | ||
} | ||
#endif |
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@{ | ||
#if NET9_0_OR_GREATER | ||
} | ||
|
||
@rendermode Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer | ||
<div>@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name</div> | ||
@ChildContent | ||
|
||
@code { | ||
[Parameter] public RenderFragment? ChildContent { get; set; } | ||
} | ||
|
||
@{ | ||
#endif | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@{ | ||
#if NET9_0_OR_GREATER | ||
} | ||
|
||
@rendermode Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveWebAssembly | ||
<div>@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name</div> | ||
@ChildContent | ||
|
||
@code { | ||
[Parameter] public RenderFragment? ChildContent { get; set; } | ||
} | ||
|
||
@{ | ||
#endif | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@{ | ||
#if NET9_0_OR_GREATER | ||
} | ||
|
||
<div>@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name</div> | ||
@ChildContent | ||
|
||
@code { | ||
[Parameter] public RenderFragment? ChildContent { get; set; } | ||
} | ||
|
||
@{ | ||
#endif | ||
} |