1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Components
.Validator
.Tests
.ValidatorTests
17 using System
.Globalization
;
18 using System
.Threading
;
19 using NUnit
.Framework
;
22 public class EmailValidatorTestCase
24 private EmailValidator validator
;
25 private TestTarget target
;
30 Thread
.CurrentThread
.CurrentCulture
=
31 Thread
.CurrentThread
.CurrentUICulture
= new CultureInfo("en-us");
33 validator
= new EmailValidator();
34 validator
.Initialize(typeof(TestTarget
).GetProperty("TargetField"));
35 target
= new TestTarget();
39 public void InvalidEmail()
41 Assert
.IsFalse(validator
.IsValid(target
, "abc"));
42 Assert
.IsFalse(validator
.IsValid(target
, "ham@ham@ham"));
46 public void ValidEmail()
48 Assert
.IsTrue(validator
.IsValid(target
, "hammett@gmail.com"));
49 Assert
.IsTrue(validator
.IsValid(target
, "hammett@uol.com.br"));
50 Assert
.IsTrue(validator
.IsValid(target
, "hammett@apache.org"));
51 Assert
.IsTrue(validator
.IsValid(target
, "hamilton.verissimo@something.com.br"));
54 public class TestTarget
56 private string targetField
;
58 public string TargetField
60 get { return targetField; }
61 set { targetField = value; }