Skip to content

Commit f69abb5

Browse files
committed
Docs: last bits of passing parameters
1 parent 424f7b4 commit f69abb5

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@ChildContent
2+
3+
@code
4+
{
5+
[Parameter]
6+
public RenderFragment ChildContent { get; set; }
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@inherits TestComponentBase
2+
3+
<Fixture Test="HelloWorldTest">
4+
<ComponentUnderTest>
5+
<Wrapper>
6+
<HelloWorld />
7+
</Wrapper>
8+
</ComponentUnderTest>
9+
10+
@code
11+
{
12+
void HelloWorldTest(Fixture fixture)
13+
{
14+
var cut = fixture.GetComponentUnderTest<HelloWorld>();
15+
}
16+
}
17+
</Fixture>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Xunit;
2+
using Bunit;
3+
using System.Collections.Generic;
4+
using Microsoft.AspNetCore.Components;
5+
using Microsoft.AspNetCore.Components.Web;
6+
7+
using static Bunit.ComponentParameterFactory;
8+
9+
namespace Bunit.Docs.Samples
10+
{
11+
public class NestedComponentTest
12+
{
13+
[Fact]
14+
public void NestedComponent()
15+
{
16+
using var ctx = new TestContext();
17+
18+
// Using C# factory methods
19+
var wrapper1 = ctx.RenderComponent<Wrapper>(
20+
ChildContent<HelloWorld>()
21+
);
22+
var cut1 = wrapper1.FindComponent<HelloWorld>();
23+
24+
// Using parameter builder
25+
var wrapper2 = ctx.RenderComponent<Wrapper>(parameters => parameters
26+
.AddChildContent<HelloWorld>()
27+
);
28+
var cut2 = wrapper2.FindComponent<HelloWorld>();
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)