public void MultipleAttachmentsAreSent() { MailMessageQueue queue = new MailMessageQueue(Repository, AttachmentFileSystem); MailMessageDequeuer dequeuer = new MailMessageDequeuer(Config, SmtpClient, Repository, AttachmentFileSystem, StaticOverridesProvider); var mm = new MailMessage(); mm.Attachments.Add(new Attachment(Path.Combine(Environment.CurrentDirectory, @"testingfiles\sample.pdf"))); mm.Attachments.Add(new Attachment(Path.Combine(Environment.CurrentDirectory, @"testingfiles\sample.txt"))); queue.EnqueueMessage(mm); var emailQueueItem = Repository.Fetch().First(); var fl = new DequeueFilterList(); fl.And(new IdDequeueFilter(emailQueueItem.ID)); var result = dequeuer.SendQueuedMessages(fl, new OverrideList()); Assert.IsNotNull(result, "Result is null"); Assert.IsNotNull(result.FirstOrDefault(), "0 results were received"); Assert.IsNotNull(result.FirstOrDefault().SentMailMessage, "Mail Message of result is null"); Assert.AreEqual(2, result.FirstOrDefault().SentMailMessage.Attachments.Count, "Attachment count is incorrect"); string originalFile; using (StreamReader sr = new StreamReader(Path.Combine(Environment.CurrentDirectory, @"testingfiles\sample.pdf"))) { originalFile = sr.ReadToEnd(); } string newFile; using (StreamReader sr = new StreamReader(result.FirstOrDefault().SentMailMessage.Attachments[0].ContentStream)) { newFile = sr.ReadToEnd(); } Assert.AreEqual(originalFile, newFile, "provided and sent attachments are not identical"); using (StreamReader sr = new StreamReader(Path.Combine(Environment.CurrentDirectory, @"testingfiles\sample.txt"))) { originalFile = sr.ReadToEnd(); } using (StreamReader sr = new StreamReader(result.FirstOrDefault().SentMailMessage.Attachments[1].ContentStream)) { newFile = sr.ReadToEnd(); } Assert.AreEqual(originalFile, newFile, "provided and sent attachments are not identical"); }
public AddCommand(MailMessageQueue mailQueue) { MailQueue = mailQueue; }
public void StaticOverridesAreApplied() { var testingStaticOverrides = new OverrideList(); testingStaticOverrides.Add(new ToOverride().Prepend("*****@*****.**")); testingStaticOverrides.Add(new CcOverride().Prepend("*****@*****.**")); testingStaticOverrides.Add(new BccOverride().Prepend("*****@*****.**")); testingStaticOverrides.Add(new SubjectOverride().Prepend("SubjectSpecialString")); testingStaticOverrides.Add(new BodyOverride().Prepend("BodySpecialString")); var staticOverridesProviderMock = new Mock<IStaticOverridesProvider>(); staticOverridesProviderMock.Setup(m => m.StaticOverrides).Returns(testingStaticOverrides); MailMessageQueue queue = new MailMessageQueue(Repository, AttachmentFileSystem); MailMessageDequeuer dequeuer = new MailMessageDequeuer(Config, SmtpClient, Repository, AttachmentFileSystem, staticOverridesProviderMock.Object); var mm = new MailMessage(); queue.EnqueueMessage(mm); var emailQueueItem = Repository.Fetch().First(); var fl = new DequeueFilterList(); fl.And(new IdDequeueFilter(emailQueueItem.ID)); var result = dequeuer.SendQueuedMessages(fl, new OverrideList()); var sent = result.First().SentMailMessage; Assert.AreEqual("*****@*****.**", sent.To.ToString(), "Static To Override was not applied"); Assert.AreEqual("*****@*****.**", sent.CC.ToString(), "Static Cc Override was not applied"); Assert.AreEqual("*****@*****.**", sent.Bcc.ToString(), "Static Bcc Override was not applied"); Assert.AreEqual("SubjectSpecialString", sent.Subject, "Static Subject Override was not applied"); Assert.AreEqual("BodySpecialString", sent.Body, "Static Body Override was not applied"); }