public void Notify() { string fromEmail = this.emailAddress; string fromEmailName = "fromEmailName"; string host = this.emailHost; string port = this.emailPort; bool stamp = true; var mockSmtpClient = new Mock<ISmtpClient>(); EmailNotification email = new EmailNotification(stamp, mockSmtpClient.Object); email.SmtpClient = mockSmtpClient.Object; email.SetFromMailAddress(fromEmail, fromEmailName/*, host, port*/); // username and password string username = "******"; string password = "******"; email.SetNetworkCredentials(username, password); string toemail = this.emailAddress; string toname = "toname"; email.SetReceiver(toemail, toname); string subject = "subject"; string text = "text"; // act email.Notify(subject, text); // assert Assert.IsTrue(email.NotificationSent == true); mockSmtpClient.Verify(a => a.Send(email.Message), Times.Once()); }
/// <summary> /// Only used to send internal IT-ish notices /// </summary> /// <param name="subject">Email subject</param> /// <param name="text">Email text</param> protected void Notify(string subject, string text) { bool stamp = true; var smtpClient = new DashboardSmtpClient(); EmailNotification email = new EmailNotification(stamp, smtpClient); email.SetFromMailAddress( this.FeedConfiguration.EmailFromAddress, this.FeedConfiguration.EmailFromName); email.SetReceiver( this.FeedConfiguration.EmailToAddress, this.FeedConfiguration.EmailToName); email.Notify(subject, text); }
public void Notify_ArgumentNullException() { // arrange bool stamp = true; var mockSmtpClient = new Mock<ISmtpClient>(); EmailNotification email = new EmailNotification(stamp, mockSmtpClient.Object); try { email.Notify("title", null); Assert.Fail("exception not thrown"); } catch (ArgumentNullException) { } catch { Assert.Fail("Invalid exception"); } try { email.Notify(null, "Text"); Assert.Fail("exception not thrown"); } catch (ArgumentNullException) { } catch { Assert.Fail("Invalid exception"); } try { email.Notify("title", "Text"); email.SetReceiver(this.emailAddress, "toname"); Assert.Fail("exception not thrown"); } catch (NullReferenceException ex) { Assert.IsTrue(ex.Message == "From"); } catch { Assert.Fail("Invalid exception"); } try { email.SetFromMailAddress(this.emailAddress, "fromEmailName"/*, this.emailHost, this.emailPort*/); email.Notify("title", "Text"); Assert.Fail("exception not thrown"); } catch (NullReferenceException ex) { Assert.IsTrue(ex.Message == "To"); } catch { Assert.Fail("Invalid exception"); } }