Ejemplo n.º 1
0
        public async Task GetUserRoleAsync()
        {
            await CreateUserAndMockingHttpContextToReturnAccessToken();

            var response   = Task.FromResult(_stringConstant.TaskMailReport);
            var requestUrl = string.Format(_stringConstant.FirstAndSecondIndexStringFormat, _stringConstant.EmailForTest, _stringConstant.UserRoleUrl);

            _mockHttpClient.Setup(x => x.GetAsync(_stringConstant.UserUrl, requestUrl, _stringConstant.AccessTokenForTest, _stringConstant.Bearer)).Returns(response);
            var userRole = await _oauthCallHttpContextRepository.GetUserRoleAsync(_stringConstant.EmailForTest);

            Assert.Equal(3, userRole.Count);
        }
        /// <summary>
        ///Method geting Employee or list of Employees
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>list of task mail report</returns>
        public async Task <List <TaskMailReportAc> > GetUserInformationAsync(string userId)
        {
            List <TaskMailReportAc> taskMailReportAcList = new List <TaskMailReportAc>();
            var user = await _userRepository.FirstAsync(x => x.Id == userId);

            //getting user information from Promact Oauth Server.
            _logger.Info("Getting user information from oauth server");
            List <UserRoleAc> userRoleAcList = await _oauthCallsRepository.GetUserRoleAsync(user.Id);

            var userInformation = userRoleAcList.First(x => x.UserName == user.UserName);

            if (userInformation.Role == _stringConstant.RoleAdmin)
            {
                //if user is admin then remove from user list. because admin dose not have any taks mail.
                userRoleAcList.Remove(userInformation);
            }
            foreach (var userRole in userRoleAcList)
            {
                TaskMailReportAc taskMailReportAc = new TaskMailReportAc(userRole.UserId, userRole.Role, userRole.Name, userEmail: userRole.UserName);
                taskMailReportAcList.Add(taskMailReportAc);
            }
            _logger.Debug("Task Report List");
            return(taskMailReportAcList);
        }