public void TestSerialization() { var expected = new SmtpProtocolException("Bad boys, bad boys. Whatcha gonna do?", new Exception("InnerException")); using (var stream = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(stream, expected); stream.Position = 0; var ex = (SmtpProtocolException)formatter.Deserialize(stream); Assert.AreEqual(expected.Message, ex.Message, "Unexpected Message."); } expected = new SmtpProtocolException("Bad boys, bad boys. Whatcha gonna do?"); using (var stream = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(stream, expected); stream.Position = 0; var ex = (SmtpProtocolException)formatter.Deserialize(stream); Assert.AreEqual(expected.Message, ex.Message, "Unexpected Message."); } expected = new SmtpProtocolException(); using (var stream = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(stream, expected); stream.Position = 0; var ex = (SmtpProtocolException)formatter.Deserialize(stream); Assert.AreEqual(expected.Message, ex.Message, "Unexpected Message."); } }
public void With_AuthenticateException(Type authenticateException) { var sender = GetMailMergeSender(); var msg = GetMimeMessage(); var config = new SmtpClientConfig { MessageOutput = MessageOutput.SmtpServer, NetworkCredential = new Credential() }; sender.Config.SmtpClientConfig[0] = config; Exception exception; if (authenticateException == typeof(AuthenticationException)) { exception = new AuthenticationException(); } else if (authenticateException == typeof(SmtpCommandException)) { exception = new SmtpCommandException(SmtpErrorCode.UnexpectedStatusCode, SmtpStatusCode.CommandNotImplemented, "unitTest"); } else if (authenticateException == typeof(SmtpProtocolException)) { exception = new SmtpProtocolException(); } else if (authenticateException == typeof(IOException)) { exception = new IOException(); } else if (authenticateException == typeof(Exception)) { exception = new Exception(); } else { throw new ArgumentOutOfRangeException(); } var smtpClient = new FakeSmtpClient { AuthenticateException = exception }; Assert.Throws(authenticateException, () => sender.SendMimeMessage(smtpClient, msg, config)); Assert.ThrowsAsync(authenticateException, async() => await sender.SendMimeMessageAsync(smtpClient, msg, config)); }