Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Object itself.
- RuleFor(x => x).NotNull();
- [Test]
- public void RequestObjectIsNull_ExpectError()
- {
- BusinessRequest request = null;
- var result = validator.Validate(request);
- Assert.IsFalse(result.IsValid);
- }
- public class MyValidator : AbstractValidator<MyObject>
- {
- public MyValidator()
- {
- RuleSet("MyRule", () =>
- {
- RuleFor(x=>x.MyProperty=="Something").WithMessage("failed");
- });
- }
- public override Task<ValidationResult> ValidateAsync(ValidationContext<MyObjec>> context, CancellationToken cancellation = default)
- {
- return context.InstanceToValidate == null ? Task.FromResult(new ValidationResult(new[] { new ValidationFailure("MyObject", "filed with null") })) : base.ValidateAsync(context, cancellation);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement