hMailServer.Core.StressTests.SmtpMessageBodySizeTests.SendMessageWithAttachment C# (CSharp) Метод

SendMessageWithAttachment() приватный статический Метод

private static SendMessageWithAttachment ( System.Net.Mail.Attachment attachment ) : InMemoryCommandHandler
attachment System.Net.Mail.Attachment
Результат hMailServer.Core.IntegrationTests.InMemoryCommandHandler
        private static InMemoryCommandHandler SendMessageWithAttachment(Attachment attachment)
        {
            var commandHandler = new InMemoryCommandHandler();

            Func<ISession> connectionFactory = () =>
                new SmtpServerSession(commandHandler, new NullLog(), new SmtpServerSessionConfiguration());

            var serverConfiguration = new ServerConfiguration();

            var smtpServer = new Server(connectionFactory, new NullLog(),  serverConfiguration);
            var runTask = smtpServer.RunAsync();
            
            var stopwatch = new Stopwatch();
            stopwatch.Start();

            using (var client = new SmtpClient(smtpServer.LocalEndpoint.Address.ToString(), smtpServer.LocalEndpoint.Port))
            using (var message = new MailMessage())
            {
                message.From = new MailAddress("[email protected]");
                message.To.Add(new MailAddress("[email protected]"));
                message.To.Add(new MailAddress("[email protected]"));
                message.Body = "Test";
                message.Attachments.Add(attachment);


                client.Send(message);
            }
            stopwatch.Stop();

            var stopTask = smtpServer.StopAsync();

            Assert.IsTrue(stopTask.Wait(TimeSpan.FromMilliseconds(2000)));
            Assert.IsTrue(runTask.Wait(TimeSpan.FromMilliseconds(2000)));

            Console.WriteLine("Sending time was {0}", stopwatch.Elapsed);

            return commandHandler;
        }
    }