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 7587951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:48:08+00:00 2026-05-30T19:48:08+00:00

I have a method that returns MvcHtmlString, so in my unit test I’m trying

  • 0

I have a method that returns MvcHtmlString, so in my unit test I’m trying to make sure that the right type comes back:

[TestMethod]
public void GetTeamNameByAlignmentTest()
{    
    var target01 = MockEventData().First().GetTeamNameByAlignment("HoMe");    
    Assert.IsInstanceOfType(target01, typeof(MvcHtmlString));
}

However the test fails

Assert.IsInstanceOfType failed.  Expected type:<System.Web.Mvc.MvcHtmlString>. Actual type:<System.Web.Mvc.{Dynamic}.DynamicMvcHtmlString>

How do I properly test for MvcHtmlString return type?

EDIT:
The Method:

 public MvcHtmlString GetTeamNameByAlignment(String alignment)
        {
        StringBuilder teamName = new StringBuilder();
        if (Participants.First().Alignment.ToLower() == alignment.ToLower())
        {
            teamName.Append(Participants.First().Team.TeamName);
            if (Participants.First().Winning == true)
            {
                teamName.Insert(0, "<b>");
                teamName.Append("</b>");
            } 
        }

        if (Participants.Last().Alignment.ToLower() == alignment.ToLower())
        {

            teamName.Append(Participants.Last().Team.TeamName);
            if (Participants.Last().Winning == true)
            {
                teamName.Insert(0, "<b>");
                teamName.Append("</b>");
            } 
        }

        return MvcHtmlString.Create(teamName.ToString());
    }

EDIT 2:

Mocked data:

private static IQueryable<Event> MockEventData()
    {
        Team team01 = new Team();
        team01.TeamName = "HomeTeam";

        Team team02 = new Team();
        team02.TeamName = "AwayTeam";


        EventParticipant participant01 = new EventParticipant();
        participant01.Alignment = "home";
        participant01.Team = team01;
        participant01.Winning = false;
        participant01.totalScore = 77;

        EventParticipant participant02 = new EventParticipant();
        participant02.Alignment = "away";
        participant02.Team = team02;
        participant02.Winning = true;
        participant02.totalScore = 99;


        Event event01 = new Event();
        event01.Participants = new List<EventParticipant> {participant01, participant02};

        IQueryable<Event> events = new List<Event> { event01 }.AsQueryable();

        return events;
    }
  • 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-30T19:48:09+00:00Added an answer on May 30, 2026 at 7:48 pm

    Looking at this source code for MvcHtmlString, DynamicMvcHtmlString looks to be a runtime-created subclass of MvcHtmlString. With that in mind, how about changing your assertion to:

    Assert.IsTrue(target01 is MvcHtmlString);
    

    ?

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

Sidebar

Related Questions

Here is my situation: type A wants to have a method that returns a
I have a method that returns an IEnumerable of some type. Now I was
I have a method that returns a PDF file using DOMPDF . It sends
I have a method that returns an instance of Map<String, List<Foo>> x(); and another
I have a method that returns an array of arrays. For convenience I use
I have a method that returns an IEnumerable that I want to be able
I have a method that returns a map defined as: public Map<String, ?> getData();
I have a method that returns a CGMutablePathRef , something like this: - (CGMutablePathRef)somePath;
I have a method that returns a double. When I call this method and
I have a method that returns either a list or a tuple. What is

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.