Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ dotnet_diagnostic.BL0006.severity = none

[*.cs]

dotnet_diagnostic.IDE0022.severity = silent # IDE0022: Use block body for methods
dotnet_diagnostic.IDE0090.severity = silent # IDE0090: Use 'new(...)'
dotnet_diagnostic.S125.severity = suggestion # S125: Sections of code should not be commented out
dotnet_diagnostic.S927.severity = suggestion # S927: Parameter names should match base declaration and other partial definitions
dotnet_diagnostic.S1075.severity = suggestion # S1075: URIs should not be hardcoded
dotnet_diagnostic.S1186.severity = suggestion # S1186: Methods should not be empty
dotnet_diagnostic.S1186.severity = silent # S1186: Methods should not be empty
dotnet_diagnostic.S1199.severity = suggestion # S1199: Nested code blocks should not be used
dotnet_diagnostic.S3925.severity = suggestion # S3925: "ISerializable" should be implemented correctly

[tests/**.cs]
[src/bunit.web/EventDispatchExtensions/**.cs]
dotnet_diagnostic.S107.severity = none # S107: Methods should not have too many parameters

dotnet_diagnostic.S3459.severity = suggestion # S3459: Unassigned members should be removed
[tests/**.cs]
dotnet_diagnostic.S125.severity = none # S125: Sections of code should not be commented out
dotnet_diagnostic.CA2012.severity = none # CA2012: Use ValueTasks correctly
dotnet_diagnostic.S3459.severity = none # S3459: Unassigned members should be removed
dotnet_diagnostic.S1186.severity = none # S1186: Methods should not be empty
19 changes: 7 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: "CI/CD"

on:
pull_request:
branches:
- dev
- main
types:
- opened
- synchronize
Expand Down Expand Up @@ -229,21 +232,13 @@ jobs:
- name: Creating library package for release
if: github.event_name == 'release'
run: |
dotnet pack -c Release -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=main -p:ContinuousIntegrationBuild=true /p:PublicRelease=true
dotnet pack src/bunit/ -c Release -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=main -p:ContinuousIntegrationBuild=true /p:PublicRelease=true
dotnet pack src/bunit.template/ -c Release -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=main -p:ContinuousIntegrationBuild=true /p:PublicRelease=true
dotnet pack -c Release -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=$BRANCH -p:ContinuousIntegrationBuild=true /p:PublicRelease=true
dotnet pack src/bunit/ -c Release -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=$BRANCH -p:ContinuousIntegrationBuild=true /p:PublicRelease=true
dotnet pack src/bunit.template/ -c Release -o ${GITHUB_WORKSPACE}/packages -p:RepositoryBranch=$BRANCH -p:ContinuousIntegrationBuild=true /p:PublicRelease=true

- name: Push packages to GitHub Package Registry
run: |
for f in ${GITHUB_WORKSPACE}/packages/*.nupkg
do
curl -vX PUT -u "egil:${{ secrets.GITHUB_TOKEN }}" -F package=@$f https://nuget.pkg.github.com/egil/
done
shell: bash
run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/'*.nupkg' -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/egil/index.json --skip-duplicate --no-symbols true

- name: Push packages to NuGet
if: github.event_name == 'release'
run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/'*.nupkg' -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols true

# - name: Push packages to GitHub Package Registry
# run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/'*.nupkg' --skip-duplicate
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ List of new features.

By [@egil](https://github.com/egil) in [#288](https://github.com/egil/bUnit/pull/288).

- Added support for registering services in bUnits `Services` collection that implements `IAsyncDisposable`. Suggested by [@jmaillet](https://github.com/jmaillet) in [#249](https://github.com/egil/bUnit/issues/249).

### Changed
List of changes in existing functionality.

Expand Down Expand Up @@ -132,6 +134,8 @@ List of any bug fixes.

- When an element, found in the DOM tree using the `Find()`, method was removed because of an event handler trigger on it, e.g. an `cut.Find("button").Click()` event trigger method, an `ElementNotFoundException` was thrown. Reported by [@nickmuller](https://github.com/nickmuller) in [#251](https://github.com/egil/bUnit/issues/251).

- In the built-in fake authentication system in bUnit, roles and claims were not available in components through the a cascading parameter of type `Task<AuthenticationState>`. Reported by [@AFAde](https://github.com/AFAde) in [#253](https://github.com/egil/bUnit/discussions/253) and fixed in [#291](https://github.com/egil/bUnit/pull/291) by [@egil](https://github.com/egil).

## [1.0.0-beta 11] - 2020-10-26

The following section list all changes in beta-11.
Expand Down
8 changes: 6 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37" PrivateAssets="All" />
</ItemGroup>
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.15.0.24505">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions src/bunit.core/ComponentParameter.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Diagnostics.CodeAnalysis;

namespace Bunit
{
/// <summary>
/// Represents a single parameter supplied to an <see cref="Microsoft.AspNetCore.Components.IComponent"/>
/// component under test.
/// </summary>
[SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "<Pending>")]
public readonly struct ComponentParameter : IEquatable<ComponentParameter>
{
/// <summary>
Expand Down
13 changes: 0 additions & 13 deletions src/bunit.core/GlobalSuppressions.cs

This file was deleted.

11 changes: 9 additions & 2 deletions src/bunit.core/TestServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class TestServiceProvider : IServiceProvider, IServiceCollection,
{
private readonly IServiceCollection _serviceCollection;
private ServiceProvider? _serviceProvider;

/// <summary>
/// Gets whether this <see cref="TestServiceProvider"/> has been initialized, and
/// no longer will accept calls to the <c>AddService</c>'s methods.
Expand Down Expand Up @@ -78,7 +78,14 @@ public object GetService(Type serviceType)
/// <inheritdoc/>
public void Dispose()
{
_serviceProvider?.Dispose();
if (_serviceProvider is null) return;

var disposedTask = _serviceProvider.DisposeAsync().AsTask();

if (!disposedTask.IsCompleted)
disposedTask.GetAwaiter().GetResult();

_serviceProvider.Dispose();
}

/// <inheritdoc/>
Expand Down
6 changes: 0 additions & 6 deletions src/bunit.web/GlobalSuppressions.cs

This file was deleted.

6 changes: 4 additions & 2 deletions src/bunit.web/JSInterop/BunitJSInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public BunitJSInterop()
{
Mode = JSRuntimeMode.Strict;
JSRuntime = new BunitJSRuntime(this);
#if NET5_0
AddCustomHandlers();
#endif
}

/// <summary>
Expand Down Expand Up @@ -83,13 +85,13 @@ internal virtual void RegisterInvocation(JSRuntimeInvocation invocation)
return result;
}

#if NET5_0
private void AddCustomHandlers()
{
#if NET5_0
AddInvocationHandler(new FocusAsyncInvocationHandler());
AddInvocationHandler(new VirtualizeJSRuntimeInvocationHandler());
AddInvocationHandler(new LooseModeJSObjectReferenceInvocationHandler(this));
#endif
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ private static AuthenticationState CreateAuthenticationState(
IEnumerable<string>? roles = null,
IEnumerable<Claim>? claims = null)
{
var identity = new FakeIdentity { Name = username };
var testPrincipal = new FakePrincipal { Identity = identity, Roles = roles ?? Array.Empty<string>() };
var principal = new ClaimsPrincipal(testPrincipal);
roles = roles ?? Array.Empty<string>();
claims = claims ?? Array.Empty<Claim>();

if (claims is not null && claims.Any())
{
principal.AddIdentity(new ClaimsIdentity(claims));
}
var usernameClaim = new Claim(ClaimsIdentity.DefaultNameClaimType, username);
var roleClaims = roles.Select(x => new Claim(ClaimsIdentity.DefaultRoleClaimType, x));
var allClaims = roleClaims.Concat(claims).Prepend(usernameClaim);

var identity = new ClaimsIdentity(claims: allClaims, authenticationType: "bUnit Fake Authentication");
var principal = new ClaimsPrincipal(identity);

return new AuthenticationState(principal);
}
Expand All @@ -117,7 +118,7 @@ private static AuthenticationState CreateAuthenticationState(
/// <returns>Instance of AuthenticationState for an unauthenticated user.</returns>
private static AuthenticationState CreateUnauthenticationState()
{
var principal = new ClaimsPrincipal(new FakePrincipal());
var principal = new ClaimsPrincipal(new ClaimsIdentity());
return new AuthenticationState(principal);
}
}
Expand Down
47 changes: 0 additions & 47 deletions src/bunit.web/TestDoubles/Authorization/FakeIdentity.cs

This file was deleted.

36 changes: 0 additions & 36 deletions src/bunit.web/TestDoubles/Authorization/FakePrincipal.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/bunit.xunit/GlobalSuppressions.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/bunit.xunit/bunit.xunit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SourceFileFinder" Version="1.0.0" />
<PackageReference Include="System.Reflection.Metadata" Version="1.8.1" />
<PackageReference Include="SourceFileFinder" Version="1.0.1" />
<PackageReference Include="System.Reflection.Metadata" Version="5.0.0" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
Expand Down
4 changes: 4 additions & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@
<PackageReference Include="AutoFixture.Xunit2" Version="4.14.0" />
<PackageReference Include="Xunit.Combinatorial" Version="1.4.1" />
<PackageReference Include="coverlet.msbuild" Version="2.9.0" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.15.0.24505">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion tests/bunit.core.tests/ComponentParameterCollectionTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Bunit.TestDoubles;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Shouldly;
Expand Down
18 changes: 0 additions & 18 deletions tests/bunit.core.tests/GlobalSuppressions.cs

This file was deleted.

3 changes: 3 additions & 0 deletions tests/bunit.core.tests/RazorTesting/FixtureBaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Shouldly;
using Xunit;
Expand All @@ -14,6 +15,7 @@ private class FixtureComponent : FixtureBase<FixtureComponent>
}

[Fact(DisplayName = "Setup, SetupAsync and Test methods are called in the correct order")]
[SuppressMessage("Minor Bug", "S4158:Empty collections should not be accessed or iterated", Justification = "False positive!")]
public async Task Test001()
{
var callLog = new List<string>(3);
Expand All @@ -40,6 +42,7 @@ Task SetupAsync(FixtureComponent fixture)
}

[Fact(DisplayName = "Setup, SetupAsync and TestAsync methods are called in the correct order")]
[SuppressMessage("Minor Bug", "S4158:Empty collections should not be accessed or iterated", Justification = "False positive!")]
public async Task Test002()
{
var callLog = new List<string>(3);
Expand Down
6 changes: 3 additions & 3 deletions tests/bunit.core.tests/Rendering/ComponentParameterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public static IEnumerable<object[]> GetEqualsTestData()
yield return new object[] { p1, p5, false };
}

[Fact(DisplayName = "Creating a cascading value throws")]
[Fact(DisplayName = "Creating a cascading value with null throws")]
public void Test001()
{
Should.Throw<ArgumentNullException>(() => ComponentParameter.CreateCascadingValue(null, null!));
Should.Throw<ArgumentNullException>(() => { ComponentParameter p = (null, null, true); });
Should.Throw<ArgumentNullException>(() => (ComponentParameter)(null, null, true));
}

[Fact(DisplayName = "Creating a regular parameter without a name throws")]
public void Test002()
{
Should.Throw<ArgumentNullException>(() => ComponentParameter.CreateParameter(null!, null));
Should.Throw<ArgumentNullException>(() => { ComponentParameter p = (null, null, false); });
Should.Throw<ArgumentNullException>(() => (ComponentParameter)(null, null, false));
}

[Theory(DisplayName = "Equals compares correctly")]
Expand Down
Loading