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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:27:28+00:00 2026-05-21T19:27:28+00:00

First, let me say I’ve searched on this topic and did come across a

  • 0

First, let me say I’ve searched on this topic and did come across a solution here:

asp.net mvc: how to mock Url.Content("~")?

However, this solution involves creating a new base controller which, in my current scenario, is not something I have permission to do. So, the question…

I’m writing some unit tests currently for an MVC3 app (the first written by my current employer so I really am trying to drive home the benefits of unit testing [while being relatively new to
unit testing myself]) and I’ve hit a snag with Url.Content

The application has an action as follows:

    [HttpGet]
    public ActionResult SearchResults()
    {
    ...
    ...
    ...

    if(results == null)
    {
        DisplayMessageInView("...Some display message...");
        return RedirectToAction("Index");
    }

where DisplayMessageInView is defined as

    private void DisplayMessageInView(string message)
    {            
        string imageUrl = Url.Content("~/Content/Images/109_AllAnnotations_Info_48x48_72.png");

        TempData["AlertMessage"] = string.Format("<img alt='info' src='{0}' />&nbsp;&nbsp;{1}", imageUrl, message);
    }

So, they’re building a message and an image to diplay to the user on the Index action. Url.Content gets in the way of unit testing this so I’m looking for suggestions to resolve/work around this.

I do have an alternative solution that involves a little more effort and refactoring, but figured this was a good
discussion point either way as I’ve run up this a few times prior and always had to do something a little out of the
ordinary.

Short of the solution above, what other options are there to push beyond this? Your input is appreciated.

Thank You

  • 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-21T19:27:29+00:00Added an answer on May 21, 2026 at 7:27 pm

    The design of the controller is incorrect and no amount of unit testing is going to fix that. Get them to allow you to correct the code and simply return an appropriate View on a null result, possibly setting a message in the ViewBag if required. Inside the view you will then display the appropriate image and message.

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

Sidebar

Related Questions

First off let me say this is my first ASP.NET project I have done.
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport
Let say I have a post from like this: <form action=myApp/form_action.asp method=post> First name:
First let me say I have read this useful article thoroughly and am using
First let me say i dont know if this is possible the way im
I can't figure this one out. At first let me say that my cache
Let say I have something like this: id | title | 1 | First
Let's say I have a first structure like this: typedef struct { int ivalue;
First let me say that I've been searching to find a solution for a
Here is one very simple question(or at least at first sight).Let's say we have

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.