21
21
using System ;
22
22
using NUnit . Framework ;
23
23
24
- namespace MailMergeLib . Tests
24
+ namespace MailMergeLib . Tests ;
25
+
26
+ [ TestFixture ]
27
+ public class EmailValidatorTest
25
28
{
26
- [ TestFixture ]
27
- public class EmailValidatorTest
29
+ static readonly string [ ] ValidAddresses =
28
30
{
29
- static readonly string [ ] ValidAddresses =
30
- {
31
- "\" Abc\\ @def\" @example.com" ,
32
- "\" Fred Bloggs\" @example.com" ,
33
- "\" Joe\\ \\ Blow\" @example.com" ,
34
- "\" Abc@def\" @example.com" ,
35
- "customer/department=shipping@example.com" ,
36
- "$A12345@example.com" ,
37
- "!def!xyz%abc@example.com" ,
38
- "_somename@example.com" ,
39
- "valid.ipv4.addr@[123.1.72.10]" ,
40
- "valid.ipv6.addr@[IPv6:0::1]" ,
41
- "valid.ipv6.addr@[IPv6:2607:f0d0:1002:51::4]" ,
42
- "valid.ipv6.addr@[IPv6:fe80::230:48ff:fe33:bc33]" ,
43
- "valid.ipv6.addr@[IPv6:fe80:0000:0000:0000:0202:b3ff:fe1e:8329]" ,
44
- "valid.ipv6v4.addr@[IPv6:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:127.0.0.1]" ,
31
+ "\" Abc\\ @def\" @example.com" ,
32
+ "\" Fred Bloggs\" @example.com" ,
33
+ "\" Joe\\ \\ Blow\" @example.com" ,
34
+ "\" Abc@def\" @example.com" ,
35
+ "customer/department=shipping@example.com" ,
36
+ "$A12345@example.com" ,
37
+ "!def!xyz%abc@example.com" ,
38
+ "_somename@example.com" ,
39
+ "valid.ipv4.addr@[123.1.72.10]" ,
40
+ "valid.ipv6.addr@[IPv6:0::1]" ,
41
+ "valid.ipv6.addr@[IPv6:2607:f0d0:1002:51::4]" ,
42
+ "valid.ipv6.addr@[IPv6:fe80::230:48ff:fe33:bc33]" ,
43
+ "valid.ipv6.addr@[IPv6:fe80:0000:0000:0000:0202:b3ff:fe1e:8329]" ,
44
+ "valid.ipv6v4.addr@[IPv6:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:127.0.0.1]" ,
45
45
46
- // examples from wikipedia
47
- "niceandsimple@example.com" ,
48
- "very.common@example.com" ,
49
- "a.little.lengthy.but.fine@dept.example.com" ,
50
- "disposable.style.email.with+symbol@example.com" ,
51
- "user@[IPv6:2001:db8:1ff::a0b:dbd0]" ,
52
- "\" much.more unusual\" @example.com" ,
53
- "\" very.unusual.@.unusual.com\" @example.com" ,
54
- "\" very.(),:;<>[]\\ \" .VERY.\\ \" very@\\ \\ \\ \" very\\ \" .unusual\" @strange.example.com" ,
55
- "postbox@com" ,
56
- "admin@mailserver1" ,
57
- "!#$%&'*+-/=?^_`{}|~@example.org" ,
58
- "\" ()<>[]:,;@\\ \\ \\ \" !#$%&'*+-/=?^_`{}| ~.a\" @example.org" ,
59
- "\" \" @example.org" ,
46
+ // examples from wikipedia
47
+ "niceandsimple@example.com" ,
48
+ "very.common@example.com" ,
49
+ "a.little.lengthy.but.fine@dept.example.com" ,
50
+ "disposable.style.email.with+symbol@example.com" ,
51
+ "user@[IPv6:2001:db8:1ff::a0b:dbd0]" ,
52
+ "\" much.more unusual\" @example.com" ,
53
+ "\" very.unusual.@.unusual.com\" @example.com" ,
54
+ "\" very.(),:;<>[]\\ \" .VERY.\\ \" very@\\ \\ \\ \" very\\ \" .unusual\" @strange.example.com" ,
55
+ "postbox@com" ,
56
+ "admin@mailserver1" ,
57
+ "!#$%&'*+-/=?^_`{}|~@example.org" ,
58
+ "\" ()<>[]:,;@\\ \\ \\ \" !#$%&'*+-/=?^_`{}| ~.a\" @example.org" ,
59
+ "\" \" @example.org" ,
60
60
61
- // examples from https://github.com/Sembiance/email-validator
62
- "\" \\ e\\ s\\ c\\ a\\ p\\ e\\ d\" @sld.com" ,
63
- "\" back\\ slash\" @sld.com" ,
64
- "\" escaped\\ \" quote\" @sld.com" ,
65
- "\" quoted\" @sld.com" ,
66
- "\" quoted-at-sign@sld.org\" @sld.com" ,
67
- "&'*+-./=?^_{}~@other-valid-characters-in-local.net" ,
68
- "01234567890@numbers-in-local.net" ,
69
- "a@single-character-in-local.org" ,
70
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org" ,
71
- "backticksarelegit@test.com" ,
72
- "bracketed-IP-instead-of-domain@[127.0.0.1]" ,
73
- "country-code-tld@sld.rw" ,
74
- "country-code-tld@sld.uk" ,
75
- "letters-in-sld@123.com" ,
76
- "local@dash-in-sld.com" ,
77
- "local@sld.newTLD" ,
78
- "local@sub.domains.com" ,
79
- "mixed-1234-in-{+^}-local@sld.net" ,
80
- "one-character-third-level@a.example.com" ,
81
- "one-letter-sld@x.org" ,
82
- "punycode-numbers-in-tld@sld.xn--3e0b707e" ,
83
- "single-character-in-sld@x.org" ,
84
- "the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-three-characters-so-it-is-valid-blah-blah.com" ,
85
- "the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-254-characters-exactly.so-it-should-be-valid.and-im-going-to-add-some-more-words-here.to-increase-the-length-blah-blah-blah-blah-bla.org" ,
86
- "uncommon-tld@sld.mobi" ,
87
- "uncommon-tld@sld.museum" ,
88
- "uncommon-tld@sld.travel" ,
89
- } ;
61
+ // examples from https://github.com/Sembiance/email-validator
62
+ "\" \\ e\\ s\\ c\\ a\\ p\\ e\\ d\" @sld.com" ,
63
+ "\" back\\ slash\" @sld.com" ,
64
+ "\" escaped\\ \" quote\" @sld.com" ,
65
+ "\" quoted\" @sld.com" ,
66
+ "\" quoted-at-sign@sld.org\" @sld.com" ,
67
+ "&'*+-./=?^_{}~@other-valid-characters-in-local.net" ,
68
+ "01234567890@numbers-in-local.net" ,
69
+ "a@single-character-in-local.org" ,
70
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org" ,
71
+ "backticksarelegit@test.com" ,
72
+ "bracketed-IP-instead-of-domain@[127.0.0.1]" ,
73
+ "country-code-tld@sld.rw" ,
74
+ "country-code-tld@sld.uk" ,
75
+ "letters-in-sld@123.com" ,
76
+ "local@dash-in-sld.com" ,
77
+ "local@sld.newTLD" ,
78
+ "local@sub.domains.com" ,
79
+ "mixed-1234-in-{+^}-local@sld.net" ,
80
+ "one-character-third-level@a.example.com" ,
81
+ "one-letter-sld@x.org" ,
82
+ "punycode-numbers-in-tld@sld.xn--3e0b707e" ,
83
+ "single-character-in-sld@x.org" ,
84
+ "the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-three-characters-so-it-is-valid-blah-blah.com" ,
85
+ "the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-254-characters-exactly.so-it-should-be-valid.and-im-going-to-add-some-more-words-here.to-increase-the-length-blah-blah-blah-blah-bla.org" ,
86
+ "uncommon-tld@sld.mobi" ,
87
+ "uncommon-tld@sld.museum" ,
88
+ "uncommon-tld@sld.travel" ,
89
+ } ;
90
90
91
- static readonly string [ ] InvalidAddresses =
92
- {
93
- "" ,
94
- "invalid" ,
95
- "invalid@" ,
96
- "invalid @" ,
97
- "invalid@[555.666.777.888]" ,
98
- "invalid@[IPv6:123456]" ,
99
- "invalid@[127.0.0.1.]" ,
100
- "invalid@[127.0.0.1]." ,
101
- "invalid@[127.0.0.1]x" ,
91
+ static readonly string [ ] InvalidAddresses =
92
+ {
93
+ "" ,
94
+ "invalid" ,
95
+ "invalid@" ,
96
+ "invalid @" ,
97
+ "invalid@[555.666.777.888]" ,
98
+ "invalid@[IPv6:123456]" ,
99
+ "invalid@[127.0.0.1.]" ,
100
+ "invalid@[127.0.0.1]." ,
101
+ "invalid@[127.0.0.1]x" ,
102
102
103
- // examples from wikipedia
104
- "Abc.example.com" ,
105
- "A@b@c@example.com" ,
106
- "a\" b(c)d,e:f;g<h>i[j\\ k]l@example.com" ,
107
- "just\" not\" right@example.com" ,
108
- "this is\" not\\ allowed@example.com" ,
109
- "this\\ still\\ \" not\\ \\ allowed@example.com" ,
103
+ // examples from wikipedia
104
+ "Abc.example.com" ,
105
+ "A@b@c@example.com" ,
106
+ "a\" b(c)d,e:f;g<h>i[j\\ k]l@example.com" ,
107
+ "just\" not\" right@example.com" ,
108
+ "this is\" not\\ allowed@example.com" ,
109
+ "this\\ still\\ \" not\\ \\ allowed@example.com" ,
110
110
111
- // examples from https://github.com/Sembiance/email-validator
112
- "! #$%`|@invalid-characters-in-local.org" ,
113
- "(),:;`|@more-invalid-characters-in-local.org" ,
114
- "* .local-starts-with-dot@sld.com" ,
115
- "<>@[]`|@even-more-invalid-characters-in-local.org" ,
116
- "@missing-local.org" ,
117
- "IP-and-port@127.0.0.1:25" ,
118
- "another-invalid-ip@127.0.0.256" ,
119
- "invalid" ,
120
- "invalid-characters-in-sld@! \" #$%(),/;<>_[]`|.org" ,
121
- "invalid-ip@127.0.0.1.26" ,
122
- "local-ends-with-dot.@sld.com" ,
123
- "missing-at-sign.net" ,
124
- "missing-sld@.com" ,
125
- "missing-tld@sld." ,
126
- "sld-ends-with-dash@sld-.com" ,
127
- "sld-starts-with-dashsh@-sld.com" ,
128
- "the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-four-characters-so-it-is-invalid-blah-blah.com" ,
129
- "the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net" ,
130
- "the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-255-characters-exactly.so-it-should-be-invalid.and-im-going-to-add-some-more-words-here.to-increase-the-lenght-blah-blah-blah-blah-bl.org" ,
131
- "two..consecutive-dots@sld.com" ,
132
- "unbracketed-IP@127.0.0.1" ,
111
+ // examples from https://github.com/Sembiance/email-validator
112
+ "! #$%`|@invalid-characters-in-local.org" ,
113
+ "(),:;`|@more-invalid-characters-in-local.org" ,
114
+ "* .local-starts-with-dot@sld.com" ,
115
+ "<>@[]`|@even-more-invalid-characters-in-local.org" ,
116
+ "@missing-local.org" ,
117
+ "IP-and-port@127.0.0.1:25" ,
118
+ "another-invalid-ip@127.0.0.256" ,
119
+ "invalid" ,
120
+ "invalid-characters-in-sld@! \" #$%(),/;<>_[]`|.org" ,
121
+ "invalid-ip@127.0.0.1.26" ,
122
+ "local-ends-with-dot.@sld.com" ,
123
+ "missing-at-sign.net" ,
124
+ "missing-sld@.com" ,
125
+ "missing-tld@sld." ,
126
+ "sld-ends-with-dash@sld-.com" ,
127
+ "sld-starts-with-dashsh@-sld.com" ,
128
+ "the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-four-characters-so-it-is-invalid-blah-blah.com" ,
129
+ "the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net" ,
130
+ "the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-255-characters-exactly.so-it-should-be-invalid.and-im-going-to-add-some-more-words-here.to-increase-the-lenght-blah-blah-blah-blah-bl.org" ,
131
+ "two..consecutive-dots@sld.com" ,
132
+ "unbracketed-IP@127.0.0.1" ,
133
133
134
- // examples of real (invalid) input from real users.
135
- "No longer available." ,
136
- "Moved."
137
- } ;
134
+ // examples of real (invalid) input from real users.
135
+ "No longer available." ,
136
+ "Moved."
137
+ } ;
138
138
139
- static readonly string [ ] ValidInternationalAddresses =
140
- {
141
- "伊昭傑@郵件.商務" , // Chinese
142
- "राम@मोहन.ईन्फो" , // Hindi
143
- "юзер@екзампл.ком" , // Ukranian
144
- "θσερ@εχαμπλε.ψομ" , // Greek
145
- } ;
139
+ static readonly string [ ] ValidInternationalAddresses =
140
+ {
141
+ "伊昭傑@郵件.商務" , // Chinese
142
+ "राम@मोहन.ईन्फो" , // Hindi
143
+ "юзер@екзампл.ком" , // Ukranian
144
+ "θσερ@εχαμπλε.ψομ" , // Greek
145
+ } ;
146
146
147
- [ Test ]
148
- public void TestValidAddresses ( )
149
- {
150
- for ( int i = 0 ; i < ValidAddresses . Length ; i ++ )
151
- Assert . IsTrue ( EmailValidator . Validate ( ValidAddresses [ i ] , true ) , "Valid Address #{0}: {1}" , i ,
152
- ValidAddresses [ i ] ) ;
153
- }
147
+ [ Test ]
148
+ public void TestValidAddresses ( )
149
+ {
150
+ for ( int i = 0 ; i < ValidAddresses . Length ; i ++ )
151
+ Assert . IsTrue ( EmailValidator . Validate ( ValidAddresses [ i ] , true ) , "Valid Address #{0}: {1}" , i ,
152
+ ValidAddresses [ i ] ) ;
153
+ }
154
154
155
- [ Test ]
156
- public void TestInvalidAddresses ( )
157
- {
158
- for ( int i = 0 ; i < InvalidAddresses . Length ; i ++ )
159
- Assert . IsFalse ( EmailValidator . Validate ( InvalidAddresses [ i ] , true ) , "Invalid Address #{0}: {1}" , i ,
160
- InvalidAddresses [ i ] ) ;
161
- }
155
+ [ Test ]
156
+ public void TestInvalidAddresses ( )
157
+ {
158
+ for ( int i = 0 ; i < InvalidAddresses . Length ; i ++ )
159
+ Assert . IsFalse ( EmailValidator . Validate ( InvalidAddresses [ i ] , true ) , "Invalid Address #{0}: {1}" , i ,
160
+ InvalidAddresses [ i ] ) ;
161
+ }
162
162
163
- [ Test ]
164
- public void TestValidInternationalAddresses ( )
165
- {
166
- for ( int i = 0 ; i < ValidInternationalAddresses . Length ; i ++ )
167
- Assert . IsTrue ( EmailValidator . Validate ( ValidInternationalAddresses [ i ] , true , true ) ,
168
- "Valid International Address #{0}" , i ) ;
169
- }
163
+ [ Test ]
164
+ public void TestValidInternationalAddresses ( )
165
+ {
166
+ for ( int i = 0 ; i < ValidInternationalAddresses . Length ; i ++ )
167
+ Assert . IsTrue ( EmailValidator . Validate ( ValidInternationalAddresses [ i ] , true , true ) ,
168
+ "Valid International Address #{0}" , i ) ;
169
+ }
170
170
171
- [ Test ]
172
- public void TestThrowsExceptionIfNull ( )
173
- {
174
- Assert . Throws < ArgumentNullException > ( ( ) => EmailValidator . Validate ( null , true , true ) , "Null Address" ) ;
175
- }
171
+ [ Test ]
172
+ public void TestThrowsExceptionIfNull ( )
173
+ {
174
+ Assert . Throws < ArgumentNullException > ( ( ) => EmailValidator . Validate ( null , true , true ) , "Null Address" ) ;
176
175
}
177
176
}
0 commit comments