public string SendEmailTo(string emailAddress, ISystemUserRepository repository) { if (string.IsNullOrEmpty(emailAddress)) { return("Please enter the e-mail address to send your password to"); } bool emailSent = _mailer.SendForgottenPasswordEmail(emailAddress, repository); if (emailSent) { return(string.Format("Your password has been e-mailed to {0}", emailAddress)); } else { return(string.Format("We could not find a user with the e-mail address {0}", emailAddress)); } }
public void Correctly_attempts_to_send_email_and_provide_feedback_when_email_cannot_be_sent() { MockRepository mocks = new MockRepository(); IForgottenPasswordMailer mailer = mocks.CreateMock <IForgottenPasswordMailer>(); ISystemUserRepository repository = mocks.CreateMock <ISystemUserRepository>(); using (mocks.Record()) { Expect.Call(mailer.SendForgottenPasswordEmail("*****@*****.**", repository)).Return(false); } using (mocks.Playback()) { IForgottenPasswordService service = new ForgottenPasswordService(mailer); string userFeedback = service.SendEmailTo("*****@*****.**", repository); Assert.That(userFeedback, Is.EqualTo("We could not find a user with the e-mail address [email protected]")); } mocks.VerifyAll(); }