-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to parameter passing in c# based tests (#203)
* componentparametercollection * Support for passing multiple template and render fragments * Automated dotnet-format update * cascading values * Finished component parameter collection, closed #142, updated tests to component parameter factory * Fixed null warnings * Automated dotnet-format update * Fixes for CodeQL warnings * Added ChildContent and RenderFragment tests * Added support for passing template fragments * Removed ComponentParameterBuilder, added support for unmatched and cascading values * Switched to C# 9 compile * Automated dotnet-format update * unnamed cascading value with add * Removed .net move hack from workflows * Fix for null errors * Automated dotnet-format update * Added extra factory method and moved ComponentParameter out into Bunit namespace * Updated docs with new parameter passing logic * Automated dotnet-format update * Updated changelog Co-authored-by: Github Actions <[email protected]>
- Loading branch information
1 parent
4f35197
commit b78098c
Showing
59 changed files
with
2,108 additions
and
1,205 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
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
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Bunit.Rendering; | ||
|
||
using static Bunit.ComponentParameterFactory; | ||
|
||
|
@@ -125,17 +126,24 @@ public void ComponentAndMarkupAsChildContent() | |
{ | ||
using var ctx = new TestContext(); | ||
|
||
// Using factory method | ||
var cut1 = ctx.RenderComponent<ChildContentParams>( | ||
ChildContent("<h1>Below you will find a most interesting alert!</h1>"), | ||
ChildContent<Alert>( | ||
("Heading", "Alert heading"), | ||
("Type", AlertType.Warning), | ||
ChildContent("<p>Hello World</p>") | ||
) | ||
); | ||
|
||
// Using parameter builder | ||
var cut = ctx.RenderComponent<ChildContentParams>(parameters => parameters | ||
.Add(p => p.ChildContent, (RenderFragment)(builder => | ||
{ | ||
builder.AddMarkupContent(1, "<h1>Below you will find a most interesting alert!</h1>"); | ||
builder.OpenComponent<Alert>(2); | ||
builder.AddAttribute(3, "Heading", "Alert heading"); | ||
builder.AddAttribute(4, "Type", AlertType.Warning); | ||
builder.AddAttribute(5, "ChildContent", (RenderFragment)(alertBuilder => alertBuilder.AddMarkupContent(1, "<p>Hello World</p>"))); | ||
builder.CloseComponent(); | ||
})) | ||
var cut2 = ctx.RenderComponent<ChildContentParams>(parameters => parameters | ||
.AddChildContent("<h1>Below you will find a most interesting alert!</h1>") | ||
.AddChildContent<Alert>(childParams => childParams | ||
.Add(p => p.Heading, "Alert heading") | ||
.Add(p => p.Type, AlertType.Warning) | ||
.AddChildContent("<p>Hello World</p>") | ||
) | ||
); | ||
} | ||
|
||
|
@@ -200,17 +208,24 @@ public void ComponentAndMarkupAsRenderFragment() | |
{ | ||
using var ctx = new TestContext(); | ||
|
||
// Using factory method | ||
var cut1 = ctx.RenderComponent<RenderFragmentParams>( | ||
RenderFragment("Content", "<h1>Below you will find a most interesting alert!</h1>"), | ||
RenderFragment<Alert>("Content", | ||
("Heading", "Alert heading"), | ||
("Type", AlertType.Warning), | ||
ChildContent("<p>Hello World</p>") | ||
) | ||
); | ||
|
||
// Using parameter builder | ||
var cut = ctx.RenderComponent<RenderFragmentParams>(parameters => parameters | ||
.Add(p => p.Content, (RenderFragment)(builder => | ||
{ | ||
builder.AddMarkupContent(1, "<h1>Below you will find a most interesting alert!</h1>"); | ||
builder.OpenComponent<Alert>(2); | ||
builder.AddAttribute(3, "Heading", "Alert heading"); | ||
builder.AddAttribute(4, "Type", AlertType.Warning); | ||
builder.AddAttribute(5, "ChildContent", (RenderFragment)(alertBuilder => alertBuilder.AddMarkupContent(1, "<p>Hello World</p>"))); | ||
builder.CloseComponent(); | ||
})) | ||
var cut2 = ctx.RenderComponent<RenderFragmentParams>(parameters => parameters | ||
.Add(p => p.Content, "<h1>Below you will find a most interesting alert!</h1>") | ||
.Add<Alert>(p => p.Content, childParams => childParams | ||
.Add(p => p.Heading, "Alert heading") | ||
.Add(p => p.Type, AlertType.Warning) | ||
.AddChildContent("<p>Hello World</p>") | ||
) | ||
); | ||
} | ||
|
||
|
@@ -240,29 +255,17 @@ public void HtmlAndComponentTemplateParams() | |
// Using factory method | ||
var cut1 = ctx.RenderComponent<TemplateParams<string>>( | ||
("Items", new string[] { "Foo", "Bar", "Baz" }), | ||
Template<string>("Template", item => builder => | ||
{ | ||
builder.OpenElement(1, "div"); | ||
builder.AddAttribute(2, "class", "item"); | ||
builder.OpenComponent<Item>(3); | ||
builder.AddAttribute(4, "Value", item); | ||
builder.CloseComponent(); | ||
builder.CloseElement(); | ||
Template<Item, string>("Template", value => new ComponentParameter[] { | ||
("Value", value) | ||
}) | ||
); | ||
|
||
// Using parameter builder | ||
var cut2 = ctx.RenderComponent<TemplateParams<string>>(parameters => parameters | ||
.Add(p => p.Items, new[] { "Foo", "Bar", "Baz" }) | ||
.Add(p => p.Template, item => builder => | ||
{ | ||
builder.OpenElement(1, "div"); | ||
builder.AddAttribute(2, "class", "item"); | ||
builder.OpenComponent<Item>(3); | ||
builder.AddAttribute(4, "Value", item); | ||
builder.CloseComponent(); | ||
builder.CloseElement(); | ||
}) | ||
.Add<Item, string>(p => p.Template, value => itemParams => itemParams | ||
.Add(p => p.Value, value) | ||
) | ||
); | ||
} | ||
|
||
|
@@ -295,7 +298,7 @@ public void UnnamedCascadingParamsTest() | |
|
||
// Using parameter builder | ||
var cut2 = ctx.RenderComponent<CascadingParams>(parameters => parameters | ||
.Add(isDarkTheme) | ||
.AddCascadingValue(isDarkTheme) | ||
); | ||
|
||
// Using parameter builder and selecting unnamed cascading parameter | ||
|
@@ -335,7 +338,7 @@ public void UnnamedAndNamedCascadingParamsTest() | |
|
||
// Using parameter builder | ||
var cut2 = ctx.RenderComponent<CascadingParams>(parameters => parameters | ||
.Add(isDarkTheme) | ||
.AddCascadingValue(isDarkTheme) | ||
.Add(p => p.UserName, "Egil Hansen") | ||
.Add(p => p.Email, "[email protected]") | ||
); | ||
|
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
Oops, something went wrong.