Adding the following validators:
[castle.git] / Components / General / Validator / Castle.Components.Validator.Tests / ValidatorTests / NotSameValueValidatorTestCase.cs
blobbaa30d3c1ca7ba35b3fa5890745c41badc1da1a7
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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 using System;
17 namespace Castle.Components.Validator.Tests.ValidatorTests
19 using System.Globalization;
20 using System.Threading;
21 using NUnit.Framework;
23 [TestFixture]
24 public class NotSameValueValidatorTestCase
26 private NotSameValueValidator validator1, validator2, validator3;
27 private TestTarget target;
29 [SetUp]
30 public void Init()
32 Thread.CurrentThread.CurrentCulture =
33 Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
35 validator1 = new NotSameValueValidator("15");
36 validator1.Initialize(typeof(TestTarget).GetProperty("TargetField1"));
38 validator2 = new NotSameValueValidator(15);
39 validator2.Initialize(typeof(TestTarget).GetProperty("TargetField2"));
41 ValidateNotSameValueAttribute attribute = new ValidateNotSameValueAttribute(typeof(Guid), Guid.Empty.ToString());
42 validator3 = (NotSameValueValidator)attribute.Build();
43 validator3.Initialize(typeof(TestTarget).GetProperty("TargetField3"));
45 target = new TestTarget();
48 [Test]
49 public void InvalidForString()
51 Assert.IsFalse(validator1.IsValid(target, "15"));
52 Assert.IsTrue(validator1.IsValid(target, "abc"));
55 [Test]
56 public void InvalidForInt()
58 Assert.IsFalse(validator2.IsValid(target, 15));
61 [Test]
62 public void ValidForString()
64 Assert.IsTrue(validator1.IsValid(target, "not 15"));
67 [Test]
68 public void ValidForInt()
70 Assert.IsTrue(validator2.IsValid(target, 100));
73 [Test]
74 public void InvalidGuid()
76 Assert.IsFalse(validator3.IsValid(target, Guid.Empty));
79 public class TestTarget
81 private string targetField1;
82 private int targetField2;
83 private Guid targetField3;
85 public string TargetField1
87 get { return targetField1; }
88 set { targetField1 = value; }
91 public int TargetField2
93 get { return targetField2; }
94 set { targetField2 = value; }
98 public Guid TargetField3
100 get { return targetField3; }
101 set { targetField3 = value; }