Skip to content

Commit 2de4763

Browse files
authored
BETA 11
BETA 11
2 parents 5274ac8 + 928fda7 commit 2de4763

File tree

227 files changed

+5712
-2005
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+5712
-2005
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- uses: actions/setup-dotnet@v1
3434
with:
35-
dotnet-version: '3.1.x'
35+
dotnet-version: '3.1.x'
3636
- uses: actions/setup-dotnet@v1
3737
with:
3838
dotnet-version: '5.0.100-rc.1.20452.10'

.github/workflows/main.yml

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -117,63 +117,45 @@ jobs:
117117
dotnet restore ${GITHUB_WORKSPACE}/TemplateTest --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
118118
dotnet test ${GITHUB_WORKSPACE}/TemplateTest
119119
120-
dotnet-format:
121-
if: github.event_name == 'pull_request'
122-
runs-on: ubuntu-latest
123-
steps:
124-
- name: Checkout repository
125-
uses: actions/checkout@v2
126-
127-
- uses: jwalton/gh-find-current-pr@v1
128-
id: findPr
129-
with:
130-
github-token: ${{ secrets.GITHUB_TOKEN }}
131-
132-
- name: Checkout PR
133-
uses: dawidd6/action-checkout-pr@v1
134-
with:
135-
pr: steps.findPr.outputs.number
136-
137-
- uses: actions/setup-dotnet@v1
138-
with:
139-
dotnet-version: '3.1.x'
140-
- uses: actions/setup-dotnet@v1
141-
with:
142-
dotnet-version: '5.0.100-rc.1.20452.10'
143-
144-
- name: Install dotnet-format
145-
run: dotnet tool install -g dotnet-format
146-
147-
- name: Run dotnet-format
148-
run: dotnet format ./bunit.sln --verbosity diag
149-
150-
- name: Commit formatted files
151-
uses: EndBug/[email protected]
152-
with:
153-
add: '.'
154-
author_name: Github Actions
155-
author_email: [email protected]
156-
message: Automated dotnet-format update
157-
env:
158-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
159-
160120
sonarcloud:
161121
if: github.event_name != 'schedule' || github.event_name != 'pull_request'
162122
runs-on: ubuntu-latest
163123
steps:
164124
- name: Checkout repository
165125
uses: actions/checkout@v2
166126
with:
167-
fetch-depth: 0
127+
fetch-depth: 0w
168128

169-
- name: Create sonar-project.properties
170-
run: echo -n -e "sonar.organization=egil\nsonar.projectKey=egil_bUnit\nsonar.sources=./src\nsonar.tests=./tests\n" > sonar-project.properties
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')"
171137
172-
- name: SonarCloud Scan
173-
uses: sonarsource/sonarcloud-github-action@master
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.100-rc.1.20452.10'
144+
145+
- name: Install dotnet-sonarscanner
146+
run: dotnet tool install --global dotnet-sonarscanner
147+
- name: Running dotnet-sonarscanner
148+
shell: bash
174149
env:
175-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176150
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"
177159
178160
code-ql:
179161
if: github.event_name != 'pull_request'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,5 @@ bunit.docs/log.txt
334334

335335
.store
336336
*coverage*.info
337+
.sonarqube
338+
tests/*/coverage

CHANGELOG.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,98 @@
22

33
All notable changes to **bUnit** will be documented in this file. The project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
<!-- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) -->
6+
7+
## [UNRELEASED BETA 11]
8+
9+
The following section list all changes in beta-11.
10+
11+
### Added
12+
List of new features.
13+
14+
- Two new overloads to the `RenderFragment()` and `ChildContent()` component parameter factory methods have been added that takes a `RenderFragment` as input. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
15+
16+
- Added a `ComponentParameterCollection` type. The `ComponentParameterCollection` is a collection of component parameters, that knows how to turn those components parameters into a `RenderFragment`, which will render a component and pass any parameters inside the collection to that component. That logic was spread out over multiple places in bUnit, and is now owned by the `ComponentParameterCollection` type. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
17+
18+
- Added additional placeholder services for `NavigationManager`, `HttpClient`, and `IStringLocalizer`, to make it easier for users to figure out why a test is failing due to missing service registration before rendering a component. By [@joro550](https://github.com/joro550) in [#223](https://github.com/egil/bUnit/pull/223).
19+
20+
- Added `Key` class that represents a keyboard key and helps to avoid constructing `KeyboardEventArgs` object manually. The key can be passed to `KeyPress`, `KeyDown`, or `KeyUp` helper methods to raise keyboard events. The `Key` class provides static special keys or can be obtained from character or string. Keys can be combined with key modifiers: `Key.Enter + Key.Alt`.
21+
22+
For example, this makes it easier to trigger keyboard events on an element:
23+
24+
```csharp
25+
var cut = ctx.RenderComponent<ComponentWithKeyboardEvents>();
26+
var element = cut.Find("input");
27+
28+
element.KeyDown(Key.Enter + Key.Control); // Triggers onkeydown event with Ctrl + Enter
29+
element.KeyUp(Key.Control + Key.Shift + 'B'); // Triggers onkeyup event with Ctrl + Shift + B
30+
element.KeyPress('1'); // Triggers onkeypress event with key 1
31+
element.KeyDown(Key.Alt + "<"); // Triggers onkeydown event with Alt + <
32+
```
33+
34+
By [@duracellko](https://github.com/duracellko) in [#101](https://github.com/egil/bUnit/issues/101).
35+
36+
- Added support for registering/adding components to a test context root render tree, which components under test is rendered inside. This allows you to simplify the "arrange" step of a test when a component under test requires a certain render tree as its parent, e.g. a cascading value.
37+
38+
For example, to pass a cascading string value `foo` to all components rendered with the test context, do the following:
39+
40+
```csharp
41+
ctx.RenderTree<CascadingValue<string>>(parameters => parameters.Add(p => p.Value, "foo"));
42+
var cut = ctx.RenderComponent<ComponentReceivingFoo>();
43+
```
44+
45+
By [@egil](https://github.com/egil) in [#236](https://github.com/egil/bUnit/pull/236).
46+
47+
- Added "catch-all" `Setup` method to bUnit's mock JS runtime, that allows you to specify only the type when setting up a planned invocation. By [@nemesv](https://github.com/nemesv) in [#234](https://github.com/egil/bUnit/issues/234).
48+
49+
### Changed
50+
List of changes in existing functionality.
51+
52+
- The `ComponentParameterBuilder` has been renamed to `ComponentParameterCollectionBuilder`, since it now builds the `ComponentParameterCollection` type, introduced in this release of bUnit. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
53+
54+
- `ComponentParameterCollectionBuilder` now allows adding cascading values that is not directly used by the component type it targets. This makes it possible to add cascading values to children of the target component. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
55+
56+
- The `Add(object)` has been replaced by `AddCascadingValue(object)` in `ComponentParameterCollectionBuilder`, to make it more clear that an unnamed cascading value is being passed to the target component or one of its child components. It is also possible to pass unnamed cascading values using the `Add(parameterSelector, value)` method, which now correctly detect if the selected cascading value parameter is named or unnamed. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
57+
58+
- It is now possible to call the `Add()`, `AddChildContent()` methods on `ComponentParameterCollectionBuilder`, and the factory methods `RenderFragment()`, `ChildContent()`, and `Template()`, _**multiple times**_ for the same parameter, if it is of type `RenderFragment` or `RenderFragment<TValue>`. Doing so previously would either result in an exception or just the last passed `RenderFragment` to be used. Now all the provided `RenderFragment` or `RenderFragment<TValue>` will be combined at runtime into a single `RenderFragment` or `RenderFragment<TValue>`.
59+
60+
For example, this makes it easier to pass e.g. both a markup string and a component to a `ChildContent` parameter:
61+
62+
```csharp
63+
var cut = ctx.RenderComponent<Component>(parameters => parameters
64+
.AddChildContent("<h1>Below you will find a most interesting alert!</h1>")
65+
.AddChildContent<Alert>(childParams => childParams
66+
.Add(p => p.Heading, "Alert heading")
67+
.Add(p => p.Type, AlertType.Warning)
68+
.AddChildContent("<p>Hello World</p>")
69+
)
70+
);
71+
```
72+
By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203).
73+
74+
- All test doubles are now in the same namespace, `Bunit.TestDoubles`. So all import statements for `Bunit.TestDoubles.JSInterop` and `Bunit.TestDoubles.Authorization` must be changed to `Bunit.TestDoubles`. By [@egil](https://github.com/egil) in [#223](https://github.com/egil/bUnit/pull/223).
75+
76+
- Marked MarkupMatches methods as assertion methods to stop SonarSource analyzers complaining about missing assertions in tests. By [@egil](https://github.com/egil) in [#229](https://github.com/egil/bUnit/pull/229).
77+
78+
- `AddTestAuthorization` now extends `TestContext` instead of `TestServiceProvider`, and also automatically adds the `CascadingAuthenticationState` component to the root render tree. [@egil](https://github.com/egil) in [#237](https://github.com/egil/bUnit/pull/367).
79+
80+
### Deprecated
81+
List of soon-to-be removed features.
82+
83+
### Removed
84+
List of now removed features.
85+
86+
- The async event dispatcher helper methods have been removed (e.g. `ClickAsync()`), as they do not provide any benefit. If you have an event that triggers async operations in the component under test, instead use `cut.WaitForState()` or `cut.WaitForAssertion()` to await the expected state in the component.
87+
88+
### Fixed
89+
List of any bug fixes.
90+
91+
- Using the ComponentParameterCollectionBuilder's `Add(p => p.Param, value)` method to add a unnamed cascading value didn't create an unnnamed cascading value parameter. By [@egil](https://github.com/egil) in [#203](https://github.com/egil/bUnit/pull/203). Credits to [Ben Sampica (@benjaminsampica)](https://github.com/benjaminsampica) for reporting and helping investigate this issue.
92+
- Triggered events now bubble correctly up the DOM tree and triggers other events of the same type. This is a **potentially breaking change,** since this changes the behaviour of event triggering and thus you might see tests start breaking as a result hereof. By [@egil](https://github.com/egil) in [#119](https://github.com/egil/bUnit/issues/119).
93+
594
## [1.0.0-beta 10] - 2020-09-15
695

7-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
96+
The following section list all changes in beta-10.
897

998
### Added
1099
List of new features.

docs/.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ trim_trailing_whitespace = false
1010

1111
[*.{cs,razor}]
1212
tab_size = 2
13+
indent_style = space
1314
dotnet_diagnostic.BL0001.severity = none
1415
dotnet_diagnostic.BL0002.severity = none
1516
dotnet_diagnostic.BL0003.severity = none
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Cascading value: @Value
2+
@code
3+
{
4+
[CascadingParameter]
5+
public string Value { get; set; }
6+
}

docs/samples/components/UserInfo.razor

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,17 @@
99
{
1010
<h1>Please log in!</h1>
1111
}
12-
<CascadingAuthenticationState>
13-
<AuthorizeView>
14-
<Authorized>
15-
<p>State: Authorized</p>
16-
</Authorized>
17-
<Authorizing>
18-
<p>State: Authorizing</p>
19-
</Authorizing>
20-
<NotAuthorized>
21-
<p>State: Not authorized</p>
22-
</NotAuthorized>
23-
</AuthorizeView>
24-
</CascadingAuthenticationState>
25-
12+
<AuthorizeView>
13+
<Authorized>
14+
<p>State: Authorized</p>
15+
</Authorized>
16+
<Authorizing>
17+
<p>State: Authorizing</p>
18+
</Authorizing>
19+
<NotAuthorized>
20+
<p>State: Not authorized</p>
21+
</NotAuthorized>
22+
</AuthorizeView>
2623
@code
2724
{
2825
bool isAuthenticated = false;

docs/samples/components/UserRights.razor

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@
22
@using System.Security.Claims
33
@using System.Globalization
44

5-
<CascadingAuthenticationState>
5+
<AuthorizeView>
6+
<h1>Hi @context.User.Identity.Name, you have these claims and rights:</h1>
7+
</AuthorizeView>
8+
<ul>
69
<AuthorizeView>
7-
<h1>Hi @context.User.Identity.Name, you have these claims and rights:</h1>
10+
@foreach (var claim in @context.User.FindAll(x => x.Type != ClaimTypes.Name))
11+
{
12+
<li>@GetClaimName(claim): @claim.Value</li>
13+
}
814
</AuthorizeView>
9-
<ul>
10-
<AuthorizeView>
11-
@foreach (var claim in @context.User.FindAll(x => x.Type != ClaimTypes.Name))
12-
{
13-
<li>@GetClaimName(claim): @claim.Value</li>
14-
}
15-
</AuthorizeView>
16-
<AuthorizeView Roles="superuser">
17-
<li>You have the role SUPER USER</li>
18-
</AuthorizeView>
19-
<AuthorizeView Roles="admin">
20-
<li>You have the role ADMIN</li>
21-
</AuthorizeView>
22-
<AuthorizeView Policy="content-editor">
23-
<li>You are a CONTENT EDITOR</li>
24-
</AuthorizeView>
25-
</ul>
26-
</CascadingAuthenticationState>
15+
<AuthorizeView Roles="superuser">
16+
<li>You have the role SUPER USER</li>
17+
</AuthorizeView>
18+
<AuthorizeView Roles="admin">
19+
<li>You have the role ADMIN</li>
20+
</AuthorizeView>
21+
<AuthorizeView Policy="content-editor">
22+
<li>You are a CONTENT EDITOR</li>
23+
</AuthorizeView>
24+
</ul>
2725

2826
@code
2927
{

docs/samples/tests/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
44
<IsPackable>false</IsPackable>
5-
<LangVersion>8.0</LangVersion>
5+
<LangVersion>9.0</LangVersion>
66
<RazorLangVersion>3.0</RazorLangVersion>
77
</PropertyGroup>
88
</Project>

docs/samples/tests/mstest/BunitTestContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Bunit.Docs.Samples
88
{
9-
public abstract class BunitTestContext : ITestContext, IDisposable
9+
public abstract class BunitTestContext : IDisposable
1010
{
1111
private Bunit.TestContext _context;
1212

@@ -29,7 +29,7 @@ public void Dispose()
2929
public IRenderedComponent<TComponent> RenderComponent<TComponent>(params ComponentParameter[] parameters) where TComponent : IComponent
3030
=> _context?.RenderComponent<TComponent>(parameters) ?? throw new InvalidOperationException("MSTest has not started executing tests yet");
3131

32-
public IRenderedComponent<TComponent> RenderComponent<TComponent>(Action<ComponentParameterBuilder<TComponent>> parameterBuilder) where TComponent : IComponent
32+
public IRenderedComponent<TComponent> RenderComponent<TComponent>(Action<ComponentParameterCollectionBuilder<TComponent>> parameterBuilder) where TComponent : IComponent
3333
=> _context?.RenderComponent<TComponent>(parameterBuilder) ?? throw new InvalidOperationException("MSTest has not started executing tests yet");
3434
}
3535
}

0 commit comments

Comments
 (0)