public async Task Create_returns_500_on_internal_error() { var student = new CreateStudentDTO(); repository.Setup(r => r.CreateStudentAsync(student)).ThrowsAsync(new Exception()); var controller = new StudentRepositoryController(repository.Object); var actual = await controller.Create(student, true); var actionResult = Assert.IsType <ActionResult <Guid> >(actual); var code = Assert.IsType <StatusCodeResult>(actionResult.Result); Assert.Equal(500, code.StatusCode); }
public async Task Create_returns_200_and_id_of_created_student() { var nextMockedId = Guid.NewGuid(); var student = new CreateStudentDTO(); repository.Setup(r => r.CreateStudentAsync(student)).ReturnsAsync(nextMockedId); var controller = new StudentRepositoryController(repository.Object); var actual = await controller.Create(student, true); var actionResult = Assert.IsType <ActionResult <Guid> >(actual); var okResult = Assert.IsType <OkObjectResult>(actionResult.Result); var actualId = Assert.IsType <Guid>(okResult.Value); Assert.Equal(200, okResult.StatusCode); Assert.Equal(nextMockedId, actualId); }