How can you assert that an expected type is returned when it is wrapped up in a System.RuntimeType?
As part of a larger unit test to verify that an action has the correct parameters and action filters assigned I'm asserting against a populated instance of MethodInfo. When I assert against "action.ReturnParameter" it fails as it's saying the type is System.RunTimeType. Whilst I understand that this is a wrapper around the expected type, I just can't seem to find a way to assert that the wrapped instance is of the expected type - the best method that I've come up with so far is to assert against name or full name, but that's horrible as it's just using "magic strings".
Can anyone help? As my Google searches haven't turned up anything useful, I'm guessing it's got a really easy solution, I'm just not seeing it.
The code is as follows:
[TestMethod]
public void CheckActionFilterSet()
{
MethodInfo action = new CustomerController((new MockHttpContext()).Object)
.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(mi => mi.Name.Equals("Search")).First();
Assert.That(action.ReturnParameter.ParameterType, Is.InstanceOf(typeof(ViewResult)), "View Result should be of expected type");
}
Exception message is:
View Result should be of expected type
Expected: instance of
<System.Web.Mvc.ViewResult>
But was:
<System.RuntimeType>