Skip to content

Commit b046939

Browse files
authored
Release of new minor version v1.5
Release of new minor version v1.5
2 parents dd3196d + 544d3eb commit b046939

37 files changed

+646
-137
lines changed

.github/workflows/verification.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,35 @@ jobs:
7373
dotnet pack src/bunit/ -c release -o ${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true
7474
dotnet pack src/bunit.template/ -c release -o ${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true
7575
76-
# Excluding windows because the restore step doesnt seem to work correct.
77-
- name: ✔ Verify template
76+
- name: ✳ Install bUnit template
7877
if: matrix.os != 'windows-latest'
7978
run: |
8079
dotnet new --install bunit.template::${NBGV_NuGetPackageVersion} --nuget-source ${GITHUB_WORKSPACE}/packages
81-
dotnet new bunit --no-restore -o ${GITHUB_WORKSPACE}/TemplateTest
82-
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${GITHUB_WORKSPACE}/TemplateTest/Directory.Build.props
83-
dotnet restore ${GITHUB_WORKSPACE}/TemplateTest --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
84-
dotnet test ${GITHUB_WORKSPACE}/TemplateTest --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none
80+
81+
# Excluding windows because the restore step doesnt seem to work correct.
82+
- name: ✔ Verify xUnit template
83+
if: matrix.os != 'windows-latest'
84+
run: |
85+
dotnet new bunit --no-restore -o ${GITHUB_WORKSPACE}/TemplateTestXunit
86+
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${GITHUB_WORKSPACE}/TemplateTestXunit/Directory.Build.props
87+
dotnet restore ${GITHUB_WORKSPACE}/TemplateTestXunit --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
88+
dotnet test ${GITHUB_WORKSPACE}/TemplateTestXunit --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none
89+
90+
- name: ✔ Verify NUnit template
91+
if: matrix.os != 'windows-latest'
92+
run: |
93+
dotnet new bunit --framework nunit --no-restore -o ${GITHUB_WORKSPACE}/TemplateTestNunit
94+
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${GITHUB_WORKSPACE}/TemplateTestNunit/Directory.Build.props
95+
dotnet restore ${GITHUB_WORKSPACE}/TemplateTestNunit --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
96+
dotnet test ${GITHUB_WORKSPACE}/TemplateTestNunit --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none
97+
98+
- name: ✔ Verify MSTest template
99+
if: matrix.os != 'windows-latest'
100+
run: |
101+
dotnet new bunit --framework mstest --no-restore -o ${GITHUB_WORKSPACE}/TemplateTestMstest
102+
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${GITHUB_WORKSPACE}/TemplateTestMstest/Directory.Build.props
103+
dotnet restore ${GITHUB_WORKSPACE}/TemplateTestMstest --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
104+
dotnet test ${GITHUB_WORKSPACE}/TemplateTestMstest --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none
85105
86106
# DocFx only works well on Windows currently
87107
- name: 📄 Build documentation

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ All notable changes to **bUnit** will be documented in this file. The project ad
66

77
## [Unreleased]
88

9+
This first release of 2022 includes a one fix and four additions. A huge thank you to [Steven Giesel (@linkdotnet)](https://github.com/linkdotnet) and [Denis Ekart (@denisekart)](https://github.com/denisekart) for their contributions to this release.
10+
11+
Also a big shout out to **bUnit's sponsors** who helped make this release happen.
12+
13+
**The higher tier sponsors are:**
14+
15+
- [Progress Telerik](https://github.com/Progress-Telerik)
16+
- [Syncfusion](https://github.com/syncfusion)
17+
- [CTRL Informatique](https://github.com/CTRL-Informatique)
18+
19+
**Other sponsors are:**
20+
21+
- [Hassan Rezk Habib (@Garderoben)](https://github.com/hassanhabib)
22+
- [Jonny Larsson (@Garderoben)](https://github.com/Garderoben)
23+
- [Domn Werner (@domn1995)](https://github.com/domn1995)
24+
- [Mladen Macanović (@stsrki)](https://github.com/stsrki)
25+
- [@ChristopheDEBOVE](https://github.com/ChristopheDEBOVE)
26+
27+
### Added
28+
29+
- Added `FakeSignOutSessionStateManage` type in Blazor, that makes it easy to test components that use the `SignOutSessionStateManage` type. By [@linkdotnet](https://github.com/linkdotnet).
30+
- Added a validation to `AddChildContent` method in `ComponentParameterCollectionBuilder` that will throw an exception if the component's `ChildContent` is a generic type. By [@denisekart](https://github.com/denisekart).
31+
- Added more optional arguments for `Click` and `DoubleClick` extensions which were introduced in .NET 5 and .NET 6. By [@linkdotnet](https://github.com/linkdotnet).
32+
- Added template support for `Nunit` and `MSTest` unit test frameworks. By [@denisekart](https://github.com/denisekart).
33+
34+
### Fixed
35+
36+
- Changed `GetDispatchEventTasks` for bubbling events such that handled exceptions are not rethrown later from the `WaitFor...` helpers methods. Reported by [@AndrewStrickland](https://github.com/AndrewStrickland). Fixed by [@linkdotnet](https://github.com/linkdotnet)
37+
938
## [1.4.15] - 2021-12-18
1039

1140
This release reintroduces `Stub<TComponent>` and related back into the main library, so the "preview" library `bunit.web.mock` is already obsolete.

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ bUnit accepts fixes and features. Here is what you should do when writing code f
1515

1616
- Follow the coding conventions used throughout the bUnit project. In general, they align with the AspNetCore teams [coding guidelines](https://github.com/dotnet/aspnetcore/wiki/Engineering-guidelines#coding-guidelines).
1717
- Add, remove, or delete unit tests to cover your changes. Make sure tests are specific to the changes you are making. Tests need to be provided for every bug/feature that is completed.
18-
- This repository follow the truck-based development approach, meaning changes should be based on the `main` branch
18+
- This repository follow the truck-based development approach, meaning changes should be based on the `main` branch.
19+
- Use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) style commit messages.
1920
- Any code or documentation you share with the bUnit projects should fall under the projects license agreement.
2021

2122
Here are some resources to help you get started on how to contribute code or new content:

Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<PropertyGroup Label="Configuration variables">
5-
<DotNet3Version>3.1.1</DotNet3Version>
5+
<DotNet3Version>3.1.22</DotNet3Version>
66
<DotNet5Version>5.0.0</DotNet5Version>
77
<DotNet6Version>6.0.0</DotNet6Version>
88
</PropertyGroup>
@@ -47,14 +47,14 @@
4747
<!-- Shared code analyzers used for all projects in the solution -->
4848
<ItemGroup Label="Code Analyzers">
4949
<PackageReference Include="AsyncFixer" Version="1.5.1" PrivateAssets="All" />
50-
<PackageReference Include="Meziantou.Analyzer" Version="1.0.681" PrivateAssets="All" />
51-
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.33.0.40503" PrivateAssets="All" />
50+
<PackageReference Include="Meziantou.Analyzer" Version="1.0.694" PrivateAssets="All" />
51+
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.35.0.42613" PrivateAssets="All" />
5252
</ItemGroup>
5353

5454
<ItemGroup Label="Implicit usings" Condition="$(MSBuildProjectName) != 'bunit.template' AND $(MSBuildProjectName) != 'bunit'">
5555
<Using Include="Microsoft.AspNetCore.Components" />
5656
<Using Include="Microsoft.AspNetCore.Components.RenderTree" />
57-
<Using Include="Microsoft.AspNetCore.Components.Rendering" />
57+
<Using Include="Microsoft.AspNetCore.Components.Rendering" />
5858
<Using Include="Microsoft.Extensions.DependencyInjection" />
5959
<Using Include="System.Runtime.Serialization" />
6060
<Using Include="System.Diagnostics.CodeAnalysis" />

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ A huge thank you to the [sponsors of my work with bUnit](https://github.com/spon
6666

6767
Shout outs and a big thank you [to all the contributors](https://github.com/bUnit-dev/bUnit/graphs/contributors) to the library, including those that raise issues, provide input to issues, and those who send pull requests. Thank you!
6868

69+
These good people have contributed code or documentation to bUnit:
70+
71+
<a href="https://github.com/bUnit-dev/bUnit/graphs/contributors">
72+
<img src="https://contrib.rocks/image?repo=bUnit-dev/bUnit" />
73+
</a>
74+
6975
## Code of conduct
7076

7177
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.

docs/site/docs/getting-started/create-test-project.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ title: Creating a new bUnit test project
55

66
# Creating a new bUnit test project
77

8-
To write tests, you need a place to put them - a test project. bUnit is not a unit test runner, so a general-purpose test framework like xUnit, NUnit, or MSTest is needed in addition to bUnit in order to write and run tests.
8+
To write tests, you need a place to put them - a test project. bUnit is not a unit test runner, so a general-purpose test framework like xUnit, NUnit, or MSTest is needed in addition to bUnit in order to write and run tests.
99

10-
To use bUnit with xUnit, the easiest approach is to use the bUnit project template described in the [Create a test project with bUnit template](#creating-a-test-project-with-bunit-template) section further down the page. To create a test project manually and in a general-purpose testing frameworks agnostic way, read the following section.
10+
To use bUnit, the easiest approach is to use the bUnit project template described in the [Create a test project with bUnit template](#creating-a-test-project-with-bunit-template) section further down the page. To create a test project manually and in a general-purpose testing frameworks agnostic way, read the following section.
1111

1212
## Creating a test project manually
1313

@@ -57,7 +57,7 @@ dotnet add package bunit --version #{NBGV_NuGetPackageVersion}#
5757

5858
**3. Configure project settings**
5959

60-
The test projects setting needs to be set to the following:
60+
The test projects setting needs to be set to the following:
6161

6262
- the project's SDK needs to be set to `Microsoft.NET.Sdk.Razor`
6363
- set the `<TargetFramework>` to `net6.0`
@@ -176,7 +176,7 @@ The result should be a test project with a `.csproj` that looks like this (non b
176176

177177
## Creating a test project with bUnit template
178178

179-
To skip a few steps in the guide above, use the [bUnit test project template](https://www.nuget.org/packages/bunit.template/). The bUnit project template currently only works with the xUnit general-purpose testing framework, but other frameworks will be supported in the future.
179+
To skip a few steps in the guide above, use the [bUnit test project template](https://www.nuget.org/packages/bunit.template/).
180180

181181
The steps for creating a test project with the bUnit template are as follows:
182182

@@ -198,11 +198,31 @@ dotnet new --install bunit.template::#{NBGV_NuGetPackageVersion}#
198198

199199
Use the following command to create a bUnit with xUnit test project:
200200

201+
# [xUnit](#tab/xunit)
202+
201203
```dotnetcli
202-
dotnet new bunit -o <NAME OF TEST PROJECT>
204+
dotnet new bunit --framework xunit -o <NAME OF TEST PROJECT>
203205
```
204206

205-
The `-o` option in the `dotnet new` command above is used to specify the name of the test project.
207+
# [NUnit](#tab/nunit)
208+
209+
```dotnetcli
210+
dotnet new bunit --framework nunit -o <NAME OF TEST PROJECT>
211+
```
212+
213+
# [MSTest](#tab/mstest)
214+
215+
```dotnetcli
216+
dotnet new bunit --framework mstest -o <NAME OF TEST PROJECT>
217+
```
218+
219+
***
220+
221+
The `--framework` option in the `dotnet new` command above is used to specify the unit testing framework used by the test project. If the `--framework` option is omitted, the default test framework `xunit` will be configured. Currently supported options are the following:
222+
223+
- `xunit` - [xUnit](https://xunit.net/),
224+
- `nunit` - [NUnit](https://nunit.org/),
225+
- `mstest` - [MSTest](https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest)
206226

207227
**3. Add the test project to your solution**
208228

src/bunit.core/ComponentParameterCollectionBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ public ComponentParameterCollectionBuilder<TComponent> AddChildContent(RenderFra
246246
if (!HasChildContentParameter())
247247
throw new ArgumentException($"The component '{typeof(TComponent)}' does not have a {ChildContent} [Parameter] attribute.", nameof(childContent));
248248

249+
if (HasGenericChildContentParameter())
250+
throw new ArgumentException($"Calling AddChildContent on component '{typeof(TComponent)}' with a generic {ChildContent} type (RenderFragment<T>) is not supported. Use the 'Add(p => p.ChildContent, p => {{content}})' method instead.", nameof(childContent));
251+
249252
return AddParameter(ChildContent, childContent);
250253
}
251254

@@ -375,6 +378,10 @@ private static bool HasChildContentParameter()
375378
=> TComponentType.GetProperty(ChildContent, BindingFlags.Public | BindingFlags.Instance) is PropertyInfo ccProp
376379
&& ccProp.GetCustomAttribute<ParameterAttribute>(inherit: false) is not null;
377380

381+
private static bool HasGenericChildContentParameter()
382+
=> TComponentType.GetProperty(ChildContent, BindingFlags.Public | BindingFlags.Instance) is PropertyInfo ccProp
383+
&& ccProp.PropertyType.IsGenericType;
384+
378385
private ComponentParameterCollectionBuilder<TComponent> AddParameter<TValue>(string name, [AllowNull] TValue value)
379386
{
380387
parameters.Add(ComponentParameter.CreateParameter(name, value));

src/bunit.core/Rendering/ITestRenderer.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,24 @@ public interface ITestRenderer
2323
/// <param name="fieldInfo">Information that the renderer can use to update the state of the existing render tree to match the UI.</param>
2424
/// <param name="eventArgs">Arguments to be passed to the event handler.</param>
2525
/// <returns>A <see cref="Task"/> which will complete once all asynchronous processing related to the event has completed.</returns>
26-
Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs);
26+
Task DispatchEventAsync(
27+
ulong eventHandlerId,
28+
EventFieldInfo fieldInfo,
29+
EventArgs eventArgs);
30+
31+
/// <summary>
32+
/// Notifies the renderer that an event has occurred.
33+
/// </summary>
34+
/// <param name="eventHandlerId">The <see cref="RenderTreeFrame.AttributeEventHandlerId"/> value from the original event attribute.</param>
35+
/// <param name="fieldInfo">Information that the renderer can use to update the state of the existing render tree to match the UI.</param>
36+
/// <param name="eventArgs">Arguments to be passed to the event handler.</param>
37+
/// <param name="ignoreUnknownEventHandlers">Set to true to ignore the <see cref="UnknownEventHandlerIdException"/>.</param>
38+
/// <returns>A <see cref="Task"/> which will complete once all asynchronous processing related to the event has completed.</returns>
39+
Task DispatchEventAsync(
40+
ulong eventHandlerId,
41+
EventFieldInfo fieldInfo,
42+
EventArgs eventArgs,
43+
bool ignoreUnknownEventHandlers);
2744

2845
/// <summary>
2946
/// Renders the <paramref name="renderFragment"/>.

src/bunit.core/Rendering/TestRenderer.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,21 @@ public IRenderedComponentBase<TComponent> RenderComponent<TComponent>(ComponentP
5959
}
6060

6161
/// <inheritdoc/>
62-
public new Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs)
62+
public new Task DispatchEventAsync(
63+
ulong eventHandlerId,
64+
EventFieldInfo fieldInfo,
65+
EventArgs eventArgs) => DispatchEventAsync(eventHandlerId, fieldInfo, eventArgs, ignoreUnknownEventHandlers: false);
66+
67+
/// <inheritdoc/>
68+
public Task DispatchEventAsync(
69+
ulong eventHandlerId,
70+
EventFieldInfo fieldInfo,
71+
EventArgs eventArgs,
72+
bool ignoreUnknownEventHandlers)
6373
{
6474
if (fieldInfo is null)
6575
throw new ArgumentNullException(nameof(fieldInfo));
6676

67-
ResetUnhandledException();
68-
6977
var result = Dispatcher.InvokeAsync(() =>
7078
{
7179
try
@@ -79,7 +87,7 @@ public IRenderedComponentBase<TComponent> RenderComponent<TComponent>(ComponentP
7987
}
8088
});
8189

82-
if (result.IsFaulted && result.Exception is not null)
90+
if (result.IsFaulted && result.Exception is not null && !(ignoreUnknownEventHandlers && result.Exception.InnerException is UnknownEventHandlerIdException))
8391
{
8492
HandleException(result.Exception);
8593
}

src/bunit.core/bunit.core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.244" PrivateAssets="All" />
18+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.255" PrivateAssets="All" />
1919
</ItemGroup>
2020

2121
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">

0 commit comments

Comments
 (0)