public void AuthenticateTest_MobileDeviceError() { GetProfileResponse response = new GetProfileResponse() { Credentials = new Credentials.AccessCredentials(), CustomerProfileObject = new CustomerProfile() }; authMock.Setup(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>())).Returns(response); ResponseBase res = new ResponseBase() { ErrorList = new HashSet <Fault>() { new Fault("", "", "") } }; RESTAPIAuthCredentials req = new RESTAPIAuthCredentials() { DeviceToken = "SDILASNP", Platform = "platform" }; RESTAPILoginResponse expectedResponse = acontroler.Authenticate(req); Assert.IsTrue(expectedResponse.ErrorList.Count == 0); authMock.Verify(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>()), Times.Once); }
public void AuthenticateTest_EmptyOrNullDevicetoken() { GetProfileResponse response = new GetProfileResponse() { Credentials = new Credentials.AccessCredentials(), CustomerProfileObject = new CustomerProfile() { ActiveHealth = true } }; authMock.Setup(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>())).Returns(response); ResponseBase res = new ResponseBase(); RESTAPIAuthCredentials req = new RESTAPIAuthCredentials() { Platform = "ios" }; RESTAPILoginResponse expectedResponse = acontroler.Authenticate(req); Assert.IsTrue(expectedResponse.ErrorList.Count == 1); Assert.IsNotNull(expectedResponse.ErrorList.Where(x => x.ReturnCode == Faults.EmptyOrNullDevicetoken.ReturnCode)); }
public void AuthenticateTest() { GetProfileResponse response = new GetProfileResponse() { Credentials = new Credentials.AccessCredentials(), CustomerProfileObject = new CustomerProfile() { ActiveHealth = true } }; authMock.Setup(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>())).Returns(response); ResponseBase res = new ResponseBase(); RESTAPIAuthCredentials req = new RESTAPIAuthCredentials() { DeviceToken = "SDILASNP", Platform = "platform" }; Assert.IsNotNull(acontroler.Authenticate(req)); authMock.Verify(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>()), Times.Once); }
public void RESTAPIAuthCredentialsTest_InvalidCredentials() { RESTAPIAuthCredentials ac = new RESTAPIAuthCredentials(); ResponseBase response = new ResponseBase(); Assert.IsFalse(ac.IsValid(response)); Assert.IsTrue(response.ErrorList.Count == 1); Assert.IsTrue(response.ErrorList.ElementAt(0).ReturnCode.Equals(Faults.InvalidCredentials.ReturnCode)); }
public RESTAPILoginResponse Authenticate(RESTAPIAuthCredentials req) { UserAuthenticationInterchange hppAuthInterchange = new UserAuthenticationInterchange() { CallerId = req.CallerId, LanguageCode = req.LanguageCode, CountryCode = req.CountryCode, Platform = req.Platform, ClientId = req.ClientId, UserId = req.UserId }; SetClientAppInfo(req.Platform, hppAuthInterchange); GetProfileResponse response = new GetProfileResponse(); if (SettingRepository.Get <bool>("TESTLoginEnabled", true)) { //response = HPIDUtils.GetCustomerProfileByTestLogin(hppAuthInterchange, false, APIMethods.None); response = HPIDUtils.GetCustomerProfileByDefaultUserLogin(response, hppAuthInterchange, false, APIMethods.None); } else { response = AuthUtils.GetCustomerProfileByAuthentication(hppAuthInterchange, false, req.AccessCode, req.RedirectUrl, APIMethods.POSTAuthenticate, req.ClientId); } RESTAPILoginResponse loginResponse = new RESTAPILoginResponse(); if (response.ErrorList.Count == 0) { loginResponse.UserID = response.Credentials.UserID; loginResponse.SessionToken = response.Credentials.SessionToken; loginResponse.CallerId = response.Credentials.CallerId; loginResponse.Roles = response.Credentials.Roles; loginResponse.Locale = response.CustomerProfileObject.Locale; loginResponse.FirstName = response.CustomerProfileObject.FirstName; loginResponse.LastName = response.CustomerProfileObject.LastName; loginResponse.Emailaddress = response.CustomerProfileObject.EmailAddress; loginResponse.Status = Enum.GetName(typeof(ResponseStatusType), ResponseStatusType.Success); //if (string.IsNullOrEmpty(req.DeviceToken)) //{ // loginResponse.ErrorList.Add(Faults.EmptyOrNullDevicetoken); //} if (response.LoginDate.HasValue) { //loginResponse.TimeOut = DateTimeFormatUtils.GetIso8601String(response.LoginDate.Value.AddMinutes(SettingRepository.Get<int>("MaxSessionTimeMinutes", 60))); } } else { loginResponse.Status = Enum.GetName(typeof(ResponseStatusType), ResponseStatusType.Failure); loginResponse.ErrorList = response.ErrorList; } return(loginResponse); }
public void RESTAPIAuthCredentialsTest_Success() { RESTAPIAuthCredentials ac = new RESTAPIAuthCredentials(); ac.DeviceToken = "deviceToken"; ac.Platform = RESTAPIPlatform.web.ToString(); ac.AccessCode = "accessCode"; ac.RedirectUrl = "redirectUrl"; ac.CallerId = "callerId"; ac.Locale = "pt-BR"; ac.ClientViewer = "SANC"; ResponseBase response = new ResponseBase(); Assert.IsTrue(ac.IsValid(response)); Assert.IsTrue(response.ErrorList.Count == 0); }
public void RESTAPIAuthCredentialsTest_ValidLanguageAndCountryCode() { RESTAPIAuthCredentials ac = new RESTAPIAuthCredentials(); ac.DeviceToken = "deviceToken"; ac.Platform = RESTAPIPlatform.web.ToString(); ac.AccessCode = "accessCode"; ac.RedirectUrl = "redirectUrl"; ac.CallerId = "callerId"; ac.ClientViewer = "SANC"; var lc = "pt"; var cc = "BR"; ac.Locale = $"{lc}-{cc}"; ResponseBase response = new ResponseBase(); Assert.IsTrue(ac.IsValid(response)); Assert.IsTrue(ac.LanguageCode == lc); Assert.IsTrue(ac.CountryCode == cc); }
public void AuthenticateTest_PassingClientId() { GetProfileResponse response = new GetProfileResponse() { ErrorList = new HashSet <Fault>() { new Fault("", "", "") } }; authMock.Setup(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>())).Returns(response); RESTAPIAuthCredentials request = new RESTAPIAuthCredentials(); string clientId = "theClientId"; request.ClientId = clientId; RESTAPILoginResponse expectedResponse = acontroler.Authenticate(request); authMock.Verify(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.Is <string>(s => s == clientId)), Times.Once); }