예제 #1
0
        public void CasualLeave()
        {
            var response   = Task.FromResult(_stringConstant.CasualLeaveResponse);
            var requestUrl = string.Format("{0}{1}", _stringConstant.CasualLeaveUrl, _stringConstant.FirstNameForTest);

            _mockHttpClient.Setup(x => x.GetAsync(_stringConstant.ProjectUserUrl, requestUrl, _stringConstant.AccessTokenForTest)).Returns(response);
            var casualLeave = _projectUserRepository.CasualLeave(_stringConstant.FirstNameForTest, _stringConstant.AccessTokenForTest).Result;

            Assert.Equal(10, casualLeave.CasualLeave);
        }
예제 #2
0
        /// <summary>
        /// Method to check leave Balance from slack
        /// </summary>
        /// <param name="leave"></param>
        /// <param name="accessToken"></param>
        /// <returns>replyText</returns>
        private async Task <string> SlackLeaveBalance(SlashCommand leave, string accessToken)
        {
            // get user details from oAuth server
            var user = await _projectUser.GetUserByUsername(leave.Username, accessToken);

            if (user.Id != null)
            {
                // get user leave allowed details from oAuth server
                var allowedLeave = await _projectUser.CasualLeave(leave.Username, accessToken);

                // method to get user's number of leave taken
                var leaveTaken       = _leaveRepository.NumberOfLeaveTaken(user.Id);
                var casualLeaveTaken = leaveTaken.CasualLeave;
                var sickLeaveTaken   = leaveTaken.SickLeave;
                var casualLeaveLeft  = allowedLeave.CasualLeave - casualLeaveTaken;
                var sickLeaveLeft    = allowedLeave.SickLeave - sickLeaveTaken;
                replyText  = string.Format("You have taken {0} casual leave out of {1}{2}You have casual leave left {3}", casualLeaveTaken, allowedLeave.CasualLeave, Environment.NewLine, casualLeaveLeft);
                replyText += string.Format("{2}You have taken {0} sick leave out of {1}{2}You have sick leave left {3}", casualLeaveTaken, allowedLeave.SickLeave, Environment.NewLine, sickLeaveLeft);
            }
            else
            {
                // if user doesn't exist in Oauth server
                replyText = _stringConstant.LeaveNoUserErrorMessage;
            }
            return(replyText);
        }