public void BodyExactFilterResults() { var filters = new DequeueFilterList(); var result = filters.And(new BodyExactFilter("Test Message - EXACTSEARCH")).Filter(Repository).Select(r => r.ID); var expected = new int[] { 3 }; Assert.That(AreArraysEqual(result, expected)); }
public void BodyContainsFilterResults() { var filters = new DequeueFilterList(); var result = filters.And(new BodyContainsFilter("SEARCHSTRING")).Filter(Repository).Select(r => r.ID); var expected = new int[] { 2 }; Assert.That(AreArraysEqual(result, expected)); }
public void IdDequeueFilterResults() { var filters = new DequeueFilterList(); var result = filters.And(new IdDequeueFilter(1)).Filter(Repository).Select(r => r.ID); var expected = new int[] { 1 }; Assert.That(AreArraysEqual(result, expected)); }
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 void CanFilterTwice() { var filters = new DequeueFilterList(); var result = filters.And(new IdDequeueFilter(1)).Filter(Repository).Select(r => r.ID); var expected = new int[] { 1 }; Assert.That(AreArraysEqual(result, expected)); //do it again with the same filterset result = filters.Filter(Repository).Select(r => r.ID); expected = new int[] { 1 }; Assert.That(AreArraysEqual(result, expected)); }
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"); }
protected override bool ParseArguments(string[] args) { filterList = new DequeueFilterList(); overrideList = new OverrideList(); bool dateRangeApplied = false; DateTime dateFrom = DateTime.MinValue, dateTo = DateTime.MaxValue; bool idRangeApplied = false; int idMin = 0, idMax = int.MaxValue; OptionSet optionSet = new OptionSet() //filters .Add("tf=|tofilter=", v => filterList.And(new ToFilter(v))) .Add("bcf=|bodycontainsfilter=", v => filterList.And(new BodyContainsFilter(v))) .Add("bef=|bodyexactfilter=", v => filterList.And(new BodyExactFilter(v))) .Add("fd=|fromdate=", (DateTime v) => { dateRangeApplied = true; dateFrom = v; }) .Add("td=|todate=", (DateTime v) => { dateRangeApplied = true; dateTo = v; }) .Add("idf=|idfilter=|id=", (int v) => filterList.And(new IdDequeueFilter(v))) .Add("rtf=|retriesfilter=", (byte v) => filterList.And(new RetriesFilter(v))) .Add("sent=|sentfilter=|issent=", (bool v) => filterList.And(new SentStatusDequeueFilter(v))) .Add("scf=|subjectcontainsfilter=", v => filterList.And(new SubjectContainsFilter(v))) .Add("sef=|subjectexactfilter=", v => filterList.And(new SubjectExactFilter(v))) .Add("idrf=|idfrom=", (int v) => { idRangeApplied = true; idMin = v; }) .Add("idrt=|idto=", (int v) => { idRangeApplied = true; idMax = v; }) .Add("haf|hasattachmentsfilter", "filter on whether an email has attachments", v => filterList.And(new HasAttachmentsFilter(true))) //overrides .Add("to=|tooverride=", v=> overrideList.Add(new ToOverride().Override(v))) .Add("cc=|ccoverride=", v => overrideList.Add(new CcOverride().Override(v))) .Add("bcc=|bccoverride=", v => overrideList.Add(new BccOverride().Override(v))) .Add("subject=|subjectoverride=", v => overrideList.Add(new SubjectOverride().Override(v))) .Add("body=|bodyoverride=", v => overrideList.Add(new BodyOverride().Override(v))) .Add("toa=|toappend=", v => overrideList.Add(new ToOverride().Append(v))) .Add("cca=|ccappend=", v => overrideList.Add(new CcOverride().Append(v))) .Add("bcca=|bccappend=", v => overrideList.Add(new BccOverride().Append(v))) .Add("subjecta=|subjectappend=", v => overrideList.Add(new SubjectOverride().Append(v))) .Add("bodya=|bodyappend=", v => overrideList.Add(new BodyOverride().Append(v))) .Add("top=|toprepend=", v => overrideList.Add(new ToOverride().Prepend(v))) .Add("ccp=|ccprepend=", v => overrideList.Add(new CcOverride().Prepend(v))) .Add("bccp=|bccprepend=", v => overrideList.Add(new BccOverride().Prepend(v))) .Add("subjectp=|subjectprepend=", v => overrideList.Add(new SubjectOverride().Prepend(v))) .Add("bodyp=|bodyprepend=", v => overrideList.Add(new BodyOverride().Prepend(v))) .Add("da|donotaudit", "whether to audit whether the email was sent (default=true)" , v => Audit = false) ; try { optionSet.Parse(args); } catch (OptionException) { Console.WriteLine("Error"); return false; } if (dateRangeApplied) { filterList.And(new DateRangeFilter(dateFrom, dateTo)); } if (idRangeApplied) { filterList.And(new IdRangeDequeueFilter(idMin, idMax)); } return true; }
protected override bool ParseArguments(string[] args) { filterList = new DequeueFilterList(); bool dateRangeApplied = false; DateTime dateFrom = DateTime.MinValue, dateTo = DateTime.MaxValue; bool idRangeApplied = false; int idMin = 0, idMax = int.MaxValue; OptionSet optionSet = new OptionSet() //filters .Add("tf=|tofilter=", v => filterList.And(new ToFilter(v))) .Add("bcf=|bodycontainsfilter=", v => filterList.And(new BodyContainsFilter(v))) .Add("bef=|bodyexactfilter=", v => filterList.And(new BodyExactFilter(v))) .Add("fd=|fromdate=", (DateTime v) => { dateRangeApplied = true; dateFrom = v; }) .Add("td=|todate=", (DateTime v) => { dateRangeApplied = true; dateTo = v; }) .Add("idf=|idfilter=|id=", (int v) => filterList.And(new IdDequeueFilter(v))) .Add("rtf=|retriesfilter=", (byte v) => filterList.And(new RetriesFilter(v))) .Add("sent=|sentfilter=|issent=", (bool v) => filterList.And(new SentStatusDequeueFilter(v))) .Add("scf=|subjectcontainsfilter=", v => filterList.And(new SubjectContainsFilter(v))) .Add("sef=|subjectexactfilter=", v => filterList.And(new SubjectExactFilter(v))) .Add("idrf=|idfrom=", (int v) => { idRangeApplied = true; idMin = v; }) .Add("idrt=|idto=", (int v) => { idRangeApplied = true; idMax = v; }) .Add("haf|hasattachmentsfilter", "filter on whether an email has attachments", v => filterList.And(new HasAttachmentsFilter(true))) .Add("p|purge", "purges attachments from storage (default=false)" , v => Purge = true) ; try { optionSet.Parse(args); } catch (OptionException) { Console.WriteLine("Error"); return false; } if (dateRangeApplied) { filterList.And(new DateRangeFilter(dateFrom, dateTo)); } if (idRangeApplied) { filterList.And(new IdRangeDequeueFilter(idMin, idMax)); } return true; }
public void RetriesFilterResults() { var filters = new DequeueFilterList(); var result = filters.And(new RetriesFilter(0)).Filter(Repository).Select(r => r.ID); var expected = new int[] { }; Assert.That(AreArraysEqual(result, expected)); filters = new DequeueFilterList(); result = filters.And(new RetriesFilter(1)).Filter(Repository).Select(r => r.ID); expected = new int[] { 3 }; Assert.That(AreArraysEqual(result, expected)); filters = new DequeueFilterList(); result = filters.And(new RetriesFilter(6)).Filter(Repository).Select(r => r.ID); expected = new int[] {1, 2, 3}; Assert.That(AreArraysEqual(result, expected)); }
public void DateRangeFilterResults() { var filters = new DequeueFilterList(); var result = filters.And(new DateRangeFilter(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2))).Filter(Repository).Select(r => r.ID); var expected = new int[] { 3 }; Assert.That(AreArraysEqual(result, expected)); }
public void SubjectExactFilterResults() { var filters = new DequeueFilterList(); var result = filters.And(new SubjectExactFilter("EXACTSUBJECTSTRING")).Filter(Repository).Select(r => r.ID); var expected = new int[] { 3 }; Assert.That(AreArraysEqual(result, expected)); }
public void SentStatusFilterResults() { var filters = new DequeueFilterList(); var result = filters.And(new SentStatusDequeueFilter(false)).Filter(Repository).Select(r => r.ID); var expected = new int[] {2, 3}; Assert.That(AreArraysEqual(result, expected)); filters = new DequeueFilterList(); result = filters.And(new SentStatusDequeueFilter(true)).Filter(Repository).Select(r => r.ID); expected = new int[] { 1 }; Assert.That(AreArraysEqual(result, expected)); }