public async Task CreateProjectUser_CallWithMockedIProjectUser_CatchesAndThrowsProjectUserException() { // Arrange var mock = new Mock <IProjectUser>(); var id = Guid.Empty; var userId = Guid.NewGuid(); var projectId = Guid.NewGuid(); var projectUser = new ProjectUserDto() { Id = id, ProjectId = projectId, UserId = userId, Username = "******", IsOwner = true }; var message = "Exception Message"; var ex = new ProjectUserException(message); mock.Setup(pu => pu.CreateProjectUserAsync(projectUser)).ThrowsAsync(ex); var controller = new ProjectUsersController(mock.Object); // Act var result = await controller.CreateProjectUser(projectUser); 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); }
public async Task CreateProjectUser_CallWithMockedIProjectUser_ReturnOkObjectResult() { // Arrange var mock = new Mock <IProjectUser>(); var id = Guid.Empty; var userId = Guid.NewGuid(); var projectId = Guid.NewGuid(); var projectUser = new ProjectUserDto() { Id = id, ProjectId = projectId, UserId = userId, Username = "******", IsOwner = true }; mock.Setup(pu => pu.CreateProjectUserAsync(projectUser)).ReturnsAsync(projectUser); var controller = new ProjectUsersController(mock.Object); // Act var result = await controller.CreateProjectUser(projectUser); var response = (OkObjectResult)result; // Assert Assert.IsType <OkObjectResult>(result); Assert.IsType <ResponseDto <ProjectUserDto> >(response.Value); }