Skip to content

Commit a6751ac

Browse files
committed
docs: fixing broken code references
1 parent 6a4411a commit a6751ac

15 files changed

Lines changed: 101 additions & 65 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h1>Counter</h1>
2+
3+
<FancyParagraph Text=@($"Current count: {currentCount}") />
4+
5+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
6+
7+
@code {
8+
int currentCount = 0;
9+
10+
void IncrementCount()
11+
{
12+
currentCount++;
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>@Text</p>
2+
@code {
3+
[Parameter]
4+
public string Text { get; set; }
5+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#if NET5_0_OR_GREATER
2+
using Xunit;
3+
using Bunit;
4+
using Moq;
5+
using NSubstitute;
6+
7+
namespace Bunit.Docs.Samples
8+
{
9+
public class CounterWithFancyParagraphTest
10+
{
11+
[Fact]
12+
public void CounterShouldIncrementWhenClicked_Moq()
13+
{
14+
using var ctx = new TestContext();
15+
Mock<FancyParagraph> mock = new Mock<FancyParagraph>();
16+
FancyParagraph mockComponent = mock.Object;
17+
18+
ctx.ComponentFactories.Add(mock.Object);
19+
20+
var cut = ctx.RenderComponent<Counter>();
21+
22+
cut.Find("button").Click();
23+
24+
cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
25+
}
26+
27+
[Fact]
28+
public void CounterShouldIncrementWhenClicked_NSubstitute()
29+
{
30+
using var ctx = new TestContext();
31+
FancyParagraph mockComponent = Substitute.For<FancyParagraph>();
32+
33+
ctx.ComponentFactories.Add(mockComponent);
34+
35+
var cut = ctx.RenderComponent<Counter>();
36+
37+
cut.Find("button").Click();
38+
39+
cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
40+
}
41+
}
42+
}
43+
#endif

docs/samples/tests/xunit/FooBarComponentFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if NET5_0_OR_GREATER
12
namespace Bunit.Docs.Samples
23
{
34
using System;
@@ -12,4 +13,5 @@ public bool CanCreate(Type componentType)
1213
public IComponent Create(Type componentType)
1314
=> new Bar();
1415
}
15-
}
16+
}
17+
#endif

docs/site/docfx.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"files": [
77
"bunit.core/bunit.core.csproj",
88
"bunit.web/bunit.web.csproj",
9-
"bunit.web.testcomponents/bunit.web.testcomponents.csproj"
109
],
1110
"exclude": [ "**/bin/**", "**/obj/**" ],
1211
"src": "../../src"

docs/site/docs/getting-started/writing-tests.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ With that in place, lets look at a simple example that tests the following `<Hel
7272
The test above does the following:
7373

7474
1. Creates a new instance of the disposable bUnit <xref:Bunit.TestContext>, and assigns it to `ctx` the variable using the `using var` syntax to avoid unnecessary source code indention.
75-
2. Renders the `<HelloWorld>` component using <xref:Bunit.TestContext>, which is done through the <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components.RenderFragment)> method. We cover passing parameters to components on the <xref:passing-parameters-to-components> page.
75+
2. Renders the `<HelloWorld>` component using <xref:Bunit.TestContext>, which is done through the `Render(RenderFragment)` method. We cover passing parameters to components on the <xref:passing-parameters-to-components> page.
7676
3. Verifies the rendered markup from the `<HelloWorld>` component using the `MarkupMatches` method. The `MarkupMatches` method performs a semantic comparison of the expected markup with the rendered markup.
7777

7878
> [!TIP]
@@ -119,7 +119,7 @@ We can remove some boilerplate code from each test by making the <xref:Bunit.Tes
119119

120120
[!code-cshtml[HelloWorldImplicitContextRazorTest.razor](../../../samples/tests/xunit/HelloWorldImplicitContextRazorTest.razor)]
121121

122-
Since xUnit instantiates test classes for each execution of the test methods inside them, and disposes of them after each test method has run, we simply inherit from <xref:Bunit.TestContext>, and methods like <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components.RenderFragment)> can then be called directly from each test. This is seen in the listing above.
122+
Since xUnit instantiates test classes for each execution of the test methods inside them, and disposes of them after each test method has run, we simply inherit from <xref:Bunit.TestContext>, and methods like <xref:Bunit.TestContext.Render(RenderFragment)> can then be called directly from each test. This is seen in the listing above.
123123

124124
# [NUnit](#tab/nunit)
125125

@@ -129,7 +129,7 @@ Since xUnit instantiates test classes for each execution of the test methods ins
129129

130130
Since NUnit instantiates a test class only once for all tests inside it, we cannot simply inherit directly from <xref:Bunit.TestContext> as we want a fresh instance of <xref:Bunit.TestContext> for each test. Instead, we create a helper class, `BunitTestContext`, listed above, and use that to hook into NUnit's `[SetUp]` and `[TearDown]` methods, which runs before and after each test. The `BunitTestContext` class inherits from the <xref:Bunit.TestContextWrapper> type, which is included specifically to make this scenario easier.
131131

132-
Then methods like <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components.RenderFragment)> can be called directly from each test, as seen in the listing above.
132+
Then methods like <xref:Bunit.TestContext.Render(RenderFragment)> can be called directly from each test, as seen in the listing above.
133133

134134
# [MSTest](#tab/mstest)
135135

@@ -139,7 +139,7 @@ Then methods like <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components
139139

140140
Since MSTest instantiates a test class only once for all tests inside it, we cannot simply inherit directly from <xref:Bunit.TestContext> as we want a fresh instance of <xref:Bunit.TestContext> for each test. Instead, we create a helper class, `BunitTestContext`, listed above, and use that to hook into MSTest's `[TestInitialize]` and `[TestCleanup]` methods. This runs before and after each test. The `BunitTestContext` class inherits from the <xref:Bunit.TestContextWrapper> type, which is included specifically to make this scenario easier.
141141

142-
Then methods like <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components.RenderFragment)> can be called directly from each test, as seen in the listing above.
142+
Then methods like <xref:Bunit.TestContext.Render(RenderFragment)> can be called directly from each test, as seen in the listing above.
143143

144144
***
145145

@@ -181,7 +181,7 @@ This is a simple example of writing tests in `.cs` files which tests the followi
181181
The test above does the following:
182182

183183
1. Creates a new instance of the disposable bUnit <xref:Bunit.TestContext>, and assigns it to the `ctx` variable using the `using var` syntax to avoid unnecessary source code indention.
184-
2. Renders the `<HelloWorld>` component using <xref:Bunit.TestContext>, which is done through the <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit.ComponentParameterCollectionBuilder{``0}})> method. We cover passing parameters to components on the <xref:passing-parameters-to-components> page.
184+
2. Renders the `<HelloWorld>` component using <xref:Bunit.TestContext>, which is done through the <xref:Bunit.TestContext.RenderComponent``1(Action{Bunit.ComponentParameterCollectionBuilder{``0}})> method. We cover passing parameters to components on the <xref:passing-parameters-to-components> page.
185185
3. Verifies the rendered markup from the `<HelloWorld>` component using the `MarkupMatches` method. The `MarkupMatches` method performs a semantic comparison of the expected markup with the rendered markup.
186186

187187
> [!TIP]
@@ -198,7 +198,7 @@ We can remove some boilerplate code from each test by making the <xref:Bunit.Tes
198198

199199
[!code-csharp[HelloWorldImplicitContextTest.cs](../../../samples/tests/xunit/HelloWorldImplicitContextTest.cs)]
200200

201-
Since xUnit instantiates test classes for each execution of the test methods inside them, and disposes of them after each test method has run, we simply inherit from <xref:Bunit.TestContext>, and methods like <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit.ComponentParameterCollectionBuilder{``0}})> can then be called directly from each test. This is seen in the listing above.
201+
Since xUnit instantiates test classes for each execution of the test methods inside them, and disposes of them after each test method has run, we simply inherit from <xref:Bunit.TestContext>, and methods like <xref:Bunit.TestContext.RenderComponent``1(Action{Bunit.ComponentParameterCollectionBuilder{``0}})> can then be called directly from each test. This is seen in the listing above.
202202

203203
# [NUnit](#tab/nunit)
204204

@@ -208,7 +208,7 @@ Since xUnit instantiates test classes for each execution of the test methods ins
208208

209209
Since NUnit instantiates a test class only once for all tests inside it, we cannot simply inherit directly from <xref:Bunit.TestContext> as we want a fresh instance of <xref:Bunit.TestContext> for each test. Instead, we create a helper class, `BunitTestContext`, listed above, and use that to hook into NUnit's `[SetUp]` and `[TearDown]` methods, which run before and after each test.
210210

211-
Then methods like <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit.ComponentParameterCollectionBuilder{``0}})> can be called directly from each test, as seen in the listing above.
211+
Then methods like <xref:Bunit.TestContext.RenderComponent``1(Action{Bunit.ComponentParameterCollectionBuilder{``0}})> can be called directly from each test, as seen in the listing above.
212212

213213
# [MSTest](#tab/mstest)
214214

@@ -218,7 +218,7 @@ Then methods like <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit
218218

219219
Since MSTest instantiates a test class only once for all tests inside it, we cannot simply inherit directly from <xref:Bunit.TestContext> as we want a fresh instance of <xref:Bunit.TestContext> for each test. Instead, we create a helper class, `BunitTestContext`, listed above, and use that to hook into MSTest's `[TestInitialize]` and `[TestCleanup]` methods. This runs before and after each test.
220220

221-
Then methods like <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit.ComponentParameterCollectionBuilder{``0}})> can be called directly from each test, as seen in the listing above.
221+
Then methods like <xref:Bunit.TestContext.RenderComponent``1(Action{Bunit.ComponentParameterCollectionBuilder{``0}})> can be called directly from each test, as seen in the listing above.
222222

223223
***
224224

docs/site/docs/interaction/trigger-event-handlers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ This is what happens in the test:
5252
1. In the arrange step of the test, the `<ClickMe>` component is rendered and the `<button>` element is found using the [`Find(string cssSelector)`](xref:Bunit.RenderedFragmentExtensions.Find(Bunit.IRenderedFragment,System.String)) method.
5353
2. The act step of the test is the `<button>`'s click event handler. In this case, the `ClickHandler` event handler method is invoked in three different ways:
5454
- The first and second invocations use the same [`Click`](xref:Bunit.MouseEventDispatchExtensions.Click(AngleSharp.Dom.IElement,System.Int64,System.Double,System.Double,System.Double,System.Double,System.Int64,System.Int64,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.String)) method. It has a number of optional arguments, some of which are passed in the second invocation. If any arguments are provided, they are added to an instance of the `MouseEventArgs` type, which is passed to the event handler if it has it as an argument.
55-
- The last invocation uses the [`Click`](xref:Bunit.MouseEventDispatchExtensions.Click(AngleSharp.Dom.IElement,Microsoft.AspNetCore.Components.Web.MouseEventArgs)) method. This takes an instance of the `MouseEventArgs` type, which is passed to the event handler if it has it as an argument.
55+
- The last invocation uses the [`Click`](xref:Bunit.MouseEventDispatchExtensions.Click(AngleSharp.Dom.IElement,MouseEventArgs)) method. This takes an instance of the `MouseEventArgs` type, which is passed to the event handler if it has it as an argument.
5656

5757
All the event dispatch helper methods have the same two overloads: one that takes a number of optional arguments, and one that takes one of the `EventArgs` types provided by Blazor.
5858

docs/site/docs/interaction/trigger-renders.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Triggering a render life cycle on a component
77

88
To trigger a re-render of a component under test, a reference to it through a <xref:Bunit.IRenderedComponent`1> type is needed. When using the <xref:Bunit.TestContext>'s `RenderComponent<TComponent>()` method, this is the type returned.
99

10-
In `.razor` based tests, using the <xref:Bunit.TestContext>'s <xref:Bunit.TestContext.Render``1(Microsoft.AspNetCore.Components.RenderFragment)> method also returns an <xref:Bunit.IRenderedComponent`1> (as opposed to the <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components.RenderFragment)> method which returns the more simple <xref:Bunit.IRenderedFragment>).
10+
In `.razor` based tests, using the <xref:Bunit.TestContext>'s <xref:Bunit.TestContext.Render``1(RenderFragment)> method also returns an <xref:Bunit.IRenderedComponent`1> (as opposed to the <xref:Bunit.TestContext.Render(RenderFragment)> method which returns the more simple <xref:Bunit.IRenderedFragment>).
1111

1212
If you have a <xref:Bunit.IRenderedFragment> or a <xref:Bunit.IRenderedComponent`1> in a test, but need a child component's <xref:Bunit.IRenderedComponent`1>, then use the `FindComponent<TComponent>()` or the `FindComponents<TComponent>()` methods, which traverse down the render tree and finds rendered components.
1313

docs/site/docs/providing-input/controlling-component-instantiation.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,4 @@ Then, before rendering the component under test, add the `FooBarComponentFactory
3131

3232
## Built-in factories
3333

34-
bUnit comes with several built-in factories that allow shallow rendering or replacing components with test dummies and test stubs. See the following pages for details:
35-
36-
- <xref:shallow-rendering>
37-
- <xref:stubbing-components>
34+
bUnit comes with several built-in factories that allow shallow rendering or replacing components with test dummies and test stubs. See the <xref:substituting-components> page for details.

0 commit comments

Comments
 (0)