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);
        }
예제 #2
0
        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();
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
 public virtual Task <IList <ValidationFailure> > ValidateAsync(CartValidationContext validationContext)
 {
     return(ValidateAsync(validationContext, "default,items,shipments,payments"));
 }