Пример #1
0
        public async Task ShouldGetCompanyById()
        {
            var company = new Company("SERASA");
            var expectedCompanyResponse = CompanyMap.CompanyToCompanyResponse(company);

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

            var response = await _service.GetById(1);

            expectedCompanyResponse.Should().BeEquivalentTo(response);
        }
Пример #2
0
        public async Task ShouldReturnErrorBecauseNotFoundCompanyAtGetGetCompanyById()
        {
            var company = new Company("SERASA");
            var expectedCompanyResponse = CompanyMap.CompanyToCompanyResponse(company);

            var expectedErrors = new HashSet <string>();

            expectedErrors.Add("Company not found");

            var ex = await Record.ExceptionAsync(() => _service.GetById(1)) as BadRequestException;

            ex.Errors.Should().BeEquivalentTo(expectedErrors);
        }
Пример #3
0
        public async Task <CompanyResponseModel> GetById(int id)
        {
            if (id <= 0)
            {
                AddError("Id invalid");
            }

            HandlerErrors();

            var company = await _companyRepository.GetById(id);

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

            HandlerErrors();

            return(CompanyMap.CompanyToCompanyResponse(company));
        }
Пример #4
0
        public async Task <CompanyResponseModel> Create(CompanyRequestModel companyRequest)
        {
            var company = CompanyMap.CompanyRequestToCompany(companyRequest);

            company.FormatProps();

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

            if (await _companyRepository.CompanyExists(company.Name))
            {
                AddError("This company name already exists");
            }

            HandlerErrors();

            await _companyRepository.Create(company);

            await _companyRepository.Save();

            return(CompanyMap.CompanyToCompanyResponse(company));
        }
Пример #5
0
        public async Task <List <CompanyResponseModel> > GetOrderByDescending()
        {
            var companies = await _companyRepository.GetOrderByDescending();

            return(companies.Select(x => CompanyMap.CompanyToCompanyResponse(x)).ToList());
        }