c# - ASP.NET MVC Simple Controller Unit Test -


i'm trying learn unit testing, , have super simple class, unit test:

public class homecontroller : controller {     public actionresult index()     {         return view(new homeviewmodel         {             logourl = this.url.content("~/images/product.png")        });     } }  [testmethod] public void index() {     assert.isnotnull(new homecontroller().index() viewresult); } 

i'm getting null reference exceptions. it's related using this.url() without httpcontext in unit test, believe.

how can unit test pass while still using this.url()? i'm fine using moq. :)

the answer can found here example (gist): https://gist.github.com/johnnyreilly/4959924

here relating stack overflow question: asp.net mvc: unit testing controllers use urlhelper

both should on right tracks.

it comes down mocking httprequestbase , httpresponsebase can mock actual httpcontextbase, being used urlhelper class.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -