Skip to content

Commit

Permalink
Release of new minor version v1.5
Browse files Browse the repository at this point in the history
Release of new minor version v1.5
  • Loading branch information
egil authored Feb 15, 2022
2 parents dd3196d + 544d3eb commit b046939
Show file tree
Hide file tree
Showing 37 changed files with 646 additions and 137 deletions.
32 changes: 26 additions & 6 deletions .github/workflows/verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,35 @@ jobs:
dotnet pack src/bunit/ -c release -o ${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true
dotnet pack src/bunit.template/ -c release -o ${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true
# Excluding windows because the restore step doesnt seem to work correct.
- name: ✔ Verify template
- name: ✳ Install bUnit template
if: matrix.os != 'windows-latest'
run: |
dotnet new --install bunit.template::${NBGV_NuGetPackageVersion} --nuget-source ${GITHUB_WORKSPACE}/packages
dotnet new bunit --no-restore -o ${GITHUB_WORKSPACE}/TemplateTest
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${GITHUB_WORKSPACE}/TemplateTest/Directory.Build.props
dotnet restore ${GITHUB_WORKSPACE}/TemplateTest --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
dotnet test ${GITHUB_WORKSPACE}/TemplateTest --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none
# Excluding windows because the restore step doesnt seem to work correct.
- name: ✔ Verify xUnit template
if: matrix.os != 'windows-latest'
run: |
dotnet new bunit --no-restore -o ${GITHUB_WORKSPACE}/TemplateTestXunit
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${GITHUB_WORKSPACE}/TemplateTestXunit/Directory.Build.props
dotnet restore ${GITHUB_WORKSPACE}/TemplateTestXunit --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
dotnet test ${GITHUB_WORKSPACE}/TemplateTestXunit --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none
- name: ✔ Verify NUnit template
if: matrix.os != 'windows-latest'
run: |
dotnet new bunit --framework nunit --no-restore -o ${GITHUB_WORKSPACE}/TemplateTestNunit
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${GITHUB_WORKSPACE}/TemplateTestNunit/Directory.Build.props
dotnet restore ${GITHUB_WORKSPACE}/TemplateTestNunit --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
dotnet test ${GITHUB_WORKSPACE}/TemplateTestNunit --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none
- name: ✔ Verify MSTest template
if: matrix.os != 'windows-latest'
run: |
dotnet new bunit --framework mstest --no-restore -o ${GITHUB_WORKSPACE}/TemplateTestMstest
echo '<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></Project>' >> ${GITHUB_WORKSPACE}/TemplateTestMstest/Directory.Build.props
dotnet restore ${GITHUB_WORKSPACE}/TemplateTestMstest --source ${GITHUB_WORKSPACE}/packages --source https://api.nuget.org/v3/index.json
dotnet test ${GITHUB_WORKSPACE}/TemplateTestMstest --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none
# DocFx only works well on Windows currently
- name: 📄 Build documentation
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ All notable changes to **bUnit** will be documented in this file. The project ad

## [Unreleased]

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.

Also a big shout out to **bUnit's sponsors** who helped make this release happen.

**The higher tier sponsors are:**

- [Progress Telerik](https://github.com/Progress-Telerik)
- [Syncfusion](https://github.com/syncfusion)
- [CTRL Informatique](https://github.com/CTRL-Informatique)

**Other sponsors are:**

- [Hassan Rezk Habib (@Garderoben)](https://github.com/hassanhabib)
- [Jonny Larsson (@Garderoben)](https://github.com/Garderoben)
- [Domn Werner (@domn1995)](https://github.com/domn1995)
- [Mladen Macanović (@stsrki)](https://github.com/stsrki)
- [@ChristopheDEBOVE](https://github.com/ChristopheDEBOVE)

### Added

- Added `FakeSignOutSessionStateManage` type in Blazor, that makes it easy to test components that use the `SignOutSessionStateManage` type. By [@linkdotnet](https://github.com/linkdotnet).
- 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).
- Added more optional arguments for `Click` and `DoubleClick` extensions which were introduced in .NET 5 and .NET 6. By [@linkdotnet](https://github.com/linkdotnet).
- Added template support for `Nunit` and `MSTest` unit test frameworks. By [@denisekart](https://github.com/denisekart).

### Fixed

- 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)

## [1.4.15] - 2021-12-18

This release reintroduces `Stub<TComponent>` and related back into the main library, so the "preview" library `bunit.web.mock` is already obsolete.
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ bUnit accepts fixes and features. Here is what you should do when writing code f

- 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).
- 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.
- This repository follow the truck-based development approach, meaning changes should be based on the `main` branch
- This repository follow the truck-based development approach, meaning changes should be based on the `main` branch.
- Use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) style commit messages.
- Any code or documentation you share with the bUnit projects should fall under the projects license agreement.

Here are some resources to help you get started on how to contribute code or new content:
Expand Down
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Label="Configuration variables">
<DotNet3Version>3.1.1</DotNet3Version>
<DotNet3Version>3.1.22</DotNet3Version>
<DotNet5Version>5.0.0</DotNet5Version>
<DotNet6Version>6.0.0</DotNet6Version>
</PropertyGroup>
Expand Down Expand Up @@ -47,14 +47,14 @@
<!-- Shared code analyzers used for all projects in the solution -->
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.5.1" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="1.0.681" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.33.0.40503" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="1.0.694" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.35.0.42613" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Label="Implicit usings" Condition="$(MSBuildProjectName) != 'bunit.template' AND $(MSBuildProjectName) != 'bunit'">
<Using Include="Microsoft.AspNetCore.Components" />
<Using Include="Microsoft.AspNetCore.Components.RenderTree" />
<Using Include="Microsoft.AspNetCore.Components.Rendering" />
<Using Include="Microsoft.AspNetCore.Components.Rendering" />
<Using Include="Microsoft.Extensions.DependencyInjection" />
<Using Include="System.Runtime.Serialization" />
<Using Include="System.Diagnostics.CodeAnalysis" />
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ A huge thank you to the [sponsors of my work with bUnit](https://github.com/spon

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!

These good people have contributed code or documentation to bUnit:

<a href="https://github.com/bUnit-dev/bUnit/graphs/contributors">
<img src="https://contrib.rocks/image?repo=bUnit-dev/bUnit" />
</a>

## Code of conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.
Expand Down
32 changes: 26 additions & 6 deletions docs/site/docs/getting-started/create-test-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ title: Creating a new bUnit test project

# Creating a new bUnit test project

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.
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.

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.
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.

## Creating a test project manually

Expand Down Expand Up @@ -57,7 +57,7 @@ dotnet add package bunit --version #{NBGV_NuGetPackageVersion}#

**3. Configure project settings**

The test projects setting needs to be set to the following:
The test projects setting needs to be set to the following:

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

## Creating a test project with bUnit template

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.
To skip a few steps in the guide above, use the [bUnit test project template](https://www.nuget.org/packages/bunit.template/).

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

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

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

# [xUnit](#tab/xunit)

```dotnetcli
dotnet new bunit -o <NAME OF TEST PROJECT>
dotnet new bunit --framework xunit -o <NAME OF TEST PROJECT>
```

The `-o` option in the `dotnet new` command above is used to specify the name of the test project.
# [NUnit](#tab/nunit)

```dotnetcli
dotnet new bunit --framework nunit -o <NAME OF TEST PROJECT>
```

# [MSTest](#tab/mstest)

```dotnetcli
dotnet new bunit --framework mstest -o <NAME OF TEST PROJECT>
```

***

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:

- `xunit` - [xUnit](https://xunit.net/),
- `nunit` - [NUnit](https://nunit.org/),
- `mstest` - [MSTest](https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest)

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

Expand Down
7 changes: 7 additions & 0 deletions src/bunit.core/ComponentParameterCollectionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ public ComponentParameterCollectionBuilder<TComponent> AddChildContent(RenderFra
if (!HasChildContentParameter())
throw new ArgumentException($"The component '{typeof(TComponent)}' does not have a {ChildContent} [Parameter] attribute.", nameof(childContent));

if (HasGenericChildContentParameter())
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));

return AddParameter(ChildContent, childContent);
}

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

private static bool HasGenericChildContentParameter()
=> TComponentType.GetProperty(ChildContent, BindingFlags.Public | BindingFlags.Instance) is PropertyInfo ccProp
&& ccProp.PropertyType.IsGenericType;

private ComponentParameterCollectionBuilder<TComponent> AddParameter<TValue>(string name, [AllowNull] TValue value)
{
parameters.Add(ComponentParameter.CreateParameter(name, value));
Expand Down
19 changes: 18 additions & 1 deletion src/bunit.core/Rendering/ITestRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,24 @@ public interface ITestRenderer
/// <param name="fieldInfo">Information that the renderer can use to update the state of the existing render tree to match the UI.</param>
/// <param name="eventArgs">Arguments to be passed to the event handler.</param>
/// <returns>A <see cref="Task"/> which will complete once all asynchronous processing related to the event has completed.</returns>
Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs);
Task DispatchEventAsync(
ulong eventHandlerId,
EventFieldInfo fieldInfo,
EventArgs eventArgs);

/// <summary>
/// Notifies the renderer that an event has occurred.
/// </summary>
/// <param name="eventHandlerId">The <see cref="RenderTreeFrame.AttributeEventHandlerId"/> value from the original event attribute.</param>
/// <param name="fieldInfo">Information that the renderer can use to update the state of the existing render tree to match the UI.</param>
/// <param name="eventArgs">Arguments to be passed to the event handler.</param>
/// <param name="ignoreUnknownEventHandlers">Set to true to ignore the <see cref="UnknownEventHandlerIdException"/>.</param>
/// <returns>A <see cref="Task"/> which will complete once all asynchronous processing related to the event has completed.</returns>
Task DispatchEventAsync(
ulong eventHandlerId,
EventFieldInfo fieldInfo,
EventArgs eventArgs,
bool ignoreUnknownEventHandlers);

/// <summary>
/// Renders the <paramref name="renderFragment"/>.
Expand Down
16 changes: 12 additions & 4 deletions src/bunit.core/Rendering/TestRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,21 @@ public IRenderedComponentBase<TComponent> RenderComponent<TComponent>(ComponentP
}

/// <inheritdoc/>
public new Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs)
public new Task DispatchEventAsync(
ulong eventHandlerId,
EventFieldInfo fieldInfo,
EventArgs eventArgs) => DispatchEventAsync(eventHandlerId, fieldInfo, eventArgs, ignoreUnknownEventHandlers: false);

/// <inheritdoc/>
public Task DispatchEventAsync(
ulong eventHandlerId,
EventFieldInfo fieldInfo,
EventArgs eventArgs,
bool ignoreUnknownEventHandlers)
{
if (fieldInfo is null)
throw new ArgumentNullException(nameof(fieldInfo));

ResetUnhandledException();

var result = Dispatcher.InvokeAsync(() =>
{
try
Expand All @@ -79,7 +87,7 @@ public IRenderedComponentBase<TComponent> RenderComponent<TComponent>(ComponentP
}
});

if (result.IsFaulted && result.Exception is not null)
if (result.IsFaulted && result.Exception is not null && !(ignoreUnknownEventHandlers && result.Exception.InnerException is UnknownEventHandlerIdException))
{
HandleException(result.Exception);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.core/bunit.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.244" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.255" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.template/bunit.template.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.244" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.255" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 11 additions & 2 deletions src/bunit.template/template/.template.config/dotnetcli.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
"skipRestore": {
"longName": "no-restore",
"shortName": ""
},
"UnitTestFramework": {
"longName": "framework",
"shortName": ""
}
}
}
},
"usageExamples": [
"--framework xunit",
"--framework nunit",
"--framework mstest"
]
}
Loading

0 comments on commit b046939

Please sign in to comment.