How to mock/fake SmtpClient in a UnitTest?

前端 未结 4 1609
野的像风
野的像风 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

    Another alternative is to use nDumbster:

    Install-Package nDumbster

    It runs an Smtp server in memory, which you can then verify against. It turns it more into an integration test, but generally those are higher value than unit tests, as you want to test the SmtpClient usage is also correct.

提交回复
热议问题