asp.net mvc - Comprehensive Unit Testing for a method -


i have controller method - currentvalues

[httpget] public actionresult currentvalues(valueretrieverviewmodel valueretrievermodel) {     int page = 0;     if(!string.isnullorempty(valueretrievermodel.page))     {         int.tryparse(valueretrievermodel.page, out page);     }      if (page <= 0) page = 1;      var values = getvalues(page);      if (values != null)     {         if (values.queryresults.count > 0)         {             viewdata["name"] = valueretrievermodel.name;              viewdata["school"] = valueretrievermodel.school;                          viewdata["team"] = valueretrievermodel.team;         }     }      var valrtrvrviewmodel = new valuesviewmodel     {         results = values,           inputparms = valueretrievermodel     };      return view("currentvalues", searchviewmodel); } 

i have controller comprehensively unit tested utilizing ms-vs-unit test suite , if needed moq too.

the core of method retrieved values - getvalues(page).

  1. what tests can write have comprehensive unit testing method? sample code helpful along test scenarios.
  2. how use moq mock valueretrieverviewmodel? should or can use moq other purpose here specifically?

the following article excellent in explaining in detail tests should write when testing controllers, including when use mocking framework. short too. http://www.arrangeactassert.com/how-to-unit-test-asp-net-mvc-controllers/

excerpt article:

let me start off discussing types of unit tests should creating mvc controllers. tests check correct action result returned controller action. includes information action result, such testing correct view returned view result.

tests check if view model expected. if have typed view expects class foo , pass class bar view model, code compile, result in runtime error 1 shown below.

if testing more controller doing much.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -