How do you unit test a mail sending function

后端 未结 6 2109
礼貌的吻别
礼貌的吻别 2021-01-31 17:41

I have a function which creates a report and sends it to a user. What I\'ve done is create a mock for the email function, and verify if the \'send\' function of the email class

6条回答
  •  梦如初夏
    2021-01-31 18:41

    In your unit test tell your mocking framework to expect a call to Send() with a specific body text.

    Example for Rhino Mocks:

    var mockMail = MockRepository.GenerateMock();
    mockMail.Expect( m => m.Send("ExpectedFrom", "ExpectedTo", "ExpectedSubject", "ExpectedBodytext") );
    
    mockMail.Send(...whatever...);
    
    mockProvider.VerifyAllExpectations();
    

提交回复
热议问题