Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1100269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:51:16+00:00 2026-05-17T00:51:16+00:00

How can you assert that an expected type is returned when it is wrapped

  • 0

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>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:51:16+00:00Added an answer on May 17, 2026 at 12:51 am

    Just call the controller method and check the type of the object that is returned:

    var result = new CustomerController((new MockHttpContext()).Object).Search(....);
    
    Assert.That(result, Is.InstanceOf(typeof(ViewResult)), "View Result should be of expected type");
    

    You can also check the values of ViewData / model if you want to…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just wondering how folks unit test and assert that the expected collection is
In NUnit, I can write either Assert.That(5, Is.EqualTo(5)); or Assert.AreEqual(5, 5); Is there any
Suppose we have 3 variables and we need to ASSERT that they can either
I have unit test in Java that writes a constant Timestamp to a row
Can the following code be expected to work in all environments that have an
I'm trying to ensure that a parameter can't be null by adding an assert
If I want to make a rule dynamic so i can use assert after
I was wondering, I am aware you can use assert to add facts or
Can you tell me if there's a way to dis- and enable junit.framework.Assert commands
I can only assume this is a bug. The first assert passes while the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.