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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:11:31+00:00 2026-05-27T21:11:31+00:00

A controller in my ASP.NET MVC application pre-populates form data displayed by my view

  • 0

A controller in my ASP.NET MVC application pre-populates form data displayed by my view according to a couple of fairly straight forward rules.

It seems like this would be a good thing to cover in my unit testing. But the only way I could see to verify the correct data is placed in the form, would be to extract the logic from the controller in what feels like an unnatural way.

Can someone suggest ways to approach this?

All the examples I’ve found of unit testing controllers seemed very trivial, such as verifying it returned the expected type of view. I’m not sure I even see the value in that.

  • 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-27T21:11:32+00:00Added an answer on May 27, 2026 at 9:11 pm

    You can test by casting the returned object to the appropriate class, instead of using their base class (which is returned by default)

    For example, to test the default AccountController you’d so something like this:

    var controller = new AccountController();
    var result = controller.LogOn() as ViewResult;
    var model = result.Model as LogOnModel;
    
    Assert.IsTrue(model.RememberMe); // assuming you "pre-populated" enabled the checkbox
    

    Checking if the returned object is filled with the right data does not seem “unnatural” to me, or did you meant it differently?

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

Sidebar

Related Questions

I have one View and one Controller in my ASP.net MVC Application. I have
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
In asp.net mvc, you can easily call/add a controller from a view, but what
I'm trying to use F# for an ASP.NET MVC application. One my controller actions
In C# ASP.NET MVC application I use Link to SQL to provide data for
I am working in an ASP.NET MVC Application. I have a view model as
I have an ASP.NET MVC 2 application with a custom StructureMap controller factory to
I have a ASP.NET MVC application which has a view populated with a model
I have a controller in an ASP.NET MVC application. The page has several filters
I'm creating a new ASP.NET MVC application. So far I've used the Account controller

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.