1

Closed

BeOfTypeImplements<> to test IEnumerable instead of specific implementation (list/dictionary)

description

Unit tests for my controller include type validation of the model.
I first attempted:
ViewResult.Model.Should().BeOfType<IEnumerable<model>>()

but it failed, stating that the type is List<model>
This is true, but I don't want to worry about that during my testing... I just need to verify that the model is IEnumerable

As a result, I must use:
ViewResult.Model.GetType().Implements<IEnumerable<model>>().Should().BeTrue()

I would prefer something along the lines of:
  • some sort of optional parameter for the BeOfType() to allow classes that inherit/implement T
    or
  • BeOfTypeImplementing<>
PS: keep up the great work... FA is probably my most frequently used nuget package :)
Closed Feb 23 at 5:39 PM by dennisdoomen
An alternative is provided.

comments

mopdam wrote Nov 3, 2012 at 1:16 PM

You can use BeAssignableTo<> for that. Like this:

ViewResult.Model.Should().BeAssignableTo<IEnumerable<model>>();

dennisdoomen wrote Jan 7 at 6:01 PM

Is that an answer to your question?