Skip to content

Commit

Permalink
.NET 7 updates (#1968)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremySkinner committed Nov 8, 2022
1 parent 0c2ff0e commit 6fd09b3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: |
7.0.100
6.0.x
- name: Build and Test
run: ./build.ps1
Expand Down
5 changes: 2 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"sdk": {
"version": "6.0.100",
"version": "7.0.100",
"rollForward": "latestFeature"
},
"others": ["3.1.201", "5.0.100"]
}
}
2 changes: 1 addition & 1 deletion src/FluentValidation.Tests/FluentValidation.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<AssemblyName>FluentValidation.Tests</AssemblyName>
<RootNamespace>FluentValidation.Tests</RootNamespace>
<IsPackable>false</IsPackable>
Expand Down
14 changes: 7 additions & 7 deletions src/FluentValidation.Tests/ForEachRuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class ForEachRuleTests {
result.Errors[1].PropertyName.ShouldEqual("NickNames[2]");
}

class request {
class Request {
public Person person = null;
}

Expand All @@ -158,10 +158,10 @@ private class MyAsyncNotNullValidator<T,TProperty> : IAsyncPropertyValidator<T,T

[Fact]
public void Nested_collection_for_null_property_should_not_throw_null_reference() {
var validator = new InlineValidator<request>();
var validator = new InlineValidator<Request>();
validator.When(r => r.person != null, () => { validator.RuleForEach(x => x.person.NickNames).NotNull(); });

var result = validator.Validate(new request());
var result = validator.Validate(new Request());
result.Errors.Count.ShouldEqual(0);
}

Expand Down Expand Up @@ -233,21 +233,21 @@ await ExclusiveDelay(1)

[Fact]
public void Nested_conditions_Rule_For() {
var validator = new InlineValidator<request>();
var validator = new InlineValidator<Request>();
validator.When(r => true, () => {
validator.When(r => r.person?.NickNames?.Any() == true, () => {
validator.RuleFor(r => r.person.NickNames)
.Must(nn => true)
.WithMessage("Failed RuleFor");
});
});
var result = validator.Validate(new request());
var result = validator.Validate(new Request());
result.IsValid.ShouldBeTrue();
}

[Fact]
public void Nested_conditions_Rule_For_Each() {
var validator = new InlineValidator<request>();
var validator = new InlineValidator<Request>();

validator.When(x => true, () => {
validator.When(r => r.person?.NickNames?.Any() == true, () => {
Expand All @@ -257,7 +257,7 @@ await ExclusiveDelay(1)
});
});

var result = validator.Validate(new request());
var result = validator.Validate(new Request());
result.Errors.Count.ShouldEqual(0);
}

Expand Down
9 changes: 9 additions & 0 deletions src/FluentValidation/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:FluentValidation.Validators.PredicateValidator`2.Predicate.#ctor(System.Object,System.IntPtr)</Target>
<Left>lib/net6.0/FluentValidation.dll</Left>
<Right>lib/net7.0/FluentValidation.dll</Right>
</Suppression>
</Suppressions>
13 changes: 11 additions & 2 deletions src/FluentValidation/DefaultValidatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace FluentValidation;

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using System.Reflection;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -162,7 +163,11 @@ public static partial class DefaultValidatorExtensions {
/// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
/// <param name="expression">The regular expression to check the value against.</param>
/// <returns></returns>
public static IRuleBuilderOptions<T, string> Matches<T>(this IRuleBuilder<T, string> ruleBuilder, string expression)
public static IRuleBuilderOptions<T, string> Matches<T>(this IRuleBuilder<T, string> ruleBuilder,
#if NET7_0_OR_GREATER
[StringSyntax(StringSyntaxAttribute.Regex)]
#endif
string expression)
=> ruleBuilder.SetValidator(new RegularExpressionValidator<T>(expression));

/// <summary>
Expand Down Expand Up @@ -231,7 +236,11 @@ public static partial class DefaultValidatorExtensions {
/// <param name="expression">The regular expression to check the value against.</param>
/// <param name="options">Regex options</param>
/// <returns></returns>
public static IRuleBuilderOptions<T, string> Matches<T>(this IRuleBuilder<T, string> ruleBuilder, string expression, RegexOptions options)
public static IRuleBuilderOptions<T, string> Matches<T>(this IRuleBuilder<T, string> ruleBuilder,
#if NET7_0_OR_GREATER
[StringSyntax(StringSyntaxAttribute.Regex)]
#endif
string expression, RegexOptions options)
=> ruleBuilder.SetValidator(new RegularExpressionValidator<T>(expression, options));

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/FluentValidation/FluentValidation.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
<Description>A validation library for .NET that uses a fluent interface to construct strongly-typed validation rules.</Description>
<PackageReleaseNotes>
FluentValidation 11 is a major release. Please read the upgrade guide at https://docs.fluentvalidation.net/en/latest/upgrading-to-11.html
Expand Down

0 comments on commit 6fd09b3

Please sign in to comment.