public async Task DeleteProject_CallWithMockedIProjectUser_ReturnOkObjectResult() { // Arrange var mock = new Mock <IProjectUser>(); var id = Guid.NewGuid(); mock.Setup(pu => pu.DeleteProjectUserAsync(id)).Returns(Task.Delay(0)); var controller = new ProjectUsersController(mock.Object); // Act var result = await controller.DeleteProject(id); var response = (OkObjectResult)result; // Assert Assert.IsType <OkObjectResult>(result); Assert.IsType <ResponseDto <ProjectUserDto> >(response.Value); }
public async Task DeleteProject_CallWithMockedIProjectUser_CatchesAndThrowsProjectUserException() { // Arrange var mock = new Mock <IProjectUser>(); var id = Guid.NewGuid(); var message = "Exception Message"; var ex = new ProjectUserException(message); mock.Setup(pu => pu.DeleteProjectUserAsync(id)).ThrowsAsync(ex); var controller = new ProjectUsersController(mock.Object); // Act var result = await controller.DeleteProject(id); var response = (BadRequestObjectResult)result; var objectResult = (ResponseDto <ErrorDto>)response.Value; // Assert Assert.IsType <BadRequestObjectResult>(result); Assert.IsType <ResponseDto <ErrorDto> >(response.Value); Assert.Equal(message, objectResult.Data.Message); }