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:

  1. the same mocked isntance (e.g. mailservicemock.object) if var mailservicemock = new mock<parentclassnotinterface>{ callsbase = true }. ofcourse mean methods have virtual.
  2. 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 technique

  • unit test when call sendserver(string, string, string, string) calls sendserver(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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -