asp.net mvc - Mock an image upload viewmodel -


i know asp mvc, trying embrace tdd. following examples here installed xunit , testdriven (which includes moq).

problem trying mock image upload viewmodel can assert being uploaded.

moq gave me problem:

invalid setup on non-virtual (overridable in vb) member

while trying to

var imagemock = new mock<imageviewmodel>(); imagemock.setup(x => x.isurl).returns(true);` 

i not sure how keep on going - nonsense create interfaces view model, programming site, not testing environment.

should replace mock environment or define interface or ... ?

please give experienced , informative advise , please provide or @ least samples you're advising me do.

thanks!

first of all, auto property?

public bool isurl {get; set;} 

if so, set value in set of test. if it's not auto property, make more sense move method, instead of property. , @ time, make method virtual (which error message saying.)

when mocking, can't mock things either not interfaces or not virtual (i believe there paid mocking libraries let you, fakeiteasy, moq , others require virtual.)

to this, need make property this:

public virtual bool isurl {get; set;} 

secondly, testing on view model? testing getters , setters largely waste of time because tested in other places of code. plus, tests on getters , setters testing compiler, not code. if getters , setters don't work in .net you've got whole host of problems. better test creation of view model , make sure has right values after creation.


Comments