c# - How to mock other class object using Rhino Mocks -


i using visual studio 2013 , mstest unit test , rhino mocks mocking object.

is there way, can mock other class object

public class organization  {     public dataset getusers()     {        dataset ds = new dataset();  // added columns , rows here // class interacting database. that's why want create  // mock of class.         return ds;     } } 

my main class below

public class users  {     public dataset getusers(organization org)     {         dataset ds = org.getusers();          return ds;     } } 

my test method below

[testmethod] public void getuserstest() {      dataset ds = new dataset();      //added mock rows , columns dataset       var objorg = mockrepository.generatemock<organization>();      objorg.expect(x => x.getusers()).return(ds);       users obj = new users();      dataset dsresult = obj.getusers(objorg); } 

it giving me error. can me write unit test above class's getusers method please?

your method not virtual method. when mock class using rhinomocks, each method want override must virtual method.

change method to:

public virtual dataset getusers() {      dataset ds = new dataset();          // added columns , rows here         // class interacting database. that's why want create          // mock of class.       return ds; } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -