nunit.analyzers icon indicating copy to clipboard operation
nunit.analyzers copied to clipboard

NUnit2024 triggers invalidly on Has.Property()

Open Sebazzz opened this issue 2 years ago • 0 comments

Code:

public static class ConstraintExtensions {
    public static RegexConstraint EqualToANiceName(this ResolvableConstraintExpression expression, string entityType) {
        return expression.Matches($@"John");
    }
}

class Person { public string Name { get;set; } }

Person p = new();

Assert.That(p, Has.Property(nameof(Person.Name)).EqualToANiceName());

Result:

Error NUnit2024 : The 'RegexConstraint' constraint cannot be used with actual argument of type 'Person' (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2024.md)

Sebazzz avatar Jan 05 '24 13:01 Sebazzz