public void TestCompleteSmtpServerSession()
        {
            var commandHandlerMock = new Mock<ISmtpServerCommandHandler>();
            commandHandlerMock.Setup(f => f.HandleHelo("example.com")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);
            commandHandlerMock.Setup(f => f.HandleMailFrom("*****@*****.**")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);
            commandHandlerMock.Setup(f => f.HandleRcptTo("*****@*****.**")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);

            commandHandlerMock.Setup(f => f.HandleData(It.IsAny<MemoryStreamWithFileBacking>()))
                .Callback((Stream stream) =>
                    VerifyMemoryStreamContents(stream, "Hello World\r\n"))
                .Returns(SmtpCommandReply.CreateDefault250SuccessTask());

            var data = "Hello World\r\n.\r\n";
            var memory = new MemoryStream(Encoding.UTF8.GetBytes(data));

            var connectionMock = ConnectionMockFactory.Create(new string[]
                {
                    "HELO example.com",
                    "MAIL FROM: [email protected]",
                    "RCPT TO: [email protected]",
                    "DATA",
                    "QUIT"
                }, new []
                {
                    memory
                });

            SmtpServerSession session = new SmtpServerSession(commandHandlerMock.Object, new NullLog(), new SmtpServerSessionConfiguration());

            var task = session.HandleConnection(connectionMock);
            task.Wait();

            commandHandlerMock.Verify(f => f.HandleHelo("example.com"));
        }
        public void SmtpConversationShouldBeLogged()
        {
            var inMemoryLog = new InMemoryLog();

            var commandHandlerMock = new Mock<ISmtpServerCommandHandler>();
            commandHandlerMock.Setup(f => f.HandleHelo("example.com")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);
            commandHandlerMock.Setup(f => f.HandleMailFrom("*****@*****.**")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);
            commandHandlerMock.Setup(f => f.HandleRcptTo("*****@*****.**")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);
            commandHandlerMock.Setup(f => f.HandleData(It.IsAny<MemoryStreamWithFileBacking>())).Returns(SmtpCommandReply.CreateDefault250SuccessTask);

            var data = "Hello World\r\n.\r\n";
            var memory = new MemoryStream(Encoding.UTF8.GetBytes(data));

            var connectionMock = ConnectionMockFactory.Create(new string[]
                {
                    "HELO example.com",
                    "MAIL FROM: [email protected]",
                    "RCPT TO: [email protected]",
                    "DATA",
                    "QUIT"
                }, new[]
                {
                    memory
                });

            SmtpServerSession session = new SmtpServerSession(commandHandlerMock.Object, inMemoryLog, new SmtpServerSessionConfiguration());

            var task = session.HandleConnection(connectionMock);
            task.Wait();

            var expectedLogEntries = new List<string>()
                {
                    "HELO example.com",
                    "MAIL FROM: [email protected]",
                    "RCPT TO: [email protected]",
                    "DATA",
                    "QUIT",

                    "250 Ok"
                };


            foreach (var expectedLogEntry in expectedLogEntries)
                Assert.IsTrue(inMemoryLog.LogEntries.Any(logEntry => logEntry.Item1.Message.Contains(expectedLogEntry)), expectedLogEntry);


        }