public RefundPointsCommandValidator(ILoyaltyDbContextFactory dbContextFactory)
        {
            RuleFor(cmd => cmd.TransactionId)
            .NotEmpty()
            .WithMessage(CommonValidationMessages.CannotBeNullOrEmpty)
            .DependentRules(() =>
            {
                RuleFor(cmd => cmd.TransactionId)
                .MustAsync(async(string transactionId, CancellationToken cancellationToken) =>
                {
                    using (var context = dbContextFactory.CreateDbContext())
                    {
                        var consumptionEvent = await context
                                               .PointsConsumedEvents
                                               .FirstOrDefaultAsync(e => e.TransactionId == transactionId).ConfigureAwait(false);

                        return(consumptionEvent != null);
                    }
                })
                .WithMessage(ValidationMessages.PointsConsumptionNotFound);
            });
        }
 public RefundPointsCommandHandler(ILoyaltyDbContextFactory dbContextFactory, IValidator <RefundPointsCommand> commandValidator)
 {
     this.dbContextFactory = dbContextFactory ?? throw new ArgumentNullException(nameof(dbContextFactory));
     this.commandValidator = commandValidator ?? throw new ArgumentNullException(nameof(commandValidator));
 }
 public PointsBalanceCalculator(ILoyaltyDbContextFactory dbContextFactory)
 {
     this.dbContextFactory = dbContextFactory ?? throw new ArgumentNullException(nameof(dbContextFactory));
 }