Asp.Net MVC2 Unit Test Controller: Request["Choice"] -


i new unit testing , trying learn tdd, cannot figure out how test this. spent 2 days on (don't worry not employer, please no smart answers).

i wrote controller want test, need assign value "choice". simplified, looks this:

    public actionresult index()     {           string s = request["choice"];           return view(new mylist.getlist(s));     } 

how assign value "choice" in test or can i? in application, value of "choice" assigned radiobutton in form in page view. test in psuedocode:

    [testmethod()]     public void indextest()     {           categorycontroller target = new categorycontroller();           var result = target.index() viewresult;           mylist actual = result.viewdata.model mylist;            // etc ...            assert.areequal(expected.list, actual.list);     } 

thanks, mario

i'm pretty sure can accept choice parameter action method. no shenanigans necessary:

public actionresult index(string choice) {       return view(new mylist.getlist(choice)); } 

this wouldn't work if choice coming cookie or server variable, assume you're expecting either query string or form post.


Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -