Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Validation
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv9288/test/Spring/Spring.Core.Tests/Validation
Modified Files:
AnyValidatorGroupTests.cs CollectionValidatorTests.cs
ExclusiveValidatorGroupTests.cs ValidationErrorsTests.cs
ValidatorGroupTests.cs ValidatorReferenceTests.cs
Added Files:
ValidationExceptionTests.cs
Log Message:
Extracted IValidationErrors interface and made ValidationErrors non-sealed.
Added ValidationException class.
Modified email, credit card, isbn and url validators to return true (valid) if object to validate is null or empty.
--- NEW FILE: ValidationExceptionTests.cs ---
#region License
/*
* Copyright 2004 the original author or authors.
*
* 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.
*/
#endregion
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
namespace Spring.Validation
{
/// <summary>
/// Unit tests for the ValidationException class.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: ValidationExceptionTests.cs,v 1.1 2008/02/05 20:40:27 aseovic Exp $</version>
[TestFixture]
public sealed class ValidationExceptionTests
{
[Test]
public void InstantiationUsingDefaultConstructor()
{
ValidationException ex = new ValidationException();
Assert.IsNull(ex.ValidationErrors);
}
[Test]
public void InstantiationSupplyingValidationErrors()
{
ValidationException ex = new ValidationException(new ValidationErrors());
Assert.IsTrue(ex.ValidationErrors.IsEmpty);
}
[Test]
public void InstantiationSupplyingMessageAndValidationErrors()
{
ValidationException ex = new ValidationException("my message", new ValidationErrors());
Assert.AreEqual("my message", ex.Message);
Assert.IsTrue(ex.ValidationErrors.IsEmpty);
}
[Test]
public void InstantiationSupplyingMessageValidationErrorsAndRootCause()
{
Exception rootCause = new Exception("root cause");
ValidationException ex = new ValidationException("my message", rootCause, new ValidationErrors());
Assert.AreEqual("my message", ex.Message);
Assert.IsTrue(ex.ValidationErrors.IsEmpty);
Assert.AreEqual(rootCause, ex.InnerException);
Assert.AreEqual("root cause", ex.InnerException.Message);
}
[Test]
public void TestExceptionSerialization()
{
MemoryStream buffer = new MemoryStream();
BinaryFormatter serializer = new BinaryFormatter();
Exception rootCause = new Exception("root cause");
ValidationException e1 = new ValidationException("my message", rootCause, new ValidationErrors());
serializer.Serialize(buffer, e1);
buffer.Position = 0;
ValidationException e2 = (ValidationException)serializer.Deserialize(buffer);
Assert.AreEqual("my message", e2.Message);
Assert.IsTrue(e2.ValidationErrors.IsEmpty);
Assert.AreEqual("root cause", e2.InnerException.Message);
}
}
}
Index: ValidationErrorsTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Validation/ValidationErrorsTests.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ValidationErrorsTests.cs 19 Feb 2007 17:56:42 -0000 1.6
--- ValidationErrorsTests.cs 5 Feb 2008 20:40:26 -0000 1.7
***************
*** 49,53 ****
public void ContainsNoErrorsDirectlyAfterInstantiation()
{
! ValidationErrors errors = new ValidationErrors();
Assert.IsTrue(errors.IsEmpty);
Assert.IsNotNull(errors.GetErrors(GoodErrorKey));
--- 49,53 ----
public void ContainsNoErrorsDirectlyAfterInstantiation()
{
! IValidationErrors errors = new ValidationErrors();
Assert.IsTrue(errors.IsEmpty);
Assert.IsNotNull(errors.GetErrors(GoodErrorKey));
***************
*** 65,69 ****
public void AddErrorWithNullKey()
{
! ValidationErrors errors = new ValidationErrors();
errors.AddError(null, ErrorMessageOne);
}
--- 65,69 ----
public void AddErrorWithNullKey()
{
! IValidationErrors errors = new ValidationErrors();
errors.AddError(null, ErrorMessageOne);
}
***************
*** 72,76 ****
public void AddErrorSunnyDay()
{
! ValidationErrors errors = new ValidationErrors();
errors.AddError(GoodErrorKey, ErrorMessageOne);
Assert.IsFalse(errors.IsEmpty);
--- 72,76 ----
public void AddErrorSunnyDay()
{
! IValidationErrors errors = new ValidationErrors();
errors.AddError(GoodErrorKey, ErrorMessageOne);
Assert.IsFalse(errors.IsEmpty);
***************
*** 82,86 ****
public void AddTwoErrorsSameKey()
{
! ValidationErrors errors = new ValidationErrors();
errors.AddError(GoodErrorKey, ErrorMessageOne);
errors.AddError(GoodErrorKey, ErrorMessageTwo);
--- 82,86 ----
public void AddTwoErrorsSameKey()
{
! IValidationErrors errors = new ValidationErrors();
errors.AddError(GoodErrorKey, ErrorMessageOne);
errors.AddError(GoodErrorKey, ErrorMessageTwo);
***************
*** 93,97 ****
public void EmptyErrorsReturnEmptyCollections()
{
! ValidationErrors errors = new ValidationErrors();
IList typedErrors = errors.GetErrors("xyz");
--- 93,97 ----
public void EmptyErrorsReturnEmptyCollections()
{
! IValidationErrors errors = new ValidationErrors();
IList typedErrors = errors.GetErrors("xyz");
***************
*** 107,111 ****
public void MergeErrorsWithNull()
{
! ValidationErrors errors = new ValidationErrors();
errors.AddError(GoodErrorKey, ErrorMessageOne);
errors.AddError(GoodErrorKey, ErrorMessageTwo);
--- 107,111 ----
public void MergeErrorsWithNull()
{
! IValidationErrors errors = new ValidationErrors();
errors.AddError(GoodErrorKey, ErrorMessageOne);
errors.AddError(GoodErrorKey, ErrorMessageTwo);
***************
*** 127,131 ****
! ValidationErrors errors = new ValidationErrors();
errors.AddError(GoodErrorKey, ErrorMessageOne);
errors.MergeErrors(otherErrors);
--- 127,131 ----
! IValidationErrors errors = new ValidationErrors();
errors.AddError(GoodErrorKey, ErrorMessageOne);
errors.MergeErrors(otherErrors);
Index: ValidatorGroupTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Validation/ValidatorGroupTests.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ValidatorGroupTests.cs 9 Apr 2006 07:24:52 -0000 1.3
--- ValidatorGroupTests.cs 5 Feb 2008 20:40:26 -0000 1.4
***************
*** 48,52 ****
vg.Validators.Add(new FalseValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 48,52 ----
vg.Validators.Add(new FalseValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 66,70 ****
vg.Validators.Add(new TrueValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 66,70 ----
vg.Validators.Add(new TrueValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 84,88 ****
vg.Validators.Add(new FalseValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 84,88 ----
vg.Validators.Add(new FalseValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 103,107 ****
vg.Validators = validators;
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 103,107 ----
vg.Validators = validators;
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
Index: CollectionValidatorTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Validation/CollectionValidatorTests.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CollectionValidatorTests.cs 8 Aug 2007 17:48:45 -0000 1.5
--- CollectionValidatorTests.cs 5 Feb 2008 20:40:26 -0000 1.6
***************
*** 81,85 ****
setPersons.AddAll(listPersons);
! ValidationErrors ve = new ValidationErrors();
Assert.IsTrue(validator.Validate(listPersons, ve));
--- 81,85 ----
setPersons.AddAll(listPersons);
! IValidationErrors ve = new ValidationErrors();
Assert.IsTrue(validator.Validate(listPersons, ve));
***************
*** 123,127 ****
validator.Validators.Add(req);
! ValidationErrors ve = new ValidationErrors();
Assert.IsFalse(validator.Validate(persons, ve));
--- 123,127 ----
validator.Validators.Add(req);
! IValidationErrors ve = new ValidationErrors();
Assert.IsFalse(validator.Validate(persons, ve));
***************
*** 202,206 ****
soc.Members.Add(new TestObject("Ivan Cikic", 28));
! ValidationErrors err1 = new ValidationErrors();
Assert.IsTrue(validator.Validate(soc, err1));
--- 202,206 ----
soc.Members.Add(new TestObject("Ivan Cikic", 28));
! IValidationErrors err1 = new ValidationErrors();
Assert.IsTrue(validator.Validate(soc, err1));
Index: ExclusiveValidatorGroupTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Validation/ExclusiveValidatorGroupTests.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ExclusiveValidatorGroupTests.cs 9 Apr 2006 07:24:52 -0000 1.3
--- ExclusiveValidatorGroupTests.cs 5 Feb 2008 20:40:26 -0000 1.4
***************
*** 48,52 ****
vg.Validators.Add(new FalseValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 48,52 ----
vg.Validators.Add(new FalseValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 69,73 ****
vg.Validators.Add(new TrueValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 69,73 ----
vg.Validators.Add(new TrueValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 90,94 ****
vg.Validators.Add(new FalseValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 90,94 ----
vg.Validators.Add(new FalseValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 108,112 ****
vg.Validators.Add(new FalseValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 108,112 ----
vg.Validators.Add(new FalseValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
Index: ValidatorReferenceTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Validation/ValidatorReferenceTests.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ValidatorReferenceTests.cs 9 Apr 2006 07:24:52 -0000 1.2
--- ValidatorReferenceTests.cs 5 Feb 2008 20:40:27 -0000 1.3
***************
*** 46,50 ****
v.Name = "validator";
! ValidationErrors errors = new ValidationErrors();
Assert.IsTrue(v.Validate(null, null, errors));
--- 46,50 ----
v.Name = "validator";
! IValidationErrors errors = new ValidationErrors();
Assert.IsTrue(v.Validate(null, null, errors));
***************
*** 62,66 ****
v.Name = "validator";
! ValidationErrors errors = new ValidationErrors();
Assert.IsFalse(v.Validate(null, null, errors));
Assert.IsFalse(v.Validate(null, errors));
--- 62,66 ----
v.Name = "validator";
! IValidationErrors errors = new ValidationErrors();
Assert.IsFalse(v.Validate(null, null, errors));
Assert.IsFalse(v.Validate(null, errors));
***************
*** 83,87 ****
v1.Name = "cv1";
! ValidationErrors errors = new ValidationErrors();
Assert.IsTrue(v1.Validate(context, null, errors));
--- 83,87 ----
v1.Name = "cv1";
! IValidationErrors errors = new ValidationErrors();
Assert.IsTrue(v1.Validate(context, null, errors));
Index: AnyValidatorGroupTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Validation/AnyValidatorGroupTests.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** AnyValidatorGroupTests.cs 9 Apr 2006 07:24:52 -0000 1.3
--- AnyValidatorGroupTests.cs 5 Feb 2008 20:40:26 -0000 1.4
***************
*** 45,49 ****
vg.Validators.Add(new FalseValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 45,49 ----
vg.Validators.Add(new FalseValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 63,67 ****
vg.Validators.Add(new TrueValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 63,67 ----
vg.Validators.Add(new TrueValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 81,85 ****
vg.Validators.Add(new FalseValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 81,85 ----
vg.Validators.Add(new FalseValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
***************
*** 98,102 ****
vg.Validators.Add(new FalseValidator());
! ValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
--- 98,102 ----
vg.Validators.Add(new FalseValidator());
! IValidationErrors errors = new ValidationErrors();
errors.AddError("existingErrors", new ErrorMessage("error", null));
|