public async Task GetMailSettingEmailIsToAsync()
        {
            await AddGroup();
            await AddMailSetting();

            var result = await _mailSettingDetailsRepository.GetMailSettingAsync(1, _stringConstant.TaskModule, _stringConstant.StringIdForTest);

            Assert.True(result.SendMail);
        }
        /// <summary>
        /// Method to conduct task mail after been started, and send next question of task mail
        /// </summary>
        /// <param name="answer">Answer of previous question ask to user</param>
        /// <param name="userId">User's slack Id</param>
        /// <returns>questionText in string format containing next question statement</returns>
        public async Task <string> QuestionAndAnswerAsync(string answer, string userId)
        {
            // method to get user's details, user's accesstoken, user's task mail details and list or else appropriate message will be send
            var userAndTaskMailDetailsWithAccessToken = await GetUserAndTaskMailDetailsAsync(userId);

            _logger.Info("Task Mail Bot Module, Is task mail question text : " + userAndTaskMailDetailsWithAccessToken.QuestionText);
            // if question text is null then only allowed
            if (string.IsNullOrEmpty(userAndTaskMailDetailsWithAccessToken.QuestionText))
            {
                _logger.Info("Task Mail Bot Module, task mail process start - QuestionAndAnswerAsync");
                _logger.Info("Task Mail Bot Module, task mail list count : " + userAndTaskMailDetailsWithAccessToken.TaskList.Count());
                if (userAndTaskMailDetailsWithAccessToken.TaskList != null)
                {
                    var taskDetails = userAndTaskMailDetailsWithAccessToken.TaskList.Last();
                    // getting inform of previous question was asked to user
                    var previousQuestion = await _botQuestionRepository.FindByIdAsync(taskDetails.QuestionId);

                    // checking if previous question was last and answered by user and previous task report was completed then asked for new task mail
                    if (previousQuestion.OrderNumber <= QuestionOrder.TaskMailSend)
                    {
                        // getting next question to be asked to user
                        var nextQuestion = await NextQuestionForTaskMailAsync(previousQuestion.OrderNumber);

                        _logger.Info("Previous question ordernumber : " + previousQuestion.OrderNumber);
                        switch (previousQuestion.OrderNumber)
                        {
                            #region Your Task
                        case QuestionOrder.YourTask:
                        {
                            // if previous question was description of task and it was not null/wrong vale then answer will ask next question
                            if (answer != null)
                            {
                                taskDetails.Description = answer;
                                userAndTaskMailDetailsWithAccessToken.QuestionText = nextQuestion.QuestionStatement;
                                taskDetails.QuestionId = nextQuestion.Id;
                            }
                            else
                            {
                                // if previous question was description of task and it was null then answer will ask for description again
                                userAndTaskMailDetailsWithAccessToken.QuestionText = previousQuestion.QuestionStatement;
                            }
                        }
                        break;
                            #endregion

                            #region Hour Spent
                        case QuestionOrder.HoursSpent:
                        {
                            // if previous question was hour of task and it was not null/wrong value then answer will ask next question
                            decimal hour;
                            // checking whether string can be convert to decimal or not
                            var taskMailHourConvertResult = decimal.TryParse(answer, out hour);
                            if (taskMailHourConvertResult)
                            {
                                decimal totalHourSpented = 0;
                                // checking range of hours
                                if (hour > 0 && hour <= Convert.ToInt32(_stringConstant.TaskMailMaximumTime))
                                {
                                    // adding up all hours of task mail
                                    foreach (var task in userAndTaskMailDetailsWithAccessToken.TaskList)
                                    {
                                        totalHourSpented += task.Hours;
                                    }
                                    totalHourSpented += hour;
                                    // checking whether all up hour doesnot exceed task mail hour limit
                                    if (totalHourSpented <= Convert.ToInt32(_stringConstant.TaskMailMaximumTime))
                                    {
                                        taskDetails.Hours = hour;
                                        userAndTaskMailDetailsWithAccessToken.QuestionText = nextQuestion.QuestionStatement;
                                        taskDetails.QuestionId = nextQuestion.Id;
                                    }
                                    else
                                    {
                                        // getting last question of task mail
                                        nextQuestion = await NextQuestionForTaskMailAsync(QuestionOrder.SendEmail);

                                        taskDetails.QuestionId = nextQuestion.Id;
                                        userAndTaskMailDetailsWithAccessToken.QuestionText = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
                                                                                                           _stringConstant.HourLimitExceed, Environment.NewLine, nextQuestion.QuestionStatement);
                                        taskDetails.Comment = _stringConstant.StartWorking;
                                    }
                                }
                                else
                                {
                                    // if previous question was hour of task and it was null or wrong value then answer will ask for hour again
                                    userAndTaskMailDetailsWithAccessToken.QuestionText = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
                                                                                                       _stringConstant.TaskMailBotHourErrorMessage, Environment.NewLine, previousQuestion.QuestionStatement);
                                }
                            }
                            else
                            {
                                // if previous question was hour of task and it was null or wrong value then answer will ask for hour again
                                userAndTaskMailDetailsWithAccessToken.QuestionText = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
                                                                                                   _stringConstant.TaskMailBotHourErrorMessage, Environment.NewLine, previousQuestion.QuestionStatement);
                            }
                        }
                        break;
                            #endregion

                            #region Status
                        case QuestionOrder.Status:
                        {
                            TaskMailStatus status;
                            // checking whether string can be convert to TaskMailStatus type or not
                            var taskMailStatusConvertResult = Enum.TryParse(answer, out status);
                            if (taskMailStatusConvertResult)
                            {
                                // if previous question was status of task and it was not null/wrong value then answer will ask next question
                                taskDetails.Status = status;
                                userAndTaskMailDetailsWithAccessToken.QuestionText = nextQuestion.QuestionStatement;
                                taskDetails.QuestionId = nextQuestion.Id;
                            }
                            else
                            {
                                // if previous question was status of task and it was null or wrong value then answer will ask for status again
                                userAndTaskMailDetailsWithAccessToken.QuestionText = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
                                                                                                   _stringConstant.TaskMailBotStatusErrorMessage,
                                                                                                   Environment.NewLine, previousQuestion.QuestionStatement);
                            }
                        }
                        break;
                            #endregion

                            #region Comment
                        case QuestionOrder.Comment:
                        {
                            if (answer != null)
                            {
                                // if previous question was comment of task and answer was not null/wrong value then answer will ask next question
                                taskDetails.Comment = answer;
                                userAndTaskMailDetailsWithAccessToken.QuestionText = nextQuestion.QuestionStatement;
                                taskDetails.QuestionId = nextQuestion.Id;
                            }
                            else
                            {
                                // if previous question was comment of task and answer was null or wrong value then answer will ask for comment again
                                userAndTaskMailDetailsWithAccessToken.QuestionText = previousQuestion.QuestionStatement;
                            }
                        }
                        break;
                            #endregion

                            #region Send Email
                        case QuestionOrder.SendEmail:
                        {
                            SendEmailConfirmation confirmation;
                            // checking whether string can be convert to TaskMailStatus type or not
                            var sendEmailConfirmationConvertResult = Enum.TryParse(answer, out confirmation);
                            if (sendEmailConfirmationConvertResult)
                            {
                                taskDetails.SendEmailConfirmation = confirmation;
                                switch (confirmation)
                                {
                                case SendEmailConfirmation.yes:
                                {
                                    // if previous question was send email of task and answer was yes then answer will ask next question
                                    taskDetails.QuestionId = nextQuestion.Id;
                                    userAndTaskMailDetailsWithAccessToken.QuestionText = nextQuestion.QuestionStatement;
                                }
                                break;

                                case SendEmailConfirmation.no:
                                {
                                    // if previous question was send email of task and answer was no then answer will say thank you and task mail stopped
                                    nextQuestion = await NextQuestionForTaskMailAsync(QuestionOrder.ConfirmSendEmail);

                                    taskDetails.QuestionId = nextQuestion.Id;
                                    userAndTaskMailDetailsWithAccessToken.QuestionText = _stringConstant.ThankYou;
                                }
                                break;
                                }
                            }
                            else
                            {
                                // if previous question was send email of task and answer was null/wrong value then answer will say thank you and task mail stopped
                                userAndTaskMailDetailsWithAccessToken.QuestionText = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
                                                                                                   _stringConstant.SendTaskMailConfirmationErrorMessage,
                                                                                                   Environment.NewLine, previousQuestion.QuestionStatement);
                            }
                        }
                        break;
                            #endregion

                            #region Confirm Send Email
                        case QuestionOrder.ConfirmSendEmail:
                        {
                            SendEmailConfirmation confirmation;
                            // checking whether string can be convert to TaskMailStatus type or not
                            var sendEmailConfirmationConvertResult = Enum.TryParse(answer, out confirmation);
                            if (sendEmailConfirmationConvertResult)
                            {
                                taskDetails.SendEmailConfirmation = confirmation;
                                userAndTaskMailDetailsWithAccessToken.QuestionText = _stringConstant.ThankYou;
                                switch (confirmation)
                                {
                                case SendEmailConfirmation.yes:
                                {
                                    EmailApplication email = new EmailApplication();
                                    email.To = new List <string>();
                                    email.CC = new List <string>();
                                    var listOfprojectRelatedToUser = (await _oauthCallsRepository.GetListOfProjectsEnrollmentOfUserByUserIdAsync(userAndTaskMailDetailsWithAccessToken.User.Id, userAndTaskMailDetailsWithAccessToken.AccessToken)).Select(x => x.Id).ToList();
                                    foreach (var projectId in listOfprojectRelatedToUser)
                                    {
                                        var mailsetting = await _mailSettingDetails.GetMailSettingAsync(projectId, _stringConstant.TaskModule, userAndTaskMailDetailsWithAccessToken.User.Id);

                                        email.To.AddRange(mailsetting.To);
                                        email.CC.AddRange(mailsetting.CC);
                                    }
                                    email.To      = email.To.Distinct().ToList();
                                    email.CC      = email.CC.Distinct().ToList();
                                    email.From    = userAndTaskMailDetailsWithAccessToken.User.Email;
                                    email.Subject = _stringConstant.TaskMailSubject;
                                    // transforming task mail details to template page and getting as string
                                    email.Body = _emailServiceTemplate.EmailServiceTemplateTaskMail(userAndTaskMailDetailsWithAccessToken.TaskList);
                                    // if previous question was confirm send email of task and it was not null/wrong value then answer will send email and reply back with thank you and task mail stopped
                                    taskDetails.QuestionId = nextQuestion.Id;
                                    // Email send
                                    if (email.To.Any())
                                    {
                                        _emailService.Send(email);
                                    }
                                }
                                break;

                                case SendEmailConfirmation.no:
                                {
                                    // if previous question was confirm send email of task and it was not null/wrong value then answer will say thank you and task mail stopped
                                    taskDetails.QuestionId = nextQuestion.Id;
                                }
                                break;
                                }
                            }
                            else
                            {
                                // if previous question was send email of task and it was null or wrong value then it will ask for send task mail confirm again
                                userAndTaskMailDetailsWithAccessToken.QuestionText = string.Format(_stringConstant.FirstSecondAndThirdIndexStringFormat,
                                                                                                   _stringConstant.SendTaskMailConfirmationErrorMessage,
                                                                                                   Environment.NewLine, previousQuestion.QuestionStatement);
                            }
                        }
                        break;
                            #endregion

                            #region Default
                        default:
                            userAndTaskMailDetailsWithAccessToken.QuestionText = _stringConstant.RequestToStartTaskMail;
                            break;
                            #endregion
                        }
                        _taskMailDetailRepository.Update(taskDetails);
                        await _taskMailDetailRepository.SaveChangesAsync();
                    }
                }
                else
                {
                    userAndTaskMailDetailsWithAccessToken.QuestionText = _stringConstant.RequestToStartTaskMail;
                }
            }
            return(userAndTaskMailDetailsWithAccessToken.QuestionText);
        }
        /// <summary>
        /// Private method to get reply text and send to team leader and management
        /// </summary>
        /// <param name="userId">User's user Id</param>
        /// <param name="leaveRequest">LeaveRequest object</param>
        /// <param name="accessToken">User's OAuth access token</param>
        /// <param name="attachment">Attachment to be send to team leader and management</param>
        private async Task GetAttachmentAndSendToTLAndManagementAsync(string userId, LeaveRequest leaveRequest, string accessToken, List <SlashAttachment> attachment)
        {
            EmailApplication email = new EmailApplication();

            email.To = new List <string>();
            email.CC = new List <string>();
            var listOfprojectRelatedToUser = (await _oauthCallRepository.GetListOfProjectsEnrollmentOfUserByUserIdAsync(userId, accessToken)).Select(x => x.Id).ToList();

            _logger.Debug("GetAttachmentAndSendToTLAndManagementAsync List of project, user has enrollement : " + listOfprojectRelatedToUser.Count);
            foreach (var projectId in listOfprojectRelatedToUser)
            {
                var mailsetting = await _mailSettingDetails.GetMailSettingAsync(projectId, _stringConstant.LeaveModule, userId);

                email.To.AddRange(mailsetting.To);
                email.CC.AddRange(mailsetting.CC);
            }
            _logger.Debug("GetAttachmentAndSendToTLAndManagementAsync List of To : " + email.To.Count);
            _logger.Debug("GetAttachmentAndSendToTLAndManagementAsync List of CC : " + email.CC.Count);
            email.To = email.To.Distinct().ToList();
            email.CC = email.CC.Distinct().ToList();
            var teamLeaderIds = (await _oauthCallRepository.GetTeamLeaderUserIdAsync(userId, accessToken)).Select(x => x.Id).ToList();

            _logger.Debug("GetAttachmentAndSendToTLAndManagementAsync List of team leaders : " + teamLeaderIds.Count);
            var managementIds = (await _oauthCallRepository.GetManagementUserNameAsync(accessToken)).Select(x => x.Id).ToList();

            _logger.Debug("GetAttachmentAndSendToTLAndManagementAsync List of managements : " + managementIds.Count);
            var userEmail = (await _userManager.FindByIdAsync(userId)).Email;

            teamLeaderIds.AddRange(managementIds);
            foreach (var teamLeaderId in teamLeaderIds)
            {
                var user = await _userManager.FindByIdAsync(teamLeaderId);

                if (user != null)
                {
                    _logger.Debug("GetAttachmentAndSendToTLAndManagementAsync Team leader user name : " + user.UserName);
                    var slackUser = await _slackUserRepository.GetByIdAsync(user.SlackUserId);

                    if (slackUser != null)
                    {
                        _logger.Debug("GetAttachmentAndSendToTLAndManagementAsync Slack details of team leader : " + slackUser.Name);
                        var incomingWebHook = await _incomingWebHook.FirstOrDefaultAsync(x => x.UserId == user.SlackUserId);

                        //Creating an object of SlashIncomingWebhook as this format of value required while responsing to slack
                        var slashIncomingWebhookText = new SlashIncomingWebhook()
                        {
                            Channel = _stringConstant.AtTheRate + slackUser.Name, Username = _stringConstant.LeaveBot, Attachments = attachment
                        };
                        var slashIncomingWebhookJsonText = JsonConvert.SerializeObject(slashIncomingWebhookText);
                        if (incomingWebHook != null)
                        {
                            await _httpClientService.PostAsync(incomingWebHook.IncomingWebHookUrl, slashIncomingWebhookJsonText, _stringConstant.JsonContentString, null, null);
                        }
                    }
                }
            }
            if (email.To.Any())
            {
                if (leaveRequest.EndDate != null)
                {
                    // creating email templates corresponding to leave applied for casual leave
                    email.Body = _emailTemplateRepository.EmailServiceTemplate(leaveRequest);
                }
                else
                {
                    // creating email templates corresponding to leave applied for casual leave
                    email.Body = _emailTemplateRepository.EmailServiceTemplateSickLeave(leaveRequest);
                }
                email.From    = userEmail;
                email.Subject = _stringConstant.EmailSubject;
                _emailService.Send(email);
                _logger.Debug("GetAttachmentAndSendToTLAndManagementAsync Email send successfullt");
            }
        }