Unit testing the request, how?

Last post 08-15-2008 11:18 AM by sdelano. 3 replies.

Sort Posts:

  • Unit testing the request, how?

    08-14-2008, 1:48 PM
    • Member
      3 point Member
    • sdelano
    • Member since 08-07-2008, 11:41 AM
    • Posts 16

    Hi all,

    I'm working on an app that will take user input from a form, and based on that input return a new view. I want to unit test this but I have searched and searched and cannot find a good way to insert elements into the request so that I can return the correct view. 

    Is there a really simple way to just add request parameters when unit testing?

    Thanks,
    sdelano

  • Re: Unit testing the request, how?

    08-14-2008, 4:20 PM
    Answer
    • Member
      3 point Member
    • sdelano
    • Member since 08-07-2008, 11:41 AM
    • Posts 16

     Nevermind, I found Moq. I would like the ability to not have to use Mocking (actually have never heard about it until today) but I guess I can work with it.

  • Re: Unit testing the request, how?

    08-14-2008, 8:23 PM
    • Contributor
      4,980 point Contributor
    • Paul Linton
    • Member since 04-29-2008, 11:16 PM
    • Posts 870

    Have a look at this blog bost

    http://weblogs.asp.net/stephenwalther/archive/2008/07/11/asp-net-mvc-tip-18-parameterize-the-http-context.aspx Stephen shows how to convert form parameters into a namevaluecollection which is passed as a parameter to your controller.  You can create a NameValueCollection in your test method and pass it to the controller under test, no need for a context or any mocking.

    hope that helps

    Got a c# problem? Try .NET Book Zero from Charles Petzold, it's a free pdf.
  • Re: Unit testing the request, how?

    08-15-2008, 11:18 AM
    • Member
      3 point Member
    • sdelano
    • Member since 08-07-2008, 11:41 AM
    • Posts 16

     Thanks for the heads up Paul. It turns out that I liked Moq and can see its usefulness in unit testing other parts of my app. I think I am going to stick with it for my purposes at the moment.

     -sdelano

Page 1 of 1 (4 items)