Back to Nunit

NUnit2026

docs/articles/nunit-analyzers/NUnit2026.md

latest2.1 KB
Original Source

NUnit2026

Wrong actual type used with the SomeItemsConstraint with EqualConstraint

TopicValue
IdNUnit2026
SeverityError
EnabledTrue
CategoryAssertion
CodeSomeItemsIncompatibleTypesAnalyzer

Description

The SomeItemsConstraint with EqualConstraint requires the actual argument to be a collection where the element type can match the type of the expected argument.

Motivation

Using Does.Contain or Contains.Item constraints with actual argument, which is either not a collection, or has wrong element type, leads to assertion error.

How to fix violations

Fix the actual value or use appropriate constraint.

<!-- start generated config severity -->

Configure severity

Via ruleset file

Configure the severity per project, for more info see MSDN.

Via .editorconfig file

ini
# NUnit2026: Wrong actual type used with the SomeItemsConstraint with EqualConstraint
dotnet_diagnostic.NUnit2026.severity = chosenSeverity

where chosenSeverity can be one of none, silent, suggestion, warning, or error.

Via #pragma directive

csharp
#pragma warning disable NUnit2026 // Wrong actual type used with the SomeItemsConstraint with EqualConstraint
Code violating the rule here
#pragma warning restore NUnit2026 // Wrong actual type used with the SomeItemsConstraint with EqualConstraint

Or put this at the top of the file to disable all instances.

csharp
#pragma warning disable NUnit2026 // Wrong actual type used with the SomeItemsConstraint with EqualConstraint

Via attribute [SuppressMessage]

csharp
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
    "NUnit2026:Wrong actual type used with the SomeItemsConstraint with EqualConstraint",
    Justification = "Reason...")]
<!-- end generated config severity -->