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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:09:27+00:00 2026-06-17T16:09:27+00:00

I am using T4MVC in my ASP.NET MVC 3 project. I have the following

  • 0

I am using T4MVC in my ASP.NET MVC 3 project. I have the following basic test:

[TestMethod]
public void IndexReturnsIndexView()
{
    var controller = new HomeController();
    var result = controller.Index();

    result.AssertViewRendered().ForView(MVC.Home.Views.Index);
}

The test fails if the controller method returns the default View:

public virtual ActionResult Index()
{
    return View();
}

The error given is:

MvcContrib.TestHelper.ActionResultAssertionException: Expected view name '~/Views/Home/Index.cshtml', actual was ''

But the test passes if I override the View to specify which viewName to return:

public virtual ActionResult Index()
{
    return View(MVC.Home.Views.Index);
}

I tried using the following assertion, but still not luck:

result.AssertViewRendered().ForView(MVC.Home.Index().GetT4MVCResult().Action);

The following error is raised:

MvcContrib.TestHelper.ActionResultAssertionException: Expected view name 'Index', actual was ''

I then realized that I had misread the assertion failure, so I changed the test to this:

result.AssertViewRendered().ForView(String.Empty);

The test passes, but the test itself seems to be useless.

Preferably I don’t want to have to specify all views by name, so how do I test this? To clarify, I am using the MvcContrib.Mvc3.TestHelper-ci 3.0.96.0, which I installed today from NuGet.

UPDATE

This isn’t an answer to the question, but I have started doing the following instead, which provides more value as a test case:

using (var controller = new FeatureController(mockGateway))
{
    // Act
    var result = controller.Index();
    var model = result.ViewData.Model as MyModel;

    // Assert
    Assert.IsNotNull(model, "Model is null or wrong type");
    result.AssertViewRendered().WithViewData<MyModel>();

    // Alternative Assert for model data
    Assert.IsTrue(model.Items.Count > 0);
}
  • 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-17T16:09:28+00:00Added an answer on June 17, 2026 at 4:09 pm

    I left this open for a considerable amount of time, so that anyone else could answer if they chose to. I’ll now answer this myself.

    The following checks to make sure that the view returned contains the expected model, and more appropriately data within that model. This is a much better unit test for the controller in question.

    using (var controller = new FeatureController(mockGateway))
    {
        // Act
        var result = controller.Index();
        var model = result.ViewData.Model as MyModel;
    
        // Assert
        Assert.IsNotNull(model, "Model is null or wrong type");
        result.AssertViewRendered().WithViewData<MyModel>();
    
        // Alternative Assert for model data
        Assert.IsTrue(model.Items.Count > 0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using T4MVC in our ASP.NET MVC project. I have a statement like
I'm using .NET 3.5, MVC 2 and T4MVC 2.6.42... I have the following action:
I'm writing specflow tests using Watin, for an Asp.Net MVC application which uses T4MVC.
I have an ASP.NET MVC 3 web application. I recently installed T4MVC templates by
I am using T4MVC and the Chirpy plugin in an ASP.Net MVC 3 website
Good day! I'm using ASP.NET MVC 2 and T4MVC and it seems some code
Yesterday I was having fully compiled ASP.NET MVC 3.0 project. Today when i opened
I have a ASP.NET MVC site and it works just fine when I run
I'm working on an ASP.NET MVC solution that has a number of different menus.
I'm using T4MVC in my project . but after deploying to a virtual directory

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.