Exemplo n.º 1
0
        public void SmtpServer_should_be_able_to_receive_mail_from_SmtpClient()
        {
            var mockEmailValidator = new Mock <IEmailValidator>();

            mockEmailValidator.Setup(x => x.Validate(It.IsAny <string>())).Returns(true);

            var testPort          = TestHelpers.GetTestPort();
            var mailDataCollector = new TestMailDataCollector();

            using (var smtpServer = new SmtpServer())
            {
                var responderFactory = new SmtpResponderFactory(smtpServer.Configuration, mockEmailValidator.Object)
                {
                    DataResponder = mailDataCollector
                };
                smtpServer.DefaultResponderFactory = responderFactory;
                smtpServer.BindAndListenTo(IPAddress.Loopback, testPort);

                var sendMailTask =
                    Task.Factory.StartNew(() => SendMail(testPort, "*****@*****.**", "*****@*****.**", "subject", "body"),
                                          TaskCreationOptions.LongRunning);

                Assert.True(sendMailTask.Wait(3000));
                mockEmailValidator.Verify(x => x.Validate("*****@*****.**"));
                mockEmailValidator.Verify(x => x.Validate("*****@*****.**"));

                var mailData = mailDataCollector.MailData;
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("subject", mailData);
                Assert.Contains("body", mailData);
            }
        }
        public void SmtpServer_should_be_able_to_receive_mail_from_SmtpClient()
        {
            var mockEmailValidator = new Mock<IEmailValidator>();
            mockEmailValidator.Setup(x => x.Validate(It.IsAny<string>())).Returns(true);

            var testPort = TestHelpers.GetTestPort();
            var mailDataCollector = new TestMailDataCollector();

            using (var smtpServer = new SmtpServer())
            {
                var responderFactory = new SmtpResponderFactory(smtpServer.Configuration, mockEmailValidator.Object) { DataResponder = mailDataCollector };
                smtpServer.DefaultResponderFactory = responderFactory;
                smtpServer.BindAndListenTo(IPAddress.Loopback, testPort);

                var sendMailTask =
                    Task.Factory.StartNew(() => SendMail(testPort, "*****@*****.**", "*****@*****.**", "subject", "body"),
                        TaskCreationOptions.LongRunning);

                Assert.True(sendMailTask.Wait(3000));
                mockEmailValidator.Verify(x => x.Validate("*****@*****.**"));
                mockEmailValidator.Verify(x => x.Validate("*****@*****.**"));

                var mailData = mailDataCollector.MailData;
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("subject", mailData);
                Assert.Contains("body", mailData);
            }
        }
        public void SmtpServer_should_be_able_to_receive_mail_from_SmtpClient()
        {
            var testPort          = GetTestPort();
            var mailDataCollector = new TestMailDataCollector();

            using (var smtpServer = new SmtpServer())
            {
                var responderFactory = new DefaultSmtpResponderFactory <ISmtpServerConfiguration>(smtpServer.Configuration)
                {
                    DataResponder = mailDataCollector
                };
                smtpServer.DefaultResponderFactory = responderFactory;
                smtpServer.BindAndListenTo(IPAddress.Loopback, testPort);

                var sendMailTask =
                    Task.Factory.StartNew(() => SendMail(testPort, "*****@*****.**", "*****@*****.**", "subject", "body"),
                                          TaskCreationOptions.LongRunning);

                Assert.True(sendMailTask.Wait(1500));

                var mailData = mailDataCollector.MailData;
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("subject", mailData);
                Assert.Contains("body", mailData);
            }
        }
Exemplo n.º 4
0
        public void SmtpServer_should_be_able_to_receive_mail_from_SmtpClient()
        {
            var testPort = GetTestPort();
            var mailDataCollector = new TestMailDataCollector();

            using (var smtpServer = new SmtpServer())
            {
                var responderFactory = new DefaultSmtpResponderFactory<ISmtpServerConfiguration>(smtpServer.Configuration) { DataResponder = mailDataCollector };
                smtpServer.DefaultResponderFactory = responderFactory;
                smtpServer.BindAndListenTo(IPAddress.Loopback, testPort);

                var sendMailTask =
                    Task.Factory.StartNew(() => SendMail(testPort, "*****@*****.**", "*****@*****.**", "subject", "body"),
                        TaskCreationOptions.LongRunning);

                Assert.True(sendMailTask.Wait(1500));

                var mailData = mailDataCollector.MailData;
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("*****@*****.**", mailData);
                Assert.Contains("subject", mailData);
                Assert.Contains("body", mailData);
            }
        }