Skip to content

Should().BeOfType(Type) doesn't support open generics #458

@abatishchev

Description

@abatishchev

I would expect this:

var response = controller.Get(); // returns OkNegotiatedContentResult<f_AnonymousType()`1>
response.Should().BeOfType(typeof(OkNegotiatedContentResult<>));

to succeed.

Instead it fails with message:

Expected type to be System.Web.Http.Results.OkNegotiatedContentResult1, but found System.Web.Http.Results.OkNegotiatedContentResult1[[<>f__AnonymousType0`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], MyProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]].

Is it something you could enhance, please?

P.S. Workaround for now:

response.GetType().GetGenericTypeDefinition()
        .Should().Be(typeof(OkNegotiatedContentResult<>));

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