public void Test_InnerSmtpClient() { var wrapper = new SmtpClientWrapper(); var client = new SmtpClient(); wrapper.InnerSmtpClient = client; Assert.AreSame(client, wrapper.InnerSmtpClient); }
public void SetUp() { var smtpClient = new SmtpClient { DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory }; _mailDirectory = Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "Mails")); smtpClient.PickupDirectoryLocation = _mailDirectory.FullName; smtpClient.Host = "smtp.gmail.com"; smtpClient.Port = 597; _smtpClient = new SmtpClientWrapper { InnerSmtpClient = smtpClient }; _mailMessage = new MvcMailMessage { From = new MailAddress("*****@*****.**") }; _mailMessage.To.Add("*****@*****.**"); _mailMessage.Subject = "Hello!"; _mailMessage.Body = "Mail Body"; }
private static void UseDefaultCredentialsTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.IsFalse(smtpClient.UseDefaultCredentials); Assert.IsFalse(smtpClientWrapper.UseDefaultCredentials); Assert.AreEqual(smtpClient.UseDefaultCredentials, smtpClientWrapper.UseDefaultCredentials); bool useDefaultCredentials = DateTime.Now.Second%2 == 0; smtpClientWrapper.UseDefaultCredentials = useDefaultCredentials; Assert.AreEqual(useDefaultCredentials, smtpClient.UseDefaultCredentials); Assert.AreEqual(useDefaultCredentials, smtpClientWrapper.UseDefaultCredentials); Assert.AreEqual(smtpClient.UseDefaultCredentials, smtpClientWrapper.UseDefaultCredentials); }
private static void TimeoutTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.AreEqual(smtpClient.Timeout, smtpClientWrapper.Timeout); int timeout = DateTime.Now.Millisecond; smtpClientWrapper.Timeout = timeout; Assert.AreEqual(timeout, smtpClient.Timeout); Assert.AreEqual(timeout, smtpClientWrapper.Timeout); Assert.AreEqual(smtpClient.Timeout, smtpClientWrapper.Timeout); }
private static void TargetNameTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); const string defaultTargetName = "SMTPSVC/"; Assert.AreEqual(defaultTargetName, smtpClient.TargetName); Assert.AreEqual(defaultTargetName, smtpClientWrapper.TargetName); Assert.AreEqual(smtpClient.TargetName, smtpClientWrapper.TargetName); string targetName = Guid.NewGuid().ToString(); smtpClientWrapper.TargetName = targetName; Assert.AreEqual(targetName, smtpClient.TargetName); Assert.AreEqual(targetName, smtpClientWrapper.TargetName); Assert.AreEqual(smtpClient.TargetName, smtpClientWrapper.TargetName); }
private static void PortTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.AreEqual(smtpClient.Port, smtpClientWrapper.Port); int port = DateTime.Now.Millisecond; smtpClientWrapper.Port = port; Assert.AreEqual(port, smtpClient.Port); Assert.AreEqual(port, smtpClientWrapper.Port); Assert.AreEqual(smtpClient.Port, smtpClientWrapper.Port); }
private static void PickupDirectoryLocationTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.IsNull(smtpClient.PickupDirectoryLocation); Assert.IsNull(smtpClientWrapper.PickupDirectoryLocation); Assert.AreEqual(smtpClient.PickupDirectoryLocation, smtpClientWrapper.PickupDirectoryLocation); string pickupDirectoryLocation = Guid.NewGuid().ToString(); smtpClientWrapper.PickupDirectoryLocation = pickupDirectoryLocation; Assert.AreEqual(pickupDirectoryLocation, smtpClient.PickupDirectoryLocation); Assert.AreEqual(pickupDirectoryLocation, smtpClientWrapper.PickupDirectoryLocation); Assert.AreEqual(smtpClient.PickupDirectoryLocation, smtpClientWrapper.PickupDirectoryLocation); }
private static void HostTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.IsNull(smtpClient.Host); Assert.IsNull(smtpClientWrapper.Host); Assert.AreEqual(smtpClient.Host, smtpClientWrapper.Host); string host = Guid.NewGuid().ToString(); smtpClientWrapper.Host = host; Assert.AreEqual(host, smtpClient.Host); Assert.AreEqual(host, smtpClientWrapper.Host); Assert.AreEqual(smtpClient.Host, smtpClientWrapper.Host); }
private static void EnableSslTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.IsFalse(smtpClient.EnableSsl); Assert.IsFalse(smtpClientWrapper.EnableSsl); Assert.AreEqual(smtpClient.EnableSsl, smtpClientWrapper.EnableSsl); bool enableSsl = DateTime.Now.Second%2 == 0; smtpClientWrapper.EnableSsl = enableSsl; Assert.AreEqual(enableSsl, smtpClient.EnableSsl); Assert.AreEqual(enableSsl, smtpClientWrapper.EnableSsl); Assert.AreEqual(smtpClient.EnableSsl, smtpClientWrapper.EnableSsl); }
private static void DeliveryMethodTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.AreEqual(SmtpDeliveryMethod.Network, smtpClient.DeliveryMethod); Assert.AreEqual(SmtpDeliveryMethod.Network, smtpClientWrapper.DeliveryMethod); Assert.AreEqual(smtpClient.DeliveryMethod, smtpClientWrapper.DeliveryMethod); SmtpDeliveryMethod smtpDeliveryMethod; switch(DateTime.Now.Second%3) { case 0: smtpDeliveryMethod = SmtpDeliveryMethod.Network; break; case 1: smtpDeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; break; default: smtpDeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; break; } smtpClientWrapper.DeliveryMethod = smtpDeliveryMethod; Assert.AreEqual(smtpDeliveryMethod, smtpClient.DeliveryMethod); Assert.AreEqual(smtpDeliveryMethod, smtpClientWrapper.DeliveryMethod); Assert.AreEqual(smtpClient.DeliveryMethod, smtpClientWrapper.DeliveryMethod); }
private static void CredentialsTest() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.IsNull(smtpClient.Credentials); Assert.IsNull(smtpClientWrapper.Credentials); Assert.AreEqual(smtpClient.Credentials, smtpClientWrapper.Credentials); ICredentialsByHost credentials = Mock.Of<ICredentialsByHost>(); smtpClientWrapper.Credentials = credentials; Assert.AreEqual(credentials, smtpClient.Credentials); Assert.AreEqual(credentials, smtpClientWrapper.Credentials); Assert.AreEqual(smtpClient.Credentials, smtpClientWrapper.Credentials); }
public void ToSmtpClient_IfTheSmtpClientWrapperParameterIsNotNull_ShouldReturnTheWrappedSmtpClient() { SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient); Assert.AreEqual(smtpClient, SmtpClientWrapper.ToSmtpClient(smtpClientWrapper)); }
public void SendAsync_WithTwoParameters_IfSendCompletedIsSubscribedTo_ShouldInvokeTheEventHandler() { bool sendCompletedIsCalled = false; SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient) { DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory, PickupDirectoryLocation = AppDomain.CurrentDomain.BaseDirectory }; smtpClientWrapper.SendCompleted += delegate { sendCompletedIsCalled = true; }; using(MailMessage mailMessage = new MailMessage("test@test", "test@test", "Test", "Test")) { smtpClientWrapper.SendAsync(mailMessage, null); } Thread.Sleep(10); // Wait so the SendCompleted event-handler has been invoked. Assert.IsTrue(sendCompletedIsCalled); }
public void SendAsync_WithFiveParameters_IfSendCompletedIsSubscribedTo_ShouldInvokeTheEventHandler() { bool sendCompletedIsCalled = false; SmtpClient smtpClient = new SmtpClient(); SmtpClientWrapper smtpClientWrapper = new SmtpClientWrapper(smtpClient) { DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory, PickupDirectoryLocation = _pickupDirectoryLocation }; smtpClientWrapper.SendCompleted += delegate { sendCompletedIsCalled = true; }; smtpClientWrapper.SendAsync("test@test", "test@test", "Test", "Test", null); Thread.Sleep(10); // Wait so the SendCompleted event-handler has been invoked. Assert.IsTrue(sendCompletedIsCalled); }
public void ImplicitOperatorsTest() { SmtpClient smtpClient = null; // ReSharper disable ExpressionIsAlwaysNull SmtpClientWrapper smtpClientWrapper = smtpClient; // ReSharper restore ExpressionIsAlwaysNull Assert.IsNull(smtpClientWrapper); smtpClient = new SmtpClient(); smtpClientWrapper = smtpClient; Assert.IsNotNull(smtpClientWrapper); Assert.AreEqual(smtpClient, smtpClientWrapper.SmtpClient); smtpClient = new SmtpClient(); smtpClientWrapper = new SmtpClientWrapper(smtpClient); SmtpClient castedSmtpClient = smtpClientWrapper; Assert.IsNotNull(castedSmtpClient); Assert.AreEqual(smtpClientWrapper.SmtpClient, castedSmtpClient); smtpClientWrapper = null; // ReSharper disable ExpressionIsAlwaysNull smtpClient = smtpClientWrapper; // ReSharper restore ExpressionIsAlwaysNull Assert.IsNull(smtpClient); }
public EmailService(SmtpClientWrapper smtpClient = null, ConfigurationService configurationService = null, CurrentHttpContextWrapper currentHttpContextWrapper = null) { _currentHttpContextWrapper = currentHttpContextWrapper ?? new CurrentHttpContextWrapper(); _smtpClient = smtpClient ?? new SmtpClientWrapper(); _configurationService = configurationService ?? new ConfigurationService(); }