예제 #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 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");
            }
        }