public async Task AddSampleAsync_ShouldReturnStatusCode400_WhenInvalid() { //arrange int id = -1; Sample sample = null; _projectBLMock.Setup(i => i.AddSampleAsync(sample, id)).Throws(new Exception()); SampleController sampleController = new SampleController(_projectBLMock.Object); //act var result = await sampleController.AddSampleAsync(); //assert Assert.IsType <StatusCodeResult>(result); Assert.Equal(400, ((StatusCodeResult)result).StatusCode); }