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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:13:19+00:00 2026-06-03T13:13:19+00:00

I want to confirm that my HomeController class is being selected by the route

  • 0

I want to confirm that my “HomeController” class is being selected by the route I’ve created. So I have a test like this:

    [TestMethod]
    [UrlToTest("http://localhost:14478/home")]
    [HostType("ASP.NET")]
    [AspNetDevelopmentServerHost("$(SolutionDir)\\MvcBuildApp")]
    public void MyTest()
    {
        System.Diagnostics.Debugger.Break();

        RouteCollection routes = new RouteCollection();
        MvcApplication.RegisterRoutes(routes);
        MvcApplication.RegisterGlobalFilters(GlobalFilters.Filters);
        //This fetches DefaultControllerFactory (for now, anyway...)
        var factory = ControllerBuilder.Current.GetControllerFactory();
        //mock a context...
        var httpContext = CreateHttpContext("http://localhost:14478/home", "GET");
        RouteData route = routes.GetRouteData(httpContext);

        var ctrlInstance = factory.CreateController(new RequestContext(httpContext, route), (string)route.Values["controller"]);

        //ASSERT the instance is of type "HomeController"
        //...
     }

It fails, saying that 'http://localhost:14478/home' completed successfully without running the test.

I noticed that in the VS output window, there is also this message No connection could be made because the target machine actively refused it 127.0.0.1:14478. I figured Cassini must not be active. So I chose to launch the site being tested (ctrl+F5) before launching the unit test. It then changed the VS output to this:

WebTestAdapter.ConnectToHostAdapter: unexpected exception occured.
Microsoft.VisualStudio.TestTools.HostAdapters.AbortTestExecutionException:
Error in the application. at
Microsoft.VisualStudio.TestTools.HostAdapters.WebTestAdapter.ConnectToHostAdapter()

To try to resolve this, I’ve followed the advice of these articles:

  • Debug while running a test in ASP.NET solution
  • Unit Tests for ASP.NET web services: this discusses the “completed successfully without running a test” error.
  • Configuring ASP.NET Unit Tests: I got the $(SolutionDir) idea from this article.

…but I still get the error no matter what I do. Suggestions?

UPDATE/CLARIFICATION
This question is not about testing MVC routes. The purpose of this question is to discover how to make ASP.NET MVC properly initialized to allow more “in depth” automated testing. I have chosen a “route testing” scenario, against the DefaultControllerFactory, merely as an example. In this example, the DefaultControllerFactory does not behave properly unless ASP.NET MVC is properly initialized.

  • 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-06-03T13:13:21+00:00Added an answer on June 3, 2026 at 1:13 pm

    You may be interested in reviewing Steve Sandersons MVC testing framework. If you download the source you will have a great example on how to initialize the MVC framwork:

    http://blog.codeville.net/2009/06/11/integration-testing-your-aspnet-mvc-application/

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

Sidebar

Related Questions

Just want to confirm that I have this correct, and would like to see
I just want to confirm that I'm understanding correctly, in Interface Builder the Class
This is a very basic question but wanted to confirm that if we have
This would seem to be obvious, but I just want to confirm that this
I have a set of objects that I want to conform to an interface,
This is an easy question and I want to confirm with you experts! I
I want to have a confirm box when user tries to close the window.
For those who code in Notepad++, I just want to confirm that Notepad++ does
I want to have the regular expression that makes sure the beginning of the
This may seem obvious to most people, but I'm just trying to confirm that

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.