コード例 #1
0
        public void TestStartTransactionValidationSuccess()
        {
            var core = new SMTPServer(DefaultLoader());

            var ip = IPAddress.Parse("127.0.0.1");

            SMTPTransaction actualTransaction = null;
            IPAddress       actualIP          = null;

            core.OnConnect += (transaction, args) =>
            {
                actualTransaction = transaction;
                actualIP          = args.IP;
            };

            SMTPTransaction expectedTransaction;
            SMTPResponse    reponse;

            using (ShimsContext.Create())
            {
                var settings = new StubIReceiveSettings();

                expectedTransaction = core.StartTransaction(ip, settings, out reponse);
            }

            Assert.Equal(SMTPStatusCode.Ready, reponse.Code);
            Assert.Same(expectedTransaction, actualTransaction);
            Assert.Same(ip, actualIP);
        }
コード例 #2
0
        public void TestStartTransactionValidationFail(SMTPStatusCode?code)
        {
            var core = new SMTPServer(DefaultLoader());

            var ip = IPAddress.Parse("127.0.0.1");

            using (ShimsContext.Create())
            {
                var closed = false;
                ShimSMTPTransaction.AllInstances.Close = transaction => { closed = true; };

                core.OnConnect += (transaction, args) =>
                {
                    args.Cancel       = true;
                    args.ResponseCode = code;
                };

                SMTPResponse reponse;
                using (ShimsContext.Create())
                {
                    var settings = new StubIReceiveSettings();

                    core.StartTransaction(ip, settings, out reponse);
                }

                Assert.Equal(code ?? SMTPStatusCode.TransactionFailed, reponse.Code);
                Assert.True(closed);
            }
        }
コード例 #3
0
        public void TestStartTransaction()
        {
            const string     banner         = "Test Banner";
            IReceiveSettings actualSettings = null;

            var core = new SMTPServer(DefaultLoader());

            var ip = IPAddress.Parse("127.0.0.1");

            using (ShimsContext.Create())
            {
                var expectedSettings = new StubIReceiveSettings
                {
                    BannerGet = () => banner
                };

                SMTPServer actualCore = null;

                ShimSMTPTransaction.ConstructorSMTPServerIReceiveSettings = (transaction, smtpCore, settings) =>
                {
                    actualSettings = settings;
                    actualCore     = smtpCore;
                };

                SMTPResponse reponse;
                core.StartTransaction(ip, expectedSettings, out reponse);

                Assert.Equal(SMTPStatusCode.Ready, reponse.Code);
                Assert.Equal(banner, reponse.Args[0]);
                Assert.Same(core, actualCore);
                Assert.Same(expectedSettings, actualSettings);
            }
        }