ValidatePositiveNumber

Description: Indicates a property must be a positive number.

Constructor(s):
  • public ValidatePositiveNumberAttribute(string message)
  • public ValidatePositiveNumberAttribute(bool includeZero, string message)

Parameters:
  • includeZero: Determines if zero should be included in the validation.
  • message: The message to be used if validation fails.

Example Usage:
public class MyEntity : EvilBaseEntity
{
    [ValidatePositiveNumber("Property1 must be a positive number.")]
    public int Property1
    {
        // Omitted for brevity
    }

    [ValidatePositiveNumber(true, "Property2 must be a positive number, including zero.")]
    public int Property2
    {
        // Omitted for brevity
    }
}


Valid Entity 1:
MyEntity entity = new MyEntity();
entity.Property1 = 1;

bool result = entity.IsValid();


Valid Entity 2:
MyEntity entity = new MyEntity();
entity.Property1 = 1;
entity.Property2 = 0;

bool result = entity.IsValid();


Valid Entity 3:
MyEntity entity = new MyEntity();
entity.Property1 = 1;
entity.Property2 = 5;

bool result = entity.IsValid();


Invalid Entity 1:
MyEntity entity = new MyEntity();
entity.Property1 = -1;

bool result = entity.IsValid();


Invalid Entity 2:
MyEntity entity = new MyEntity();
entity.Property1 = 5;
entity.Property2 = -1;

bool result = entity.IsValid();

Last edited Dec 7, 2006 at 3:01 PM by Arcware, version 1

Comments

justinc Jul 14, 2008 at 4:33 PM 
You should change your bool result = entity.IsValid(); to Assert.IsTrue(entity.IsValid()) or Assert.IsFalse(entity.IsValid()) to be more specific about the expected results.