public void RunMethod_ShouldMarkRecipientAsSent() { // Arrange var stubRepository = new Mock<IRepository>(); var stubMailHelper = new Mock<IMailHelper>(); var stubRecipient = new Recipient(); stubRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient); // Act var bulkMailSender = new BulkSender(stubRepository.Object, stubMailHelper.Object); bulkMailSender.Run(); // Assert Assert.AreEqual(SendingStatus.Success, stubRecipient.Status); }
public void RunMethod_ShouldSendEmailToFirstUnsentAddress() { // Arrange var stubRepository = new Mock<IRepository>(); var mockMailHelper = new Mock<IMailHelper>(); var stubRecipient = new Recipient("*****@*****.**"); stubRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient); mockMailHelper.Setup(mh => mh.SendEmail("*****@*****.**")).Verifiable(); // Act var bulkMailSender = new BulkSender(stubRepository.Object, mockMailHelper.Object); bulkMailSender.Run(); // Assert mockMailHelper.Verify(); }
public void RunMethod_ShouldSaveExceptionMesssage_IfSendingWasNotSuccessful() { // Arrange var stubRepository = new Mock<IRepository>(); var stubMailHelper = new Mock<IMailHelper>(); var stubRecipient = new Recipient(); stubRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient); stubMailHelper.Setup(mh => mh.SendEmail(It.IsAny<string>())).Throws(new Exception("sending failed")); // Act var bulkMailSender = new BulkSender(stubRepository.Object, stubMailHelper.Object); bulkMailSender.Run(); // Assert Assert.AreEqual("sending failed", stubRecipient.Exception); }
public void RunMethod_ShouldSetLastAttemptDate_IfSendingWasSuccessful() { // Arrange var stubRepository = new Mock<IRepository>(); var stubMailHelper = new Mock<IMailHelper>(); var stubRecipient = new Recipient(); stubRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient); // Act var bulkMailSender = new BulkSender(stubRepository.Object, stubMailHelper.Object); bulkMailSender.Run(); // Assert Assert.IsNotNull(stubRecipient.LastAttemptDate); }
public void RunMethod_ShouldUpdateRecipientInDatabase_IfSendingWasSuccesful() { // Arrange var mockRepository = new Mock<IRepository>(); var stubMailHelper = new Mock<IMailHelper>(); var stubRecipient = new Recipient(); mockRepository.Setup(r => r.GetFirstUnsentAddress()).Returns(stubRecipient); mockRepository.Setup(r => r.Update(stubRecipient)).Verifiable(); // Act var bulkMailSender = new BulkSender(mockRepository.Object, stubMailHelper.Object); bulkMailSender.Run(); // Assert mockRepository.Verify(); }