Skip to content

NotContainItemsAssignableTo<T> #2249

@Leo506

Description

@Leo506

Background and motivation

Now there is method ContainItemsAssignableTo<T> and it's very usefull for sequence validation. But sometimes I need to check that sequence does not contain any elements of specified type. So I need to write somethink like this:

var myList = GetListForAssert();
myList.Should().ContainItemsAssignableTo<MyType1>();
myList.OfType<MyType2>().Should().BeEmpty();

API Proposal

public class GenericCollectionAssertions<TCollection, T, TAssertions>
{
    public AndConstraint<TAssertions> NotContainItemsAssignableTo<T>(string because="", params object[] becauseArgs)
    public AndConstraint<TAssertions> NotContainItemsAssignableTo(Type type, string because="", params object[] becauseArgs)
}

API Usage

var myList = GetList();
myList.Should().NotContainItemsAssignableTo<MyType>();

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions