public void Should_Throw_When_Service_Request_Does_Not_Exist() { MockServiceRequests(); var comment = new ServiceRequestCommentDto { Content = "test content", ServiceRequestId = 1 }; var userAndOrg = new UserAndOrganizationDto { OrganizationId = 2, UserId = "UserId" }; Assert.ThrowsAsync <ValidationException>(async() => await _serviceRequestService.CreateCommentAsync(comment, userAndOrg)); }
public async Task Should_Return_Successfully_Created_Service_Request_Comment() { MockServiceRequests(); var comment = new ServiceRequestCommentDto { Content = "test content", ServiceRequestId = 1 }; var userAndOrg = new UserAndOrganizationDto { OrganizationId = 1, UserId = "UserId" }; await _serviceRequestService.CreateCommentAsync(comment, userAndOrg); _serviceRequestCommentsDbSet.Received(1).Add(Arg.Any <ServiceRequestComment>()); await _uow.Received(1).SaveChangesAsync(false); }
public async Task CreateCommentAsync(ServiceRequestCommentDto comment, UserAndOrganizationDto userAndOrganizationDto) { var serviceRequest = await _serviceRequestsDbSet .SingleOrDefaultAsync(x => x.Id == comment.ServiceRequestId && x.OrganizationId == userAndOrganizationDto.OrganizationId); if (serviceRequest == null) { throw new ValidationException(ErrorCodes.ContentDoesNotExist, "Service request does not exist"); } var timestamp = DateTime.UtcNow; var serviceRequestComment = new ServiceRequestComment { Content = comment.Content, EmployeeId = userAndOrganizationDto.UserId, OrganizationId = userAndOrganizationDto.OrganizationId, ServiceRequest = serviceRequest, CreatedBy = userAndOrganizationDto.UserId, ModifiedBy = userAndOrganizationDto.UserId, Modified = timestamp, Created = timestamp }; _serviceRequestCommentsDbSet.Add(serviceRequestComment); await _uow.SaveChangesAsync(false); var createdComment = new ServiceRequestCreatedCommentDto { ServiceRequestId = comment.ServiceRequestId, CommentedEmployeeId = serviceRequestComment.EmployeeId, CommentContent = serviceRequestComment.Content }; _asyncRunner.Run <IServiceRequestNotificationService>(async notifier => await notifier.NotifyAboutNewCommentAsync(createdComment), _uow.ConnectionName); }