Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public async Task <List <DebitResponseModel> > GetCompanyDebits(int companyId)
        {
            if (companyId <= 0)
            {
                AddError("The company id is Invalid");
            }

            var debits = await _debitRepository.GetCompanyDebits(companyId);

            return(debits.Select(x => DebitMap.DebitToDebitResponse(x)).ToList());
        }
        public async Task ShouldGetDebitById()
        {
            var debit = new Debit(1);

            var expectedDebit = DebitMap.DebitToDebitResponse(debit);

            _debitRepository.GetById(1).Returns(debit);

            var response = await _debitService.GetById(1);

            response.Should().BeEquivalentTo(expectedDebit);
        }
Exemplo n.º 4
0
        public async Task <DebitResponseModel> GetById(int id)
        {
            if (id <= 0)
            {
                AddError("Id invalid");
            }

            HandlerErrors();

            var debit = await _debitRepository.GetById(id);

            if (debit == null)
            {
                AddError("Debit not found");
            }

            HandlerErrors();

            return(DebitMap.DebitToDebitResponse(debit));
        }
        public async Task GetCompanyDebits()
        {
            var date = DateTime.UtcNow;

            var debitsOfCompanyModels = new List <DebitResponseModel>();
            var debitsOfCompany       = new List <Debit>();

            var debitOfCompany1 = new Debit(1);

            var debitResponseOfCompany1 = DebitMap.DebitToDebitResponse(debitOfCompany1);

            for (int i = 0; i < 5; i++)
            {
                debitsOfCompanyModels.Add(debitResponseOfCompany1);
                debitsOfCompany.Add(debitOfCompany1);
            }

            _debitRepository.GetCompanyDebits(1).Returns(debitsOfCompany);

            var response = await _debitService.GetCompanyDebits(1);

            response.Should().BeEquivalentTo(debitsOfCompanyModels);
        }