How to mock/fake SmtpClient in a UnitTest?

前端 未结 4 1620
野的像风
野的像风 2020-12-30 03:38

I want to use it to fake System.Net.Mail.SmtpClient in a MS-Test UnitTest. Therefor I added a Fakes Assembmly of System.dll. Then I create a ShimsContext<

4条回答
  •  醉酒成梦
    2020-12-30 03:58

    This isn't really an answer to your question, but an alternative aproach:

    In the app.config, set up the smtp settings to deliver the mails as files to a local directory instead. Then you can load the file and check the contents in your assert section.

    You'll have to write a bit more code for the assertion (or preferably create some helper functions) but you won't have to do anything that affects the production code.

提交回复
热议问题