Search Results for

    Show / Hide Table of Contents

    NUnit2025

    Wrong actual type used with ContainsConstraint

    Topic Value
    Id NUnit2025
    Severity Hidden
    Enabled False
    Category Assertion
    Code ContainsConstraintWrongActualTypeAnalyzer

    Description

    The ContainsConstraint requires the type of the actual value to be either a string or a collection of strings.

    Motivation

    Using a ContainsConstraint with an actual argument, which is neither a string nor a collection of strings, leads to an assertion error.

    How to fix violations

    Fix the actual value or use appropriate constraint.

    Configure severity

    Via ruleset file

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

    Via .editorconfig file

    # NUnit2025: Wrong actual type used with ContainsConstraint
    dotnet_diagnostic.NUnit2025.severity = chosenSeverity
    

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

    Via #pragma directive

    #pragma warning disable NUnit2025 // Wrong actual type used with ContainsConstraint
    Code violating the rule here
    #pragma warning restore NUnit2025 // Wrong actual type used with ContainsConstraint
    

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

    #pragma warning disable NUnit2025 // Wrong actual type used with ContainsConstraint
    

    Via attribute [SuppressMessage]

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
        "NUnit2025:Wrong actual type used with ContainsConstraint",
        Justification = "Reason...")]
    
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0