Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 3
0
        public void SetFromMailAddress()
        {
            // arrange
            bool stamp = true;
            var mockSmtpClient = new DashboardSmtpClient();
            EmailNotification email = new EmailNotification(stamp, mockSmtpClient);

            string fromEmail = this.emailAddress;
            string fromEmailName = "fromEmailName";

            // act
            email.SetFromMailAddress(fromEmail, fromEmailName);

            // assert
            Assert.IsTrue(email.From != null);
            Assert.IsTrue(email.From.Address == fromEmail);
            Assert.IsTrue(email.From.DisplayName == fromEmailName);
        }
Ejemplo n.º 4
0
        public void SetSmtpClient_ArgumentNullException()
        {
            // arrange
            bool stamp = true;
            var mockSmtpClient = new Mock<ISmtpClient>();
            EmailNotification email = new EmailNotification(stamp, mockSmtpClient.Object);

            try
            {
                email.SetFromMailAddress(this.emailAddress, null);
                Assert.Fail("exception not thrown");
            }
            catch (ArgumentNullException)
            {
            }
            catch
            {
                Assert.Fail("Invalid exception");
            }

            try
            {
                email.SetFromMailAddress(null, "fromEmailName");
                Assert.Fail("exception not thrown");
            }
            catch (ArgumentNullException)
            {
            }
            catch
            {
                Assert.Fail("Invalid exception");
            }
        }
Ejemplo n.º 5
0
        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");
            }
        }