c# - Mock a response of a inner function but test the outer function -


i have c# code setup way.

public class client : iclient {     public string funca()     {        var output = funcb(1);        //do on output , produce finalresult        return finalresult;     }      public string funcb(int x)     {          // operations on produces string result          return result;     } } 

i want mock funcb output let funca perform based on output funcb.

in test class following:

public class mockclient {     private mock<iclient> _mockclient;      public mockclient()     {         _mockclient = new mock<iclient>();     }      [testmethod]     public void testclient()     {         _mockclient.setup(foo => foo.funcb(it.isany<int>())).returns("test");         var testoutput = _mockclient.object.funca();     } } 

the variable testoutput returns null. understand why, because object created interface. not sure how work around problem. inputs on helpful.

i assuming using moq based off of syntax? if so, can use "partial mocks". example:

change funcb virtual

public virtual string funcb(int x) {     // operations on produces string result     return result; } 

then mock concrete type , set callbase property true:

[testmethod] public void testclient() {     mock<client> _mockclient = mock<client>();     _mockclient.callbase = true;     _mockclient.setup(foo => foo.funcb(it.isany<int>())).returns("test");     var testoutput = _mockclient.object.funca(); } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -