public async Task Add_Returns_CreatedAtAction() { CompanyForAddDto companyDto = new CompanyForAddDto(); ActionResult <CompanyDto> result = await _companiesController.Add(companyDto); Assert.IsType <CreatedAtActionResult>(result.Result); }
public async Task <ActionResult <CompanyDto> > Add(CompanyForAddDto companyForAdd) { Company company = _mapper.Map <Company>(companyForAdd); await _companyService.AddAsync(company); return(CreatedAtAction(nameof(GetById), new { id = company.CompanyId }, _mapper.Map <CompanyDto>(company))); }
public async Task Add_Returns_ActionResult() { CompanyForAddDto companyDto = new CompanyForAddDto(); ActionResult <CompanyDto> result = await _companiesController.Add(companyDto); Assert.NotNull(result); }
public async Task Add_Returns_ActionNameGetById() { CompanyForAddDto companyDto = new CompanyForAddDto(); ActionResult <CompanyDto> result = await _companiesController.Add(companyDto); CreatedAtActionResult actionResult = result.Result as CreatedAtActionResult; Assert.Equal(nameof(CompaniesController.GetById), actionResult.ActionName); }
public async Task Add_Calls_CompanyServiceAddAsync() { CompanyForAddDto companyForAddDto = new CompanyForAddDto(); Company company = new Company { CompanyId = 5 }; _companiesController = new CompaniesController(_companyServiceMock.Object, _mapperMock.Object); _mapperMock.Setup(x => x.Map <Company>(companyForAddDto)).Returns(company); await _companiesController.Add(companyForAddDto); _companyServiceMock.Verify(x => x.AddAsync(company), Times.Once()); }
public async Task <IActionResult> AddCompany(CompanyForAddDto companyForAddDto) { if (await _repo.CompanyExists(companyForAddDto.CompanyName)) { return(BadRequest("Company Name already exists")); } var companyToAdd = _mapper.Map <Company>(companyForAddDto); var createdCompany = await _repo.AddCompany(companyToAdd); var companyToReturn = _mapper.Map <CompanyForListDto>(createdCompany); return(CreatedAtRoute("GetCompany", new { controller = "Companys", id = createdCompany.Id }, companyToReturn)); }
public async Task Add_Returns_RouteIdEqualToCompanyId() { CompanyForAddDto companyDto = new CompanyForAddDto(); Company company = new Company { CompanyId = 5 }; _companiesController = new CompaniesController(_companyServiceMock.Object, _mapperMock.Object); _mapperMock.Setup(x => x.Map <Company>(companyDto)).Returns(company); ActionResult <CompanyDto> result = await _companiesController.Add(companyDto); CreatedAtActionResult actionResult = result.Result as CreatedAtActionResult; Assert.Equal(5, actionResult.RouteValues["id"]); }