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); }
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); }
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)); }
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)); }
public async Task <List <CompanyResponseModel> > GetOrderByDescending() { var companies = await _companyRepository.GetOrderByDescending(); return(companies.Select(x => CompanyMap.CompanyToCompanyResponse(x)).ToList()); }