Skip to content

Commit 27b610f

Browse files
committed
Docs: Parameters passing
1 parent c4cf0b2 commit 27b610f

10 files changed

Lines changed: 381 additions & 80 deletions

docs/samples/components/Alert.razor

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,16 @@
22
[Parameter] public string Heading { get; set; }
33
[Parameter] public AlertType Type { get; set; }
44
[Parameter] public RenderFragment ChildContent { get; set; }
5-
}
5+
}
6+
<div role="alert" class="alert alert-@(Type.ToString().ToLower()) alert-dismissible fade show">
7+
@if (!string.IsNullOrWhiteSpace(Heading))
8+
{
9+
<h4 class="alert-heading">@Heading</h4>
10+
}
11+
<div class="alert-content">
12+
@ChildContent
13+
</div>
14+
<button type="button" class="close" aria-label="Close">
15+
<span aria-hidden="true">&times;</span>
16+
</button>
17+
</div>

docs/samples/components/AllKindsOfParams.razor

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Components;
6+
using Microsoft.AspNetCore.Components.Web;
7+
8+
namespace Bunit.Docs.Samples
9+
{
10+
public class ChildContentParams : ComponentBase
11+
{
12+
[Parameter]
13+
public RenderFragment ChildContent { get; set; }
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Components;
6+
using Microsoft.AspNetCore.Components.Web;
7+
8+
namespace Bunit.Docs.Samples
9+
{
10+
public class EventCallbackParams : ComponentBase
11+
{
12+
[Parameter]
13+
public EventCallback<MouseEventArgs> OnClick { get; set; }
14+
15+
[Parameter]
16+
public EventCallback OnSomething { get; set; }
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Components;
6+
using Microsoft.AspNetCore.Components.Web;
7+
8+
namespace Bunit.Docs.Samples
9+
{
10+
public class NonBlazorTypesParams : ComponentBase
11+
{
12+
[Parameter]
13+
public int Numbers { get; set; }
14+
15+
[Parameter]
16+
public List<string> Lines { get; set; }
17+
}
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.Components;
5+
using Microsoft.AspNetCore.Components.Web;
6+
7+
namespace Bunit.Docs.Samples
8+
{
9+
public class RenderFragmentParams : ComponentBase
10+
{
11+
[Parameter]
12+
public RenderFragment Content { get; set; }
13+
}
14+
}

docs/samples/tests/razor/AllKindsOfParamsTest.razor

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,95 @@
22

33
<Fixture Test="f => {}">
44
<ComponentUnderTest>
5-
<AllKindsOfParams Numbers="42" Lines=@(new List<string> { "Hello", "World" })>
6-
</AllKindsOfParams>
5+
<NonBlazorTypesParams Numbers="42" Lines=@(new List<string> { "Hello", "World" }) />
76
</ComponentUnderTest>
87
</Fixture>
98

109
<Fixture Test="f => {}">
1110
<ComponentUnderTest>
12-
<AllKindsOfParams OnClick=@(args => { /* handle callback */ })
13-
OnSomething=@(() => { /* handle callback */ })>
14-
</AllKindsOfParams>
11+
<EventCallbackParams OnClick=@(args => { /* handle callback */ })
12+
OnSomething=@(() => { /* handle callback */ }) />
1513
</ComponentUnderTest>
1614
</Fixture>
1715

1816
<Fixture Test="f => {}">
1917
<ComponentUnderTest>
20-
<AllKindsOfParams>
18+
<ChildContentParams>
2119
<h1>Hello World</h1>
22-
</AllKindsOfParams>
20+
</ChildContentParams>
2321
</ComponentUnderTest>
2422
</Fixture>
2523

2624
<Fixture Test="f => {}">
2725
<ComponentUnderTest>
28-
<AllKindsOfParams>
26+
<ChildContentParams>
2927
<Counter />
30-
</AllKindsOfParams>
28+
</ChildContentParams>
3129
</ComponentUnderTest>
3230
</Fixture>
3331

3432
<Fixture Test="f => {}">
3533
<ComponentUnderTest>
36-
<AllKindsOfParams>
34+
<ChildContentParams>
3735
<Alert Heading="Alert heading" Type="AlertType.Warning">
3836
<p>Hello World</p>
3937
</Alert>
40-
</AllKindsOfParams>
38+
</ChildContentParams>
4139
</ComponentUnderTest>
4240
</Fixture>
4341

4442
<Fixture Test="f => {}">
4543
<ComponentUnderTest>
46-
<AllKindsOfParams>
44+
<ChildContentParams>
4745
<h1>Below you will find a most interesting alert!</h1>
4846
<Alert Heading="Alert heading" Type="AlertType.Warning">
4947
<p>Hello World</p>
5048
</Alert>
51-
</AllKindsOfParams>
49+
</ChildContentParams>
50+
</ComponentUnderTest>
51+
</Fixture>
52+
53+
<Fixture Test="f => {}">
54+
<ComponentUnderTest>
55+
<RenderFragmentParams>
56+
<Content>
57+
<h1>Hello World</h1>
58+
</Content>
59+
</RenderFragmentParams>
60+
</ComponentUnderTest>
61+
</Fixture>
62+
63+
<Fixture Test="f => {}">
64+
<ComponentUnderTest>
65+
<RenderFragmentParams>
66+
<Content>
67+
<Counter />
68+
</Content>
69+
</RenderFragmentParams>
70+
</ComponentUnderTest>
71+
</Fixture>
72+
73+
<Fixture Test="f => {}">
74+
<ComponentUnderTest>
75+
<RenderFragmentParams>
76+
<Content>
77+
<Alert Heading="Alert heading" Type="AlertType.Warning">
78+
<p>Hello World</p>
79+
</Alert>
80+
</Content>
81+
</RenderFragmentParams>
82+
</ComponentUnderTest>
83+
</Fixture>
84+
85+
<Fixture Test="f => {}">
86+
<ComponentUnderTest>
87+
<RenderFragmentParams>
88+
<Content>
89+
<h1>Below you will find a most interesting alert!</h1>
90+
<Alert Heading="Alert heading" Type="AlertType.Warning">
91+
<p>Hello World</p>
92+
</Alert>
93+
</Content>
94+
</RenderFragmentParams>
5295
</ComponentUnderTest>
5396
</Fixture>

docs/samples/tests/razor/PassingParametersToComponents.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
Before you really get the benefit of TDD, you need to practice...
1515
</Alert>
1616
</TestInput>
17-
<ExpectedOutput>@* ... *@</ExpectedOutput>
17+
<ExpectedOutput>
18+
<div diff:ignore>...</div>
19+
</ExpectedOutput>
1820
</SnapshotTest>

0 commit comments

Comments
 (0)