Digits confusing behavior

Description

Using the current (14 July 2010) trunk, this test fails:

public class Entity
{
public virtual string ZipCode { get; set; }
}

public class EntityValidator : ValidationDef<Entity>
{
public EntityValidator()
{
Define(r => r.ZipCode)
.Digits(5)
.WithMessage("Error: Zip Code must have 5 digits");

}
}

[Test]
public void DigitsWorks()
{
var entity = new Entity()
{
ZipCode = "1234"
};

var ve = Environment.SharedEngineProvider.GetEngine();

ve.Validate(entity).Any().Should().Be.True();
}

It seems Digits requires up to X digits, not exactly X digits. I don't believe this is the behavior an average person would expect.

Along with this change, perhaps the addition of Digits(int minDigits, int maxDigits) would make this distinction more clear.

Environment

None

Activity

Show:

Dario Quintana 
October 12, 2010 at 2:08 PM

Hi Jason,

I believe this is not a bug but a feature. This validator of digits validates in this way:
Checks wheter the member is a number having up to IntegerDigits, and FractionalDigits fractional digits, always "up to" X number.

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created July 14, 2010 at 3:17 PM
Updated October 12, 2010 at 2:08 PM
Who's Looking?

Flag notifications