Example #1
0
        public void RecipientValidationSucessTest()
        {
            var          provider         = new RecipientValidationProvider();
            var          transportMoq     = new Mock <ITransport>(MockBehavior.Loose);
            const string recipientAddress = "*****@*****.**";

            SetResponses(string.Format("RCPT TO: {0}", recipientAddress), "DATA");

            Mock <IMessageRecipientValidator> validatorMock = new Mock <IMessageRecipientValidator>();

            validatorMock.Setup(s => s.ValidateRecipient(It.IsAny <string>())).Returns(true);

            var context = new SmtpSessionContext()
            {
                Transport          = _transportMock.Object,
                RecipientValidator = validatorMock.Object
            };

            var result = provider.RunAsync(context).Result as RecipientValidationResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(SmtpStatusCode.OK, result.StatusCode);
            Assert.IsNotNull(result.Recipients);
            List <string> reciientList = new List <string>(result.Recipients);

            Assert.IsTrue(reciientList.Count == 1);
            Assert.AreEqual(recipientAddress, reciientList[0]);
        }
Example #2
0
        virtual protected async Task ProcessSession()
        {
            _tokenSource = new CancellationTokenSource();
            var token = _tokenSource.Token;

            var handshakeResult = await HandshakeProvider.RunAsync(_sessionContext, token);

            SendReponse(handshakeResult.StatusReason, handshakeResult.StatusCode);

            if (AuthProvider != null)
            {
                var authresult = await AuthProvider.RunAsync(_sessionContext, token);

                SendReponse(authresult.StatusReason, authresult.StatusCode);
            }

            var senderValidationResult = await SenderValidationProvider.RunAsync(_sessionContext, token);

            SendReponse(senderValidationResult.StatusReason, senderValidationResult.StatusCode);

            var recipientValidationResult = await RecipientValidationProvider.RunAsync(_sessionContext, token);

            SendReponse(recipientValidationResult.StatusReason, recipientValidationResult.StatusCode);

            var messageReaderResult = await MessageReaderProvider.RunAsync(_sessionContext, token);

            SendReponse(messageReaderResult.StatusReason, messageReaderResult.StatusCode);
        }
Example #3
0
        public void RecipientValidationBadCommandTest()
        {
            var          provider         = new RecipientValidationProvider();
            var          transportMoq     = new Mock <ITransport>(MockBehavior.Loose);
            const string recipientAddress = "*****@*****.**";

            SetResponses(string.Format("MAIL TO: {0}", recipientAddress), "DATA");

            var context = new SmtpSessionContext()
            {
                Transport = _transportMock.Object
            };


            var result = provider.RunAsync(context).Result as RecipientValidationResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(SmtpStatusCode.UNKNOWN_COMMAND, result.StatusCode);
            Assert.IsNull(result.Recipients);
        }