public void TestArgumentExceptions() { var orderBy = new OrderBy[] { OrderBy.Arrival }; var messagesMissingInfo = new [] { new MessageSummary(0) }; var emptyOrderBy = new OrderBy[0]; int depth; var summary = new MessageSummary(0); summary.UniqueId = UniqueId.MinValue; summary.Envelope = new Envelope(); summary.References = new MessageIdList(); summary.Envelope.MessageId = "*****@*****.**"; summary.Envelope.Subject = "This is the subject"; summary.Envelope.Date = DateTimeOffset.Now; summary.Size = 0; var messages = new MessageSummary[] { summary }; Assert.Throws <ArgumentNullException> (() => MessageThreader.GetThreadableSubject(null, out depth)); Assert.Throws <ArgumentNullException> (() => MessageThreader.Thread((IEnumerable <MessageSummary>)null, ThreadingAlgorithm.References)); Assert.Throws <ArgumentNullException> (() => MessageThreader.Thread((IEnumerable <MessageSummary>)null, ThreadingAlgorithm.References, orderBy)); Assert.Throws <ArgumentException> (() => MessageThreader.Thread(messagesMissingInfo, ThreadingAlgorithm.References)); Assert.Throws <ArgumentNullException> (() => MessageThreader.Thread(messages, ThreadingAlgorithm.References, null)); Assert.Throws <ArgumentException> (() => MessageThreader.Thread(messages, ThreadingAlgorithm.References, emptyOrderBy)); }
public void TestThreading() { const string defaultDate = "01 Jan 1997 12:00:00 -0400"; // this test case was borrowed from Jamie Zawinski's TestThreader.java MakeThreadable("A", "<1>", defaultDate, null); MakeThreadable("B", "<2>", defaultDate, "<1>"); MakeThreadable("C", "<3>", defaultDate, "<1> <2>"); MakeThreadable("D", "<4>", defaultDate, "<1>"); MakeThreadable("E", "<5>", defaultDate, "<3> <x1> <x2> <x3>"); MakeThreadable("F", "<6>", defaultDate, "<2>"); MakeThreadable("G", "<7>", defaultDate, "<nonesuch>"); MakeThreadable("H", "<8>", defaultDate, "<nonesuch>"); MakeThreadable("Loop1", "<loop1>", defaultDate, "<loop2> <loop3>"); MakeThreadable("Loop2", "<loop2>", defaultDate, "<loop3> <loop1>"); MakeThreadable("Loop3", "<loop3>", defaultDate, "<loop1> <loop2>"); MakeThreadable("Loop4", "<loop4>", defaultDate, "<loop5>"); MakeThreadable("Loop5", "<loop5>", defaultDate, "<loop4>"); MakeThreadable("Loop6", "<loop6>", defaultDate, "<loop6>"); MakeThreadable("Loop7", "<loop7>", defaultDate, "<loop8> <loop9> <loop10> <loop8> <loop9> <loop10>"); MakeThreadable("Loop8", "<loop8>", defaultDate, "<loop9> <loop10> <loop7> <loop9> <loop10> <loop7>"); MakeThreadable("Loop8", "<loop9>", defaultDate, "<loop10> <loop7> <loop8> <loop10> <loop7> <loop8>"); MakeThreadable("Loop10", "<loop10>", defaultDate, "<loop7> <loop8> <loop9> <loop7> <loop8> <loop9>"); MakeThreadable("Ambig1", "<ambig1>", defaultDate, null); MakeThreadable("Ambig2", "<ambig2>", defaultDate, "<ambig1>"); MakeThreadable("Ambig3", "<ambig3>", defaultDate, "<ambig1> <ambig2>"); MakeThreadable("Ambig4", "<ambig4>", defaultDate, "<ambig1> <ambig2> <ambig3>"); MakeThreadable("Ambig5a", "<ambig5a>", defaultDate, "<ambig1> <ambig2> <ambig3> <ambig4>"); MakeThreadable("Ambig5b", "<ambig5b>", defaultDate, "<ambig1> <ambig3> <ambig2> <ambig4>"); MakeThreadable("dup", "<dup>", defaultDate, null); MakeThreadable("dup-kid", "<dup-kid>", defaultDate, "<dup>"); MakeThreadable("dup-kid", "<dup-kid>", defaultDate, "<dup>"); MakeThreadable("dup-kid-2", "<dup-kid-2>", defaultDate, "<dup>"); MakeThreadable("dup-kid-2", "<dup-kid-2>", defaultDate, "<dup>"); MakeThreadable("dup-kid-2", "<dup-kid-2>", defaultDate, "<dup>"); MakeThreadable("same subject 1", "<ss1.1>", defaultDate, null); MakeThreadable("same subject 1", "<ss1.2>", defaultDate, null); MakeThreadable("missingmessage", "<missa>", defaultDate, null); MakeThreadable("missingmessage", "<missc>", defaultDate, "<missa> <missb>"); MakeThreadable("liar 1", "<liar.1>", defaultDate, "<liar.a> <liar.c>"); MakeThreadable("liar 2", "<liar.2>", defaultDate, "<liar.a> <liar.b> <liar.c>"); MakeThreadable("liar2 1", "<liar2.1>", defaultDate, "<liar2.a> <liar2.b> <liar2.c>"); MakeThreadable("liar2 2", "<liar2.2>", defaultDate, "<liar2.a> <liar2.c>"); MakeThreadable("xx", "<*****@*****.**>", "Thu, 06 Mar 1997 18:28:50 -0800", null); MakeThreadable("lkjhlkjh", "<*****@*****.**>", "Sat, 08 Mar 1997 14:15:59 -0800", null); MakeThreadable("test 2", "<*****@*****.**>", "Sat, 08 Mar 1997 14:18:14 -0800", null); MakeThreadable("enc", "<*****@*****.**>", "Sat, 08 Mar 1997 14:18:40 -0800", null); MakeThreadable("lkjhlkjh", "<*****@*****.**>", "Sat, 08 Mar 1997 14:24:21 -0800", null); MakeThreadable("eng", "<*****@*****.**>", "Sat, 08 Mar 1997 14:26:44 -0800", null); MakeThreadable("lkjhl", "<*****@*****.**>", "Sat, 08 Mar 1997 14:27:07 -0800", null); MakeThreadable("Re: certs and signed messages", "<*****@*****.**>", "Sat, 08 Mar 1997 19:38:18 -0800", "<*****@*****.**>"); MakeThreadable("from dogbert", "<*****@*****.**>", "Sun, 09 Mar 1997 16:23:10 -0800", null); MakeThreadable("lkjhlkjhl", "<*****@*****.**>", "Thu, 20 Mar 1997 21:35:38 -0800", null); MakeThreadable("le:/u/jwz/mime/smi", "<*****@*****.**>", "Thu, 20 Mar 1997 23:45:33 -0800", null); MakeThreadable("ile:/u/jwz", "<*****@*****.**>", "Thu, 20 Mar 1997 23:57:22 -0800", null); MakeThreadable("ljkljhlkjhl", "<*****@*****.**>", "Tue, 06 May 1997 16:12:16 -0700", null); MakeThreadable("lkjh", "<*****@*****.**>", "Tue, 06 May 1997 16:14:14 -0700", null); MakeThreadable("foo", "<*****@*****.**>", "Thu, 08 May 1997 16:46:09 -0700", null); MakeThreadable("Welcome to Netscape", "<*****@*****.**>", "Wed, 14 May 1997 23:20:45 -0700", null); MakeThreadable("Re: Welcome to Netscape", "<*****@*****.**>", "Wed, 14 May 1997 23:33:45 -0700", "<*****@*****.**>"); MakeThreadable("[Fwd: enc/signed test 1]", "<*****@*****.**>", "Tue, 27 May 1997 16:31:46 -0700", null); const string expected = @"A B C E F D dummy G H Loop5 Loop4 Loop6 Ambig1 Ambig2 Ambig3 Ambig4 Ambig5a Ambig5b dup dup-kid dup-kid dup-kid-2 dup-kid-2 dup-kid-2 dummy same subject 1 same subject 1 missingmessage missingmessage dummy liar 1 liar 2 dummy liar2 1 liar2 2 xx dummy lkjhlkjh lkjhlkjh test 2 enc eng lkjhl Re: certs and signed messages from dogbert lkjhlkjhl le:/u/jwz/mime/smi ile:/u/jwz ljkljhlkjhl lkjh foo Welcome to Netscape Re: Welcome to Netscape [Fwd: enc/signed test 1] "; var threads = MessageThreader.Thread(ThreadingAlgorithm.References, summaries); var builder = new StringBuilder(); foreach (var thread in threads) { WriteMessageThread(builder, thread, 0); } //Console.WriteLine (builder); Assert.AreEqual(expected, builder.ToString(), "Threading did not produce the expected results"); }