public async void CancelLeave() { await _leaveRequestRepository.ApplyLeaveAsync(leave); var leaves = await _leaveRequestRepository.CancelLeaveAsync(1); Assert.Equal(Condition.Cancel, leaves.Status); }
/// <summary> /// Method to Cancel leave, only allowed to the applier of the leave to cancel the leave /// </summary> /// <param name="leaveId">leave request Id</param> /// <param name="userId">User's user Id</param> /// <param name="accessToken">User's access token</param> /// <returns>Reply text to be send</returns> private async Task <string> LeaveCancelByIdAsync(int leaveId, string userId, string accessToken) { // get user details from oAuth server User user = await _oauthCallsRepository.GetUserByUserIdAsync(userId, accessToken); _logger.Debug("LeaveCancelByIdAsync user name : " + user.UserName); LeaveRequest leave = await _leaveRepository.LeaveByIdAsync(leaveId); _logger.Debug("LeaveCancelByIdAsync leave employee id : " + leave.EmployeeId); // only authorize user of leave is allowed to cancel there leave if (user.Id == leave.EmployeeId) { // method to cancel leave LeaveRequest updateLeave = await _leaveRepository.CancelLeaveAsync(leaveId); _logger.Debug("LeaveCancelByIdAsync leave cancel sucessfully"); replyText = string.Format(_stringConstant.ReplyTextForCancelLeave, updateLeave.Id, updateLeave.FromDate.ToShortDateString(), updateLeave.EndDate.Value.ToShortDateString(), updateLeave.Status); } else { // if leave doesn't exist or unauthorize trespass try to do replyText = _stringConstant.ReplyTextForErrorInCancelLeave; } return(replyText); }