/
OutlookTests.cs
446 lines (333 loc) · 14.1 KB
/
OutlookTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
using Thought.vCards;
namespace Tests.Samples
{
/* ===================================================================
* OutlookTests
* -------------------------------------------------------------------
* Tests for Outlook-generated vCards.
* =================================================================== */
[TestFixture]
public class OutlookTests
{
/// <summary>
/// The issuing organization of the certificate embedded
/// into the Outlook vCard.
/// </summary>
public const string KeyIssuer =
"CN=Thawte Personal Freemail Issuing CA, O=Thawte Consulting (Pty) Ltd., C=ZA";
/// <summary>
/// The subject of the certificate.
/// </summary>
public const string KeySubject =
"E=dave@thoughtproject.com, CN=Thawte Freemail Member";
#region [ CycleOutlookCertificate ]
[Test]
public void CycleOutlookCertificate()
{
// Load the vCard with the test certificate.
vCard card = new vCard(
new StreamReader(new MemoryStream(SampleCards.OutlookCertificate)));
Helper.CycleStandard(card);
}
#endregion
#region [ CycleOutlookSimple ]
[Test]
public void CycleOutlookSimple()
{
vCard card = new vCard(
new StreamReader(new MemoryStream(SampleCards.OutlookSimple)));
Helper.CycleStandard(card);
}
#endregion
#region [ ParseOutlookCertificate ]
[Test]
public void ParseOutlookCertificate()
{
// 01 BEGIN:VCARD
// 02 VERSION:2.1
// 03 N:Pinch;David;John
// 04 FN:David John Pinch
// 05 NICKNAME:Dave
// 06 ORG:Thought Project
// 07 TITLE:Dictator
// 08 TEL;WORK;VOICE:800-929-5805
// 09 TEL;HOME;VOICE:612-269-6017
// 10 KEY;X509;ENCODING=BASE64:
// 11 MIICZDCCAc2gAwIBAgIQRMnJkySZCu8S15WhdyuljjANBgkqhkiG9w0BAQUFADBiMQswCQYD
// 12 VQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UE
// 13 AxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwHhcNMDcwNTExMTU0NTI2
// 14 WhcNMDgwNTEwMTU0NTI2WjBJMR8wHQYDVQQDExZUaGF3dGUgRnJlZW1haWwgTWVtYmVyMSYw
// 15 JAYJKoZIhvcNAQkBFhdkYXZlQHRob3VnaHRwcm9qZWN0LmNvbTCBnzANBgkqhkiG9w0BAQEF
// 16 AAOBjQAwgYkCgYEAmLhq0UDsgB8paOBzXCtv9SbwccPYJhJr6f7bK3JO1xkCbKmzoLhCZUVB
// 17 4zP5bWTBnQYpolA9t1Pbrd29flX90xizEljCuL2uOz4cFc+NoF7h0h5nFvnFVAmzsJmLnCop
// 18 vp0GD4jy3cpQhBNAoSqQbwjSuqyFtHeVMIbNlU3Y/Y8CAwEAAaM0MDIwIgYDVR0RBBswGYEX
// 19 ZGF2ZUB0aG91Z2h0cHJvamVjdC5jb20wDAYDVR0TAQH/BAIwADANBgkqhkiG9w0BAQUFAAOB
// 20 gQCuMF4mUI5NWv0DqblQH/pqJN0eCjj2j4iQhJNTHtfhrS0ETbakgldJCzg5Rv+8V2Dil7gs
// 21 4zMmwOuDrHVBqWDvF0/hXzMn5KKWEmzCZshVyFJ24IWkIj4t3wOMG21NdSA+zX7TEc3s7oWh
// 22 zi6q4lcDj3pOzUyDmaEEBYcyWLKXpA==
// 23
// 24
// 25 EMAIL;PREF;INTERNET:dave@thoughtproject.com
// 26 REV:20070511T163814Z
// 27 END:VCARD
vCard card = new vCard(
new StreamReader(new MemoryStream(SampleCards.OutlookCertificate)));
// 03 N:Pinch;David;John
Assert.AreEqual(
"Pinch",
card.FamilyName,
"N at line 3 has a different family name.");
Assert.AreEqual(
"David",
card.GivenName,
"N at line 3 has a different given name.");
Assert.AreEqual(
"John",
card.AdditionalNames,
"N at line 3 has a different middle name.");
Assert.AreEqual(
1,
card.Certificates.Count,
"Only one certificate was expected.");
// 04 FN:David John Pinch
Assert.AreEqual(
"David John Pinch",
card.FormattedName,
"FN at line 4 has a different formatted name.");
// 05 NICKNAME:Dave
Assert.AreEqual(
1,
card.Nicknames.Count,
"Exactly one nickname is located at line 5.");
Assert.AreEqual(
"Dave",
card.Nicknames[0],
"NICKNAME at line 5 has a different value.");
// 06 ORG:Thought Project
Assert.AreEqual(
"Thought Project",
card.Organization,
"ORG at line 6 has a different value.");
// 07 TITLE:Dictator
Assert.AreEqual(
"Dictator",
card.Title,
"TITLE at line 7 has a different value.");
// 08 TEL;WORK;VOICE:800-929-5805
// 09 TEL;HOME;VOICE:612-269-6017
Assert.AreEqual(
2,
card.Phones.Count,
"Two telephone numbers are defined at lines 8 and 9.");
Assert.IsTrue(
card.Phones[0].IsWork,
"TEL at line 8 is a work number.");
Assert.IsTrue(
card.Phones[0].IsVoice,
"TEL at line 8 is a voice number.");
Assert.AreEqual(
"800-929-5805",
card.Phones[0].FullNumber,
"TEL at line 8 has a different value.");
// 09 TEL;HOME;VOICE:612-269-6017
Assert.IsTrue(
card.Phones[1].IsHome,
"TEL at line 9 is a home number.");
Assert.IsTrue(
card.Phones[1].IsVoice,
"TEL at line 9 is a voice number.");
Assert.AreEqual(
"612-269-6017",
card.Phones[1].FullNumber,
"TEL at line 9 has a different value.");
// 10 KEY;X509;ENCODING=BASE64:
Assert.AreEqual(
1,
card.Certificates.Count,
"There is one certificate starting on line 10.");
Assert.AreEqual(
"X509",
card.Certificates[0].KeyType,
"KEY on line 10 has a different key type.");
// Create an instance of the certificate.
X509Certificate2 cert =
new X509Certificate2(card.Certificates[0].Data);
Assert.AreEqual(
KeyIssuer,
cert.Issuer,
"The key issuer has a different value.");
Assert.AreEqual(
KeySubject,
cert.Subject,
"The key subject has a different value.");
}
#endregion
#region [ ParseOutlookSimple ]
[Test]
public void ParseOutlookSimple()
{
// 01 BEGIN:VCARD
// 02 VERSION:2.1
// 03 N:Pinch;David;John
// 04 FN:David John Pinch
// 05 NICKNAME:Dave
// 06 ORG:Thought Project
// 07 TITLE:Dictator
// 08 TEL;WORK;VOICE:800-929-5805
// 09 TEL;HOME;VOICE:612-269-6017
// 10 ADR;HOME:;;129 15th Street #3;Minneapolis;MN;55403;United States of America
// 11 LABEL;HOME;ENCODING=QUOTED-PRINTABLE:129 15th Street #3=0D=0AMinneapolis, MN 55403=0D=0AUnited States of America
// 12 URL;WORK:http://www.thoughtproject.com
// 13 EMAIL;PREF;INTERNET:dave@thoughtproject.com
// 14 REV:20061130T234000Z
// 15 END:VCARD
vCard card = new vCard(
new StreamReader(new MemoryStream(SampleCards.OutlookSimple)));
// 03 N:Pinch;David;John
Assert.AreEqual(
"Pinch",
card.FamilyName,
"N at line 3 has a different family name.");
Assert.AreEqual(
"David",
card.GivenName,
"N at line 3 has a different given name.");
Assert.AreEqual(
"John",
card.AdditionalNames,
"N at line 3 has a different middle name.");
// 04 FN:David John Pinch
Assert.AreEqual(
"David John Pinch",
card.FormattedName,
"FN at line 4 has a different formatted name.");
// 05 NICKNAME:Dave
Assert.AreEqual(
1,
card.Nicknames.Count,
"Exactly one nickname is located at line 5.");
Assert.AreEqual(
"Dave",
card.Nicknames[0],
"NICKNAME at line 5 has a different value.");
// 06 ORG:Thought Project
Assert.AreEqual(
"Thought Project",
card.Organization,
"ORG at line 6 has a different value.");
// 07 TITLE:Dictator
Assert.AreEqual(
"Dictator",
card.Title,
"TITLE at line 7 has a different value.");
// 08 TEL;WORK;VOICE:800-929-5805
// 09 TEL;HOME;VOICE:612-269-6017
Assert.AreEqual(
2,
card.Phones.Count,
"Two telephone numbers are defined at lines 8 and 9.");
Assert.IsTrue(
card.Phones[0].IsWork,
"TEL at line 8 is a work number.");
Assert.IsTrue(
card.Phones[0].IsVoice,
"TEL at line 8 is a voice number.");
Assert.AreEqual(
"800-929-5805",
card.Phones[0].FullNumber,
"TEL at line 8 has a different value.");
// 09 TEL;HOME;VOICE:612-269-6017
Assert.IsTrue(
card.Phones[1].IsHome,
"TEL at line 9 is a home number.");
Assert.IsTrue(
card.Phones[1].IsVoice,
"TEL at line 9 is a voice number.");
Assert.AreEqual(
"612-269-6017",
card.Phones[1].FullNumber,
"TEL at line 9 has a different value.");
// 10 ADR;HOME:;;129 15th Street #3;Minneapolis;MN;55403;United States of America
Assert.AreEqual(
1,
card.DeliveryAddresses.Count,
"There is one delivery address at line 10.");
Assert.AreEqual(
"129 15th Street #3",
card.DeliveryAddresses[0].Street,
"ADR at line 10 has a different street.");
Assert.AreEqual(
"Minneapolis",
card.DeliveryAddresses[0].City,
"ADR at line 10 has a different city.");
Assert.AreEqual(
"MN",
card.DeliveryAddresses[0].Region,
"ADR at line 10 has a different region/state.");
Assert.AreEqual(
"55403",
card.DeliveryAddresses[0].PostalCode,
"ADR at line 10 has a different postal code.");
Assert.AreEqual(
"United States of America",
card.DeliveryAddresses[0].Country,
"ADR at line 10 has a different country.");
// 11 LABEL;HOME;ENCODING=QUOTED-PRINTABLE:129 15th Street #3=0D=0AMinneapolis, MN 55403=0D=0AUnited States of America
Assert.AreEqual(
1,
card.DeliveryLabels.Count,
"There is one delivery label at line 11.");
Assert.IsTrue(
card.DeliveryLabels[0].IsHome,
"LABEL at line 11 is a home delivery address.");
Assert.AreEqual(
"129 15th Street #3\r\nMinneapolis, MN 55403\r\nUnited States of America",
card.DeliveryLabels[0].Text,
"LABEL at line 11 has a different decoded value.");
// 12 URL;WORK:http://www.thoughtproject.com
Assert.AreEqual(
1,
card.Websites.Count,
"There is one web site (URL) at line 12.");
Assert.IsTrue(
card.Websites[0].IsWorkSite,
"The web site at line 12 is a work-related web site.");
Assert.AreEqual(
"http://www.thoughtproject.com",
card.Websites[0].Url,
"URL at line 12 has a different value.");
// 13 EMAIL;PREF;INTERNET:dave@thoughtproject.com
Assert.AreEqual(
1,
card.EmailAddresses.Count,
"There is one email address at line 13.");
Assert.IsTrue(
card.EmailAddresses[0].IsPreferred,
"The email address at line 13 is the preferred email address.");
Assert.AreEqual(
"dave@thoughtproject.com",
card.EmailAddresses[0].Address,
"EMAIL at line 13 has a different value.");
// 14 REV:20061130T234000Z
Assert.AreEqual(
vCardStandardReader.ParseDate("20061130T234000Z").Value,
card.RevisionDate.Value,
"REV at line 14 has a different value.");
}
#endregion
#region [ ParseOutlookSimple ]
[Test]
public void ParseUnicodeSimple()
{
vCard card = new vCard(
new StreamReader(new MemoryStream(SampleCards.UnicodeNameSample)));
Assert.NotNull(card);
Assert.AreEqual("³ÂÀö¾ý", card.GivenName);
}
#endregion
}
}