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

add .net 8 support #228

Merged
merged 1 commit into from
May 28, 2024
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
14 changes: 7 additions & 7 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
types: [ published ]

env:
NETCORE_VERSION: '7.0.x'
NETCORE_VERSION: '8.0.x'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
PROJECT_NAME: FluentValidation
Expand Down Expand Up @@ -42,12 +42,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.NETCORE_VERSION }}

- name: Create Release NuGet package
run: |
arrTag=(${GITHUB_REF//\// })
Expand All @@ -56,17 +56,17 @@ jobs:
VERSION="${VERSION:1}"
echo Clean Version: $VERSION
dotnet pack -v normal -c Release --include-symbols --include-source -p:PackageVersion=$VERSION -o nupkg src/Blazored.$PROJECT_NAME/Blazored.$PROJECT_NAME.csproj

- name: Push to NuGet Feed
run: dotnet nuget push ./nupkg/*.nupkg --source $NUGET_FEED --api-key $NUGET_KEY --skip-duplicate

- name: Publish Sample Site
run: dotnet publish -c Release samples/BlazorWebAssembly/BlazorWebAssembly.csproj

- name: Rewrite base href
uses: SteveSandersonMS/ghaction-rewrite-base-href@v1
with:
html_path: samples/BlazorWebAssembly/bin/Release/net7.0/publish/wwwroot/index.html
html_path: samples/BlazorWebAssembly/bin/Release/net8.0/publish/wwwroot/index.html
base_href: /${{ env.PROJECT_NAME }}/

- name: Deploy to Github Pages
Expand All @@ -75,5 +75,5 @@ jobs:
ACCESS_TOKEN: $GITHUB_TOKEN
BASE_BRANCH: main # The branch the action should deploy from.
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: samples/BlazorWebAssembly/bin/Release/net7.0/publish/wwwroot # The folder the action should deploy.
FOLDER: samples/BlazorWebAssembly/bin/Release/net8.0/publish/wwwroot # The folder the action should deploy.
SINGLE_COMMIT: true
2 changes: 1 addition & 1 deletion .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

env:
PROJECT_NAME: Blazored.FluentValidation
NETCORE_VERSION: '7.0.x'
NETCORE_VERSION: '8.0.x'

jobs:
build:
Expand Down
16 changes: 11 additions & 5 deletions src/Blazored.FluentValidation/Blazored.FluentValidation.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>

Expand Down Expand Up @@ -31,14 +31,20 @@
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.9.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="FluentValidation" Version="11.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.31" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="FluentValidation" Version="11.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.20" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using FluentValidation;
using FluentValidation.Internal;
using FluentValidation.Results;

using Microsoft.AspNetCore.Components.Forms;
using Microsoft.Extensions.DependencyInjection;

using static FluentValidation.AssemblyScanner;

namespace Blazored.FluentValidation;
Expand Down Expand Up @@ -59,12 +61,12 @@ private static async Task ValidateModel(EditContext editContext,

messages.Clear();
fluentValidationValidator.LastValidationResult = new Dictionary<FieldIdentifier, List<ValidationFailure>>();

foreach (var validationResult in validationResults.Errors)
{
var fieldIdentifier = ToFieldIdentifier(editContext, validationResult.PropertyName);
messages.Add(fieldIdentifier, validationResult.ErrorMessage);

if (fluentValidationValidator.LastValidationResult.TryGetValue(fieldIdentifier, out var failures))
{
failures.Add(validationResult);
Expand All @@ -88,7 +90,7 @@ private static async Task ValidateField(EditContext editContext,
{
var properties = new[] { fieldIdentifier.FieldName };
var context = new ValidationContext<object>(fieldIdentifier.Model, new PropertyChain(), new MemberNameValidatorSelector(properties));

validator ??= GetValidatorForModel(serviceProvider, fieldIdentifier.Model, disableAssemblyScanning);

if (validator is not null)
Expand Down Expand Up @@ -160,7 +162,7 @@ private static FieldIdentifier ToFieldIdentifier(in EditContext editContext, in

var obj = editContext.Model;
var nextTokenEnd = propertyPath.IndexOfAny(Separators);

// Optimize for a scenario when parsing isn't needed.
if (nextTokenEnd < 0)
{
Expand All @@ -187,8 +189,8 @@ private static FieldIdentifier ToFieldIdentifier(in EditContext editContext, in
// we've got an Item property
var indexerType = prop.GetIndexParameters()[0].ParameterType;
var indexerValue = Convert.ChangeType(nextToken.ToString(), indexerType);
newObj = prop.GetValue(obj, new [] { indexerValue });

newObj = prop.GetValue(obj, new[] { indexerValue });
}
else
{
Expand Down Expand Up @@ -233,7 +235,7 @@ private static FieldIdentifier ToFieldIdentifier(in EditContext editContext, in
}

obj = newObj;

nextTokenEnd = propertyPathAsSpan.IndexOfAny(Separators);
if (nextTokenEnd < 0)
{
Expand Down
14 changes: 7 additions & 7 deletions src/Blazored.FluentValidation/FluentValidationsValidator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using FluentValidation;
using FluentValidation.Internal;
using FluentValidation.Results;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using System;
using FluentValidation.Results;

namespace Blazored.FluentValidation;

Expand Down Expand Up @@ -48,7 +48,7 @@ public async Task<bool> ValidateAsync(Action<ValidationStrategy<object>>? option
{
throw new NullReferenceException(nameof(CurrentEditContext));
}

ValidateOptions = options;

try
Expand All @@ -61,7 +61,7 @@ public async Task<bool> ValidateAsync(Action<ValidationStrategy<object>>? option
throw new InvalidOperationException("No pending ValidationResult found");
}

await (Task<ValidationResult>) asyncValidationTask;
await (Task<ValidationResult>)asyncValidationTask;

return !CurrentEditContext.GetValidationMessages().Any();
}
Expand Down Expand Up @@ -95,10 +95,10 @@ public ValidationFailure[] GetFailuresFromLastValidation(FieldIdentifier? fieldI

if (fieldIdentifier is null)
return LastValidationResult.Values.SelectMany(f => f).ToArray();

if (!LastValidationResult.TryGetValue(fieldIdentifier.Value, out var failures))
return Array.Empty<ValidationFailure>();
return Array.Empty<ValidationFailure>();

return failures.ToArray();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<EditForm
<EditForm
Model="@_person"
OnValidSubmit="ValidSubmit"
OnInvalidSubmit="InvalidSubmit">
Expand All @@ -11,21 +11,21 @@
{
<FluentValidationValidator DisableAssemblyScanning="DisableAssemblyScanning.Value" />
}

<ValidationSummary/>

<p>
<label>First name: </label>
<InputText name="@nameof(_person.FirstName)" @bind-Value="@_person.FirstName"/>
</p>

<button type="submit">Save</button>
</EditForm>

@code {
[Parameter] public bool? DisableAssemblyScanning { get; set; }
private readonly Person _person = new();

internal ValidationResultType Result { get; private set; } = ValidationResultType.Valid;

private void ValidSubmit() => Result = ValidationResultType.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Blazored.FluentValidation.Tests.AssemblyScanning;
public class Tests : TestContext
{
private readonly Fixture _fixture = new();

[Fact]
public void DisableAssemblyScanning_SetToTrue_NoValidationHappens()
{
Expand Down Expand Up @@ -50,7 +50,7 @@ public void DisableAssemblyScanning_NotSet_ValidationHappens()
// Assert
cut.Instance.Result.Should().Be(ValidationResultType.Error);
}

[Fact]
public void DisableAssemblyScanning_SetToTrueButValidatorsRegistered_ValidationHappens()
{
Expand All @@ -66,7 +66,7 @@ public void DisableAssemblyScanning_SetToTrueButValidatorsRegistered_ValidationH
// Assert
cut.Instance.Result.Should().Be(ValidationResultType.Error);
}

private class Fixture
{
public Person InvalidPerson() => new()
Expand Down
10 changes: 5 additions & 5 deletions tests/Blazored.FluentValidation.Tests/BasicValidation/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@ public void Validate_AgeTooOld_ValidationErrorsPresent()
// Arrange
var cut = RenderComponent<Component>();
var person = _fixture.ValidPerson() with { Age = 250 };

// Act
FillForm(cut, person);
cut.Find("button").Click();

// Assert
cut.Find(".validation-errors>.validation-message").TextContent.Should().Contain(PersonValidator.AgeMax);
}

[Fact]
public void Validate_AddressLine1Missing_ValidationErrorsPresent()
{
// Arrange
var cut = RenderComponent<Component>();
var person = _fixture.ValidPerson() with { Address = new() { Line1 = string.Empty } };

// Act
FillForm(cut, person);
cut.Find("button").Click();

// Assert
cut.Find(".validation-errors>.validation-message").TextContent.Should().Contain(AddressValidator.Line1Required);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -10,23 +10,23 @@
<Using Include="Bunit" />
<Using Include="Bunit.TestDoubles" />
<Using Include="Microsoft.Extensions.DependencyInjection" />
<Using Include="Xunit"/>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="1.26.64" />
<PackageReference Include="bunit" Version="1.28.9" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="FluentValidation" Version="11.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,48 @@ public void GetFailuresFromLastValidation_PersonValid_ResultIsValid()
// Arrange
var person = _fixture.ValidPerson();
var cut = RenderComponent<AsyncComponent>();

// Act
FillForm(cut, person);
cut.Find("button").Click();
cut.WaitForState(() => cut.Instance.Result is not null);

// Assert
cut.Instance.Result.Should().Be(ValidationResultType.Valid);
}

[Fact]
public void GetFailuresFromLastValidation_EmailInvalid_ResultIsError()
{
// Arrange
var person = _fixture.ValidPerson() with { EmailAddress = "invalid-email" };
var cut = RenderComponent<AsyncComponent>();

// Act
FillForm(cut, person);
cut.Find("button").Click();
cut.WaitForState(() => cut.Instance.Result is not null);

// Assert
cut.Instance.Result.Should().Be(ValidationResultType.Error);
}

[Fact]
public void GetFailuresFromLastValidation_AgeSuspect_ResultIsWarning()
{
// Arrange
var person = _fixture.ValidPerson() with { Age = 69 };
var cut = RenderComponent<AsyncComponent>();

// Act
FillForm(cut, person);
cut.Find("button").Click();
cut.WaitForState(() => cut.Instance.Result is not null);

// Assert
cut.Instance.Result.Should().Be(ValidationResultType.Warning);
}


private static void FillForm(IRenderedComponent<AsyncComponent> cut, Person person)
{
Expand Down
Loading
Loading