コード例 #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());
        }
コード例 #2
0
        public void Email()
        {
            // arrange
            bool stamp = true;
            var mockSmtpClient = new Mock<ISmtpClient>();

            // act
            EmailNotification email = new EmailNotification(stamp, mockSmtpClient.Object);

            // assert
            Assert.IsTrue(email.StampEmailWithTime == stamp);
        }
コード例 #3
0
        /// <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);
        }
コード例 #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");
            }
        }
コード例 #5
0
        public void SetReceiver()
        {
            // arrange
            bool stamp = true;
            var mockSmtpClient = new Mock<ISmtpClient>();
            EmailNotification email = new EmailNotification(stamp, mockSmtpClient.Object);

            string toEmail = this.emailAddress;
            string toName = "toemailname";

            // act
            email.SetReceiver(toEmail, toName);

            // assert
            Assert.IsTrue(email.To != null);
            Assert.IsTrue(email.To.Address == toEmail);
            Assert.IsTrue(email.To.DisplayName == toName);
        }
コード例 #6
0
        public void SetNetworkCredentials_ArgumentNullException()
        {
            // arrange
            bool stamp = true;
            var mockSmtpClient = new Mock<ISmtpClient>();
            EmailNotification email = new EmailNotification(stamp, mockSmtpClient.Object);

            try
            {
                email.SetNetworkCredentials("user", null);
                Assert.Fail("exception not thrown");
            }
            catch (ArgumentNullException)
            {
            }
            catch
            {
                Assert.Fail("Invalid exception");
            }

            try
            {
                email.SetNetworkCredentials(null, "password");
                Assert.Fail("exception not thrown");
            }
            catch (ArgumentNullException)
            {
            }
            catch
            {
                Assert.Fail("Invalid exception");
            }
        }
コード例 #7
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);
        }
コード例 #8
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");
            }
        }