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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:19:10+00:00 2026-05-25T10:19:10+00:00

Basically I want to set 20 or so Request.Form values, send a POST to

  • 0

Basically I want to set 20 or so Request.Form values, send a POST to my controller, and then check the result.

I found a couple articles such as this one which describe how you can do this with a combination of NUnit, MVCContrib, and Rhino Mocks. But I don’t know if this is truly necessary.

It would seem that Visual Studio 2010 and ASP.NET MVC 2 should be able to do this natively and display the results in the little “Test Results” window. In fact, when I create a new unit test with the wizard, it comes up with this…

[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("G:\\Webs\\MyWebsite.com\\MyWebsite", "/")]
[UrlToTest("http://localhost:43383/")]
public void PaypalIPNTest()
{
    BuyController target = new BuyController(); // TODO: Initialize to an appropriate value
    ActionResult expected = new EmptyResult(); // TODO: Initialize to an appropriate value
    ActionResult actual;
    actual = target.PaypalIPN();
    Assert.AreEqual(expected, actual);
    Assert.Inconclusive("Verify the correctness of this test method.");
}

Is it possible to feed target.PaypalIPN() my Request.Form variables based on the above code? Or do I need to rely on 3rd party libraries to get this done?

  • 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-25T10:19:10+00:00Added an answer on May 25, 2026 at 10:19 am

    In fact, when I create a new unit test with the wizard, it comes up with this

    Yes, and all that you can keep from this is the method signature. The method body is useless.

    So let’s start by looking at this:

    Is it possible to feed target.PaypalIPN() my Request.Form variables

    By reading this sentence I assume that your controller action looks something like this:

    [HttpPost]
    public ActionResult PaypalIPN()
    {
        string foo = Request["foo"];
        string bar = Request["bar"];
        ... do something with foo and bar
    }
    

    So the first is to improve this code by introducing view models:

    public class MyViewModel
    {
        public string Foo { get; set; }
        public string Bar { get; set; }
    }
    

    and then modify your method signature to:

    [HttpPost]
    public ActionResult PaypalIPN(MyViewModel model)
    {
        ... do something with model.Foo and model.Bar
    }
    

    Now your controller is abstracted from any HttpContext infrastructure code (which really should be left to the framework, it is not your controller actions responsibility to read request parameters => that’s plumbing code) and unit testing it is really a simple matter:

    [TestMethod()]
    public void PaypalIPNTest()
    {
        // arrange
        var sut = new BuyController();
        var model = new MyViewModel
        {
            Foo = "some foo",
            Bar = "some bar",
        };
    
        // act
        var actual = sut.PaypalIPN(model);
    
        // assert
        // TODO:
    }
    

    OK, this being said, here we dealt with some really simple controller action. For more advanced scenarios you really should consider using a mocking framework. Personally I use MvcContrib.TestHelper with Rhino Mocks to unit test my ASP.NET MVC applications.

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

Sidebar

Related Questions

Basically I want to know how to set center alignment for a cell using
Basically I want to set Content-Type: application/json; in order to call a dot net
Basically I want to send gps coordinates (displayed on a map in the iPhone)
I found this code in a couple of websites (http://goo.gl/usUSP): <?php // Basic request
I basically want to set up a proxy server using Java which will capture
I have a rails controller I dont ever want to set a cookie. I
I want to run an ajax request within a function. Basically... function doIt(id) {
I basically want to use link_to to link to the index method of a
I basically want to do this: grep 'example.com' www_log > example.com.YYYY-MM-DD-H:i:S.log ...with of course
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not

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.