public async Task ShouldCreateDebit()
        {
            var expectedDebit = new Debit(1);
            var debitRequest  = new DebitRequestModel()
            {
                CompanyId = 1,
            };

            var company = new Company("SERASA");

            _companyRepository.GetById(1).Returns(company);

            var response = await _debitService.Create(debitRequest);

            await _companyRepository
            .Received(1)
            .GetById(Arg.Is <int>(x =>
                                  x == 1));

            await _debitRepository
            .Received(1)
            .Create(Arg.Is <Debit>(x => x.CompanyId == 1));

            expectedDebit.Should().BeEquivalentTo(response);
        }
示例#2
0
        public async Task <IActionResult> CreateCategoriesAndDebits([FromRoute] int id)
        {
            try
            {
                var responseCsv = CSVParserService.ReadCsvFileReturnDebit_Invoice_Amount(Request.Form.Files[0]);

                var debit = new DebitRequestModel()
                {
                    CompanyId = id
                };

                var invoice = new InvoiceRequestModel()
                {
                    CompanyId = id
                };

                using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    await _invoiceService.CreateAmountInvoice(responseCsv.AmountInvoices, invoice);

                    await _debitService.CreateAmountDebits(responseCsv.AmountDebits, debit);

                    scope.Complete();
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(HandleControllerErrors(ex));
            }
        }
示例#3
0
        public async Task <DebitResponseModel> Create(DebitRequestModel debitRequest)
        {
            var debit = DebitMap.DebitRequestToDebit(debitRequest);

            if (!debit.IsValid())
            {
                AddErrors(debit.GetErrors());
            }

            HandlerErrors();

            var company = await _companyRepository.GetById(debit.CompanyId);

            if (company == null)
            {
                AddError("Company not found");
            }

            HandlerErrors();

            await _debitRepository.Create(debit);

            company.CalculateReliability();

            await _debitRepository.Save();

            return(DebitMap.DebitToDebitResponse(debit));
        }
 public IEnumerable<ValidationResult> Validate(DebitRequestModel model){
   
   //do some validation
   yield return new ValidationResult {
     MemberName = "cardId",
     ErrorMessage = "Invalid CardId."
   }
 }  
示例#5
0
        public async Task <bool> CreateAmountDebits(int amount, DebitRequestModel debitRequest)
        {
            var sucess = false;

            for (int i = 0; i < amount; i++)
            {
                await Create(debitRequest);
            }

            sucess = true;
            return(sucess);
        }
        public async Task ShouldReturnErrorBecausseNotFoundCompanyAtCreateDebit()
        {
            var debitRequest = new DebitRequestModel()
            {
                CompanyId = 1,
            };

            var expectedErrors = new HashSet <string>();

            expectedErrors.Add("Company not found");

            var ex = await Record.ExceptionAsync(() => _debitService.Create(debitRequest)) as BadRequestException;

            expectedErrors.Should().BeEquivalentTo(ex.Errors);
        }
        public async Task ShouldReturnErrorAtCreateDebit()
        {
            var debitRequest = new DebitRequestModel()
            {
                CompanyId = -1,
            };

            var company = new Company("SERASA");

            _companyRepository.GetById(1).Returns(company);

            var expectedErrors = new HashSet <string>();

            expectedErrors.Add("The company Id is invalid");

            var ex = await Record.ExceptionAsync(() => _debitService.Create(debitRequest)) as BadRequestException;

            expectedErrors.Should().BeEquivalentTo(ex.Errors);
        }
示例#8
0
 public static Debit DebitRequestToDebit(DebitRequestModel debitRequest)
 {
     return(AutoMapperFunc.ChangeValues <DebitRequestModel, Debit>(debitRequest));
 }