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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:46:10+00:00 2026-06-14T14:46:10+00:00

I have a mock (using Moq) setup for a Mvc3 controller eg. [TestMethod] public

  • 0

I have a mock (using Moq) setup for a Mvc3 controller eg.

[TestMethod]
public void Step_One_Post_Should_Redirect_To_Step_Two()
{
    // this test checks that when I submit a type parameter of StepOneModel and
    // the next button was clicked Request["next"] ,  then goto Step Two
}

The only thing stopping this test running is the Save Method called from the controller, which fails as values aren’t properly set in Session in this test context. Really I want to omit this database call from this unit test.

Basically how do I stup/mock the Save(model) call from the controller action?

[HttpPost]
public ActionResult Index(IStepViewModel step)
{
    // after model is deserialized
    if (!string.IsNullOrEmpty(Request["next"]))
    {
        Save(model)  <-- the bit blocking me
    }

    return View(model)  <-- the bit I want to assert against
}
  • 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-14T14:46:11+00:00Added an answer on June 14, 2026 at 2:46 pm

    I suggest using the excellent library MvcContrib-test helpers

    It gives you mocked session out of the box.

    General Concepts

    One of the major advantages of the new MVC.Net framework is the ease with which it can be tested. While this is generally true, there are a number of areas where testing the framework becomes difficult to do. The TestHelper assists by providing a Controller Factory that creates controllers with internal data members correctly initialized. These include:

    • HttpContext
    • HttpRequest
    • HttpResponse
    • HttpSession <———————–
    • Form
    • TempData
    • QueryString
    • ApplicationPath
    • PathInfo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MVC3.NET I have a file upload method in a controller that works fine
I have some code in a test using Moq: public class Invoice { ...
I have a unit test that creates a mock calls my method to be
I'm using MoQ to test some controllers I have. I'm not able to set
At the moment I have: [Test] public void DrawDrawsAllScreensInTheReverseOrderOfTheStack() { // Arrange. var screenMockOne
I have a controller in C# using the ASP.Net MVC framework public class HomeController:Controller{
I'm using Moq with a MVC3 project and EF (code first). I currently have
I have a private method that should return true.I m using Nunit and MOQ
I have an object I'm trying to mock using moq. The object's constructor has
I have this method to unit test: public virtual TEntity Get(int id) { return

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.