docs/articles/nunit-analyzers/NUnit2022.md
| Topic | Value |
|---|---|
| Id | NUnit2022 |
| Severity | Error |
| Enabled | True |
| Category | Assertion |
| Code | MissingPropertyAnalyzer |
The actual argument should have the required property for the constraint.
Using property constraints (e.g. Has.Count.EqualTo(1), Has.Property("Prop").EqualTo(expected), etc)
makes sense only when provided actual argument has those properties defined.
[Test]
public void Test()
{
var enumerable = new [] {1,2,3}.Where(i => i > 1);
// Actual argument type 'IEnumerable<int>' has no property 'Count'.
Assert.That(enumerable, Has.Count.EqualTo(2));
}
Fix your property name, or use another constraint.
<!-- start generated config severity -->Configure the severity per project, for more info see MSDN.
# NUnit2022: Missing property required for constraint
dotnet_diagnostic.NUnit2022.severity = chosenSeverity
where chosenSeverity can be one of none, silent, suggestion, warning, or error.
#pragma warning disable NUnit2022 // Missing property required for constraint
Code violating the rule here
#pragma warning restore NUnit2022 // Missing property required for constraint
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2022 // Missing property required for constraint
[SuppressMessage][System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
"NUnit2022:Missing property required for constraint",
Justification = "Reason...")]