question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TestHelper "broken?" after update to .NET Core 3.1.1

See original GitHub issue

System 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:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Mar 3, 2020

Thanks a lot for your help - we really appreciate your work!

0reactions
JeremySkinnercommented, Mar 3, 2020

But it worked in 8.1.2 ??

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found