Skip to content

Type.Should().Be(Type) doesn't support open generics #954

@thepinkmile

Description

@thepinkmile

I would expect this:

var response = result.GetType(); // returns ICustomInterface<int>
response.Should().Be(typeof(ICustomInterface<>));

to succeed.

Instead it fails with message:

Expected type to be ICustomInterface1, but found ICustomInterface1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].

I believe this is related to the change made for: #458

P.S. Workaround for now:

result.GetType().GetGenericTypeDefinition()
        .Should().Be(typeof(ICustomInterface<>));

I am also using this in a few "And" constraints which forces me to do:

 result.Should().NotBeNull()
    .And.Subject.GetGenericTypeDefinition().Should().Be(typeof(ICustomInterface<>));

Which is ugly and stops me being able to add more assertions as the Subject is now the GenericTypeDefinition and not the actual Type I am validating.

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