Skip to content

Commit c3441cb

Browse files
committed
Updated changelog, renamed render methods in TestContextBase for better overloading possibilities in the future
1 parent 2fd82a1 commit c3441cb

8 files changed

Lines changed: 94 additions & 88 deletions

File tree

.github/workflows/deploy-docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
with:
2323
setAllVars: true
2424

25-
- name: Setting VERSION
26-
run: echo "::set-env name=VERSION::$NBGV_NuGetPackageVersion"
27-
25+
- name: Setting VERSION env
26+
run: echo "VERSION=$NBGV_NuGetPackageVersion" >> $GITHUB_ENV
27+
2828
- name: Update tokens in project files
2929
uses: cschleiden/replace-tokens@v1
3030
with:

.github/workflows/main.yml

Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ jobs:
7070

7171
verify-template:
7272
if: github.event_name != 'schedule'
73-
env:
74-
BRANCH: ''
75-
VERSION: ''
7673
runs-on: ubuntu-latest
7774
steps:
7875
- name: Checkout repository
@@ -84,10 +81,11 @@ jobs:
8481
with:
8582
setAllVars: true
8683

84+
- uses: nelonoel/branch-name@v1.0.1
8785
- name: Setting VERSION and BRANCH env
8886
run: |
89-
echo "::set-env name=VERSION::$NBGV_NuGetPackageVersion"
90-
echo "::set-env name=BRANCH::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')"
87+
echo "VERSION=$NBGV_NuGetPackageVersion" >> $GITHUB_ENV
88+
echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV
9189
9290
- name: Update tokens in project files
9391
uses: cschleiden/replace-tokens@v1
@@ -121,79 +119,78 @@ jobs:
121119
if: github.event_name != 'schedule' && github.event_name != 'pull_request'
122120
runs-on: ubuntu-latest
123121
steps:
124-
- name: Checkout repository
125-
uses: actions/checkout@v2
126-
with:
127-
fetch-depth: 0w
128-
129-
- uses: dotnet/nbgv@master
130-
with:
131-
setAllVars: true
132-
133-
- name: Setting VERSION and BRANCH env
134-
run: |
135-
echo "::set-env name=VERSION::$NBGV_NuGetPackageVersion"
136-
echo "::set-env name=BRANCH::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')"
137-
138-
- uses: actions/setup-dotnet@v1
139-
with:
140-
dotnet-version: '3.1.x'
141-
- uses: actions/setup-dotnet@v1
142-
with:
143-
dotnet-version: '5.0.x'
144-
145-
- name: Install dotnet-sonarscanner
146-
run: dotnet tool install --global dotnet-sonarscanner
147-
- name: Running dotnet-sonarscanner
148-
shell: bash
149-
env:
150-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
151-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152-
run: |
153-
dotnet sonarscanner begin /k:"egil_bUnit" /o:"egil" /n:"bUnit" /v:"$NBGV_NuGetPackageVersion" /d:sonar.login="$SONAR_TOKEN" /d:sonar.host.url=https://sonarcloud.io /d:sonar.branch.name="$BRANCH" /d:sonar.verbose="true" /d:sonar.cs.opencover.reportsPaths="tests/**/coverage/*.opencover.xml"
154-
dotnet build
155-
dotnet test tests/bunit.core.tests/ /p:CollectCoverage=true /p:CoverletOutput=./coverage/ /p:CoverletOutputFormat=opencover /p:ExcludeByAttribute=\"Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute\"
156-
dotnet test tests/bunit.web.tests/ /p:CollectCoverage=true /p:CoverletOutput=./coverage/ /p:CoverletOutputFormat=opencover /p:ExcludeByAttribute=\"Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute\"
157-
dotnet test tests/bunit.xunit.tests/ /p:CollectCoverage=true /p:CoverletOutput=./coverage/ /p:CoverletOutputFormat=opencover /p:ExcludeByAttribute=\"Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute\"
158-
dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"
122+
- name: Checkout repository
123+
uses: actions/checkout@v2
124+
with:
125+
fetch-depth: 0
126+
127+
- uses: dotnet/nbgv@master
128+
with:
129+
setAllVars: true
130+
131+
- uses: nelonoel/branch-name@v1.0.1
132+
133+
- name: Setting VERSION and BRANCH env
134+
run: |
135+
echo "VERSION=$NBGV_NuGetPackageVersion" >> $GITHUB_ENV
136+
echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV
137+
138+
- uses: actions/setup-dotnet@v1
139+
with:
140+
dotnet-version: '3.1.x'
141+
- uses: actions/setup-dotnet@v1
142+
with:
143+
dotnet-version: '5.0.x'
144+
145+
- name: Install dotnet-sonarscanner
146+
run: dotnet tool install --global dotnet-sonarscanner
147+
- name: Running dotnet-sonarscanner
148+
shell: bash
149+
env:
150+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
151+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152+
run: |
153+
dotnet sonarscanner begin /k:"egil_bUnit" /o:"egil" /n:"bUnit" /v:"$NBGV_NuGetPackageVersion" /d:sonar.login="$SONAR_TOKEN" /d:sonar.host.url=https://sonarcloud.io /d:sonar.branch.name="$BRANCH" /d:sonar.verbose="true" /d:sonar.cs.opencover.reportsPaths="tests/**/coverage/*.opencover.xml"
154+
dotnet build
155+
dotnet test tests/bunit.core.tests/ /p:CollectCoverage=true /p:CoverletOutput=./coverage/ /p:CoverletOutputFormat=opencover /p:ExcludeByAttribute=\"Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute\"
156+
dotnet test tests/bunit.web.tests/ /p:CollectCoverage=true /p:CoverletOutput=./coverage/ /p:CoverletOutputFormat=opencover /p:ExcludeByAttribute=\"Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute\"
157+
dotnet test tests/bunit.xunit.tests/ /p:CollectCoverage=true /p:CoverletOutput=./coverage/ /p:CoverletOutputFormat=opencover /p:ExcludeByAttribute=\"Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute\"
158+
dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"
159159
160160
code-ql:
161161
if: github.event_name != 'pull_request'
162162
runs-on: ubuntu-latest
163163
steps:
164-
- name: Checkout repository
165-
uses: actions/checkout@v2
166-
with:
167-
# We must fetch at least the immediate parents so that if this is
168-
# a pull request then we can checkout the head.
169-
fetch-depth: 0
170-
171-
- uses: actions/setup-dotnet@v1
172-
with:
173-
dotnet-version: '3.1.x'
174-
- uses: actions/setup-dotnet@v1
175-
with:
176-
dotnet-version: '5.0.x'
177-
178-
- name: Initialize CodeQL
179-
uses: github/codeql-action/init@v1
180-
with:
181-
languages: csharp
182-
config-file: ./.github/codeql/codeql-config.yml
183-
184-
- name: Building library
185-
run: dotnet build -p:ContinuousIntegrationBuild=true
186-
187-
- name: Perform CodeQL Analysis
188-
uses: github/codeql-action/analyze@v1
164+
- name: Checkout repository
165+
uses: actions/checkout@v2
166+
with:
167+
# We must fetch at least the immediate parents so that if this is
168+
# a pull request then we can checkout the head.
169+
fetch-depth: 0
170+
171+
- uses: actions/setup-dotnet@v1
172+
with:
173+
dotnet-version: '3.1.x'
174+
- uses: actions/setup-dotnet@v1
175+
with:
176+
dotnet-version: '5.0.x'
177+
178+
- name: Initialize CodeQL
179+
uses: github/codeql-action/init@v1
180+
with:
181+
languages: csharp
182+
config-file: ./.github/codeql/codeql-config.yml
183+
184+
- name: Building library
185+
run: dotnet build -p:ContinuousIntegrationBuild=true
186+
187+
- name: Perform CodeQL Analysis
188+
uses: github/codeql-action/analyze@v1
189189

190190
publish-nuget-packages:
191191
if: (github.event_name == 'push' && github.ref == 'refs/heads/dev') || github.event_name == 'release'
192192
needs: [dotnet-build, dotnet-test, verify-template]
193193
runs-on: ubuntu-latest
194-
env:
195-
VERSION: ''
196-
BRANCH: ''
197194
steps:
198195
- name: Checkout Repository
199196
uses: actions/checkout@v2
@@ -204,10 +201,11 @@ jobs:
204201
with:
205202
setAllVars: true
206203

204+
- uses: nelonoel/branch-name@v1.0.1
207205
- name: Setting VERSION and BRANCH env
208206
run: |
209-
echo "::set-env name=VERSION::$NBGV_NuGetPackageVersion"
210-
echo "::set-env name=BRANCH::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')"
207+
echo "VERSION=$NBGV_NuGetPackageVersion" >> $GITHUB_ENV
208+
echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV
211209
212210
- name: Update tokens in project files
213211
uses: cschleiden/replace-tokens@v1

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ List of new features.
1313

1414
- Added support for triggering `@ontoggle` event handlers through a dedicated `Toggle()` method. By [@egil](https://github.com/egil) in [#256](https://github.com/egil/bUnit/pull/256).
1515

16-
- Added out of the box support for `<Virtualize>` component. When a `<Virtualize>` component is used in a component under test, it's JavaScript interop-calls are faked by bUnits JSInterop, and it should result in all items being rendered immediately.
16+
- Added support for components that call `ElementReference.FocusAsync`. These calls are handled by the bUnits JSInterop, that also allows you to verify that `FocusAsync` has been called for a specific element. For example, if a component has rendered an `<input>` element, then the following code will verify that it has been focused using `FocusAsync`:
17+
18+
```csharp
19+
var cut = RenderComponent<FocusingComponent>();
20+
21+
var input = cut.Find("input");
22+
23+
JSInterop.VerifyFocusAsyncInvoke()
24+
.Arguments[0] // the first argument is the ElemenetReference
25+
.ShouldBeElementReferenceTo(input);
26+
```
27+
28+
By [@egil](https://github.com/egil) in [#260](https://github.com/egil/bUnit/pull/260).
1729

1830
### Changed
1931
List of changes in existing functionality.

src/bunit.core/TestContextBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ protected TestContextBase()
5757
/// Renders a component, declared in the <paramref name="renderFragment"/>, inside the <see cref="RenderTree"/>.
5858
/// </summary>
5959
/// <typeparam name="TComponent">The type of component to render.</typeparam>
60-
/// <param name="renderFragment">The <see cref="RenderFragment"/> that contains a declaration of the component.</param>
60+
/// <param name="renderFragment">The <see cref="RenderFragmentBase"/> that contains a declaration of the component.</param>
6161
/// <returns>A <see cref="IRenderedComponentBase{TComponent}"/>.</returns>
62-
protected IRenderedComponentBase<TComponent> RenderComponent<TComponent>(RenderFragment renderFragment) where TComponent : IComponent
62+
protected IRenderedComponentBase<TComponent> RenderComponentBase<TComponent>(RenderFragment renderFragment) where TComponent : IComponent
6363
{
6464
// Wrap TComponent in any layout components added to the test context.
6565
// If one of the layout components is the same type as TComponent,
@@ -79,9 +79,9 @@ protected IRenderedComponentBase<TComponent> RenderComponent<TComponent>(RenderF
7979
/// <summary>
8080
/// Renders a fragment, declared in the <paramref name="renderFragment"/>, inside the <see cref="RenderTree"/>.
8181
/// </summary>
82-
/// <param name="renderFragment">The <see cref="RenderFragment"/> to render.</param>
82+
/// <param name="renderFragment">The <see cref="RenderFragmentBase"/> to render.</param>
8383
/// <returns>A <see cref="IRenderedFragmentBase"/>.</returns>
84-
protected IRenderedFragmentBase RenderFragment(RenderFragment renderFragment)
84+
protected IRenderedFragmentBase RenderFragmentBase(RenderFragment renderFragment)
8585
{
8686
// Wrap fragment in a FragmentContainer so the start of the test supplied
8787
// razor fragment can be found after, and then wrap in any layout components

src/bunit.web/RazorTesting/Fixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ private ComponentUnderTest SelectComponentUnderTest(string _)
142142

143143
private IRenderedComponent<TComponent> Factory<TComponent>(RenderFragment fragment) where TComponent : IComponent
144144
{
145-
return (IRenderedComponent<TComponent>)RenderComponent<TComponent>(fragment);
145+
return (IRenderedComponent<TComponent>)RenderComponentBase<TComponent>(fragment);
146146
}
147147

148148
private IRenderedFragment Factory(RenderFragment fragment)
149149
{
150-
return (IRenderedFragment)RenderFragment(fragment);
150+
return (IRenderedFragment)RenderFragmentBase(fragment);
151151
}
152152

153153
private static IRenderedComponent<TComponent> TryCastTo<TComponent>(IRenderedFragment target, [System.Runtime.CompilerServices.CallerMemberName] string sourceMethod = "") where TComponent : IComponent

src/bunit.web/RazorTesting/SnapshotTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ protected override async Task Run()
6868
if (SetupAsync is not null)
6969
await TryRunAsync(SetupAsync, this).ConfigureAwait(false);
7070

71-
var renderedTestInput = (IRenderedFragment)RenderFragment(TestInput!);
71+
var renderedTestInput = (IRenderedFragment)RenderFragmentBase(TestInput!);
7272
var inputHtml = renderedTestInput.Markup;
7373

74-
var renderedExpectedRender = (IRenderedFragment)RenderFragment(ExpectedOutput!);
74+
var renderedExpectedRender = (IRenderedFragment)RenderFragmentBase(ExpectedOutput!);
7575
var expectedHtml = renderedExpectedRender.Markup;
7676

7777
VerifySnapshot(inputHtml, expectedHtml);

src/bunit.web/TestContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public TestContext()
3737
public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(params ComponentParameter[] parameters) where TComponent : IComponent
3838
{
3939
var renderFragment = new ComponentParameterCollection { parameters }.ToRenderFragment<TComponent>();
40-
return (IRenderedComponent<TComponent>)RenderComponent<TComponent>(renderFragment);
40+
return (IRenderedComponent<TComponent>)RenderComponentBase<TComponent>(renderFragment);
4141
}
4242

4343
/// <summary>
@@ -49,7 +49,7 @@ public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(params
4949
public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>> parameterBuilder) where TComponent : IComponent
5050
{
5151
var renderFragment = new ComponentParameterCollectionBuilder<TComponent>(parameterBuilder).Build().ToRenderFragment<TComponent>();
52-
return (IRenderedComponent<TComponent>)RenderComponent<TComponent>(renderFragment);
52+
return (IRenderedComponent<TComponent>)RenderComponentBase<TComponent>(renderFragment);
5353
}
5454
}
5555
}

tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusAsyncInvocationHandlerTest.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#if NET5_0
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
62
using System.Threading.Tasks;
73
using Microsoft.AspNetCore.Components;
84
using Microsoft.AspNetCore.Components.Rendering;

0 commit comments

Comments
 (0)