Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net 5 support #187

Merged
merged 37 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
77cba3f
Multi target frameworks support, many nullable warnings and errors re…
egil Aug 12, 2020
dd8af6c
updated build script
egil Aug 12, 2020
96bd17d
Update .github/workflows/CI-PR.yml
egil Aug 12, 2020
d9a5054
Update .github/workflows/CI-PR.yml
egil Aug 12, 2020
3f7880e
updated build script
egil Aug 12, 2020
c2f2467
updated build script
egil Aug 12, 2020
1a1bdfb
updated build script
egil Aug 12, 2020
3a5474b
updated build script 2
egil Aug 12, 2020
397045e
updated nerdbank gitversioning in bunit.csproj
egil Aug 12, 2020
fe2f47a
update to template build params
egil Aug 12, 2020
03eea20
update to template build
egil Aug 12, 2020
532384a
update to template build
egil Aug 12, 2020
00d496e
update to template install
egil Aug 12, 2020
a8944f9
update to version setting
egil Aug 12, 2020
a04acda
workflow cleanup
egil Aug 12, 2020
38b1a8b
new pr checks
egil Aug 13, 2020
dc0b068
update to pr
egil Aug 13, 2020
dd12e61
update to checkout depth
egil Aug 13, 2020
c040c7e
update to step order
egil Aug 13, 2020
0cf794e
added test step
egil Aug 13, 2020
68398fc
run dotnet format manually
egil Aug 13, 2020
f99a4d9
run dotnet format commit changes
egil Aug 13, 2020
00a81c7
run dotnet format commit changes
egil Aug 13, 2020
8a38772
run dotnet format commit changes
egil Aug 13, 2020
be85bb2
tweaks
egil Aug 13, 2020
97a8f47
tweaks 2
egil Aug 13, 2020
84c0e3d
Automated dotnet-format update
actions-user Aug 13, 2020
aad8e09
workflow reorg
egil Aug 13, 2020
084305b
added missing checkout depth
egil Aug 13, 2020
f2dbf11
added coveralls
egil Aug 13, 2020
3ff2f5a
tweaks to coveralls upload
egil Aug 13, 2020
32df836
exclude assets from coverage
egil Aug 13, 2020
0162f07
exclude assets from coverage
egil Aug 13, 2020
ffef035
Automated dotnet-format update
actions-user Aug 13, 2020
c74aa80
coveralls version
egil Aug 13, 2020
c65db7b
coveralls version
egil Aug 13, 2020
7dc0ac8
added changed to changelog
egil Aug 13, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/CI-PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
files: '["*.csproj", "**/*.csproj"]'
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.202'
dotnet-version: '5.0.100'
egil marked this conversation as resolved.
Show resolved Hide resolved
- name: Building library
run: |
dotnet restore src
Expand Down
7 changes: 0 additions & 7 deletions global.json

This file was deleted.

23 changes: 11 additions & 12 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>CS8600;CS8602;CS8603;CS8625</WarningsAsErrors>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>CS8600;CS8602;CS8603;CS8625</WarningsAsErrors>
<Deterministic>true</Deterministic>
</PropertyGroup>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
11 changes: 7 additions & 4 deletions src/bunit.core.tests/ComponentParameterFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using Bunit.Rendering;
using Bunit.TestAssets.SampleComponents;
using Bunit.TestDoubles.JSInterop;

using Microsoft.AspNetCore.Components.Rendering;

using Shouldly;

using Xunit;
Expand Down Expand Up @@ -37,12 +40,12 @@ public void Test005()
instance.RegularParam.ShouldBe("some value");
instance.UnnamedCascadingValue.ShouldBe(42);
instance.NamedCascadingValue.ShouldBe(1337);
Should.Throw<Exception>(async () => await instance.NonGenericCallback.InvokeAsync(null)).Message.ShouldBe("NonGenericCallback");
Should.Throw<Exception>(async () => await instance.NonGenericCallback.InvokeAsync(EventArgs.Empty)).Message.ShouldBe("NonGenericCallback");
Should.Throw<Exception>(async () => await instance.GenericCallback.InvokeAsync(EventArgs.Empty)).Message.ShouldBe("GenericCallback");

new RenderedFragment(Services, Renderer.RenderFragment(instance.ChildContent!)).Markup.ShouldBe(nameof(ChildContent));
new RenderedFragment(Services, Renderer.RenderFragment(instance.OtherContent!)).Markup.ShouldBe(nameof(AllTypesOfParams<string>.OtherContent));
Should.Throw<Exception>(() => instance.ItemTemplate!("")(null)).Message.ShouldBe("ItemTemplate");
Should.Throw<Exception>(() => instance.ItemTemplate!("")(new RenderTreeBuilder())).Message.ShouldBe("ItemTemplate");
}

[Fact(DisplayName = "All types of parameters are correctly assigned to component on re-render")]
Expand Down Expand Up @@ -77,11 +80,11 @@ public void Test002()

instance.Attributes["some-unmatched-attribute"].ShouldBe("unmatched value");
instance.RegularParam.ShouldBe("some value");
Should.Throw<Exception>(async () => await instance.NonGenericCallback.InvokeAsync(null)).Message.ShouldBe("NonGenericCallback");
Should.Throw<Exception>(async () => await instance.NonGenericCallback.InvokeAsync(EventArgs.Empty)).Message.ShouldBe("NonGenericCallback");
Should.Throw<Exception>(async () => await instance.GenericCallback.InvokeAsync(EventArgs.Empty)).Message.ShouldBe("GenericCallback");
new RenderedFragment(Services, Renderer.RenderFragment(instance.ChildContent!)).Markup.ShouldBe(nameof(ChildContent));
new RenderedFragment(Services, Renderer.RenderFragment(instance.OtherContent!)).Markup.ShouldBe(nameof(AllTypesOfParams<string>.OtherContent));
Should.Throw<Exception>(() => instance.ItemTemplate!("")(null)).Message.ShouldBe("ItemTemplate");
Should.Throw<Exception>(() => instance.ItemTemplate!("")(new RenderTreeBuilder())).Message.ShouldBe("ItemTemplate");
}

[Fact(DisplayName = "Template(name, markupFactory) helper correctly renders markup template")]
Expand Down
15 changes: 12 additions & 3 deletions src/bunit.core.tests/bunit.core.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<RootNamespace>Bunit</RootNamespace>
<AssemblyName>Bunit.Core.Tests</AssemblyName>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-preview.7.*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.14.0" />
<PackageReference Include="AngleSharp.Css" Version="0.14.0" />
<PackageReference Include="AngleSharp.Diffing" Version="0.14.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.core/Extensions/ComponentParameterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static RenderFragment CreateComponentRenderFragment(IReadOnlyList<ComponentParam
for (var i = 0; i < parameters.Count; i++)
{
var para = parameters[i];
if (!para.IsCascadingValue)
if (!para.IsCascadingValue && para.Name is { })
builder.AddAttribute(i + 1, para.Name, para.Value);
}

Expand Down
22 changes: 22 additions & 0 deletions src/bunit.core/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;

namespace Bunit.Extensions
{
/// <summary>
/// Helper methods for working with <see cref="IEnumerable{T}"/>
/// </summary>
public static class EnumerableExtensions
{
/// <summary>
/// Returns true if the numerable is null or empty.
/// </summary>
public static bool IsNullOrEmpty<T>([NotNullWhen(false)]this IEnumerable<T>? enumerable)
{
return enumerable is null || !enumerable.Any();
}
}
}
10 changes: 7 additions & 3 deletions src/bunit.core/Extensions/RenderedComponentRenderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Bunit.Rendering;
Expand Down Expand Up @@ -72,12 +72,16 @@ private static ParameterView ToParameterView(IReadOnlyList<ComponentParameter> p
var parameterView = ParameterView.Empty;
if (parameters.Any())
{
var paramDict = new Dictionary<string, object?>();
var paramDict = new Dictionary<string, object>();
foreach (var param in parameters)
{
if (param.IsCascadingValue)
throw new InvalidOperationException($"You cannot provide a new cascading value through the {nameof(SetParametersAndRender)} method.");
paramDict.Add(param.Name!, param.Value);
if(param.Name is null)
throw new InvalidOperationException($"A parameters name is required.");

// BANG: it should technically be allowed to pass null
paramDict.Add(param.Name, param.Value!);
}
parameterView = ParameterView.FromDictionary(paramDict);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void WaitForState(this IRenderedFragmentBase renderedFragment, Fun
{
waiter.WaitTask.Wait();
}
catch (AggregateException e)
catch (AggregateException e) when (e.InnerException is { })
{
throw e.InnerException;
}
Expand All @@ -50,7 +50,7 @@ public static void WaitForAssertion(this IRenderedFragmentBase renderedFragment,
{
waiter.WaitTask.Wait();
}
catch (AggregateException e)
catch (AggregateException e) when (e.InnerException is { })
{
throw e.InnerException;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void OnAfterRender()
}
}

private void OnTimeout(object state)
private void OnTimeout(object? state)
{
if (_isDisposed)
return;
Expand Down
30 changes: 1 addition & 29 deletions src/bunit.core/RazorTesting/FixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class FixtureBase<TFixture> : RazorTestBase
/// <summary>
/// Gets or sets the child content of the fragment.
/// </summary>
[Parameter] public RenderFragment ChildContent { get; set; } = default!;
[Parameter] public RenderFragment? ChildContent { get; set; }

/// <summary>
/// Gets or sets the setup action to perform before the <see cref="Test"/> action or
Expand Down Expand Up @@ -48,20 +48,6 @@ public abstract class FixtureBase<TFixture> : RazorTestBase
/// </summary>
[Parameter] public Func<TFixture, Task>? TestAsync { get; set; }

/// <summary>
/// Obsolete. Methods assigned to this parameter will not be invoked.
/// </summary>
[Obsolete("This feature has been removed since it caused confusion about the state of the fixture being passed to the test methods. Methods assigned to this parameter will not be invoked.")]
[Parameter]
public IReadOnlyCollection<Action<TFixture>>? Tests { get; set; }

/// <summary>
/// Obsolete. Methods assigned to this parameter will not be invoked.
/// </summary>
[Obsolete("This feature has been removed since it caused confusion about the state of the fixture being passed to the test methods. Methods assigned to this parameter will not be invoked.")]
[Parameter]
public IReadOnlyCollection<Func<TFixture, Task>>? TestsAsync { get; set; }

/// <inheritdoc/>
public override Task SetParametersAsync(ParameterView parameters)
{
Expand All @@ -71,17 +57,9 @@ public override Task SetParametersAsync(ParameterView parameters)
Test = parameters.GetValueOrDefault<Action<TFixture>>(nameof(Test));
TestAsync = parameters.GetValueOrDefault<Func<TFixture, Task>>(nameof(TestAsync));

#pragma warning disable CS0618 // Type or member is obsolete
if (parameters.TryGetValue<IReadOnlyCollection<Action<TFixture>>>(nameof(Tests), out var tests))
Tests = tests;
if (parameters.TryGetValue<IReadOnlyCollection<Func<TFixture, Task>>>(nameof(TestsAsync), out var asyncTests))
TestsAsync = asyncTests;
#pragma warning restore CS0618 // Type or member is obsolete

return base.SetParametersAsync(parameters);
}


/// <inheritdoc/>
[SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "Validating component parameters")]
public override void Validate()
Expand All @@ -93,12 +71,6 @@ public override void Validate()
throw new ArgumentException($"No test action provided via the '{nameof(Test)}' or '{nameof(TestAsync)}' parameters to the {GetType().Name} component.", nameof(Test));
if (Test is { } && TestAsync is { })
throw new ArgumentException($"Only one of the '{nameof(Test)}' or '{nameof(TestAsync)}' actions can be provided to the {GetType().Name} component at the same time.", nameof(Test));
#pragma warning disable CS0618 // Type or member is obsolete
if (Tests is { })
throw new ArgumentException($"The use of the '{nameof(Tests)}' parameter has been obsoleted, and any methods assigned to it will not longer be invoked.");
if (TestsAsync is { })
throw new ArgumentException($"The use of the '{nameof(TestsAsync)}' parameter has been obsoleted, and any methods assigned to it will not longer be invoked.");
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <inheritdoc/>
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.core/Rendering/ComponentParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public bool Equals(ComponentParameter other)
=> string.Equals(Name, other.Name, StringComparison.Ordinal) && Value == other.Value && IsCascadingValue == other.IsCascadingValue;

/// <inheritdoc/>
public override bool Equals(object obj) => obj is ComponentParameter other && Equals(other);
public override bool Equals(object? obj) => obj is ComponentParameter other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode() => HashCode.Combine(Name, Value, IsCascadingValue);
Expand Down
45 changes: 26 additions & 19 deletions src/bunit.core/bunit.core.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>Bunit</RootNamespace>
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
<RazorLangVersion>3.0</RazorLangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>Bunit</RootNamespace>
<AssemblyName>Bunit.Core</AssemblyName>
</PropertyGroup>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<PackageId>bunit.core</PackageId>
Expand All @@ -26,21 +26,28 @@
<Description>
bUnit.core is the base library that provides support for testing Blazor components. You need to install bUnit.web as well to test web-based Blazor components.
</Description>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Deterministic>true</Deterministic>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0-preview.7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-preview.7.*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.91">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.2.31">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

Expand Down
5 changes: 4 additions & 1 deletion src/bunit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".items", ".items", "{A5D7B6
.editorconfig = .editorconfig
..\CHANGELOG.md = ..\CHANGELOG.md
Directory.Build.props = Directory.Build.props
..\global.json = ..\global.json
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand Down Expand Up @@ -41,8 +40,12 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{785D7644-18F2-45E4-9B30-016ADB7AB9E3}"
ProjectSection(SolutionItems) = preProject
..\.github\workflows\CI-CD-Docs.yml = ..\.github\workflows\CI-CD-Docs.yml
..\.github\workflows\CI-PR.yml = ..\.github\workflows\CI-PR.yml
..\.github\workflows\CI.yml = ..\.github\workflows\CI.yml
..\.github\workflows\DEV-GPR-PUSH.yml = ..\.github\workflows\DEV-GPR-PUSH.yml
..\.github\workflows\nuget-pack-push.yml = ..\.github\workflows\nuget-pack-push.yml
..\.github\workflows\NUGET-PUSH.yml = ..\.github\workflows\NUGET-PUSH.yml
..\.github\workflows\RELEASE.yml = ..\.github\workflows\RELEASE.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.template", "bunit.template\bunit.template.csproj", "{58FB9C26-7170-426C-ACE8-A98237710CDB}"
Expand Down
8 changes: 4 additions & 4 deletions src/bunit.template/bunit.template.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>A project template for a testing Blazor/Razor components using the bUnit library.</Description>
<PackageDescription>
A project template for a testing Blazor/Razor components using the bUnit library.
A project template for a testing Blazor/Razor components using the bUnit library.

bUnit is a testing library for Blazor Components. You can easily define components under test in C# or Razor syntax and verify outcome using semantic HTML diffing/comparison logic. You can easily interact with and inspect components, trigger event handlers, provide cascading values, inject services, mock IJSRuntime, and perform snapshot testing.
bUnit is a testing library for Blazor Components. You can easily define components under test in C# or Razor syntax and verify outcome using semantic HTML diffing/comparison logic. You can easily interact with and inspect components, trigger event handlers, provide cascading values, inject services, mock IJSRuntime, and perform snapshot testing.

The library's goal is to make it easy to write comprehensive, stable unit tests for Blazor Components/Razor Components. Go to bunit.egilhansen.com to learn more.
The library's goal is to make it easy to write comprehensive, stable unit tests for Blazor Components/Razor Components. Go to bunit.egilhansen.com to learn more.
</PackageDescription>
<PackageTags>bUnit;razor components;blazor components;unit testing;testing blazor components;blazor server;blazor wasm</PackageTags>
<PackageProjectUrl>https://github.com/egil/bunit</PackageProjectUrl>
Expand All @@ -30,7 +30,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.91">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.2.31">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading