Forgot to commit a file?

                                         [exec]
                                         [exec] Failures:
                                         [exec] 1)
Castle.Components.Validator.Tests.ValidatorTests.IPAddressValidatorTestCase.Localized_Error_Messages_Can_Be_Obtained
:
                                         [exec]  String lengths
differ.  Expected length=34, but was length=32.
                                         [exec]  Strings differ at index 0.
                                         [exec]  expected: <"Vul
s.v.p. een geldig IP adres in.">
                                         [exec]   but was: <"Please
enter a valid IP address.">
                                         [exec]  ------------^

2009/5/29  <[email protected]>:
>
> User: roelofb
> Date: 2009/05/29 04:51 AM
>
> Added:
>  /trunk/Components/Validator/Castle.Components.Validator.Tests/ValidatorTests/
>  IPAddressValidatorTestCase.cs
>  /trunk/Components/Validator/Castle.Components.Validator/Attributes/
>  ValidateIPAddressAttribute.cs
>  /trunk/Components/Validator/Castle.Components.Validator/Validators/
>  IPAddressValidator.cs
>
> Modified:
>  /trunk/Components/Validator/
>  Validator-vs2008.sln
>  /trunk/Components/Validator/Castle.Components.Validator.Tests/
>  Castle.Components.Validator.Tests-vs2008.csproj
>  /trunk/Components/Validator/Castle.Components.Validator/
>  Castle.Components.Validator-vs2008.csproj, MessageConstants.cs, 
> Messages.Designer.cs, Messages.nl.resx, Messages.resx
>  /trunk/Components/Validator/Castle.Components.Validator/Attributes/
>  AbstractCrossReferenceValidationAttribute.cs
>
> Log:
>  Added IPAddressValidator
>
> File Changes:
>
> Directory: /trunk/Components/Validator/Castle.Components.Validator/Attributes/
> ==============================================================================
>
> File [modified]: AbstractCrossReferenceValidationAttribute.cs
> Delta lines: +55 -0
> ===================================================================
>
> --- 
> trunk/Components/Validator/Castle.Components.Validator/Attributes/ValidateIPAddressAttribute.cs
>                              (rev 0)
> +++ 
> trunk/Components/Validator/Castle.Components.Validator/Attributes/ValidateIPAddressAttribute.cs
>      2009-05-29 11:51:03 UTC (rev 5718)
> @@ -0,0 +1,55 @@
> +// Copyright 2004-2009 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.Attributes
> +{
> +       using System;
> +
> +       /// <summary>
> +       /// Validate that this is a valid address.
> +       /// </summary>
> +       [Serializable]
> +       [AttributeUsage(AttributeTargets.Property | 
> AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = 
> true)]
> +       public class ValidateIPAddressAttribute : AbstractValidationAttribute
> +       {
> +               /// <summary>
> +               /// Initializes a new instance of the <see 
> cref="ValidateIPAddressAttribute"/> class.
> +               /// </summary>
> +               public ValidateIPAddressAttribute()
> +               {
> +               }
> +
> +               /// <summary>
> +               /// Initializes a new instance of the <see 
> cref="ValidateIPAddressAttribute"/> class.
> +               /// </summary>
> +               /// <param name="errorMessage">The error message.</param>
> +               public ValidateIPAddressAttribute(string errorMessage) : 
> base(errorMessage)
> +               {
> +               }
> +
> +               /// <summary>
> +               /// Constructs and configures an <see cref="IValidator"/>
> +               /// instance based on the properties set on the attribute 
> instance.
> +               /// </summary>
> +               /// <returns></returns>
> +               public override IValidator Build()
> +               {
> +                       IValidator validator = new IPAddressValidator();
> +
> +                       ConfigureValidatorMessage(validator);
> +
> +                       return validator;
> +               }
> +       }
> +}
>
> File [added]: ValidateIPAddressAttribute.cs
> Delta lines: +2 -0
> ===================================================================
>
> --- 
> trunk/Components/Validator/Castle.Components.Validator/Castle.Components.Validator-vs2008.csproj
>     2009-05-27 21:52:27 UTC (rev 5717)
> +++ 
> trunk/Components/Validator/Castle.Components.Validator/Castle.Components.Validator-vs2008.csproj
>     2009-05-29 11:51:03 UTC (rev 5718)
> @@ -59,6 +59,7 @@
>     <Compile Include="Attributes\ValidateEmailAttribute.cs" />
>     <Compile Include="Attributes\ValidateGroupNotEmptyAttribute.cs" />
>     <Compile Include="Attributes\ValidateIntegerAttribute.cs" />
> +    <Compile Include="Attributes\ValidateIPAddressAttribute.cs" />
>     <Compile Include="Attributes\ValidateIsGreaterAttribute.cs" />
>     <Compile Include="Attributes\ValidateIsLesserAttribute.cs" />
>     <Compile Include="Attributes\ValidateLengthAttribute.cs" />
> @@ -150,6 +151,7 @@
>     <Compile Include="Validators\CollectionNotEmptyValidator.cs" />
>     <Compile Include="Validators\AbstractCrossReferenceValidator.cs" />
>     <Compile Include="Validators\GuidValidator.cs" />
> +    <Compile Include="Validators\IPAddressValidator.cs" />
>     <Compile Include="Validators\IsGreaterValidator.cs" />
>     <Compile Include="Validators\IsLesserValidator.cs" />
>
> Directory: /trunk/Components/Validator/Castle.Components.Validator/
> ===================================================================
>
> File [modified]: Castle.Components.Validator-vs2008.csproj
> Delta lines: +1 -0
> ===================================================================
>
> --- 
> trunk/Components/Validator/Castle.Components.Validator/MessageConstants.cs  
> 2009-05-27 21:52:27 UTC (rev 5717)
> +++ 
> trunk/Components/Validator/Castle.Components.Validator/MessageConstants.cs  
> 2009-05-29 11:51:03 UTC (rev 5718)
> @@ -44,5 +44,6 @@
>                public const string InvalidCreditCardMessage = 
> "credit_card_invalid";
>                public const string GreaterThanMessage = 
> "greater_than_invalid";
>                public const string LesserThanMessage = "lesser_than_invalid";
> +               public const string InvalidIPAddressMessage = "ipaddress";
>        }
>
> File [modified]: MessageConstants.cs
> Delta lines: +28 -1
> ===================================================================
>
> --- 
> trunk/Components/Validator/Castle.Components.Validator/Messages.Designer.cs 
> 2009-05-27 21:52:27 UTC (rev 5717)
> +++ 
> trunk/Components/Validator/Castle.Components.Validator/Messages.Designer.cs 
> 2009-05-29 11:51:03 UTC (rev 5718)
> @@ -1,7 +1,7 @@
>  //------------------------------------------------------------------------------
>  // <auto-generated>
>  //     This code was generated by a tool.
> -//     Runtime Version:2.0.50727.1433
> +//     Runtime Version:2.0.50727.4918
>  //
>  //     Changes to this file may cause incorrect behavior and will be lost if
>  //     the code is regenerated.
> @@ -151,6 +151,15 @@
>         }
>
>         /// <summary>
> +        ///   Looks up a localized string similar to Please enter a valid 
> GUID (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
> +        /// </summary>
> +        internal static string guid {
> +            get {
> +                return ResourceManager.GetString("guid", resourceCulture);
> +            }
> +        }
> +
> +        /// <summary>
>         ///   Looks up a localized string similar to Please enter a valid 
> integer in this field.
>         /// </summary>
>         internal static string integer_invalid {
> @@ -160,6 +169,15 @@
>         }
>
>         /// <summary>
> +        ///   Looks up a localized string similar to Please enter a valid IP 
> address..
> +        /// </summary>
> +        internal static string ipaddress {
> +            get {
> +                return ResourceManager.GetString("ipaddress", 
> resourceCulture);
> +            }
> +        }
> +
> +        /// <summary>
>         ///   Looks up a localized string similar to This is a required field.
>         /// </summary>
>         internal static string isrequired {
> @@ -293,5 +311,14 @@
>                 return ResourceManager.GetString("time_invalid", 
> resourceCulture);
>             }
>         }
> +
> +        /// <summary>
> +        ///   Looks up a localized string similar to Please enter a valid 
> time-span (ddd.hh:mm:ss.xxx).
> +        /// </summary>
> +        internal static string timespan {
> +            get {
> +                return ResourceManager.GetString("timespan", 
> resourceCulture);
> +            }
> +        }
>     }
>
> File [modified]: Messages.Designer.cs
> Delta lines: +7 -1
> ===================================================================
>
> --- trunk/Components/Validator/Castle.Components.Validator/Messages.nl.resx   
>   2009-05-27 21:52:27 UTC (rev 5717)
> +++ trunk/Components/Validator/Castle.Components.Validator/Messages.nl.resx   
>   2009-05-29 11:51:03 UTC (rev 5718)
> @@ -189,4 +189,10 @@
>   <data name="not_same_value_invalid" xml:space="preserve">
>     <value>Veld mag niet gelijk zijn aan '{0}'</value>
>   </data>
> -</root>
> +  <data name="ipaddress" xml:space="preserve">
> +    <value>Vul s.v.p. een geldig IP adres in.</value>
> +  </data>
> +  <data name="timespan" xml:space="preserve">
> +    <value>Vul s.v.p. een geldige tijdsduur in (ddd.hh:mm:ss.xxx)</value>
> +  </data>
> +</root>
>
> File [modified]: Messages.nl.resx
> Delta lines: +4 -1
> ===================================================================
>
> --- trunk/Components/Validator/Castle.Components.Validator/Messages.resx      
>   2009-05-27 21:52:27 UTC (rev 5717)
> +++ trunk/Components/Validator/Castle.Components.Validator/Messages.resx      
>   2009-05-29 11:51:03 UTC (rev 5718)
> @@ -201,4 +201,7 @@
>   <data name="timespan" xml:space="preserve">
>     <value>Please enter a valid time-span (ddd.hh:mm:ss.xxx)</value>
>   </data>
> -</root>
> +  <data name="ipaddress" xml:space="preserve">
> +    <value>Please enter a valid IP address.</value>
> +  </data>
> +</root>
>
> File [modified]: Messages.resx
> Delta lines: +88 -0
> ===================================================================
>
> --- 
> trunk/Components/Validator/Castle.Components.Validator/Validators/IPAddressValidator.cs
>                              (rev 0)
> +++ 
> trunk/Components/Validator/Castle.Components.Validator/Validators/IPAddressValidator.cs
>      2009-05-29 11:51:03 UTC (rev 5718)
> @@ -0,0 +1,88 @@
> +// Copyright 2004-2009 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.Net;
> +
> +       /// <summary>
> +       /// Validate that this is a valid address.
> +       /// </summary>
> +       public class IPAddressValidator : AbstractValidator
> +       {
> +               /// <summary>
> +               /// Checks if the <c>fieldValue</c> can be converted to a 
> valid <see cref="IPAddress"/>.
> +               /// Null or empty value are allowed.
> +               /// </summary>
> +               /// <param name="instance">The target type instance</param>
> +               /// <param name="fieldValue">The property/field value. It can 
> be null.</param>
> +               /// <returns>
> +               ///     <c>true</c> if the value is accepted (has passed the 
> validation test)
> +               /// </returns>
> +               public override bool IsValid(object instance, object 
> fieldValue)
> +               {
> +                       if (fieldValue == null || fieldValue.ToString() == 
> "") return true;
> +
> +                       if (fieldValue is IPAddress)
> +                       {
> +                               return true;
> +                       }
> +
> +                       string ip = fieldValue.ToString();
> +                       IPAddress ipAddress;
> +                       if (IPAddress.TryParse(ip, out ipAddress))
> +                       {
> +                               return true;
> +                       }
> +
> +                       return false;
> +               }
> +
> +               /// <summary>
> +               /// Gets a value indicating whether this validator supports 
> browser validation.
> +               /// </summary>
> +               /// <value>
> +               ///     <see langword="true"/> if browser validation is 
> supported; otherwise, <see langword="false"/>.
> +               /// </value>
> +               public override bool SupportsBrowserValidation
> +               {
> +                       get { return true; }
> +               }
> +
> +               /// <summary>
> +               /// Returns the key used to internationalize error messages
> +               /// </summary>
> +               /// <value></value>
> +               protected override string MessageKey
> +               {
> +                       get { return 
> MessageConstants.InvalidIPAddressMessage; }
> +               }
> +
> +               /// <summary>
> +               /// Applies the browser validation by setting up one or
> +               /// more input rules on <see 
> cref="IBrowserValidationGenerator"/>.
> +               /// </summary>
> +               /// <param name="config">The config.</param>
> +               /// <param name="inputType">Type of the input.</param>
> +               /// <param name="generator">The generator.</param>
> +               /// <param name="attributes">The attributes.</param>
> +               /// <param name="target">The target.</param>
> +               public override void 
> ApplyBrowserValidation(BrowserValidationConfiguration config, 
> InputElementType inputType, IBrowserValidationGenerator generator, 
> System.Collections.IDictionary attributes, string target)
> +               {
> +                       base.ApplyBrowserValidation(config, inputType, 
> generator, attributes, target);
> +
> +                       generator.SetRegExp(target, 
> @"^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$",
>  BuildErrorMessage());
> +               }
> +       }
> +}
>
> Directory: /trunk/Components/Validator/Castle.Components.Validator.Tests/
> =========================================================================
>
> File [modified]: Castle.Components.Validator.Tests-vs2008.csproj
> Delta lines: +137 -0
> ===================================================================
>
> --- 
> trunk/Components/Validator/Castle.Components.Validator.Tests/ValidatorTests/IPAddressValidatorTestCase.cs
>                            (rev 0)
> +++ 
> trunk/Components/Validator/Castle.Components.Validator.Tests/ValidatorTests/IPAddressValidatorTestCase.cs
>    2009-05-29 11:51:03 UTC (rev 5718)
> @@ -0,0 +1,137 @@
> +// Copyright 2004-2009 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;
> +       using System.Globalization;
> +       using System.Net;
> +       using System.Resources;
> +       using System.Threading;
> +       using NUnit.Framework;
> +
> +       [TestFixture]
> +       public class IPAddressValidatorTestCase
> +       {
> +               private IPAddressValidator validator;
> +               private TestTarget target;
> +
> +               [SetUp]
> +               public void Init()
> +               {
> +                       Thread.CurrentThread.CurrentCulture =
> +                               Thread.CurrentThread.CurrentUICulture = new 
> CultureInfo("en-us");
> +
> +                       validator = new IPAddressValidator();
> +                       validator.Initialize(new CachedValidationRegistry(), 
> typeof(TestTarget).GetProperty("TargetField"));
> +                       target = new TestTarget();
> +               }
> +
> +               [Test]
> +               public void Succeeds_On_Valid_Dotted_IPAddresses()
> +               {
> +                       Assert.IsTrue(validator.IsValid(target, "10.0.0.0"));
> +                       Assert.IsTrue(validator.IsValid(target, 
> "192.168.1.1"));
> +                       Assert.IsTrue(validator.IsValid(target, 
> "255.255.255.255"));
> +                       Assert.IsTrue(validator.IsValid(target, 
> "192.168.0.0"));
> +                       Assert.IsTrue(validator.IsValid(target, 
> "67.199.26.208"));
> +               }
> +
> +               [Test]
> +               public void Succeeds_On_Valid_Numeric_IPAddresses()
> +               {
> +                       Assert.IsTrue(validator.IsValid(target, "167772160"));
> +                       Assert.IsTrue(validator.IsValid(target, 
> "3232235777"));
> +                       Assert.IsTrue(validator.IsValid(target, 
> "4294967294"));
> +                       Assert.IsTrue(validator.IsValid(target, 
> "3232235520"));
> +                       Assert.IsTrue(validator.IsValid(target, 
> "1137122000"));
> +               }
> +
> +               [Test]
> +               public void Fails_On_Invalid_Dotted_IPAddresses()
> +               {
> +                       Assert.IsFalse(validator.IsValid(target, 
> "123.456.789"));
> +                       Assert.IsFalse(validator.IsValid(target, 
> "this.is.not.a.valid.ip.address"));
> +                       Assert.IsFalse(validator.IsValid(target, 
> "260.255.255.255"));
> +                       Assert.IsFalse(validator.IsValid(target, 
> "192.999.0.0"));
> +               }
> +
> +               [Test]
> +               public void Fails_On_Invalid_Numeric_IPAddresses()
> +               {
> +                       Assert.IsFalse(validator.IsValid(target, 
> "0033996344"));
> +                       Assert.IsFalse(validator.IsValid(target, 
> "0033996351"));
> +                       Assert.IsFalse(validator.IsValid(target, 
> "0123456789"));
> +               }
> +
> +               [Test]
> +               public void Fails_On_Invalid_Textual_IPAddresses()
> +               {
> +                       Assert.IsFalse(validator.IsValid(target, "Invalid IP 
> Address"));
> +                       Assert.IsFalse(validator.IsValid(target, 
> "this.is.not.a.valid.ip.address"));
> +               }
> +
> +               [Test]
> +               public void NullOrEmptyStrings_Are_Valid()
> +               {
> +                       Assert.IsTrue(validator.IsValid(target, null));
> +                       Assert.IsTrue(validator.IsValid(target, ""));
> +               }
> +
> +               [Test]
> +               public void Accepts_System_Net_IPAddress()
> +               {
> +                       Assert.IsTrue(validator.IsValid(target, 
> IPAddress.Parse("67.199.26.208")));
> +               }
> +
> +               [Test]
> +               public void Localized_Error_Messages_Can_Be_Obtained()
> +               {
> +                       ChangeCultureAndTest("en-us", (messageValidator) => 
> Assert.AreEqual("Please enter a valid IP address.", 
> messageValidator.ErrorMessage));
> +                       ChangeCultureAndTest("nl-NL", (messageValidator) => 
> Assert.AreEqual("Vul s.v.p. een geldig IP adres in.", 
> messageValidator.ErrorMessage));
> +               }
> +
> +               private static void ChangeCultureAndTest(string name, 
> Action<AbstractValidator> test)
> +               {
> +                       CultureInfo currentCulture = 
> Thread.CurrentThread.CurrentCulture;
> +
> +                       try
> +                       {
> +                               Thread.CurrentThread.CurrentCulture = 
> Thread.CurrentThread.CurrentUICulture = new CultureInfo(name);
> +
> +                               var resourceManager = new 
> ResourceManager("Castle.Components.Validator.Messages", 
> typeof(CachedValidationRegistry).Assembly);
> +
> +                               var validator = new IPAddressValidator();
> +                               validator.Initialize(new 
> CachedValidationRegistry(resourceManager), 
> typeof(TestTarget).GetProperty("TargetField"));
> +
> +                               test(validator);
> +                       }
> +                       finally
> +                       {
> +                               Thread.CurrentThread.CurrentCulture = 
> Thread.CurrentThread.CurrentUICulture = currentCulture;
> +                       }
> +               }
> +
> +               public class TestTarget
> +               {
> +                       private string targetField;
> +
> +                       public string TargetField
> +                       {
> +                               get { return targetField; }
> +                               set { targetField = value; }
> +                       }
> +               }
> +       }
> +}
>
> Directory: /trunk/Components/Validator/
> =======================================
>
> File [modified]: Validator-vs2008.sln
> Delta lines: +0 -0
> ===================================================================
>
> Directory: 
> /trunk/Components/Validator/Castle.Components.Validator.Tests/ValidatorTests/
> ========================================================================================
>
> File [added]: IPAddressValidatorTestCase.cs
> Delta lines: +3 -0
> ===================================================================
>
> --- trunk/Components/Validator/Validator-vs2008.sln     2009-05-27 21:52:27 
> UTC (rev 5717)
> +++ trunk/Components/Validator/Validator-vs2008.sln     2009-05-29 11:51:03 
> UTC (rev 5718)
> @@ -29,4 +29,7 @@
>        GlobalSection(SolutionProperties) = preSolution
>                HideSolutionNode = FALSE
>        EndGlobalSection
> +       GlobalSection(ExtensibilityGlobals) = postSolution
> +               VisualSVNWorkingCopyRoot = .
> +       EndGlobalSection
>
> Directory: /trunk/Components/Validator/Castle.Components.Validator/Validators/
> ==============================================================================
>
> File [added]: IPAddressValidator.cs
> Delta lines: +1 -0
> ===================================================================
>
> --- 
> trunk/Components/Validator/Castle.Components.Validator.Tests/Castle.Components.Validator.Tests-vs2008.csproj
>         2009-05-27 21:52:27 UTC (rev 5717)
> +++ 
> trunk/Components/Validator/Castle.Components.Validator.Tests/Castle.Components.Validator.Tests-vs2008.csproj
>         2009-05-29 11:51:03 UTC (rev 5718)
> @@ -65,6 +65,7 @@
>     <Compile Include="ValidatorTests\CreditCardValidatorTestCase.cs" />
>     <Compile Include="ValidatorTests\GroupNotEmptyValidatorTestCase.cs" />
>     <Compile Include="ValidatorTests\GuidValidatorTestCase.cs" />
> +    <Compile Include="ValidatorTests\IPAddressValidatorTestCase.cs" />
>     <Compile Include="ValidatorTests\IsGreaterValidatorTestCase.cs" />
>     <Compile Include="ValidatorTests\IsLesserValidatorTestCase.cs" />
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Development List" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to