public async Task Process_NoParameters_Accepted()
        {
            TestMocks mocks = new TestMocks();

            ParameterProcessorMap map = new ParameterProcessorMap();
            await map.Process(mocks.Connection.Object, new string[] { }, true).ConfigureAwait(false);
        }
예제 #2
0
        public void Session()
        {
            TestMocks mocks = new TestMocks();

            SessionEventArgs s = new SessionEventArgs(mocks.Session.Object);

            Assert.Equal(s.Session, mocks.Session.Object);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>The <see cref="IMessageBuilder"/></returns>
        protected override IMessageBuilder GetInstance()
        {
            FileInfo tempFile = new FileInfo(Path.GetTempFileName());

            TestMocks mocks = new TestMocks();

            return(new FileMessageBuilder(tempFile, false));
        }
        public async Task Process_UnknownParameter_Throws()
        {
            SmtpServerException e = await Assert.ThrowsAsync <SmtpServerException>(async() =>
            {
                TestMocks mocks = new TestMocks();

                ParameterProcessorMap map = new ParameterProcessorMap();
                await map.Process(mocks.Connection.Object, new string[] { "KEYA=VALUEA" }, true).ConfigureAwait(false);
            }).ConfigureAwait(false);

            Assert.Equal("Parameter KEYA is not recognised", e.Message);
        }
예제 #5
0
        public async Task AbortMessage()
        {
            TestMocks mocks = new TestMocks();

            Connection connection = await Connection.Create(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object).ConfigureAwait(false);

            await connection.NewMessage().ConfigureAwait(false);

            await connection.AbortMessage().ConfigureAwait(false);

            Assert.Null(connection.CurrentMessage);
        }
예제 #6
0
        public async Task Process_BadCommand_500Response()
        {
            TestMocks mocks = new TestMocks();

            mocks.ConnectionChannel.Setup(c => c.ReadLine()).ReturnsAsync("BADCOMMAND").Callback(() => mocks.Connection.Object.CloseConnection().Wait());

            Connection connection = await Connection.Create(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object).ConfigureAwait(false);

            await connection.ProcessAsync().ConfigureAwait(false);

            mocks.ConnectionChannel.Verify(cc => cc.WriteLine(It.IsRegex("500 .*", RegexOptions.IgnoreCase)));
        }
예제 #7
0
        public async Task Process_GreetingWritten()
        {
            TestMocks mocks = new TestMocks();

            mocks.ConnectionChannel.Setup(c => c.WriteLine(It.IsAny <string>())).Callback(() => mocks.Connection.Object.CloseConnection().Wait());

            Connection connection = await Connection.Create(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object).ConfigureAwait(false);

            await connection.ProcessAsync().ConfigureAwait(false);

            mocks.ConnectionChannel.Verify(cc => cc.WriteLine(It.IsRegex("220 .*", RegexOptions.IgnoreCase)));
        }
예제 #8
0
        public async Task Process_EmptyCommand_NoResponse()
        {
            TestMocks mocks = new TestMocks();

            mocks.ConnectionChannel.Setup(c => c.ReadLine()).ReturnsAsync("").Callback(() => mocks.Connection.Object.CloseConnection().Wait());

            Connection connection = await Connection.Create(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object).ConfigureAwait(false);

            await connection.ProcessAsync().ConfigureAwait(false);

            // Should only print service ready message
            mocks.ConnectionChannel.Verify(cc => cc.WriteLine(It.Is <string>(s => !s.StartsWith("220 ", StringComparison.OrdinalIgnoreCase))), Times.Never());
        }
예제 #9
0
        public async Task Process_TooManyBadCommands_Disconnected()
        {
            TestMocks mocks = new TestMocks();

            mocks.ServerBehaviour.SetupGet(b => b.MaximumNumberOfSequentialBadCommands).Returns(2);

            mocks.ConnectionChannel.Setup(c => c.ReadLine()).ReturnsAsync("BADCOMMAND");

            Connection connection = await Connection.Create(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object).ConfigureAwait(false);

            await connection.ProcessAsync().ConfigureAwait(false);

            mocks.ConnectionChannel.Verify(c => c.ReadLine(), Times.Exactly(2));
            mocks.ConnectionChannel.Verify(cc => cc.WriteLine(It.IsRegex("221 .*", RegexOptions.IgnoreCase)));
        }
예제 #10
0
        public async Task Process_GoodCommand_Processed()
        {
            TestMocks    mocks    = new TestMocks();
            Mock <IVerb> mockVerb = new Mock <IVerb>();

            mocks.VerbMap.Setup(v => v.GetVerbProcessor(It.IsAny <string>())).Returns(mockVerb.Object).Callback(() => mocks.Connection.Object.CloseConnection().Wait());

            mocks.ConnectionChannel.Setup(c => c.ReadLine()).ReturnsAsync("GOODCOMMAND");

            Connection connection = await Connection.Create(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object).ConfigureAwait(false);

            await connection.ProcessAsync().ConfigureAwait(false);

            mockVerb.Verify(v => v.Process(It.IsAny <IConnection>(), It.IsAny <SmtpCommand>()));
        }
        public async Task Process_KnownParameters_Processed()
        {
            TestMocks mocks = new TestMocks();
            Mock <IParameterProcessor> keyAProcessor = new Mock <IParameterProcessor>();
            Mock <IParameterProcessor> keyBProcessor = new Mock <IParameterProcessor>();

            ParameterProcessorMap map = new ParameterProcessorMap();

            map.SetProcessor("keya", keyAProcessor.Object);
            map.SetProcessor("keyb", keyBProcessor.Object);

            await map.Process(mocks.Connection.Object, new string[] { "KEYA=VALUEA", "KEYB=VALUEB" }, true).ConfigureAwait(false);

            keyAProcessor.Verify(p => p.SetParameter(mocks.Connection.Object, "KEYA", "VALUEA"));
            keyBProcessor.Verify(p => p.SetParameter(mocks.Connection.Object, "KEYB", "VALUEB"));
        }
예제 #12
0
        public async Task CommitMessage()
        {
            TestMocks mocks = new TestMocks();

            Connection connection = await Connection.Create(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object).ConfigureAwait(false);

            IMessageBuilder messageBuilder = await connection.NewMessage().ConfigureAwait(false);

            IMessage message = await messageBuilder.ToMessage().ConfigureAwait(false);

            await connection.CommitMessage().ConfigureAwait(false);

            mocks.Session.Verify(s => s.AddMessage(message));
            mocks.ServerBehaviour.Verify(b => b.OnMessageReceived(connection, message));
            Assert.Null(connection.CurrentMessage);
        }
예제 #13
0
        public async Task Process_SmtpServerExceptionThrow_ResponseWritten()
        {
            TestMocks    mocks    = new TestMocks();
            Mock <IVerb> mockVerb = new Mock <IVerb>();

            mocks.VerbMap.Setup(v => v.GetVerbProcessor(It.IsAny <string>())).Returns(mockVerb.Object);
            mockVerb.Setup(v => v.Process(It.IsAny <IConnection>(), It.IsAny <SmtpCommand>())).Returns(Task.FromException(new SmtpServerException(new SmtpResponse(500, "error"))));

            mocks.ConnectionChannel.Setup(c => c.ReadLine()).ReturnsAsync("GOODCOMMAND").Callback(() => mocks.Connection.Object.CloseConnection().Wait());

            Connection connection = await Connection.Create(mocks.Server.Object, mocks.ConnectionChannel.Object, mocks.VerbMap.Object).ConfigureAwait(false);

            await connection.ProcessAsync().ConfigureAwait(false);

            mocks.ConnectionChannel.Verify(cc => cc.WriteLine(It.IsRegex("500 error", RegexOptions.IgnoreCase)));
        }