Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Pankraty/FluentValidation.HttpExtensions
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v.0.1.0
Choose a base ref
...
head repository: Pankraty/FluentValidation.HttpExtensions
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 1 commit
  • 10 files changed
  • 2 contributors

Commits on Aug 2, 2022

  1. Add .Net 6.0 support and fix issue with PropertyName for the whole en…

    …tity (#4)
    
    * Added .net6.0 support
    
    * Fix issue with PropertyName in UseHttpCode
    
    Co-authored-by: Yana Vdovina <y.vdovina@rowi.com>
    YanaVdovina and Yana Vdovina authored Aug 2, 2022
    Copy the full SHA
    7c68527 View commit details
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -23,6 +23,10 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Pack
run: |
cd src
2 changes: 1 addition & 1 deletion src/FluentValidation.HttpExtensions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<LangVersion>9</LangVersion>
<AssemblyName>Pankraty.FluentValidation.HttpExtensions</AssemblyName>
<Title>Pankraty.FluentValidation.HttpExtensions</Title>
17 changes: 12 additions & 5 deletions src/IRuleBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -34,16 +34,23 @@ public static IRuleBuilderOptions<T, TProperty> AsLocked<T, TProperty>(
ruleBuilder.UseHttpCode(HttpStatusCode.Locked);

private static string BuildPropertyName(HttpStatusCode httpStatusCode) =>
$"{ErrorStatusConst.Prefix}{(int) httpStatusCode}";
$"{ErrorStatusConst.Prefix}{(int)httpStatusCode}";

private static IRuleBuilderOptions<T, TProperty> UseHttpCode<T, TProperty>(
this IRuleBuilderOptions<T, TProperty> ruleBuilder, HttpStatusCode httpStatusCode)
{
string propertyName = "";
return ruleBuilder
.Configure(x => propertyName = x.GetDisplayName(null))
.WithName(propertyName)
.OverridePropertyName(BuildPropertyName(httpStatusCode));

var options = ruleBuilder.Configure(x => propertyName = x.GetDisplayName(null));

if (!string.IsNullOrEmpty(propertyName))
{
options.WithName(propertyName);
}

options.OverridePropertyName(BuildPropertyName(httpStatusCode));

return options;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<LangVersion>9</LangVersion>
</PropertyGroup>

Original file line number Diff line number Diff line change
@@ -36,29 +36,32 @@ public async Task Use_Multiple_Messages()
{
"Could not find Name James Bond",
"Could not find Address London, Great Britain",
"Could not find entity"
});
}

[Fact]
public async Task Use_Single_Message_When_Another_Rule_Passed()
{
_testEntity.Name = "Existing";
_testEntity.Address = "London, Great Britain";
_testEntity.Name = "James Bond";
_testEntity.PostalCode = "Existing";
_testEntity.Address = "Existing";

var response = await Post();
var problems = await response.DeserializeAs<ValidationProblemDetails>();

response.StatusCode.Should().Be(HttpStatusCode.NotFound);
problems.Errors.Should()
.OnlyContain(x => x.Key == "" &&
x.Value.Single() == "Could not find Address London, Great Britain");
x.Value.Single() == "Could not find Name James Bond");
}

[Fact]
public async Task Return_200_When_All_Rules_Passed()
{
_testEntity.Name = "Existing";
_testEntity.Address = "Existing";
_testEntity.PostalCode = "Existing";

var response = await Post();

2 changes: 1 addition & 1 deletion tests/TestApplication/TestApplication.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<LangVersion>9</LangVersion>
</PropertyGroup>

5 changes: 5 additions & 0 deletions tests/TestInfrastructure/NotFoundValidator.cs
Original file line number Diff line number Diff line change
@@ -16,6 +16,11 @@ public NotFoundValidator()
.Must(x => x == "Existing")
.AsNotFound()
.WithMessage("Could not find {PropertyName} {PropertyValue}");

RuleFor(x => x)
.Must(x => x.Address == "Existing" && x.PostalCode == "Existing")
.AsNotFound()
.WithMessage("Could not find entity");
}
}
}
1 change: 1 addition & 0 deletions tests/TestInfrastructure/TestEntity.cs
Original file line number Diff line number Diff line change
@@ -16,5 +16,6 @@ public class NotFoundEntity
{
public string Name { get; set; }
public string Address { get; set; }
public string PostalCode { get; set; }
}
}
2 changes: 1 addition & 1 deletion tests/TestInfrastructure/TestInfrastructure.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<LangVersion>9</LangVersion>
<RootNamespace>FluentValidation.HttpExtensions.TestInfrastructure</RootNamespace>
</PropertyGroup>