Пример #1
0
        public void GetTeamLeaderUserName()
        {
            var teamLeaderResponse   = Task.FromResult(_stringConstant.TeamLeaderDetailsFromOauthServer);
            var teamLeaderRequestUrl = string.Format("{0}{1}", _stringConstant.TeamLeaderDetailsUrl, _stringConstant.FirstNameForTest);

            _mockHttpClient.Setup(x => x.GetAsync(_stringConstant.ProjectUserUrl, teamLeaderRequestUrl, _stringConstant.AccessTokenForTest)).Returns(teamLeaderResponse);
            string teamLeaderUsername = "";
            var    teamLeader         = _projectUserRepository.GetTeamLeaderUserName(_stringConstant.FirstNameForTest, _stringConstant.AccessTokenForTest).Result;

            foreach (var team in teamLeader)
            {
                teamLeaderUsername = team.Email;
            }
            Assert.Equal(teamLeaderUsername, _stringConstant.TeamLeaderEmailForTest);
        }
        /// <summary>
        /// Private method to get reply text and send to team leader and management
        /// </summary>
        /// <param name="username"></param>
        /// <param name="leaveRequest"></param>
        /// <param name="accessToken"></param>
        /// <param name="attachment"></param>
        /// <returns></returns>
        private async Task GetAttachmentAndSendToTLAndManagement(string username, LeaveRequest leaveRequest, string accessToken, List <SlashAttachment> attachment)
        {
            var teamLeaders = await _projectUser.GetTeamLeaderUserName(username, accessToken);

            var management = await _projectUser.GetManagementUserName(accessToken);

            var userDetail = await _projectUser.GetUserByUsername(username, accessToken);

            foreach (var user in management)
            {
                teamLeaders.Add(user);
            }
            foreach (var teamLeader in teamLeaders)
            {
                //Creating an object of SlashIncomingWebhook as this format of value required while responsing to slack
                var text = new SlashIncomingWebhook()
                {
                    Channel = "@" + teamLeader.SlackUserName, Username = _stringConstant.LeaveBot, Attachments = attachment
                };
                var textJson = JsonConvert.SerializeObject(text);
                WebRequestMethod(textJson, _envVariableRepository.IncomingWebHookUrl);
                EmailApplication email = new EmailApplication();
                // creating email templates corresponding to leave applied
                email.Body    = EmailServiceTemplate(leaveRequest);
                email.From    = userDetail.Email;
                email.Subject = _stringConstant.EmailSubject;
                email.To      = teamLeader.Email;
                _email.Send(email);
            }
        }