0

Just started learning mvc3. I've built a fairly basic website (also using EF-Code-First if that makes a difference), now I'm trying to progress to building tests for it

My controller gets querystring data by going Request["whatever"], and when I run the test it says request is null

All the tutorials I've looked at so far have kinda lost me. Going into mocks and such, which they seem to assume prior knowledge of (never used mocks, so don't understand them yet)

Does anyone have a nice and basic tutorial to get me into unit testing? Or perhaps could give me an example

1 Answer 1

2

It is against MVC's design pattern to use HttpRequest directly. You can access the query string variables on your action as parameters.

Sign up to request clarification or add additional context in comments.

3 Comments

An added bonus of putting them as action parameters (aside from easier unit testing) is that it is type safe also (no need to parse the id, just declare the parameter as an int). If it's an optional parameter and you're dealing with a value type, make it nullable.
Thank you mind readers :p Switched to action parameters and it works nicely
You are forgetting cases where you need to loop through the entire querystring collection as you may not know the values in advance. FormCollection enables this behavior for form values, but there is no equivalent for querystring!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.