public OrderValidator(IProductCommandRepository productRepository, IServiceMethodCommandRepository serviceMethodRepository)
        {
            _productRepository       = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
            _serviceMethodRepository = serviceMethodRepository ?? throw new ArgumentNullException(nameof(serviceMethodRepository));

            RuleFor(itm => itm).MustAsync(async(o, cancellation) => await ProductExists(o.ProductId).ConfigureAwait(false)).WithMessage(ErrorMessages.OrderedProductDoesNotExist);
            RuleFor(itm => itm).MustAsync(async(o, cancellation) => await ProductAvailable(o.ProductId).ConfigureAwait(false))
            .When(itm => ProductExists(itm.ProductId).Result == true).WithMessage(ErrorMessages.OrdredProductIsNotAvailable);
            RuleFor(itm => itm).MustAsync(async(o, cancellation) => await ServiceMethodExists(o.ServiceMethodId).ConfigureAwait(false)).WithMessage(ErrorMessages.OrderedServiceMethodDoesNotExist);
        }
        public PlaceOrdersCommandValidator(IProductCommandRepository productRepository, IServiceMethodCommandRepository serviceMethodRepository)
        {
            _productRepository       = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
            _serviceMethodRepository = serviceMethodRepository ?? throw new ArgumentNullException(nameof(serviceMethodRepository));

            RuleFor(itm => itm.CustomerDetails).NotNull().WithMessage(ErrorMessages.NoCustomerDataSupplied);
            RuleFor(itm => itm.CustomerDetails.Name).NotEmpty().When(itm => itm.CustomerDetails != null).WithErrorCode(ErrorMessages.NoCustomerNameSupplied);
            RuleForEach(itm => itm.Orders).SetValidator(new OrderValidator(_productRepository, _serviceMethodRepository));

            Thread.Sleep(5000);
        }
Esempio n. 3
0
 public AddServiceMethodCommandHandler(IServiceMethodCommandRepository serviceMethodRepository, ILogger logger, IEventPublisher <INotification> eventPublisher)
 {
     _serviceMethodRepository = serviceMethodRepository ?? throw new ArgumentNullException(nameof(serviceMethodRepository));
     _logger         = logger ?? throw new ArgumentNullException(nameof(logger));
     _eventPublisher = eventPublisher ?? throw new ArgumentNullException(nameof(eventPublisher));
 }