c# - Setup Mock to redirect to overloaded method -
i have method called:
sendmail(string from, string to, string subject, string smtpserver) and overloaded method
sendmail(string from, string to, string subject, smtpclient smtpclient) in unit test want setup mailservice mock when method sendmail(string, string, string, string) called want instead call overloaded method sendmail(string, string, string, smtpclient) , modify last parameter created smtpclient test object.
is there way that?
what want use .callback(...) on setup
mailservicemock .setup(m => m.sendmail(it.isany<string>(), it.isany<string>(), it.isany<string>(), it.isany<string>()) .callback((string from, string to, string subject, string server) => mailservice.sendmail(from, to, subject, server, somesmtpserver) more importantly why trying this?
normally test mock got called (string, stirng, string, string).
and testclass/fixture test when call
(string from, string to, string subject, string smtpserver) overload, call smtpserver overload correct details.
edit: after comments
mailservice not typo.
this either be:
- the same mocked isntance (e.g.
mailservicemock.object) ifvar mailservicemock = new mock<parentclassnotinterface>{ callsbase = true }. ofcourse mean methods have virtual. - an actual concrete implementation of class/interface.
as second note, if break one/some/all of following:
unit test calling class/method calls
sendserver(string, string, string, string). use technique describe on blog: codeperf[dot]net - tdd – mock.throw interface call verification techniqueunit test when call
sendserver(string, string, string, string)callssendserver(string, string, string, smtpserver)smtpserver being set correctly.integration test sendserver(string, string, string, smtpserver)` sends email.
possibly end-to-end test (no mocks) works.
Comments
Post a Comment