Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public interface IDataService
Task<List<DataModel>> GetData();
public class TestController : ControllerBase
private readonly IDataSerivce _dataService;
public TestController(IDataService dataService)
_dataService = dataService;
public async Task<IActionResult> Get()
return Ok(await _dataService.GetData());
public class given_an_instance_of_test_controller
public void assert_that_data_is_returned_from_get_call()
// arrange
var dataServiceMock = new Mock<IDataService>();
dataServiceMock.Setup(x => x.GetData()).ReturnsAsync(new List<DataModel> { new DataModel() } });
var controller = new TestController();
// act
var result = controller.Get().GetAwaiter().GetResult() as OkObjectResult;
// assert
var resultValue = result.Value as List<DataModel>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.