public UserDetails GetloggedUser(string userId = "", string emailId = "")
        {
            var token = _httpContextAccessor?.HttpContext?.GetTokenAsync("access_token")?.Result;

            string url = _config.Value.UserServiceUrl + "getUser";

            if (userId != "")
            {
                url += "/" + userId;
            }
            if (emailId != "")
            {
                url += "/" + emailId;
            }

            ServiceRequest request = new ServiceRequest
            {
                Url                 = url,
                ContentType         = "application/json",
                HttpMethod          = "GET",
                AuthorizationHeader = token
            };
            var webRequest = _serviceHelper.CreateWebRequest(request);
            BaseHttpResponse webResponse = _serviceHelper.HandleRequest(webRequest);

            if (webResponse.HttpStatusCode == HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <UserDetails>(webResponse.Description));
            }

            _log.LogError(webResponse.Description);

            return(new UserDetails());
        }
        public void SaveFeedbackReply(FeedbackReply feedbackReply)
        {
            ServiceRequest request = new ServiceRequest
            {
                Url                 = _config.Value.FeedbackServiceUrl + "saveFeedbackReply",
                ContentType         = "application/json",
                HttpMethod          = "POST",
                Request             = JsonConvert.SerializeObject(feedbackReply),
                AuthorizationHeader = _httpContextAccessor.HttpContext.GetTokenAsync("access_token")?.Result
            };
            var webRequest = _serviceHelper.CreateWebRequest(request);
            BaseHttpResponse webResponse = _serviceHelper.HandleRequest(webRequest);

            if (webResponse.HttpStatusCode != HttpStatusCode.OK)
            {
                _log.LogError(webResponse.Description);
            }
        }
예제 #3
0
        public void GetloggedUser_ReturnsUserDetail()
        {
            //Arrange

            var baseHttpResponse = new BaseHttpResponse
            {
                HttpStatusCode = HttpStatusCode.OK,
                Description    = "{Id:1,'UserId':'sample'}"
            };
            Mock <HttpRequest> request = new Mock <HttpRequest>();

            request.Setup(x => x.Headers).Returns(new HeaderDictionary());
            _mockHttpContext.Setup(x => x.Request).Returns(request.Object);

            Mock <IAuthenticationService> auth    = new Mock <IAuthenticationService>();
            Mock <IServiceProvider>       service = new Mock <IServiceProvider>();

            service.Setup(x => x.GetService(It.IsAny <Type>())
                          ).Returns(auth.Object
                                    );

            _mockHttpContext.Setup(x => x.RequestServices).Returns(
                service.Object);

            _mokhttpContextAccessor.Setup(_ => _.HttpContext).Returns(
                _mockHttpContext.Object
                );

            var settings = new ServiceSettings {
                UserServiceUrl = "http://localhost:8080/users/"
            };
            var serviceResponse = (HttpWebRequest)WebRequest.Create(new Uri(settings.UserServiceUrl + "getUser"));

            _mokconfig.Setup(s => s.Value).Returns(settings);
            _mokserviceHelper.Setup(s => s.CreateWebRequest(It.IsAny <ServiceRequest>())).Returns(serviceResponse);
            _mokserviceHelper.Setup(s => s.HandleRequest(serviceResponse)).Returns(baseHttpResponse);

            //Act
            _userAdapter = new UserAdapter(_mokserviceHelper.Object, _mokconfig.Object, _moklog.Object, _mokhttpContextAccessor.Object);
            var actual = _userAdapter.GetloggedUser("anuth", "anuth");

            //Assert
            Assert.AreEqual("sample", actual.UserId);
        }
        public void SaveFeedbackQuestionTest()
        {
            //Arrange
            var feedBack         = new Feedback();
            var baseHttpResponse = new BaseHttpResponse
            {
                HttpStatusCode = HttpStatusCode.OK
            };
            Mock <HttpRequest> request = new Mock <HttpRequest>();

            request.Setup(x => x.Headers).Returns(new HeaderDictionary());
            _mockHttpContext.Setup(x => x.Request).Returns(request.Object);

            Mock <IAuthenticationService> auth    = new Mock <IAuthenticationService>();
            Mock <IServiceProvider>       service = new Mock <IServiceProvider>();

            service.Setup(x => x.GetService(It.IsAny <Type>())
                          ).Returns(auth.Object
                                    );

            _mockHttpContext.Setup(x => x.RequestServices).Returns(
                service.Object);

            _mokhttpContextAccessor.Setup(_ => _.HttpContext).Returns(
                _mockHttpContext.Object
                );
            var settings = new ServiceSettings {
                FeedbackServiceUrl = "http://localhost:8080/Feedback/"
            };
            var serviceResponse = (HttpWebRequest)WebRequest.Create(new Uri(settings.FeedbackServiceUrl + "saveFeedbackQuestion"));

            _mokconfig.Setup(s => s.Value).Returns(settings);
            _mokserviceHelper.Setup(s => s.CreateWebRequest(It.IsAny <ServiceRequest>())).Returns(serviceResponse);
            _mokserviceHelper.Setup(s => s.HandleRequest(serviceResponse)).Returns(baseHttpResponse);

            //Act
            _feedbackAdapter = new FeedbackAdapter(_mokserviceHelper.Object, _mokconfig.Object, _moklog.Object, _mokhttpContextAccessor.Object);
            _feedbackAdapter.SaveFeedbackQuestion(feedBack);

            //Assert
            _mokserviceHelper.Verify(s => s.CreateWebRequest(It.IsAny <ServiceRequest>()));
            _mokserviceHelper.Verify(s => s.HandleRequest(serviceResponse));
        }
        public List <UserDetails> GetUsersByRole(string role)
        {
            var token = _httpContextAccessor?.HttpContext?.GetTokenAsync("access_token")?.Result;

            ServiceRequest request = new ServiceRequest
            {
                Url                 = _config.Value.UserServiceUrl + "getUsersByRole/" + role,
                ContentType         = "application/json",
                HttpMethod          = "GET",
                AuthorizationHeader = token
            };
            var webRequest = _serviceHelper.CreateWebRequest(request);
            BaseHttpResponse webResponse = _serviceHelper.HandleRequest(webRequest);

            if (webResponse.HttpStatusCode == HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <List <UserDetails> >(webResponse.Description));
            }

            _log.LogError(webResponse.Description);

            return(new List <UserDetails>());
        }
        public long GetNotificationsCount(string userid)
        {
            var token = _httpContextAccessor?.HttpContext?.GetTokenAsync("access_token")?.Result;

            ServiceRequest request = new ServiceRequest
            {
                Url                 = _config.Value.FeedbackServiceUrl + "getNotificationsCount/" + userid,
                ContentType         = "application/json",
                HttpMethod          = "GET",
                AuthorizationHeader = token
            };
            var webRequest = _serviceHelper.CreateWebRequest(request);
            BaseHttpResponse webResponse = _serviceHelper.HandleRequest(webRequest);

            if (webResponse.HttpStatusCode == HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <long>(webResponse.Description));
            }

            _log.LogError(webResponse.Description);

            return(0);
        }