Skip to content

ContainItemsAssignableTo vs AllBeAssignableTo #1618

@jnyrup

Description

@jnyrup

Description

Is there any difference between ContainItemsAssignableTo and AllBeAssignableTo?
Spending five minutes looking at them, they seem to test the same scenario.
(With the exception, that AllBeAssignableTo has special handling for IEnumerable<Type>)

In contrast to other Contain methods, ContainItemsAssignableTo expects all elements to satisfy and not just a subset.

Complete minimal example reproducing the issue

class Base { }
class Derived : Base { }

public void MyTestMethod()
{
    new[] { new Derived(), new Base() }.Should().AllBeAssignableTo<Derived>();  // fails as expected
    
    new[] { new Derived(), new Base() }.Should().ContainItemsAssignableTo<Derived>(); // <-- I would have expected this to pass
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions