public void ShouldReturnInvalidPaymentException() { Assert.Throws <InvalidPaymentException>(() => _invalidCreditCardPayment.Validate()); }
public void ShouldReturnInvalidCreditCardPaymentException() { _validCreditCardPayment.CardNumber = null; Assert.Throws <InvalidCreditCardPaymentException>(() => _validCreditCardPayment.Validate()); }
public Task <CommandResult> Handle(CreateCreditCardPaymentCommand command, CancellationToken cancellationToken) { try { if (!command.Valdiate().IsValid) { AddNotifications(command.Valdiate().Errors.ToList()); return(Task.FromResult(new CommandResult("Não foi possível realizar o pagamento"))); } var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Document, EDocumentTypeEnum.CPF); var email = new Email(command.Email); var address = new Address(command.Street, command.City, command.State, command.ZipCode, command.ZipCode, command.Number); AddNotifications(name.Validate().Errors.ToList()); AddNotifications(email.Validate().Errors.ToList()); AddNotifications(document.Validate().Errors.ToList()); AddNotifications(address.Validate().Errors.ToList()); var payment = new CreditCardPayment(command.CardHolderName, command.CardNumber, name, address, DateTime.Now, command.Total, command.TotalPaid, document, email, command.SecurityCode, command.ValidDate); payment.AddItems(command.Products); AddNotifications(payment.Validate().Errors.ToList()); _productRepository.CheckStock(command.Products); if (IsValid()) { var productDrop = (from product in _productRepository.GetTableNoTracking() join cart in command.Products on product.Id equals cart.Id select new Product { Amount = (product.Amount - cart.Amount), Description = product.Description, EanCode = product.EanCode, Id = product.Id, Image = product.Image, Value = product.Value, Weight = product.Weight }).ToList(); _paymentRepository.Post(payment); _productRepository.PutRange(productDrop); if (!payment.Validate().IsValid) { AddNotifications(payment.Validate().Errors.ToList()); } } return(Task.FromResult(new CommandResult("Pagamento realizado com sucesso"))); } catch (Exception ex) { return(Task.FromResult(new CommandResult("Não foi possível realizar o pagamento"))); } }