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
18 using System
.Globalization
;
19 using System
.Threading
;
20 using NUnit
.Framework
;
23 public class NotSameValueValidatorTestCase
25 private NotSameValueValidator validator1
, validator2
, validator3
;
26 private TestTarget target
;
31 Thread
.CurrentThread
.CurrentCulture
=
32 Thread
.CurrentThread
.CurrentUICulture
= new CultureInfo("en-us");
34 validator1
= new NotSameValueValidator("15");
35 validator1
.Initialize(typeof(TestTarget
).GetProperty("TargetField1"));
37 validator2
= new NotSameValueValidator(15);
38 validator2
.Initialize(typeof(TestTarget
).GetProperty("TargetField2"));
40 ValidateNotSameValueAttribute attribute
= new ValidateNotSameValueAttribute(typeof(Guid
), Guid
.Empty
.ToString());
41 validator3
= (NotSameValueValidator
) attribute
.Build();
42 validator3
.Initialize(typeof(TestTarget
).GetProperty("TargetField3"));
44 target
= new TestTarget();
48 public void InvalidForString()
50 Assert
.IsFalse(validator1
.IsValid(target
, "15"));
51 Assert
.IsTrue(validator1
.IsValid(target
, "abc"));
55 public void InvalidForInt()
57 Assert
.IsFalse(validator2
.IsValid(target
, 15));
61 public void ValidForString()
63 Assert
.IsTrue(validator1
.IsValid(target
, "not 15"));
67 public void ValidForInt()
69 Assert
.IsTrue(validator2
.IsValid(target
, 100));
73 public void InvalidGuid()
75 Assert
.IsFalse(validator3
.IsValid(target
, Guid
.Empty
));
78 public class TestTarget
80 private string targetField1
;
81 private int targetField2
;
82 private Guid targetField3
;
84 public string TargetField1
86 get { return targetField1; }
87 set { targetField1 = value; }
90 public int TargetField2
92 get { return targetField2; }
93 set { targetField2 = value; }
97 public Guid TargetField3
99 get { return targetField3; }
100 set { targetField3 = value; }