예제 #1
0
 public void Enqueue(Mail mail)
 {
     using (IQueueWrapper queue = _factory.CreateSender(QueueSettings.QueueName))
     {
         queue.Enqueue(QueueSettings.QueueName, mail);
     }
 }
예제 #2
0
        public void Enqueue_EnqueueCalledInQueueWrapper()
        {
            var factory = new Mock<IQueueFactory>();
            var queueWrapper = new Mock<IQueueWrapper>();
            factory.Setup(x => x.CreateSender(QueueSettings.QueueName)).Returns(queueWrapper.Object);
            var queueReceiver = new QueueSender(factory.Object);
            var mail = new Mail();

            queueReceiver.Enqueue(mail);

            factory.Verify(x => x.CreateSender(QueueSettings.QueueName));
            queueWrapper.Verify(x => x.Enqueue(QueueSettings.QueueName, mail));
            Assert.True(true);
        }
예제 #3
0
        public void Dequeue_ProcessCalledInMailProcessor()
        {
            var factory = new Mock<IQueueFactory>();
            var mailProcessor = new Mock<IMailProcessor>();
            var queueWrapper = new Mock<IQueueWrapper>();
            var mail = new Mail();
            queueWrapper.Setup(x => x.Dequeue<Mail>()).Returns(mail);
            factory.Setup(x => x.CreateReceiver(QueueSettings.QueueName)).Returns(queueWrapper.Object);
            var queueReceiver = new QueueReceiver(factory.Object, mailProcessor.Object);

            queueReceiver.Dequeue();

            factory.Verify(x => x.CreateReceiver(QueueSettings.QueueName));
            queueWrapper.Verify(x => x.Dequeue<Mail>());
            mailProcessor.Verify(x => x.Process(mail));
        }
예제 #4
0
        public void Process(Mail mailData)
        {
            var email = new MailMessage
                {
                    From = new MailAddress(mailData.Sender),
                    Subject = mailData.Subject,
                    Body = mailData.Body
                };
            mailData.Receivers.ForEach(x => email.To.Add(new MailAddress(x)));

            var client = new SmtpClient
                {
                    Port = 25,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Host = "smtp.google.com"
                };

            client.Send(email);
        }