Search Results for

    Show / Hide Table of Contents

    SomeItems Constraint

    SomeItemsConstraint applies a constraint to each item in an IEnumerable, succeeding if at least one of them succeeds. An exception is thrown if the actual value passed does not implement IEnumerable.

    This constraint will also cover Contains functionality. See examples below.

    Constructor

    SomeItemsConstraint(Constraint itemConstraint)
    

    Syntax

    Has.Some...
    Has.Member(object)
    Contains.Item(object)
    Does.Contain(object)
    

    Modifiers

    ...IgnoreCase
    ...IgnoreWhiteSpace  // From version 4.2
    ...Using(IEqualityComparer comparer)
    ...Using(IComparer comparer)
    ...Using<T>(IEqualityComparer<T> comparer)
    ...Using<T>(IComparer<T> comparer)
    ...Using<T>(Comparison<T> comparer)
    ...Using<TActualCollectionElement, TExpectedElement>(Func<TActualCollectionElement, TExpectedElement, bool> comparer)
    ...UsingPropertiesComparer()  // From version 4.1
    ...UsingPropertiesComparer(
          Func<PropertiesComparerConfiguration,
               PropertiesComparerConfiguration> configure) // From version 4.4
    

    Examples of Use

    int[] iarray = new int[] { 1, 2, 3 };
    string[] sarray = new string[] { "a", "b", "c" };
    Assert.That(iarray, Has.Some.GreaterThan(2));
    Assert.That(sarray, Has.Some.Length.EqualTo(1));
    

    Contains examples

    [Test]
    public void CollectionContains_Examples()
    {
        int[] intArray = [1, 2, 3];
        string[] stringArray = ["a", "b", "c"];
        
        Assert.That(intArray, Has.Member(3));
        Assert.That(stringArray, Has.Member("b"));
        Assert.That(stringArray, Contains.Item("c"));
        Assert.That(stringArray, Has.No.Member("x"));
        Assert.That(intArray, Does.Contain(3));
    }
    

    Note

    Has.Member(), Contains.Item() and Does.Contain() work the same as Has.Some.EqualTo().

    • 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