Browse Source
Merge pull request #2441 from kelely/dev
When using FluentValidation for validation, members in ValidationResult are missing
pull/2483/head
Halil İbrahim Kalkan
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
22 additions and
2 deletions
-
framework/src/Volo.Abp.FluentValidation/Volo/Abp/FluentValidation/FluentObjectValidationContributor.cs
-
framework/test/Volo.Abp.FluentValidation.Tests/Volo/Abp/FluentValidation/ApplicationService_FluentValidation_Tests.cs
|
|
|
@ -32,7 +32,7 @@ namespace Volo.Abp.FluentValidation |
|
|
|
context.Errors.AddRange( |
|
|
|
result.Errors.Select( |
|
|
|
error => |
|
|
|
new ValidationResult(error.ErrorMessage) |
|
|
|
new ValidationResult(error.ErrorMessage, new[] { error.PropertyName }) |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using FluentValidation; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
@ -48,7 +49,23 @@ namespace Volo.Abp.FluentValidation |
|
|
|
{ |
|
|
|
// MyStringValue should be aaa, MyStringValue2 should be bbb. MyStringValue3 should be ccc
|
|
|
|
|
|
|
|
await Assert.ThrowsAsync<AbpValidationException>(async () => await _myAppService.MyMethodAsync( |
|
|
|
var exception = Assert.Throws<AbpValidationException>(() => _myAppService.MyMethod(new MyMethodInput |
|
|
|
{ |
|
|
|
MyStringValue = "a", |
|
|
|
MyMethodInput2 = new MyMethodInput2 |
|
|
|
{ |
|
|
|
MyStringValue2 = "b" |
|
|
|
}, |
|
|
|
MyMethodInput3 = new MyMethodInput3 |
|
|
|
{ |
|
|
|
MyStringValue3 = "c" |
|
|
|
} |
|
|
|
})); |
|
|
|
exception.ValidationErrors.ShouldContain(x => x.MemberNames.Contains("MyStringValue")); |
|
|
|
exception.ValidationErrors.ShouldContain(x => x.MemberNames.Contains("MyMethodInput2.MyStringValue2")); |
|
|
|
exception.ValidationErrors.ShouldContain(x => x.MemberNames.Contains("MyMethodInput3.MyStringValue3")); |
|
|
|
|
|
|
|
exception = await Assert.ThrowsAsync<AbpValidationException>(async () => await _myAppService.MyMethodAsync( |
|
|
|
new MyMethodInput |
|
|
|
{ |
|
|
|
MyStringValue = "a", |
|
|
|
@ -61,6 +78,9 @@ namespace Volo.Abp.FluentValidation |
|
|
|
MyStringValue3 = "c" |
|
|
|
} |
|
|
|
})); |
|
|
|
exception.ValidationErrors.ShouldContain(x => x.MemberNames.Contains("MyStringValue")); |
|
|
|
exception.ValidationErrors.ShouldContain(x => x.MemberNames.Contains("MyMethodInput2.MyStringValue2")); |
|
|
|
exception.ValidationErrors.ShouldContain(x => x.MemberNames.Contains("MyMethodInput3.MyStringValue3")); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
|