Exemple #1
0
        public void Authentication_HrApi_Pass_Return200()
        {
            //Arrage
            string empid    = "TEST";
            string password = "******";

            HttpCallResult httpCallResult = new HttpCallResult
            {
                StatusCode    = "200",
                FaultInfo     = null,
                ReturnContent = "[{\"NAME_AC\": \"ESURENA RACHEL DOMINGUEZ\",\"Z_SITE_ID\": \"WIH\",\"status\": true}]"
            };

            _restfulApiClient.Post(Arg.Any <string>(), Arg.Any <Dictionary <string, string> >(), Arg.Any <string>()).Returns(httpCallResult);

            HrIdentityResponse expectedResponse = new HrIdentityResponse
            {
                Name_Ac   = "ESURENA RACHEL DOMINGUEZ",
                Z_Site_ID = "WIH",
                Status    = true
            };

            //Act
            HrIdentityResponse actualResponse = _targetObj.Authentication(empid, password);

            //Assert
            Assert.AreEqual(expectedResponse.Name_Ac, actualResponse.Name_Ac);
            Assert.AreEqual(expectedResponse.Z_Site_ID, actualResponse.Z_Site_ID);
            Assert.AreEqual(expectedResponse.Status, actualResponse.Status);
        }
Exemple #2
0
        public void RestfulApiClient_Post_Return_StatusCode_200()
        {
            //Arrange
            string url         = "https://portalapp-dev.wistron.com/api/Test/FakeAPComment";
            string contentBody = "{}";

            HttpCallResult expectedResponse = new HttpCallResult
            {
                FaultInfo     = null,
                ReturnContent = null,
                StatusCode    = "200"
            };

            //Act
            HttpCallResult actualResponse = _targetObj.Post(url, _header, contentBody);

            //Assert
            Assert.AreEqual(expectedResponse.FaultInfo, actualResponse.FaultInfo);
            Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode);
        }
Exemple #3
0
        /// <summary>
        /// 已知格式 status 200 登入成功: [{"NAME_AC":"ESURENA RACHEL DOMINGUEZ","Z_SITE_ID":"WIH","status":true}]
        /// status 200 登入失敗  :  [{"status":false}]
        /// status 401 : {"error":{"statusCode":401,"name":"Error","message":"Authorization Required","code":"AUTHORIZATION_REQUIRED"}}
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public HrIdentityResponse Authentication(string empid, string password)
        {
            try
            {
                //http://{endpoint}/hrapi_external/portal_dlemp
                string url = $"{_config.Hr.BaseUrl}{"/"}{_config.Hr.IdentityCertificationPath}";

                //none header attbibutes
                Dictionary <string, string> headers = new Dictionary <string, string>();

                HrIdentityRequest hrIdentityRequest = new HrIdentityRequest
                {
                    account       = _config.Hr.Account,
                    password      = _config.Hr.PassWord,
                    emplid        = empid,
                    user_password = password
                };

                string jsonStr = JsonConvert.SerializeObject(hrIdentityRequest, Formatting.Indented);

                HttpCallResult result = _restfulApiClient.Post(url, headers, jsonStr);

                if (result.StatusCode == "200" || result.StatusCode == "201")
                {
                    List <HrIdentityResponse> hrIdentityResponses = JsonConvert.DeserializeObject <List <HrIdentityResponse> >(result.ReturnContent);
                    if (hrIdentityResponses != null)
                    {
                        //已知格式
                        return(hrIdentityResponses.FirstOrDefault());
                    }
                    else
                    {
                        //如果拿到不適預期的格式一律給驗證錯誤
                        return new HrIdentityResponse {
                                   Name_Ac = "", Z_Site_ID = "", Status = false
                        }
                    };
                }
                else//status 401 or another
                {
                    return new HrIdentityResponse {
                               Name_Ac = "", Z_Site_ID = "", Status = false
                    }
                };
            }
            catch (Exception ex)
            {
                var exception = new Exception("Invoke HR API Exception:::Authentication", ex);
                throw exception;
            }
        }