Adding the following validators:
[castle.git] / Components / General / Validator / Castle.Components.Validator.Tests / ValidatorTests / GroupNotEmptyValidatorTestCase.cs
blobb41f6885ce1999763b62292a2a5320b2206b9c6f
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 namespace Castle.Components.Validator.Tests.ValidatorTests
17 using System.Globalization;
18 using System.Threading;
19 using NUnit.Framework;
21 [TestFixture]
22 public class GroupNotEmptyValidatorTestCase
24 private GroupNotEmptyValidator validator;
25 private TestTarget target;
27 [SetUp]
28 public void Init()
30 Thread.CurrentThread.CurrentCulture =
31 Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
33 validator = new GroupNotEmptyValidator("Dummy");
34 validator.Initialize(typeof(TestTarget).GetProperty("Foo"));
35 validator.FriendlyName = "BAR";
36 validator.Initialize(typeof(TestTarget).GetProperty("Bar"));
37 target = new TestTarget();
40 [Test]
41 public void BothEmptyStrings()
43 target.Bar = null;
44 target.Foo = "";
45 Assert.IsFalse(validator.IsValid(target));
48 [Test]
49 public void BothNonEmptyStrings()
51 target.Bar = "Abva";
52 target.Foo = "tdhf";
53 Assert.IsTrue(validator.IsValid(target));
56 [Test]
57 public void FirstEmptySecondFull()
59 target.Bar = "";
60 target.Foo = " ";
61 Assert.IsTrue(validator.IsValid(target));
65 [Test]
66 public void FirstFullSecondEmpty()
68 target.Bar = "aa ";
69 target.Foo = "";
70 Assert.IsTrue(validator.IsValid(target));
73 [Test]
74 public void ErrorMessage()
76 Assert.IsFalse(validator.IsValid(target));
78 Assert.IsTrue(
79 "At least one of the values in (Foo, BAR) should not be empty"== validator.ErrorMessage
80 || "At least one of the values in (BAR, Foo) should not be empty" == validator.ErrorMessage);
84 public class TestTarget
86 private string foo;
87 private string bar;
90 public string Bar
92 get { return bar; }
93 set { bar = value; }
96 public string Foo
98 get { return foo; }
99 set { foo = value; }