public async Task SendAsync_SenderThrowsException_TrueForContinueOnException_LogContainsExceptionThrownAndMessageSubject() { // Arrange var builder = new WeeeSenderBuilder(); var senderException = new Exception(); var message = new MailMessage { Subject = "TestEmail" }; A.CallTo(() => builder.Sender.SendAsync(A <MailMessage> ._)) .Throws(senderException); Exception generatedException = null; A.CallTo(() => builder.Logger.Write(LogEventLevel.Error, A <Exception> ._, A <string> ._)) .Invokes((LogEventLevel l, Exception x, String m) => generatedException = x); var weeeSender = builder.Build(); // Act var result = await weeeSender.SendAsync(message, true); // Assert Assert.NotNull(generatedException); Assert.Contains("'TestEmail'", generatedException.Message); Assert.Same(senderException, generatedException.InnerException); Assert.True(result); }
public async Task SendAsync_SenderThrowsException_TrueForContinueOnException_LogContainsExceptionThrownAndMessageSubject() { // Arrange var builder = new WeeeSenderBuilder(); var senderException = new Exception(); var message = new MailMessage { Subject = "TestEmail" }; A.CallTo(() => builder.Sender.SendAsync(A<MailMessage>._)) .Throws(senderException); Exception generatedException = null; A.CallTo(() => builder.Logger.Write(LogEventLevel.Error, A<Exception>._, A<string>._)) .Invokes((LogEventLevel l, Exception x, String m) => generatedException = x); var weeeSender = builder.Build(); // Act var result = await weeeSender.SendAsync(message, true); // Assert Assert.NotNull(generatedException); Assert.Contains("'TestEmail'", generatedException.Message); Assert.Same(senderException, generatedException.InnerException); Assert.True(result); }
public async Task SendAsync_SendsSpecifiedMailMessage(bool continueOnException) { // Arrange var builder = new WeeeSenderBuilder(); var weeeSender = builder.Build(); var mailMessage = new MailMessage(); // Act await weeeSender.SendAsync(mailMessage, continueOnException); // Assert A.CallTo(() => builder.Sender.SendAsync(mailMessage)) .MustHaveHappened(); }
public async Task SendAsync_SendsSpecifiedMailMessage(bool continueOnException) { // Arrange var builder = new WeeeSenderBuilder(); var weeeSender = builder.Build(); var mailMessage = new MailMessage(); // Act await weeeSender.SendAsync(mailMessage, continueOnException); // Assert A.CallTo(() => builder.Sender.SendAsync(mailMessage)) .MustHaveHappened(); }
public async Task SendAsync_SenderThrowsException_FalseForContinueOnException_ExceptionIsNotThrown() { // Arrange var builder = new WeeeSenderBuilder(); var senderException = new Exception(); A.CallTo(() => builder.Sender.SendAsync(A<MailMessage>._)) .Throws(senderException); var weeeSender = builder.Build(); // Act, Assert var thrownException = await Record.ExceptionAsync(() => weeeSender.SendAsync(A.Dummy<MailMessage>(), false)); Assert.NotNull(thrownException); Assert.Same(senderException, thrownException); }
public async Task SendAsync_SenderThrowsException_FalseForContinueOnException_ExceptionIsNotThrown() { // Arrange var builder = new WeeeSenderBuilder(); var senderException = new Exception(); A.CallTo(() => builder.Sender.SendAsync(A <MailMessage> ._)) .Throws(senderException); var weeeSender = builder.Build(); // Act, Assert var thrownException = await Record.ExceptionAsync(() => weeeSender.SendAsync(A.Dummy <MailMessage>(), false)); Assert.NotNull(thrownException); Assert.Same(senderException, thrownException); }
public async Task SendAsync_SenderThrowsException_TrueForContinueOnException_ExceptionIsLogged() { // Arrange var builder = new WeeeSenderBuilder(); A.CallTo(() => builder.Sender.SendAsync(A <MailMessage> ._)) .Throws(new Exception()); var weeeSender = builder.Build(); // Act var result = await weeeSender.SendAsync(A.Dummy <MailMessage>(), true); // Assert A.CallTo(() => builder.Sender.SendAsync(A <MailMessage> ._)) .MustHaveHappened(); A.CallTo(() => builder.Logger.Write(LogEventLevel.Error, A <Exception> ._, A <string> ._)) .MustHaveHappened(); Assert.True(result); }
public async Task SendAsync_SenderThrowsException_TrueForContinueOnException_ExceptionIsLogged() { // Arrange var builder = new WeeeSenderBuilder(); A.CallTo(() => builder.Sender.SendAsync(A<MailMessage>._)) .Throws(new Exception()); var weeeSender = builder.Build(); // Act var result = await weeeSender.SendAsync(A.Dummy<MailMessage>(), true); // Assert A.CallTo(() => builder.Sender.SendAsync(A<MailMessage>._)) .MustHaveHappened(); A.CallTo(() => builder.Logger.Write(LogEventLevel.Error, A<Exception>._, A<string>._)) .MustHaveHappened(); Assert.True(result); }