public async Task <IList <ValidationFailure> > ValidateAsync(CartValidationContext validationContext) { EnsureCartExists(); var result = await new CartValidator(validationContext).ValidateAsync(this, ruleSet: ValidationRuleSet); if (!result.IsValid) { ValidationErrors.AddRange(result.Errors); } return(result.Errors); }
public async Task ValidateAsync_CartValid_CartValidated() { // Arrange var cartAggregate = GetValidCartAggregate(); var context = new CartValidationContext(); // Act await cartAggregate.ValidateAsync(context, "default"); // Assert cartAggregate.IsValidated.Should().BeTrue(); }
public virtual async Task <IList <ValidationFailure> > ValidateAsync(CartValidationContext validationContext, string ruleSet) { if (validationContext == null) { throw new ArgumentNullException(nameof(validationContext)); } validationContext.CartAggregate = this; EnsureCartExists(); var result = await AbstractTypeFactory <CartValidator> .TryCreateInstance().ValidateAsync(validationContext, options => options.IncludeRuleSets(ruleSet)); if (!result.IsValid) { ValidationErrors.AddRange(result.Errors); } IsValidated = true; return(result.Errors); }
protected override void ApplyRuleForItems(CartValidationContext cartContext, ValidationContext <CartValidationContext> context) { var result = new ValidationResult(new ValidationFailure[] { new ValidationFailure("FakeFailure", "FakeFailure") }); result.Errors.Apply(x => context.AddFailure(x)); }
public virtual Task <IList <ValidationFailure> > ValidateAsync(CartValidationContext validationContext) { return(ValidateAsync(validationContext, "default,items,shipments,payments")); }