public void ShouldReturnErrorWhenBoletoNumberIsInvalid() { var command = new CreateBoletoPaymentCommand(); command.BoletoNumber = "000-000"; command.Valdiate().IsValid.Should().Be(false); }
public void ShouldReturnSuccessWhenBoletoNumberIsValid() { var command = new CreateBoletoPaymentCommand(); command.BoletoNumber = "00000.00000 00000.000000 00000.000000 0 00000000000000"; command.Valdiate().IsValid.Should().Be(true); }
public Task <CommandResult> Handle(CreateBoletoPaymentCommand 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.Neighborhood, 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 BoletoPayment(name, address, command.BoletoNumber, DateTime.Now, command.Total, command.TotalPaid, document, email); 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()); } } else { return(Task.FromResult(new CommandResult("Não foi possível realizar o pagamento"))); } 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"))); } }