public async Task GetSampleByIdShouldGetSample() { var sampleId = 1; var sample = new Sample { Id = sampleId }; _projectBLMock.Setup(x => x.GetSampleByIDAsync(It.IsAny <int>())).Returns(Task.FromResult(sample)); var sampleController = new SampleController(_projectBLMock.Object); var result = await sampleController.GetSampleByIDAsync(sampleId); Assert.Equal(sampleId, ((Sample)((OkObjectResult)result).Value).Id); _projectBLMock.Verify(x => x.GetSampleByIDAsync(sampleId)); }
public async Task GetSampleByIDAsync_ShouldReturnNotFound_WhenSampleIsInvalid() { //arrange int id = -2; Sample sample = null; _projectBLMock.Setup(i => i.GetSampleByIDAsync(id)).ReturnsAsync(sample); SampleController sampleController = new SampleController(_projectBLMock.Object); //act var result = await sampleController.GetSampleByIDAsync(id); //assert Assert.IsType <NotFoundResult>(result); }