TestHelper "broken?" after update to .NET Core 3.1.1
See original GitHub issueSystem Details
- FluentValidation version: 8.6.1 (was using 8.1.2 before)
- Web Framework version: ASP.NET Core 3.1.1
Issue Description
Runtime validation works as expected, but TestHelper - ShouldHaveValidationErrorFor does not get validation error.
public class CreateTagParametersValidator : AbstractValidator<CreateTagParameters>
{
public CreateTagParametersValidator()
{
RuleFor(req => req.OrganizationId).NotEmpty();
RuleFor(req => req.Request).NotNull();
RuleFor(req => req.Request.TagName).NotEmpty().When(req => req.Request != null);
RuleForEach(req => req.Request.Assets).SetValidator(new TagAssetInstanceValidator()).When(req => req.Request != null);
}
}
public class TagAssetInstanceValidator : AbstractValidator<TagAssetInstance>
{
public TagAssetInstanceValidator()
{
RuleFor(t => t.AssetId).NotEmpty();
}
}
using AutoFixture.Xunit2;
[Theory, AutoData]
public void Should_Have_Error_For_Null_AssetId(
CreateTagParametersValidator validator,
CreateTagParameters parameters)
{
// No validation error here !?
validator.ShouldHaveValidationErrorFor(parameters, p => p.Request.Assets[0], p => p.Request.Assets[0].AssetId = null);
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Moq Verify Not Working as Expected After Upgrading to . ...
1. After upgrading to .NET Core 3.1 and Moq Version 4.14.5, the verify method is failing saying the method specified hasn't been called...
Read more >Breaking changes in .NET Core 3.1
NET Core 3.1 has been updated to implement the new SameSite behavior. The update redefines the behavior of SameSiteMode.
Read more >too particular about .NET Core runtime version
Test Explorer recently stopped running my unit tests on the . NET Core runtime. Net472 tests still run fine. Looking at the Tests...
Read more >Migration from Asp.Net Core 2.2 to 3.1 — Real project
The purpose of this article is to share my personal experience of migrating a medium complexity real project from Asp.Net Core 2.2 and ......
Read more >Upgrading from ASP.NET Core 3.1 to 5.0 (Preview 1)
In this post, I want to take a look at the steps required to upgrade some projects to the first preview of .NET...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks a lot for your help - we really appreciate your work!
I’m afraid not - it was a false-positive. We’ve never supported indexers inside expression trees like this, but older versions of the testhelper (including 8.1.2) actually silently failed to run when an indexer was encountered (leading to a false positive). This was fixed last year in the 8.5 release (which is why you’re now correctly getting an error), and I also added the string-based overload to work around this limitation.
The lambda-based overloads only support simple property access expressions, and for anything more complex (including indexers), you’ll need to use the string overloads.