Skip to content

AllBeAssignableTo behaving not like foreach BeAssignableTo #1006

@matthiaslischka

Description

@matthiaslischka

I use some reflection to test that all my controllers implement my BaseController.
When I test with AllBeAssignableTo it fails:

var myBaseControllerType = typeof(BaseController);
var controllers = myBaseControllerType.Assembly.Types().Where(x => x.Implements(typeof(ControllerBase)) && x != myBaseControllerType);
controllers.Should().AllBeAssignableTo<BaseController>();

Expected type to be "MyProject.Controllers.BaseController", but found "[System.RuntimeType, System.RuntimeType, System.RuntimeType, System.RuntimeType]".

However, when I use foreach, it works like a charm

var myBaseControllerType = typeof(BaseController);
var controllers = myBaseControllerType.Assembly.Types().Where(x => x.Implements(typeof(ControllerBase)) && x != myBaseControllerType);
foreach (var controller in controllers)
{
	controller.Should().BeAssignableTo<BaseController>();
}

To me this is very unexpected. Can someone explain it? Or is it a bug? Not sure.

BR Matthias

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions