From 65b134c42bca08e6aa100dee17dd90e3024ed346 Mon Sep 17 00:00:00 2001 From: ayende Date: Wed, 4 Apr 2007 07:17:00 +0000 Subject: [PATCH] Reformatting the code according to castle guidelines. git-svn-id: https://svn.castleproject.org/svn/castle/trunk@3674 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- .../CachedValidationRegistryTestCase.cs | 6 +- .../ErrorSummaryTestCase.cs | 2 +- .../Models/Client.cs | 6 +- .../Models/InsertUpdateClass.cs | 2 +- .../Models/Person.cs | 2 +- .../Models/Supplier.cs | 2 +- .../ValidatorRunnerTestCase.cs | 29 +- .../CollectionNotEmptyValidatorTestCase.cs | 11 +- .../ValidatorTests/DateTimeValidatorTestCase.cs | 2 +- .../ValidatorTests/DateValidatorTestCase.cs | 2 +- .../ValidatorTests/DecimalValidatorTestCase.cs | 2 +- .../ValidatorTests/DoubleValidatorTestCase.cs | 2 +- .../ValidatorTests/EmailValidatorTestCase.cs | 2 +- .../GroupNotEmptyValidatorTestCase.cs | 205 +++++---- .../ValidatorTests/IntegerValidatorTestCase.cs | 2 +- .../ValidatorTests/LengthValidatorTestCase.cs | 2 +- .../ValidatorTests/NonEmptyValidatorTestCase.cs | 2 +- .../NotSameValueValidatorTestCase.cs | 35 +- .../ValidatorTests/RangeValidatorTestCase.cs | 30 +- .../RegularExpressionValidatorTestCase.cs | 2 +- .../ValidatorTests/SameAsValidatorTestCase.cs | 2 +- .../ValidatorTests/SingleValidatorTestCase.cs | 2 +- .../ValidatorsExecutionOrderTestCase.cs | 2 +- .../Attributes/AbstractValidationAttribute.cs | 18 +- .../ValidateCollectionNotEmptyAttribute.cs} | 35 +- .../Attributes/ValidateDateAttribute.cs | 2 +- .../Attributes/ValidateEmailAttribute.cs | 5 +- ...ribute.cs => ValidateGroupNotEmptyAttribute.cs} | 43 +- .../Attributes/ValidateLengthAttribute.cs | 4 +- .../Attributes/ValidateNonEmptyAttribute.cs | 11 +- .../Attributes/ValidateNotSameValueAttribute.cs | 178 ++++---- .../Attributes/ValidateRangeAttribute.cs | 7 +- .../Attributes/ValidateSameAsAttribute.cs | 6 +- .../CachedValidationRegistry.cs | 49 +- .../Castle.Components.Validator/ErrorSummary.cs | 2 +- .../Castle.Components.Validator/IValidator.cs | 10 +- .../IValidatorBuilder.cs | 19 +- .../IValidatorRegistry.cs | 44 +- .../IWebValidationGenerator.cs | 2 +- .../InputElementType.cs | 2 +- .../MessageConstants.cs | 12 +- .../Messages.Designer.cs | 507 ++++++++++----------- .../ValidationInternalError.cs | 2 +- .../Castle.Components.Validator/ValidatorRunner.cs | 22 +- .../Validators/AbstractValidator.cs | 26 +- .../Validators/CollectionNotEmptyValidator.cs | 122 +++-- .../Validators/DateTimeValidator.cs | 4 +- .../Validators/DateValidator.cs | 6 +- .../Validators/DecimalValidator.cs | 6 +- .../Validators/DoubleValidator.cs | 6 +- .../Validators/EmailValidator.cs | 8 +- .../Validators/IntegerValidator.cs | 6 +- .../Validators/LengthValidator.cs | 26 +- .../Validators/NonEmptyValidator.cs | 4 +- .../Validators/NotSameValueValidator.cs | 137 +++--- .../Validators/RangeValidator.cs | 63 +-- .../Validators/RegularExpressionValidator.cs | 6 +- .../Validators/SameAsValidator.cs | 4 +- .../Validators/SingleValidator.cs | 6 +- .../WebValidationConfiguration.cs | 2 +- 60 files changed, 878 insertions(+), 888 deletions(-) rewrite Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/GroupNotEmptyValidatorTestCase.cs (76%) copy Components/General/Validator/Castle.Components.Validator/{InputElementType.cs => Attributes/ValidateCollectionNotEmptyAttribute.cs} (58%) copy Components/General/Validator/Castle.Components.Validator/Attributes/{ValidateNonEmptyAttribute.cs => ValidateGroupNotEmptyAttribute.cs} (50%) rewrite Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNotSameValueAttribute.cs (81%) rewrite Components/General/Validator/Castle.Components.Validator/Messages.Designer.cs (96%) rewrite Components/General/Validator/Castle.Components.Validator/Validators/CollectionNotEmptyValidator.cs (67%) rewrite Components/General/Validator/Castle.Components.Validator/Validators/NotSameValueValidator.cs (73%) diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/CachedValidationRegistryTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/CachedValidationRegistryTestCase.cs index 536eb4d98..a288d6d41 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/CachedValidationRegistryTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/CachedValidationRegistryTestCase.cs @@ -32,7 +32,7 @@ namespace Castle.Components.Validator.Tests public void RunWhenEverytimeTest() { IValidator[] validators = registry.GetValidators(new ValidatorRunner(registry), typeof(Client), RunWhen.Everytime); - + Assert.IsNotNull(validators); Assert.AreEqual(8, validators.Length); @@ -45,7 +45,7 @@ namespace Castle.Components.Validator.Tests [Test] public void RunWhenCustomTest() { - IValidator[] validators = registry.GetValidators(new ValidatorRunner(registry), typeof(Client), RunWhen.Custom); + IValidator[] validators = registry.GetValidators(new ValidatorRunner(registry), typeof(Client), RunWhen.Custom); Assert.IsNotNull(validators); Assert.AreEqual(9, validators.Length); // RunWhen.Everytime is returned too @@ -56,4 +56,4 @@ namespace Castle.Components.Validator.Tests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ErrorSummaryTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ErrorSummaryTestCase.cs index eaa2e270a..469564984 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ErrorSummaryTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ErrorSummaryTestCase.cs @@ -42,4 +42,4 @@ namespace Castle.Components.Validator.Tests Assert.AreEqual(2, errorSummary.InvalidPropertiesCount); } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/Models/Client.cs b/Components/General/Validator/Castle.Components.Validator.Tests/Models/Client.cs index d58b3ab70..b2d898b43 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/Models/Client.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/Models/Client.cs @@ -30,7 +30,7 @@ namespace Castle.Components.Validator.Tests.Models this.confirmation = confirmation; } - [ValidateGroupNotEmpty("EmailOrPass")] + [ValidateGroupNotEmpty("EmailOrPass")] [ValidateEmail] public string Email { @@ -38,7 +38,7 @@ namespace Castle.Components.Validator.Tests.Models set { email = value; } } - [ValidateGroupNotEmpty("EmailOrPass")] + [ValidateGroupNotEmpty("EmailOrPass")] [ValidateLength(3, 12, "Invalid password length")] public string Password { @@ -53,4 +53,4 @@ namespace Castle.Components.Validator.Tests.Models set { confirmation = value; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/Models/InsertUpdateClass.cs b/Components/General/Validator/Castle.Components.Validator.Tests/Models/InsertUpdateClass.cs index b8bd9933b..6bcf7a747 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/Models/InsertUpdateClass.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/Models/InsertUpdateClass.cs @@ -46,4 +46,4 @@ namespace Castle.Components.Validator.Tests.Models set { prop4 = value; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/Models/Person.cs b/Components/General/Validator/Castle.Components.Validator.Tests/Models/Person.cs index c0eb634e7..6b3b3857a 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/Models/Person.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/Models/Person.cs @@ -60,4 +60,4 @@ namespace Castle.Components.Validator.Tests.Models set { address = value; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/Models/Supplier.cs b/Components/General/Validator/Castle.Components.Validator.Tests/Models/Supplier.cs index 03cb4509c..e08454763 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/Models/Supplier.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/Models/Supplier.cs @@ -32,4 +32,4 @@ namespace Castle.Components.Validator.Tests.Models set { email = value; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorRunnerTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorRunnerTestCase.cs index 647e3117b..da540bac5 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorRunnerTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorRunnerTestCase.cs @@ -42,16 +42,16 @@ namespace Castle.Components.Validator.Tests public void IsValidForInsertUpdate() { InsertUpdateClass obj = new InsertUpdateClass(); - + Assert.IsFalse(runner.IsValid(obj, RunWhen.Insert)); - + obj.Prop1 = "value"; obj.Prop2 = "value"; - + Assert.IsTrue(runner.IsValid(obj, RunWhen.Insert)); Assert.IsFalse(runner.IsValid(obj, RunWhen.Update)); - + obj.Prop3 = "value"; obj.Prop4 = "value"; @@ -67,16 +67,15 @@ namespace Castle.Components.Validator.Tests Assert.IsTrue(runner.IsValid(client)); } - [Test] - public void GroupValidation() - { - Client client = new Client(); - client.Email = "foo@bar.com"; - Assert.IsFalse(runner.IsValid(client)); - - Assert.AreEqual(0, runner.GetErrorSummary(client).GetErrorsForProperty("Email").Length); - Assert.AreEqual(0, runner.GetErrorSummary(client).GetErrorsForProperty("Password").Length); + [Test] + public void GroupValidation() + { + Client client = new Client(); + client.Email = "foo@bar.com"; + Assert.IsFalse(runner.IsValid(client)); - } + Assert.AreEqual(0, runner.GetErrorSummary(client).GetErrorsForProperty("Email").Length); + Assert.AreEqual(0, runner.GetErrorSummary(client).GetErrorsForProperty("Password").Length); + } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/CollectionNotEmptyValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/CollectionNotEmptyValidatorTestCase.cs index 09371b7a2..0dab1d94d 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/CollectionNotEmptyValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/CollectionNotEmptyValidatorTestCase.cs @@ -12,10 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System.Collections.Generic; - namespace Castle.Components.Validator.Tests.ValidatorTests { + using System.Collections.Generic; using System.Globalization; using System.Threading; using NUnit.Framework; @@ -23,7 +22,7 @@ namespace Castle.Components.Validator.Tests.ValidatorTests [TestFixture] public class CollectionNotEmptyValidatorTestCase { - private CollectionNotEmptyValidator validator; + private CollectionNotEmptyValidator validator; private TestTarget target; [SetUp] @@ -47,16 +46,16 @@ namespace Castle.Components.Validator.Tests.ValidatorTests [Test] public void NonEmptyCollection() { - Assert.IsTrue(validator.IsValid(target, "1,2,3".Split(',') ) ); + Assert.IsTrue(validator.IsValid(target, "1,2,3".Split(','))); } public class TestTarget { - private IList targetField = new List(); + private IList targetField = new List(); public IList TargetField { - get { return targetField; } + get { return targetField; } set { targetField = value; } } } diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DateTimeValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DateTimeValidatorTestCase.cs index c074ca20e..b3bbc5d5c 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DateTimeValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DateTimeValidatorTestCase.cs @@ -64,4 +64,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DateValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DateValidatorTestCase.cs index 34885024d..accfd33d5 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DateValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DateValidatorTestCase.cs @@ -64,4 +64,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DecimalValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DecimalValidatorTestCase.cs index 05a9f0192..94676bccc 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DecimalValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DecimalValidatorTestCase.cs @@ -59,4 +59,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DoubleValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DoubleValidatorTestCase.cs index 9d4bcad52..3f8637a1c 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DoubleValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/DoubleValidatorTestCase.cs @@ -59,4 +59,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/EmailValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/EmailValidatorTestCase.cs index 295ab7d81..e3270009f 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/EmailValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/EmailValidatorTestCase.cs @@ -62,4 +62,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/GroupNotEmptyValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/GroupNotEmptyValidatorTestCase.cs dissimilarity index 76% index b41f6885c..bcadad304 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/GroupNotEmptyValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/GroupNotEmptyValidatorTestCase.cs @@ -1,103 +1,102 @@ -// Copyright 2004-2007 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Castle.Components.Validator.Tests.ValidatorTests -{ - using System.Globalization; - using System.Threading; - using NUnit.Framework; - - [TestFixture] - public class GroupNotEmptyValidatorTestCase - { - private GroupNotEmptyValidator validator; - private TestTarget target; - - [SetUp] - public void Init() - { - Thread.CurrentThread.CurrentCulture = - Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); - - validator = new GroupNotEmptyValidator("Dummy"); - validator.Initialize(typeof(TestTarget).GetProperty("Foo")); - validator.FriendlyName = "BAR"; - validator.Initialize(typeof(TestTarget).GetProperty("Bar")); - target = new TestTarget(); - } - - [Test] - public void BothEmptyStrings() - { - target.Bar = null; - target.Foo = ""; - Assert.IsFalse(validator.IsValid(target)); - } - - [Test] - public void BothNonEmptyStrings() - { - target.Bar = "Abva"; - target.Foo = "tdhf"; - Assert.IsTrue(validator.IsValid(target)); - } - - [Test] - public void FirstEmptySecondFull() - { - target.Bar = ""; - target.Foo = " "; - Assert.IsTrue(validator.IsValid(target)); - } - - - [Test] - public void FirstFullSecondEmpty() - { - target.Bar = "aa "; - target.Foo = ""; - Assert.IsTrue(validator.IsValid(target)); - } - - [Test] - public void ErrorMessage() - { - Assert.IsFalse(validator.IsValid(target)); - - Assert.IsTrue( - "At least one of the values in (Foo, BAR) should not be empty"== validator.ErrorMessage - || "At least one of the values in (BAR, Foo) should not be empty" == validator.ErrorMessage); - - } - - public class TestTarget - { - private string foo; - private string bar; - - - public string Bar - { - get { return bar; } - set { bar = value; } - } - - public string Foo - { - get { return foo; } - set { foo = value; } - } - } - } -} \ No newline at end of file +// Copyright 2004-2007 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Castle.Components.Validator.Tests.ValidatorTests +{ + using System.Globalization; + using System.Threading; + using NUnit.Framework; + + [TestFixture] + public class GroupNotEmptyValidatorTestCase + { + private GroupNotEmptyValidator validator; + private TestTarget target; + + [SetUp] + public void Init() + { + Thread.CurrentThread.CurrentCulture = + Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); + + validator = new GroupNotEmptyValidator("Dummy"); + validator.Initialize(typeof(TestTarget).GetProperty("Foo")); + validator.FriendlyName = "BAR"; + validator.Initialize(typeof(TestTarget).GetProperty("Bar")); + target = new TestTarget(); + } + + [Test] + public void BothEmptyStrings() + { + target.Bar = null; + target.Foo = ""; + Assert.IsFalse(validator.IsValid(target)); + } + + [Test] + public void BothNonEmptyStrings() + { + target.Bar = "Abva"; + target.Foo = "tdhf"; + Assert.IsTrue(validator.IsValid(target)); + } + + [Test] + public void FirstEmptySecondFull() + { + target.Bar = ""; + target.Foo = " "; + Assert.IsTrue(validator.IsValid(target)); + } + + + [Test] + public void FirstFullSecondEmpty() + { + target.Bar = "aa "; + target.Foo = ""; + Assert.IsTrue(validator.IsValid(target)); + } + + [Test] + public void ErrorMessage() + { + Assert.IsFalse(validator.IsValid(target)); + + Assert.IsTrue( + "At least one of the values in (Foo, BAR) should not be empty" == validator.ErrorMessage + || "At least one of the values in (BAR, Foo) should not be empty" == validator.ErrorMessage); + } + + public class TestTarget + { + private string foo; + private string bar; + + + public string Bar + { + get { return bar; } + set { bar = value; } + } + + public string Foo + { + get { return foo; } + set { foo = value; } + } + } + } +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/IntegerValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/IntegerValidatorTestCase.cs index b119b802d..c8e75e69d 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/IntegerValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/IntegerValidatorTestCase.cs @@ -59,4 +59,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/LengthValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/LengthValidatorTestCase.cs index 77bc34edf..1f57e678e 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/LengthValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/LengthValidatorTestCase.cs @@ -67,4 +67,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/NonEmptyValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/NonEmptyValidatorTestCase.cs index 598a4cb4e..def5d0aec 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/NonEmptyValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/NonEmptyValidatorTestCase.cs @@ -60,4 +60,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/NotSameValueValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/NotSameValueValidatorTestCase.cs index baa30d3c1..a5a880a9e 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/NotSameValueValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/NotSameValueValidatorTestCase.cs @@ -12,10 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; - namespace Castle.Components.Validator.Tests.ValidatorTests { + using System; using System.Globalization; using System.Threading; using NUnit.Framework; @@ -23,7 +22,7 @@ namespace Castle.Components.Validator.Tests.ValidatorTests [TestFixture] public class NotSameValueValidatorTestCase { - private NotSameValueValidator validator1, validator2, validator3; + private NotSameValueValidator validator1, validator2, validator3; private TestTarget target; [SetUp] @@ -35,12 +34,12 @@ namespace Castle.Components.Validator.Tests.ValidatorTests validator1 = new NotSameValueValidator("15"); validator1.Initialize(typeof(TestTarget).GetProperty("TargetField1")); - validator2 = new NotSameValueValidator(15); + validator2 = new NotSameValueValidator(15); validator2.Initialize(typeof(TestTarget).GetProperty("TargetField2")); - ValidateNotSameValueAttribute attribute = new ValidateNotSameValueAttribute(typeof(Guid), Guid.Empty.ToString()); - validator3 = (NotSameValueValidator)attribute.Build(); - validator3.Initialize(typeof(TestTarget).GetProperty("TargetField3")); + ValidateNotSameValueAttribute attribute = new ValidateNotSameValueAttribute(typeof(Guid), Guid.Empty.ToString()); + validator3 = (NotSameValueValidator) attribute.Build(); + validator3.Initialize(typeof(TestTarget).GetProperty("TargetField3")); target = new TestTarget(); } @@ -70,17 +69,17 @@ namespace Castle.Components.Validator.Tests.ValidatorTests Assert.IsTrue(validator2.IsValid(target, 100)); } - [Test] - public void InvalidGuid() - { - Assert.IsFalse(validator3.IsValid(target, Guid.Empty)); - } + [Test] + public void InvalidGuid() + { + Assert.IsFalse(validator3.IsValid(target, Guid.Empty)); + } public class TestTarget { private string targetField1; private int targetField2; - private Guid targetField3; + private Guid targetField3; public string TargetField1 { @@ -95,11 +94,11 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } - public Guid TargetField3 - { - get { return targetField3; } - set { targetField3 = value; } - } + public Guid TargetField3 + { + get { return targetField3; } + set { targetField3 = value; } + } } } } \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/RangeValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/RangeValidatorTestCase.cs index 6ae468234..4c8a05a0d 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/RangeValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/RangeValidatorTestCase.cs @@ -22,9 +22,16 @@ namespace Castle.Components.Validator.Tests.ValidatorTests [TestFixture] public class RangeValidatorTestCase { - private RangeValidator validatorIntLow, validatorIntHigh, validatorIntLowOrHigh, - validatorDateTimeLow, validatorDateTimeHigh, validatorDateTimeLowOrHigh, - validatorStringLow, validatorStringHigh, validatorStringLowOrHigh; + private RangeValidator validatorIntLow, + validatorIntHigh, + validatorIntLowOrHigh, + validatorDateTimeLow, + validatorDateTimeHigh, + validatorDateTimeLowOrHigh, + validatorStringLow, + validatorStringHigh, + validatorStringLowOrHigh; + private TestTargetInt intTarget; private TestTargetDateTime dateTimeTarget; private TestTargetString stringTarget; @@ -64,7 +71,7 @@ namespace Castle.Components.Validator.Tests.ValidatorTests validatorStringHigh = new RangeValidator(String.Empty, "yyy"); validatorStringHigh.Initialize(typeof(TestTargetString).GetProperty("TargetField")); - + validatorStringLowOrHigh = new RangeValidator(RangeValidationType.String, 'b'.ToString(), 'y'.ToString()); validatorStringLowOrHigh.Initialize(typeof(TestTargetString).GetProperty("TargetField")); @@ -105,6 +112,7 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } #region Integer range tests + [Test] public void RangeIntTooLowValidator() { @@ -139,9 +147,11 @@ namespace Castle.Components.Validator.Tests.ValidatorTests //pass when compare to number not too high Assert.IsTrue(validatorIntLowOrHigh.IsValid(intTarget, 0)); } + #endregion #region DateTime range tests + [Test] public void RangeDateTimeTooLowValidator() { @@ -170,15 +180,17 @@ namespace Castle.Components.Validator.Tests.ValidatorTests //fail when compare to non-date Assert.IsFalse(validatorDateTimeLowOrHigh.IsValid(dateTimeTarget, "abc")); //fail when compare to date too low - Assert.IsFalse(validatorDateTimeLowOrHigh.IsValid(dateTimeTarget, new DateTime(1999,01,01))); + Assert.IsFalse(validatorDateTimeLowOrHigh.IsValid(dateTimeTarget, new DateTime(1999, 01, 01))); //fail when compare to date too high - Assert.IsFalse(validatorDateTimeLowOrHigh.IsValid(dateTimeTarget, new DateTime(2100,01,01))); + Assert.IsFalse(validatorDateTimeLowOrHigh.IsValid(dateTimeTarget, new DateTime(2100, 01, 01))); //pass when compare to date not too low or high - Assert.IsTrue(validatorDateTimeLowOrHigh.IsValid(dateTimeTarget, new DateTime(2007,01,01))); + Assert.IsTrue(validatorDateTimeLowOrHigh.IsValid(dateTimeTarget, new DateTime(2007, 01, 01))); } + #endregion #region String range tests + [Test] public void RangeStringTooLowValidator() { @@ -207,7 +219,7 @@ namespace Castle.Components.Validator.Tests.ValidatorTests //pass when compare to string not too low or high Assert.IsTrue(validatorStringLowOrHigh.IsValid(intTarget, "m")); } - #endregion + #endregion } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/RegularExpressionValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/RegularExpressionValidatorTestCase.cs index 189550880..77edbb79c 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/RegularExpressionValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/RegularExpressionValidatorTestCase.cs @@ -21,4 +21,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests { // TODO: Implement this test case } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/SameAsValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/SameAsValidatorTestCase.cs index ea12bde90..89e1ae928 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/SameAsValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/SameAsValidatorTestCase.cs @@ -99,4 +99,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/SingleValidatorTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/SingleValidatorTestCase.cs index 87f84ba21..2edc43a72 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/SingleValidatorTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorTests/SingleValidatorTestCase.cs @@ -60,4 +60,4 @@ namespace Castle.Components.Validator.Tests.ValidatorTests } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorsExecutionOrderTestCase.cs b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorsExecutionOrderTestCase.cs index d913e2b28..46eb4ad80 100644 --- a/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorsExecutionOrderTestCase.cs +++ b/Components/General/Validator/Castle.Components.Validator.Tests/ValidatorsExecutionOrderTestCase.cs @@ -46,4 +46,4 @@ namespace Castle.Components.Validator.Tests Assert.AreEqual("This is a required field", summary.ErrorMessages[2]); } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/AbstractValidationAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/AbstractValidationAttribute.cs index 1e88d81ea..d52c91398 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/AbstractValidationAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/AbstractValidationAttribute.cs @@ -117,14 +117,14 @@ namespace Castle.Components.Validator public abstract IValidator Build(); - /// - /// Constructs and configures an - /// instance based on the properties set on the attribute instance. - /// - public virtual IValidator Build(ValidatorRunner validatorRunner, Type type) - { - return Build(); - } + /// + /// Constructs and configures an + /// instance based on the properties set on the attribute instance. + /// + public virtual IValidator Build(ValidatorRunner validatorRunner, Type type) + { + return Build(); + } /// /// Applies the common configuration defined on the attribute. @@ -145,4 +145,4 @@ namespace Castle.Components.Validator } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/InputElementType.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateCollectionNotEmptyAttribute.cs similarity index 58% copy from Components/General/Validator/Castle.Components.Validator/InputElementType.cs copy to Components/General/Validator/Castle.Components.Validator/Attributes/ValidateCollectionNotEmptyAttribute.cs index ab0d0bf95..ad0efaf1e 100644 --- a/Components/General/Validator/Castle.Components.Validator/InputElementType.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateCollectionNotEmptyAttribute.cs @@ -15,33 +15,22 @@ namespace Castle.Components.Validator { /// - /// Defines an html element type + /// Validates that the collection is not empty /// - public enum InputElementType + public class ValidateCollectionNotEmptyAttribute : AbstractValidationAttribute { /// - /// Nothing specified + /// Constructs and configures an + /// instance based on the properties set on the attribute instance. /// - Undefined, + /// + public override IValidator Build() + { + CollectionNotEmptyValidator validator = new CollectionNotEmptyValidator(); - /// - /// Text input element - /// - Text, - - /// - /// Select element - /// - Select, + ConfigureValidatorMessage(validator); - /// - /// Radio element - /// - Radio, - - /// - /// Checkbox element - /// - Checkbox + return validator; + } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateDateAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateDateAttribute.cs index 4471bdce4..b505abbee 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateDateAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateDateAttribute.cs @@ -54,4 +54,4 @@ namespace Castle.Components.Validator return validator; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateEmailAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateEmailAttribute.cs index 0fa272a39..1c62f0c73 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateEmailAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateEmailAttribute.cs @@ -16,9 +16,6 @@ namespace Castle.Components.Validator { using System; - using Castle.Components.Validator; - - /// /// Validate that this email address is a valid one. /// @@ -57,4 +54,4 @@ namespace Castle.Components.Validator return validator; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNonEmptyAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateGroupNotEmptyAttribute.cs similarity index 50% copy from Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNonEmptyAttribute.cs copy to Components/General/Validator/Castle.Components.Validator/Attributes/ValidateGroupNotEmptyAttribute.cs index 90dd5bf16..39a90af1f 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNonEmptyAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateGroupNotEmptyAttribute.cs @@ -12,34 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. - namespace Castle.Components.Validator { using System; - using System.Collections; - using Castle.Components.Validator; + using System.Collections; /// - /// Validate that the property is not null or empty (for strings) + /// Validate that at least one of the properties in the group is not null or empty (for strings) /// [Serializable] - public class ValidateNonEmptyAttribute : AbstractValidationAttribute + public class ValidateGroupNotEmptyAttribute : AbstractValidationAttribute { - private readonly IDictionary validatorPerGroup = Hashtable.Synchronized(new Hashtable()); - - /// - /// Initializes a new instance of the class. - /// - public ValidateNonEmptyAttribute() - { - } + private string group; + private static IDictionary groupsPerType = Hashtable.Synchronized(new Hashtable()); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// The error message. - public ValidateNonEmptyAttribute(String errorMessage) : base(errorMessage) + /// The group. + public ValidateGroupNotEmptyAttribute(string group) { + this.group = group; } /// @@ -49,11 +42,21 @@ namespace Castle.Components.Validator /// public override IValidator Build() { - IValidator validator = new NonEmptyValidator(); - + throw new NotSupportedException("You must call Build with a type parameter"); + } + + public override IValidator Build(ValidatorRunner validatorRunner, Type type) + { + GroupNotEmptyValidator validator = (GroupNotEmptyValidator) + validatorRunner.ExtendedProperties[group]; + if (validator == null) + { + validatorRunner.ExtendedProperties[group] = validator + = new GroupNotEmptyValidator(group); + } ConfigureValidatorMessage(validator); - + return validator; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateLengthAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateLengthAttribute.cs index a666726e5..79e41a812 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateLengthAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateLengthAttribute.cs @@ -16,8 +16,6 @@ namespace Castle.Components.Validator { using System; - using Castle.Components.Validator; - /// /// Validate that this property has the required length (either exact or in a range) /// @@ -78,4 +76,4 @@ namespace Castle.Components.Validator return validator; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNonEmptyAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNonEmptyAttribute.cs index 90dd5bf16..d2443977a 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNonEmptyAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNonEmptyAttribute.cs @@ -16,8 +16,7 @@ namespace Castle.Components.Validator { using System; - using System.Collections; - using Castle.Components.Validator; + using System.Collections; /// /// Validate that the property is not null or empty (for strings) @@ -25,7 +24,7 @@ namespace Castle.Components.Validator [Serializable] public class ValidateNonEmptyAttribute : AbstractValidationAttribute { - private readonly IDictionary validatorPerGroup = Hashtable.Synchronized(new Hashtable()); + private readonly IDictionary validatorPerGroup = Hashtable.Synchronized(new Hashtable()); /// /// Initializes a new instance of the class. @@ -50,10 +49,10 @@ namespace Castle.Components.Validator public override IValidator Build() { IValidator validator = new NonEmptyValidator(); - + ConfigureValidatorMessage(validator); - + return validator; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNotSameValueAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNotSameValueAttribute.cs dissimilarity index 81% index 9c76a0a74..a1198666d 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNotSameValueAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateNotSameValueAttribute.cs @@ -1,89 +1,89 @@ -// Copyright 2004-2007 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Reflection; - -namespace Castle.Components.Validator -{ - /// - /// Validates that the content has not been set to the specified value - /// - public class ValidateNotSameValueAttribute : AbstractValidationAttribute - { - private readonly object value; - - /// - /// Initializes a new instance of the class. - /// - public ValidateNotSameValueAttribute(object mustNotBeThisValue) - { - this.value = mustNotBeThisValue; - } - - /// - /// Initializes a new instance of the class. - /// - /// Type of the value. - /// The must not be this value. - public ValidateNotSameValueAttribute(Type valueType, object mustNotBeThisValue) - :this(valueType,mustNotBeThisValue, null) - { - - } - - /// - /// Initializes a new instance of the class. - /// - public ValidateNotSameValueAttribute(Type valueType, object mustNotBeThisValue, string errorMessage) - : base(errorMessage) - { - if (mustNotBeThisValue==null) - { - throw new ArgumentException( - "You cannot use ValidateNotSameValue validator for null values, use ValidateNotEmpty for this"); - } - if (typeof(IConvertible).IsAssignableFrom(valueType)) - this.value = Convert.ChangeType(mustNotBeThisValue, valueType); - else - { - MethodBase createInstance = valueType.GetMethod("Parse",BindingFlags.Public|BindingFlags.Static); - if(createInstance!=null) - { - this.value = createInstance.Invoke(null, new object[] { mustNotBeThisValue }); - } - ConstructorInfo ctor = valueType.GetConstructor(new Type[] { mustNotBeThisValue.GetType() }); - if(ctor==null) - { - throw new ArgumentException( - "valueType must be a type that implements IConvertible, or have a Parse method, or have a constructor that accept a " + mustNotBeThisValue.GetType() - ); - } - this.value = Activator.CreateInstance(valueType, mustNotBeThisValue); - } - } - - /// - /// Constructs and configures an - /// instance based on the properties set on the attribute instance. - /// - /// - public override IValidator Build() - { - IValidator validator = new NotSameValueValidator(value); - ConfigureValidatorMessage(validator); - return validator; - } - } -} \ No newline at end of file +// Copyright 2004-2007 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Castle.Components.Validator +{ + using System; + using System.Reflection; + + /// + /// Validates that the content has not been set to the specified value + /// + public class ValidateNotSameValueAttribute : AbstractValidationAttribute + { + private readonly object value; + + /// + /// Initializes a new instance of the class. + /// + public ValidateNotSameValueAttribute(object mustNotBeThisValue) + { + value = mustNotBeThisValue; + } + + /// + /// Initializes a new instance of the class. + /// + /// Type of the value. + /// The must not be this value. + public ValidateNotSameValueAttribute(Type valueType, object mustNotBeThisValue) + : this(valueType, mustNotBeThisValue, null) + { + } + + /// + /// Initializes a new instance of the class. + /// + public ValidateNotSameValueAttribute(Type valueType, object mustNotBeThisValue, string errorMessage) + : base(errorMessage) + { + if (mustNotBeThisValue == null) + { + throw new ArgumentException( + "You cannot use ValidateNotSameValue validator for null values, use ValidateNotEmpty for this"); + } + if (typeof(IConvertible).IsAssignableFrom(valueType)) + value = Convert.ChangeType(mustNotBeThisValue, valueType); + else + { + MethodBase createInstance = valueType.GetMethod("Parse", BindingFlags.Public | BindingFlags.Static); + if (createInstance != null) + { + value = createInstance.Invoke(null, new object[] {mustNotBeThisValue}); + } + ConstructorInfo ctor = valueType.GetConstructor(new Type[] {mustNotBeThisValue.GetType()}); + if (ctor == null) + { + throw new ArgumentException( + "valueType must be a type that implements IConvertible, or have a Parse method, or have a constructor that accept a " + + mustNotBeThisValue.GetType() + ); + } + value = Activator.CreateInstance(valueType, mustNotBeThisValue); + } + } + + /// + /// Constructs and configures an + /// instance based on the properties set on the attribute instance. + /// + /// + public override IValidator Build() + { + IValidator validator = new NotSameValueValidator(value); + ConfigureValidatorMessage(validator); + return validator; + } + } +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateRangeAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateRangeAttribute.cs index 9399e7a5f..8665dde43 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateRangeAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateRangeAttribute.cs @@ -16,8 +16,6 @@ namespace Castle.Components.Validator { using System; - using Castle.Components.Validator; - /// /// Validate that this property has the required length (either exact or in a range) /// @@ -107,7 +105,8 @@ namespace Castle.Components.Validator /// The minimum value, or DateTime.MinValue if this should not be tested. /// The maximum value, or DateTime.MaxValue if this should not be tested. /// The error message to be displayed if the validation fails. - public ValidateRangeAttribute(RangeValidationType type, object min, object max, string errorMessage) : base(errorMessage) + public ValidateRangeAttribute(RangeValidationType type, object min, object max, string errorMessage) + : base(errorMessage) { validator = new RangeValidator(type, min, max); } @@ -124,4 +123,4 @@ namespace Castle.Components.Validator return validator; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateSameAsAttribute.cs b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateSameAsAttribute.cs index 2f3eeb9a0..379458b32 100644 --- a/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateSameAsAttribute.cs +++ b/Components/General/Validator/Castle.Components.Validator/Attributes/ValidateSameAsAttribute.cs @@ -49,10 +49,10 @@ namespace Castle.Components.Validator public override IValidator Build() { IValidator validator = new SameAsValidator(propertyToCompare); - + ConfigureValidatorMessage(validator); - + return validator; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/CachedValidationRegistry.cs b/Components/General/Validator/Castle.Components.Validator/CachedValidationRegistry.cs index 0854f7267..49f2e71aa 100644 --- a/Components/General/Validator/Castle.Components.Validator/CachedValidationRegistry.cs +++ b/Components/General/Validator/Castle.Components.Validator/CachedValidationRegistry.cs @@ -29,16 +29,16 @@ namespace Castle.Components.Validator #region IValidatorRegistry Members - /// - /// Gets all validators associated with a . - /// - /// The validators returned are initialized. - /// - /// - /// The validator runner. - /// Target type. - /// Restrict the set returned to the phase specified - /// A Validator array + /// + /// Gets all validators associated with a . + /// + /// The validators returned are initialized. + /// + /// + /// The validator runner. + /// Target type. + /// Restrict the set returned to the phase specified + /// A Validator array public IValidator[] GetValidators(ValidatorRunner validatorRunner, Type targetType, RunWhen runWhen) { PropertyInfo[] properties = (PropertyInfo[]) propertiesPerType[targetType]; @@ -59,18 +59,19 @@ namespace Castle.Components.Validator return (IValidator[]) list.ToArray(typeof(IValidator)); } - /// - /// Gets all validators associated with a property. - /// - /// The validators returned are initialized. - /// - /// - /// The validator runner. - /// Target type. - /// The property. - /// Restrict the set returned to the phase specified - /// A Validator array - public IValidator[] GetValidators(ValidatorRunner validatorRunner, Type targetType, PropertyInfo property, RunWhen runWhen) + /// + /// Gets all validators associated with a property. + /// + /// The validators returned are initialized. + /// + /// + /// The validator runner. + /// Target type. + /// The property. + /// Restrict the set returned to the phase specified + /// A Validator array + public IValidator[] GetValidators(ValidatorRunner validatorRunner, Type targetType, PropertyInfo property, + RunWhen runWhen) { object[] builders = (object[]) attrsPerProperty[property]; @@ -81,7 +82,7 @@ namespace Castle.Components.Validator } ArrayList validators = new ArrayList(); - + foreach(IValidatorBuilder builder in builders) { IValidator validator = builder.Build(validatorRunner, targetType); @@ -104,4 +105,4 @@ namespace Castle.Components.Validator return ((validator.RunWhen & when) != 0); } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/ErrorSummary.cs b/Components/General/Validator/Castle.Components.Validator/ErrorSummary.cs index 083fe363e..a427268d4 100644 --- a/Components/General/Validator/Castle.Components.Validator/ErrorSummary.cs +++ b/Components/General/Validator/Castle.Components.Validator/ErrorSummary.cs @@ -138,4 +138,4 @@ namespace Castle.Components.Validator invalidPropertiesCount = property2Messages.Count; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/IValidator.cs b/Components/General/Validator/Castle.Components.Validator/IValidator.cs index 0f8b4f345..8ff22c76f 100644 --- a/Components/General/Validator/Castle.Components.Validator/IValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/IValidator.cs @@ -54,7 +54,7 @@ namespace Castle.Components.Validator /// /// The execution order. int ExecutionOrder { get; set; } - + /// /// The error message to be displayed if the validation fails /// @@ -102,12 +102,12 @@ namespace Castle.Components.Validator /// The attributes. /// The target. void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target); + IWebValidationGenerator generator, IDictionary attributes, string target); - /// + /// /// Gets the property name. The /// is returned if non-null, otherwise it will return the property name. /// - string Name { get; } + string Name { get; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/IValidatorBuilder.cs b/Components/General/Validator/Castle.Components.Validator/IValidatorBuilder.cs index 4d6d46717..b7ddf1c1b 100644 --- a/Components/General/Validator/Castle.Components.Validator/IValidatorBuilder.cs +++ b/Components/General/Validator/Castle.Components.Validator/IValidatorBuilder.cs @@ -15,20 +15,19 @@ namespace Castle.Components.Validator { - using System; - using Castle.Components.Validator; + using System; /// /// Constructs an implementation. /// public interface IValidatorBuilder { - /// - /// Builds this instance. - /// - /// The validator runner. - /// The type that this validator is built for - /// - IValidator Build(ValidatorRunner validatorRunner, Type type); + /// + /// Builds this instance. + /// + /// The validator runner. + /// The type that this validator is built for + /// + IValidator Build(ValidatorRunner validatorRunner, Type type); } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/IValidatorRegistry.cs b/Components/General/Validator/Castle.Components.Validator/IValidatorRegistry.cs index 6e355cce6..3c071a730 100644 --- a/Components/General/Validator/Castle.Components.Validator/IValidatorRegistry.cs +++ b/Components/General/Validator/Castle.Components.Validator/IValidatorRegistry.cs @@ -22,29 +22,29 @@ namespace Castle.Components.Validator /// public interface IValidatorRegistry { - /// - /// Gets all validators associated with a . - /// - /// The validators returned are initialized. - /// - /// - /// The validator runner. - /// Target type. - /// Restrict the set returned to the phase specified - /// A Validator array + /// + /// Gets all validators associated with a . + /// + /// The validators returned are initialized. + /// + /// + /// The validator runner. + /// Target type. + /// Restrict the set returned to the phase specified + /// A Validator array IValidator[] GetValidators(ValidatorRunner validatorRunner, Type targetType, RunWhen runWhen); - /// - /// Gets all validators associated with a property. - /// - /// The validators returned are initialized. - /// - /// - /// The validator runner. - /// Target type. - /// The property. - /// Restrict the set returned to the phase specified - /// A Validator array + /// + /// Gets all validators associated with a property. + /// + /// The validators returned are initialized. + /// + /// + /// The validator runner. + /// Target type. + /// The property. + /// Restrict the set returned to the phase specified + /// A Validator array IValidator[] GetValidators(ValidatorRunner validatorRunner, Type targetType, PropertyInfo property, RunWhen runWhen); } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/IWebValidationGenerator.cs b/Components/General/Validator/Castle.Components.Validator/IWebValidationGenerator.cs index 2753436ec..488ddf307 100644 --- a/Components/General/Validator/Castle.Components.Validator/IWebValidationGenerator.cs +++ b/Components/General/Validator/Castle.Components.Validator/IWebValidationGenerator.cs @@ -97,4 +97,4 @@ namespace Castle.Components.Validator /// The violation message. void SetDate(string violationMessage); } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/InputElementType.cs b/Components/General/Validator/Castle.Components.Validator/InputElementType.cs index ab0d0bf95..87d1a28a1 100644 --- a/Components/General/Validator/Castle.Components.Validator/InputElementType.cs +++ b/Components/General/Validator/Castle.Components.Validator/InputElementType.cs @@ -44,4 +44,4 @@ namespace Castle.Components.Validator /// Checkbox } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/MessageConstants.cs b/Components/General/Validator/Castle.Components.Validator/MessageConstants.cs index 150e17bb1..b7b1c8f61 100644 --- a/Components/General/Validator/Castle.Components.Validator/MessageConstants.cs +++ b/Components/General/Validator/Castle.Components.Validator/MessageConstants.cs @@ -14,7 +14,7 @@ namespace Castle.Components.Validator { - class MessageConstants + internal class MessageConstants { public const string GenericInvalidField = "generic_invalid"; public const string IsRequiredMessage = "isrequired"; @@ -34,9 +34,9 @@ namespace Castle.Components.Validator public const string RangeTooHighMessage = "range_toohigh"; public const string RangeTooLowMessage = "range_toolow"; public const string RangeTooHighOrLowMessage = "range_toohighorlow"; - public const string NotSameAsMessage = "not_same_as_invalid"; - public const string GroupNotEmpty = "group_not_empty_invalid"; - public const string GroupNotEmptySeperator = "group_not_empty_seperator"; - public const string CollectionNotEmpty = "collection_not_empty"; + public const string NotSameAsMessage = "not_same_as_invalid"; + public const string GroupNotEmpty = "group_not_empty_invalid"; + public const string GroupNotEmptySeperator = "group_not_empty_seperator"; + public const string CollectionNotEmpty = "collection_not_empty"; } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Messages.Designer.cs b/Components/General/Validator/Castle.Components.Validator/Messages.Designer.cs dissimilarity index 96% index 5bfa85ec8..386c33fb8 100644 --- a/Components/General/Validator/Castle.Components.Validator/Messages.Designer.cs +++ b/Components/General/Validator/Castle.Components.Validator/Messages.Designer.cs @@ -1,261 +1,246 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:2.0.50727.42 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Castle.Components.Validator { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Messages { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Messages() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Castle.Components.Validator.Messages", typeof(Messages).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Collection must not be empty. - /// - internal static string collection_not_empty { - get { - return ResourceManager.GetString("collection_not_empty", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Please enter a valid date. - /// - internal static string date_invalid { - get { - return ResourceManager.GetString("date_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Please enter a valid decimal in this field. - /// - internal static string decimal_invalid { - get { - return ResourceManager.GetString("decimal_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Please enter a valid double in this field. - /// - internal static string double_invalid { - get { - return ResourceManager.GetString("double_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Please enter a valid email address. For example fred@domain.com. - /// - internal static string email { - get { - return ResourceManager.GetString("email", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must be {0} characters long. - /// - internal static string exactlength { - get { - return ResourceManager.GetString("exactlength", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field has an invalid content. - /// - internal static string generic_invalid { - get { - return ResourceManager.GetString("generic_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to At least one of the values in ({0}) should not be empty. - /// - internal static string group_not_empty_invalid { - get { - return ResourceManager.GetString("group_not_empty_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to , . - /// - internal static string group_not_empty_seperator { - get { - return ResourceManager.GetString("group_not_empty_seperator", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Please enter a valid integer in this field. - /// - internal static string integer_invalid { - get { - return ResourceManager.GetString("integer_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to This is a required field. - /// - internal static string isrequired { - get { - return ResourceManager.GetString("isrequired", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must be between {0} and {1} characters long. - /// - internal static string length_invalidrange { - get { - return ResourceManager.GetString("length_invalidrange", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must be less than {0} characters long. - /// - internal static string length_toolong { - get { - return ResourceManager.GetString("length_toolong", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must be more than {0} characters long. - /// - internal static string length_tooshort { - get { - return ResourceManager.GetString("length_tooshort", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must not equals '{0}'. - /// - internal static string not_same_as_invalid { - get { - return ResourceManager.GetString("not_same_as_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must be between {0} and {1}. - /// - internal static string range_invalid { - get { - return ResourceManager.GetString("range_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must be less than or equal to {0}. - /// - internal static string range_toohigh { - get { - return ResourceManager.GetString("range_toohigh", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must be between {0} and {1}. - /// - internal static string range_toohighorlow { - get { - return ResourceManager.GetString("range_toohighorlow", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field must be greater than or equal to {0}. - /// - internal static string range_toolow { - get { - return ResourceManager.GetString("range_toolow", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Fields do not match. - /// - internal static string same_as_invalid { - get { - return ResourceManager.GetString("same_as_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field value is invalid (not a valid single). - /// - internal static string single_invalid { - get { - return ResourceManager.GetString("single_invalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Field value is invalid (not a valid time). - /// - internal static string time_invalid { - get { - return ResourceManager.GetString("time_invalid", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Castle.Components.Validator +{ + using System.CodeDom.Compiler; + using System.ComponentModel; + using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; + using System.Globalization; + using System.Resources; + using System.Runtime.CompilerServices; + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [DebuggerNonUserCode()] + [CompilerGenerated()] + internal class Messages + { + private static ResourceManager resourceMan; + + private static CultureInfo resourceCulture; + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Messages() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [EditorBrowsable(EditorBrowsableState.Advanced)] + internal static ResourceManager ResourceManager + { + get + { + if (ReferenceEquals(resourceMan, null)) + { + ResourceManager temp = new ResourceManager("Castle.Components.Validator.Messages", typeof(Messages).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [EditorBrowsable(EditorBrowsableState.Advanced)] + internal static CultureInfo Culture + { + get { return resourceCulture; } + set { resourceCulture = value; } + } + + /// + /// Looks up a localized string similar to Collection must not be empty. + /// + internal static string collection_not_empty + { + get { return ResourceManager.GetString("collection_not_empty", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Please enter a valid date. + /// + internal static string date_invalid + { + get { return ResourceManager.GetString("date_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Please enter a valid decimal in this field. + /// + internal static string decimal_invalid + { + get { return ResourceManager.GetString("decimal_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Please enter a valid double in this field. + /// + internal static string double_invalid + { + get { return ResourceManager.GetString("double_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Please enter a valid email address. For example fred@domain.com. + /// + internal static string email + { + get { return ResourceManager.GetString("email", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must be {0} characters long. + /// + internal static string exactlength + { + get { return ResourceManager.GetString("exactlength", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field has an invalid content. + /// + internal static string generic_invalid + { + get { return ResourceManager.GetString("generic_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to At least one of the values in ({0}) should not be empty. + /// + internal static string group_not_empty_invalid + { + get { return ResourceManager.GetString("group_not_empty_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to , . + /// + internal static string group_not_empty_seperator + { + get { return ResourceManager.GetString("group_not_empty_seperator", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Please enter a valid integer in this field. + /// + internal static string integer_invalid + { + get { return ResourceManager.GetString("integer_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to This is a required field. + /// + internal static string isrequired + { + get { return ResourceManager.GetString("isrequired", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must be between {0} and {1} characters long. + /// + internal static string length_invalidrange + { + get { return ResourceManager.GetString("length_invalidrange", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must be less than {0} characters long. + /// + internal static string length_toolong + { + get { return ResourceManager.GetString("length_toolong", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must be more than {0} characters long. + /// + internal static string length_tooshort + { + get { return ResourceManager.GetString("length_tooshort", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must not equals '{0}'. + /// + internal static string not_same_as_invalid + { + get { return ResourceManager.GetString("not_same_as_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must be between {0} and {1}. + /// + internal static string range_invalid + { + get { return ResourceManager.GetString("range_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must be less than or equal to {0}. + /// + internal static string range_toohigh + { + get { return ResourceManager.GetString("range_toohigh", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must be between {0} and {1}. + /// + internal static string range_toohighorlow + { + get { return ResourceManager.GetString("range_toohighorlow", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field must be greater than or equal to {0}. + /// + internal static string range_toolow + { + get { return ResourceManager.GetString("range_toolow", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Fields do not match. + /// + internal static string same_as_invalid + { + get { return ResourceManager.GetString("same_as_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field value is invalid (not a valid single). + /// + internal static string single_invalid + { + get { return ResourceManager.GetString("single_invalid", resourceCulture); } + } + + /// + /// Looks up a localized string similar to Field value is invalid (not a valid time). + /// + internal static string time_invalid + { + get { return ResourceManager.GetString("time_invalid", resourceCulture); } + } + } +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/ValidationInternalError.cs b/Components/General/Validator/Castle.Components.Validator/ValidationInternalError.cs index 43d415f97..fadaf1c6e 100644 --- a/Components/General/Validator/Castle.Components.Validator/ValidationInternalError.cs +++ b/Components/General/Validator/Castle.Components.Validator/ValidationInternalError.cs @@ -50,4 +50,4 @@ namespace Castle.Components.Validator { } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/ValidatorRunner.cs b/Components/General/Validator/Castle.Components.Validator/ValidatorRunner.cs index cf02a9003..1bf5b0b63 100644 --- a/Components/General/Validator/Castle.Components.Validator/ValidatorRunner.cs +++ b/Components/General/Validator/Castle.Components.Validator/ValidatorRunner.cs @@ -32,8 +32,8 @@ namespace Castle.Components.Validator /// public class ValidatorRunner { - private readonly static IDictionary type2Validator; - private readonly IDictionary extendedProperties = new Hashtable(); + private static readonly IDictionary type2Validator; + private readonly IDictionary extendedProperties = new Hashtable(); private readonly bool inferValidators; private readonly IDictionary errorPerInstance; private readonly IValidatorRegistry registry; @@ -50,12 +50,12 @@ namespace Castle.Components.Validator type2Validator[typeof(DateTime)] = typeof(DateTimeValidator); } - public IDictionary ExtendedProperties - { - get { return extendedProperties; } - } + public IDictionary ExtendedProperties + { + get { return extendedProperties; } + } - /// + /// /// Initializes a new instance of the class. /// /// The instance registry. @@ -159,7 +159,7 @@ namespace Castle.Components.Validator if (defaultValidatorForType != null) { - validators = new IValidator[] { (IValidator) Activator.CreateInstance(defaultValidatorForType) }; + validators = new IValidator[] {(IValidator) Activator.CreateInstance(defaultValidatorForType)}; validators[0].Initialize(property); } @@ -205,9 +205,9 @@ namespace Castle.Components.Validator return validators; } - class ValidatorComparer : IComparer + private class ValidatorComparer : IComparer { - private readonly static ValidatorComparer instance = new ValidatorComparer(); + private static readonly ValidatorComparer instance = new ValidatorComparer(); public int Compare(object x, object y) { @@ -223,4 +223,4 @@ namespace Castle.Components.Validator } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/AbstractValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/AbstractValidator.cs index 3c73ee3c8..9d3857a0e 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/AbstractValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/AbstractValidator.cs @@ -19,7 +19,6 @@ namespace Castle.Components.Validator using System.Reflection; using System.Resources; using System.Threading; - using Castle.Components.Validator; /// /// Abstract implementation @@ -39,9 +38,9 @@ namespace Castle.Components.Validator /// static AbstractValidator() { - resourceManager = - new ResourceManager("Castle.Components.Validator.Messages", - typeof(AbstractValidator).Assembly); + resourceManager = + new ResourceManager("Castle.Components.Validator.Messages", + typeof(AbstractValidator).Assembly); } /// @@ -66,11 +65,15 @@ namespace Castle.Components.Validator /// public object GetFieldOrPropertyValue(object instance, string fieldOrPropertyName) { - PropertyInfo pi = instance.GetType().GetProperty(fieldOrPropertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); + PropertyInfo pi = + instance.GetType().GetProperty(fieldOrPropertyName, + BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); if (pi == null) { - FieldInfo fi = instance.GetType().GetField(fieldOrPropertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); + FieldInfo fi = + instance.GetType().GetField(fieldOrPropertyName, + BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); if (fi != null) { @@ -82,7 +85,8 @@ namespace Castle.Components.Validator return pi.GetValue(instance, null); } - throw new ValidationException("No public instance field or property named " + fieldOrPropertyName + " for type " + instance.GetType().FullName); + throw new ValidationException("No public instance field or property named " + fieldOrPropertyName + " for type " + + instance.GetType().FullName); } /// @@ -150,8 +154,8 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public virtual void ApplyWebValidation(WebValidationConfiguration config, - InputElementType inputType, IWebValidationGenerator generator, - IDictionary attributes, string target) + InputElementType inputType, IWebValidationGenerator generator, + IDictionary attributes, string target) { if (target.Contains(".")) { @@ -221,7 +225,7 @@ namespace Castle.Components.Validator /// A resource set instance protected internal static ResourceSet GetResourceForCurrentCulture() { - return resourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true); + return resourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true); } /// @@ -241,4 +245,4 @@ namespace Castle.Components.Validator } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/CollectionNotEmptyValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/CollectionNotEmptyValidator.cs dissimilarity index 67% index 3e1c0d87f..db4e3af5a 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/CollectionNotEmptyValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/CollectionNotEmptyValidator.cs @@ -1,63 +1,59 @@ -// Copyright 2004-2007 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Castle.Components.Validator -{ - using System; - using System.Collections; - - /// - /// Validates that the content is a collection that is not empty - /// - public class CollectionNotEmptyValidator : AbstractValidator - { - /// - /// Implementors should perform the actual validation upon - /// the property value - /// - /// The target type instance - /// The property/field value. It can be null. - /// - /// true if the value is accepted (has passed the validation test) - /// - public override bool IsValid(object instance, object fieldValue) - { - ICollection collection = fieldValue as ICollection; - if (collection == null) - { - return false; - } - return collection.Count != 0; - } - - /// - /// Gets a value indicating whether this validator supports web validation. - /// - /// - /// if web validation is supported; otherwise, . - /// - public override bool SupportsWebValidation - { - get { return false; } - } - - protected override string MessageKey - { - get - { - return MessageConstants.CollectionNotEmpty; - } - } - } -} \ No newline at end of file +// Copyright 2004-2007 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Castle.Components.Validator +{ + using System.Collections; + + /// + /// Validates that the content is a collection that is not empty + /// + public class CollectionNotEmptyValidator : AbstractValidator + { + /// + /// Implementors should perform the actual validation upon + /// the property value + /// + /// The target type instance + /// The property/field value. It can be null. + /// + /// true if the value is accepted (has passed the validation test) + /// + public override bool IsValid(object instance, object fieldValue) + { + ICollection collection = fieldValue as ICollection; + if (collection == null) + { + return false; + } + return collection.Count != 0; + } + + /// + /// Gets a value indicating whether this validator supports web validation. + /// + /// + /// if web validation is supported; otherwise, . + /// + public override bool SupportsWebValidation + { + get { return false; } + } + + protected override string MessageKey + { + get { return MessageConstants.CollectionNotEmpty; } + } + } +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/DateTimeValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/DateTimeValidator.cs index 152afe5bb..fa813570d 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/DateTimeValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/DateTimeValidator.cs @@ -44,7 +44,7 @@ namespace Castle.Components.Validator return true; } - catch (Exception) + catch(Exception) { return false; } @@ -87,4 +87,4 @@ namespace Castle.Components.Validator get { return MessageConstants.InvalidDateMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/DateValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/DateValidator.cs index a496b9abf..dcf7f4198 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/DateValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/DateValidator.cs @@ -47,7 +47,7 @@ namespace Castle.Components.Validator } return false; } - catch (Exception) + catch(Exception) { return false; } @@ -74,7 +74,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -90,4 +90,4 @@ namespace Castle.Components.Validator get { return MessageConstants.InvalidDateMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/DecimalValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/DecimalValidator.cs index 33d5acff4..dba853aa6 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/DecimalValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/DecimalValidator.cs @@ -43,7 +43,7 @@ namespace Castle.Components.Validator Convert.ToDecimal(fieldValue.ToString()); return true; } - catch (Exception) + catch(Exception) { return false; } @@ -70,7 +70,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -89,4 +89,4 @@ namespace Castle.Components.Validator get { return MessageConstants.InvalidDecimalMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/DoubleValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/DoubleValidator.cs index 22f7a00b1..34a0619c0 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/DoubleValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/DoubleValidator.cs @@ -44,7 +44,7 @@ namespace Castle.Components.Validator return true; } - catch (Exception) + catch(Exception) { return false; } @@ -71,7 +71,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -90,4 +90,4 @@ namespace Castle.Components.Validator get { return MessageConstants.InvalidDoubleMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/EmailValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/EmailValidator.cs index d205cec74..9e4854d10 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/EmailValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/EmailValidator.cs @@ -27,8 +27,8 @@ namespace Castle.Components.Validator /// From http://www.codeproject.com/aspnet/Valid_Email_Addresses.asp /// private static readonly String emailRule = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + - @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + - @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; /// /// Initializes a new instance of the class. @@ -57,7 +57,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -73,4 +73,4 @@ namespace Castle.Components.Validator get { return MessageConstants.InvalidEmailMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/IntegerValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/IntegerValidator.cs index 9cf8901c2..c51e4ec4d 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/IntegerValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/IntegerValidator.cs @@ -55,7 +55,7 @@ namespace Castle.Components.Validator return true; } - catch (Exception) + catch(Exception) { return false; } @@ -82,7 +82,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -101,4 +101,4 @@ namespace Castle.Components.Validator get { return MessageConstants.InvalidIntegerMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/LengthValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/LengthValidator.cs index fbf93618c..21f0209e7 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/LengthValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/LengthValidator.cs @@ -51,7 +51,8 @@ namespace Castle.Components.Validator { if (minLength == int.MinValue && maxLength == int.MaxValue) { - throw new ArgumentException("Both minLength and maxLength were set in such as way that neither would be tested. At least one must be tested."); + throw new ArgumentException( + "Both minLength and maxLength were set in such as way that neither would be tested. At least one must be tested."); } if (minLength > maxLength) @@ -61,12 +62,14 @@ namespace Castle.Components.Validator if (minLength != int.MinValue && minLength < 0) { - throw new ArgumentOutOfRangeException("The minLength parameter must be set to either int.MinValue or a non-negative number."); + throw new ArgumentOutOfRangeException( + "The minLength parameter must be set to either int.MinValue or a non-negative number."); } if (maxLength < 0) { - throw new ArgumentOutOfRangeException("The maxLength parameter must be set to either int.MaxValue or a non-negative number."); + throw new ArgumentOutOfRangeException( + "The maxLength parameter must be set to either int.MaxValue or a non-negative number."); } this.minLength = minLength; @@ -154,7 +157,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -191,23 +194,24 @@ namespace Castle.Components.Validator if (exactLength != int.MinValue) { return string.Format(GetResourceForCurrentCulture().GetString(MessageConstants.ExactLengthMessage), exactLength); - } + } else if (minLength == int.MinValue && maxLength != int.MaxValue) { return string.Format(GetResourceForCurrentCulture().GetString(MessageConstants.LengthTooLongMessage), maxLength); - } + } else if (minLength != int.MinValue && maxLength == int.MaxValue) { return string.Format(GetResourceForCurrentCulture().GetString(MessageConstants.LengthTooShortMessage), minLength); - } + } else if (minLength != int.MinValue || maxLength != int.MaxValue) { - return string.Format(GetResourceForCurrentCulture().GetString(MessageConstants.LenghtInRangeMessage), minLength, maxLength); - } - else + return + string.Format(GetResourceForCurrentCulture().GetString(MessageConstants.LenghtInRangeMessage), minLength, maxLength); + } + else { throw new InvalidOperationException(); } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/NonEmptyValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/NonEmptyValidator.cs index 8d4470006..e4e278257 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/NonEmptyValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/NonEmptyValidator.cs @@ -56,7 +56,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -72,4 +72,4 @@ namespace Castle.Components.Validator get { return MessageConstants.IsRequiredMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/NotSameValueValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/NotSameValueValidator.cs dissimilarity index 73% index 8f7746c51..7ffc05695 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/NotSameValueValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/NotSameValueValidator.cs @@ -1,70 +1,67 @@ -// Copyright 2004-2007 Castle Project - http://www.castleproject.org/ -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace Castle.Components.Validator -{ - using System.Collections; - using System.Reflection; - - /// - /// Validates that the content is not set to the specified value - /// - public class NotSameValueValidator : AbstractValidator - { - private readonly object value; - - /// - /// Initializes a new instance of the class. - /// - public NotSameValueValidator(object value) - { - this.value = value; - } - - /// - /// Validates that the fieldValue - /// is not set to the specified value - /// - /// The target type instance - /// The property/field value. It can be null. - /// - /// true if the value is accepted (has passed the validation test) - /// - public override bool IsValid(object instance, object fieldValue) - { - return Equals(value, fieldValue) == false; - } - - /// - /// Gets a value indicating whether this validator supports web validation. - /// - /// - /// if web validation is supported; otherwise, . - /// - public override bool SupportsWebValidation - { - get { return false; } - } - - protected override string MessageKey - { - get { return MessageConstants.NotSameAsMessage; } - } - - protected override string BuildErrorMessage() - { - return string.Format(GetResourceForCurrentCulture().GetString(MessageConstants.NotSameAsMessage), value); - } - } -} \ No newline at end of file +// Copyright 2004-2007 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Castle.Components.Validator +{ + /// + /// Validates that the content is not set to the specified value + /// + public class NotSameValueValidator : AbstractValidator + { + private readonly object value; + + /// + /// Initializes a new instance of the class. + /// + public NotSameValueValidator(object value) + { + this.value = value; + } + + /// + /// Validates that the fieldValue + /// is not set to the specified value + /// + /// The target type instance + /// The property/field value. It can be null. + /// + /// true if the value is accepted (has passed the validation test) + /// + public override bool IsValid(object instance, object fieldValue) + { + return Equals(value, fieldValue) == false; + } + + /// + /// Gets a value indicating whether this validator supports web validation. + /// + /// + /// if web validation is supported; otherwise, . + /// + public override bool SupportsWebValidation + { + get { return false; } + } + + protected override string MessageKey + { + get { return MessageConstants.NotSameAsMessage; } + } + + protected override string BuildErrorMessage() + { + return string.Format(GetResourceForCurrentCulture().GetString(MessageConstants.NotSameAsMessage), value); + } + } +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/RangeValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/RangeValidator.cs index eaddf40a3..d43617ee9 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/RangeValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/RangeValidator.cs @@ -133,7 +133,7 @@ namespace Castle.Components.Validator try { //check properties for valid types - switch (type) + switch(type) { case RangeValidationType.Integer: return GetIntValue(max, int.MaxValue); @@ -145,9 +145,10 @@ namespace Castle.Components.Validator throw new ArgumentException("Unknown RangeValidatorType found."); } } - catch (InvalidCastException) + catch(InvalidCastException) { - throw new ArgumentException("RangeValidator's maximum value data type is incompatible with the RangeValidationType specified."); + throw new ArgumentException( + "RangeValidator's maximum value data type is incompatible with the RangeValidationType specified."); } } @@ -174,14 +175,14 @@ namespace Castle.Components.Validator int intValue; try { - intValue = (int)fieldValue; - valid = intValue >= (int)min && intValue <= (int)max; + intValue = (int) fieldValue; + valid = intValue >= (int) min && intValue <= (int) max; } catch { if (int.TryParse(fieldValue.ToString(), out intValue)) { - valid = intValue >= (int)min && intValue <= (int)max; + valid = intValue >= (int) min && intValue <= (int) max; } } break; @@ -189,32 +190,37 @@ namespace Castle.Components.Validator DateTime dtValue; try { - dtValue = (DateTime)fieldValue; - valid = dtValue >= (DateTime)min && dtValue <= (DateTime)max; + dtValue = (DateTime) fieldValue; + valid = dtValue >= (DateTime) min && dtValue <= (DateTime) max; } catch { if (DateTime.TryParse(fieldValue.ToString(), out dtValue)) { - valid = dtValue >= (DateTime)min && dtValue <= (DateTime)max; + valid = dtValue >= (DateTime) min && dtValue <= (DateTime) max; } } break; case RangeValidationType.String: string stringValue = fieldValue.ToString(); - string minv = this.min.ToString(); - string maxv = this.max.ToString(); + string minv = min.ToString(); + string maxv = max.ToString(); valid = ( - (String.IsNullOrEmpty(minv) || String.Compare(stringValue, minv, StringComparison.InvariantCultureIgnoreCase) >= 0) - && (String.IsNullOrEmpty(maxv) || String.Compare(stringValue, maxv, StringComparison.InvariantCultureIgnoreCase) <= 0) - ); + (String.IsNullOrEmpty(minv) || + String.Compare(stringValue, minv, StringComparison.InvariantCultureIgnoreCase) >= 0) + && + (String.IsNullOrEmpty(maxv) || + String.Compare(stringValue, maxv, StringComparison.InvariantCultureIgnoreCase) <= 0) + ); break; default: valid = false; break; } } - catch { } + catch + { + } return valid; } @@ -252,7 +258,7 @@ namespace Castle.Components.Validator { if (type == RangeValidationType.DateTime) { - return BuildDateTimeErrorMessage((DateTime)min, (DateTime)max); + return BuildDateTimeErrorMessage((DateTime) min, (DateTime) max); } if (type == RangeValidationType.String) @@ -262,7 +268,7 @@ namespace Castle.Components.Validator if (type == RangeValidationType.Integer) { - return BuildIntegerErrorMessage((int)min, (int)max); + return BuildIntegerErrorMessage((int) min, (int) max); } throw new InvalidOperationException(); @@ -359,7 +365,8 @@ namespace Castle.Components.Validator { if (String.IsNullOrEmpty(min) && String.IsNullOrEmpty(max)) { - throw new ArgumentException("Both min and max were set in such as way that neither would be tested. At least one must be tested."); + throw new ArgumentException( + "Both min and max were set in such as way that neither would be tested. At least one must be tested."); } } @@ -367,7 +374,8 @@ namespace Castle.Components.Validator { if (min == int.MinValue && max == int.MaxValue) { - throw new ArgumentException("Both min and max were set in such as way that neither would be tested. At least one must be tested."); + throw new ArgumentException( + "Both min and max were set in such as way that neither would be tested. At least one must be tested."); } if (min > max) { @@ -383,7 +391,8 @@ namespace Castle.Components.Validator { if (min == DateTime.MinValue && max == DateTime.MaxValue) { - throw new ArgumentException("Both min and max were set in such as way that neither would be tested. At least one must be tested."); + throw new ArgumentException( + "Both min and max were set in such as way that neither would be tested. At least one must be tested."); } if (min > max) { @@ -406,7 +415,7 @@ namespace Castle.Components.Validator try { //check properties for valid types - switch (type) + switch(type) { case RangeValidationType.Integer: return GetIntValue(min, int.MinValue); @@ -418,9 +427,10 @@ namespace Castle.Components.Validator throw new ArgumentException("Unknown RangeValidatorType found."); } } - catch (InvalidCastException) + catch(InvalidCastException) { - throw new ArgumentException("RangeValidator's mininum value data type is incompatible with the RangeValidationType specified."); + throw new ArgumentException( + "RangeValidator's mininum value data type is incompatible with the RangeValidationType specified."); } } @@ -429,7 +439,7 @@ namespace Castle.Components.Validator int intValue = defaultValue; try { - intValue = (int)value; + intValue = (int) value; } catch { @@ -438,12 +448,13 @@ namespace Castle.Components.Validator } return intValue; } + private DateTime GetDateTimeValue(object value, DateTime defaultValue) { DateTime dtValue = defaultValue; try { - dtValue = (DateTime)value; + dtValue = (DateTime) value; } catch { @@ -453,4 +464,4 @@ namespace Castle.Components.Validator return dtValue; } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/RegularExpressionValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/RegularExpressionValidator.cs index 743993e04..1d2764df9 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/RegularExpressionValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/RegularExpressionValidator.cs @@ -34,7 +34,7 @@ namespace Castle.Components.Validator public RegularExpressionValidator(String expression) : this(expression, RegexOptions.Compiled) { } - + /// /// Initializes a new instance of the class. /// @@ -107,11 +107,11 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); generator.SetRegExp(expression, BuildErrorMessage()); } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/SameAsValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/SameAsValidator.cs index 70c601d15..8ddcf0e04 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/SameAsValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/SameAsValidator.cs @@ -99,7 +99,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -115,4 +115,4 @@ namespace Castle.Components.Validator get { return MessageConstants.SameAsMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/Validators/SingleValidator.cs b/Components/General/Validator/Castle.Components.Validator/Validators/SingleValidator.cs index 20ec9bb4e..6bc6db583 100644 --- a/Components/General/Validator/Castle.Components.Validator/Validators/SingleValidator.cs +++ b/Components/General/Validator/Castle.Components.Validator/Validators/SingleValidator.cs @@ -44,7 +44,7 @@ namespace Castle.Components.Validator return true; } - catch (Exception) + catch(Exception) { return false; } @@ -71,7 +71,7 @@ namespace Castle.Components.Validator /// The attributes. /// The target. public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType, - IWebValidationGenerator generator, IDictionary attributes, string target) + IWebValidationGenerator generator, IDictionary attributes, string target) { base.ApplyWebValidation(config, inputType, generator, attributes, target); @@ -90,4 +90,4 @@ namespace Castle.Components.Validator get { return MessageConstants.InvalidSingleMessage; } } } -} +} \ No newline at end of file diff --git a/Components/General/Validator/Castle.Components.Validator/WebValidationConfiguration.cs b/Components/General/Validator/Castle.Components.Validator/WebValidationConfiguration.cs index c6bf6dfdd..af844a6b9 100644 --- a/Components/General/Validator/Castle.Components.Validator/WebValidationConfiguration.cs +++ b/Components/General/Validator/Castle.Components.Validator/WebValidationConfiguration.cs @@ -51,4 +51,4 @@ namespace Castle.Components.Validator return string.Empty; } } -} +} \ No newline at end of file -- 2.11.4.GIT