
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Sandra.SimpleValidator
Advanced tools
Sandra.SimpleValidator is designed to be... a simple validator, nothing more. It has no ability to inject repositories and query the database to validate stuff. It has no ability to generate JavaScript validation.
Sandra.SimpleValidator is designed to be... a simple validator, nothing more. It has no ability to inject repositories and query the database to validate stuff. It has no ability to generate JavaScript validation.
It's purely used to validate a Model/ViewModel or DTO, or something that requires super simple validation such as Required, Minimum Length, etc.
To use simply create a validator:
public class UserValidator : ValidateThis<User>
{
public UserValidator()
{
For(x => x.UserName)
.Ensure(new Required());
For(x => x.Email)
.Ensure(new Required())
.Ensure(new Email());
For(x => x.Locale)
.Ensure(new Required());
}
}
Tell the validation service about any validators.
// this will look at the assembly associated to the generic argument and find all validators
ValidationService.RegisterAllFrom<UserValidator>();
Then you can inject the ValidationService
into your Controller
or NancyModule
public class HomeModule : NancyModule
{
public HomeModule(ValidationService validate)
{
Get["/"] = _ =>
{
var user = this.Bind<User>();
var validationResult = validate.This(user);
if (validationResult.IsInvalid)
{
//Handle errors with
//validationResult.Messages
return "Validation has fails :(";
}
return "Validation was successful :)";
};
}
}
And that's it. The ValidationService
method is virtual so you can mock and test it, and unit testing your Validators is easy too, simply create an instance of the validator and call validate on the model you want to test.
[Fact]
public void Given_Valid_Model_Should_Return_IsValid_As_True()
{
var validator = new TestClassValidator();
var model = new TestClass
{
Name = "Hello World",
Thing = "Thing!"
};
var result = validator.Validate(model);
Assert.True(result.IsValid);
}
FAQs
Sandra.SimpleValidator is designed to be... a simple validator, nothing more. It has no ability to inject repositories and query the database to validate stuff. It has no ability to generate JavaScript validation.
We found that sandra.simplevalidator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.