public async Task GetSectorById_InputIsSectorData_OneSectorReturned(int id) { //Arrange sectorRepositoryMock.Setup(sectorRepository => sectorRepository.GetEntityByIdAsync(It.IsAny <int>())) .ReturnsAsync((int id) => sectorsContext.Find(sector => sector.Id == id)); //Act var resultSectorDTO = (await sectorService.GetSectorByIdAsync(id)) as SectorDTO; //Assert Assert.IsNotNull(resultSectorDTO); Assert.AreEqual(sectorsContext[id - 1].Id, resultSectorDTO.Id); }
public async Task <IActionResult> Get([FromRoute] int id) { var dto = await sectorService.GetSectorByIdAsync(id); if (dto == null) { return(NotFound()); } else { return(Ok(dto)); } }