Ensures the collection has a specified item count.
Collection count must equal {count}.
Using type instance.
var validator = new ValidatorBuilder<IEnumerable<string>>()
.Count(2)
.Build();
var result = validator.Validate(new[] { "One", "Two" });
Using selector expression.
var validator = new ValidatorBuilder<Employee>()
.Count(e => e.Skills, 2)
.Build();
var result = validator.Validate(new Employee { Skills = new[] { "Cromulent" } });
Using For function.
var validator = new ValidatorBuilder<Employee>()
.For(e => e.Skills, v => v.Count(1))
.Build();
var result = validator.Validate(new Employee { Skills = new[] { "Vandalism" } });
Ensures the collection has a specified minimum item count.
Collection count must be at least {count}.
Using type instance.
var validator = new ValidatorBuilder<IEnumerable<string>>()
.MinCount(2)
.Build();
var result = validator.Validate(new[] { "One" });
Using selector expression.
var validator = new ValidatorBuilder<Employee>()
.MinCount(e => e.Skills, 2)
.Build();
var result = validator.Validate(new Employee { Skills = new[] { "Cromulent" } });
Using For function.
var validator = new ValidatorBuilder<Employee>()
.For(e => e.Skills, v => v.MinCount(1))
.Build();
var result = validator.Validate(new Employee { Skills = new[] { "Vandalism" } });
Ensures the collection has a specified maximum item count.
Collection count cannot be greater than {count}.
Using type instance.
var validator = new ValidatorBuilder<IEnumerable<string>>()
.MaxCount(2)
.Build();
var result = validator.Validate(new[] { "One" });
Using selector expression.
var validator = new ValidatorBuilder<Employee>()
.MaxCount(e => e.Skills, 2)
.Build();
var result = validator.Validate(new Employee { Skills = new[] { "Cromulent" } });
Using For function.
var validator = new ValidatorBuilder<Employee>()
.For(e => e.Skills, v => v.MaxCount(1))
.Build();
var result = validator.Validate(new Employee { Skills = new[] { "Vandalism" } });
Ensures the collection contains the specified item.
Collection must contain item '{item}'.
Using type instance.
var validator = new ValidatorBuilder<IEnumerable<string>>()
.Contains("Two")
.Build();
var result = validator.Validate(new[] { "One", "Two", "Three" });
Using selector expression.
var validator = new ValidatorBuilder<Employee>()
.Contains(e => e.Skills, "Cromulent")
.Build();
var result = validator.Validate(new Employee { Skills = new[] { "Cromulent" } });
Using For function.
var validator = new ValidatorBuilder<Employee>()
.For(e => e.Skills, v => v.Contains("Chill"))
.Build();
var result = validator.Validate(new Employee { Skills = new[] { "Wisdom" } });