public void GetCustomerProfileforHPIDTest_MissingRefreshToken() { CustomerHPIDUtils custUtils = new CustomerHPIDUtils(); TokenDetails sessionToken = new TokenDetails() { AccessToken = "accessToken", tokenScopeType = TokenScopeType.apiProfileGetCall }; hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>())). Callback((CustomerIds i, string u, GetProfileResponse r) => { r.ErrorList.Add(Faults.HPIDInvalidToken); }).Returns(false); User isaacUser = new User() { RefreshToken = null }; isacMock.Setup(x => x.GetRefreshToken(It.IsAny <string>(), It.IsAny <TokenDetails>())).Returns(isaacUser); GetProfileResponse response = custUtils.GetCustomerProfileforHPID(new UserAuthenticationInterchange(), sessionToken, false, It.IsAny <APIMethods>()); customerUtilsMock.Verify(x => x.UpdateLogoutDate(It.IsAny <ResponseBase>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); Assert.IsTrue(response.ErrorList.Count == 1); Assert.IsTrue(response.ErrorList.Contains(Faults.HPIDSessionTimeout)); }
public void GetCustomerProfileTest_InvalidIsacPrifile() { bool IsNewCustomer = true; CustomerHPIDUtils custUtils = new CustomerHPIDUtils(); TokenDetails sessionToken = new TokenDetails(); UserAuthenticationInterchange hppAuthInt = new UserAuthenticationInterchange() { ClientId = "hpsa9" }; User aProfile = new User() { EmailConsent = true }; List <RoleMapping> roleMappings = new List <RoleMapping>(); RoleMapping role = new RoleMapping(); role.RoleId = 1; role.RoleMappingId = 1; role.UserId = 1; role.CreatedDate = DateTime.UtcNow; roleMappings.Add(role); aProfile.RoleMappings = roleMappings; sessionToken.AccessToken = "sessionToken"; hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>())).Returns(true); isacMock.Setup(x => x.FindOrInsertHPIDProfile(It.IsAny <ResponseBase>(), It.IsAny <RequestFindOrInsertHPIDProfile>(), out IsNewCustomer)).Returns(aProfile); GetProfileResponse response = custUtils.GetCustomerProfileforHPID(hppAuthInt, sessionToken, false, It.IsAny <APIMethods>()); Assert.IsTrue(response.ErrorList.Count == 1); Assert.IsTrue(IsNewCustomer); }
public void CreateCustomerProfileTest_MissingSessionToken() { CustomerHPIDUtils custUtils = new CustomerHPIDUtils(); TokenDetails sessionToken = new TokenDetails(); GetProfileResponse response = custUtils.GetCustomerProfileforHPID(null, sessionToken, false, It.IsAny <APIMethods>()); Assert.IsTrue(response.ErrorList.Contains(Faults.InvalidCredentials)); }
public void GetCustomerProfileforHPIDTest_Success() { CustomerHPIDUtils custUtils = new CustomerHPIDUtils(); User isaacUser = new User() { UserId = 120034, RefreshToken = "refreshToken", RefreshTokenType = 1, ActiveHealth = true, EmailConsent = true, PrimaryUse = PrimaryUseType.Item003.ToString() }; isacMock.Setup(x => x.GetRefreshToken(It.IsAny <string>(), It.IsAny <TokenDetails>())).Returns(isaacUser); TokenDetails sessionToken = new TokenDetails() { AccessToken = "expiredAccessToken", tokenScopeType = TokenScopeType.apiProfileGetCall }; hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>())). Callback((CustomerIds i, string u, GetProfileResponse r) => { r.ErrorList.Add(Faults.HPIDInvalidToken); }).Returns(false); queryUtilsMock.Setup(x => x.GetHPPToken(It.IsAny <IIdeaDatabaseDataContext>(), It.IsAny <int>(), It.IsAny <string>())). Returns(new UserAuthentication() { UserId = 123, ClientId = "Test" }); TokenDetails refreshToken = new TokenDetails() { AccessToken = "newAccessToken" }; hpidUtilsMock.Setup(x => x.GetHPIDSessionToken(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ResponseBase>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(refreshToken); hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsIn <string>(refreshToken.AccessToken), It.IsAny <GetProfileResponse>())). Callback((CustomerIds i, string u, GetProfileResponse r) => { r.CustomerProfileObject = new CustomerProfile(); }).Returns(true); GetProfileResponse response = custUtils.GetCustomerProfileforHPID(new UserAuthenticationInterchange(), sessionToken, It.IsAny <bool>(), It.IsAny <APIMethods>()); hpidUtilsMock.Verify(x => x.GetHPIDSessionToken(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ResponseBase>(), It.Is <string>(y => y == "Test"), It.IsAny <int>()), Times.Once); Assert.IsTrue(response.ErrorList.Count == 0); Assert.IsTrue(response.CustomerProfileObject.ActiveHealth == isaacUser.ActiveHealth); Assert.IsTrue(response.CustomerProfileObject.EmailConsent == EmailConsentType.Y.ToString()); }
public void GetCustomerProfileTest_IsacPrifileThrowsException() { bool IsNewCustomer = false; CustomerHPIDUtils custUtils = new CustomerHPIDUtils(); TokenDetails sessionToken = new TokenDetails(); sessionToken.AccessToken = "sessionToken"; hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>())).Returns(true); isacMock.Setup(x => x.FindOrInsertHPIDProfile(It.IsAny <ResponseBase>(), It.IsAny <RequestFindOrInsertHPIDProfile>(), out IsNewCustomer)).Throws(new Exception()); GetProfileResponse response = custUtils.GetCustomerProfileforHPID(null, sessionToken, false, It.IsAny <APIMethods>()); Assert.IsTrue(response.ErrorList.Count == 1); Assert.IsTrue(response.ErrorList.First().ReturnCode.Equals("GetCustomerProfileFailed")); }
public void CreateCustomerProfileTest_HPIDconnectionFailure() { CustomerHPIDUtils custUtils = new CustomerHPIDUtils(); TokenDetails sessionToken = new TokenDetails(); sessionToken.AccessToken = "sessionToken"; hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>())). Callback((CustomerIds i, string s, GetProfileResponse r) => { r.ErrorList.Add(Faults.HPIDInternalError); }).Returns(false); GetProfileResponse response = custUtils.GetCustomerProfileforHPID(null, sessionToken, false, It.IsAny <APIMethods>()); Assert.IsTrue(response.ErrorList.Contains(Faults.HPIDInternalError)); }
public void GetCustomerProfileforHPIDTest_SessionTokenExpired() { CustomerHPIDUtils custUtils = new CustomerHPIDUtils(); TokenDetails sessionToken = new TokenDetails() { AccessToken = "accessToken", tokenScopeType = TokenScopeType.apiProfileGetByTokenCall }; hpidUtilsMock.Setup(x => x.GetIdsAndProfile(It.IsAny <CustomerIds>(), It.IsAny <string>(), It.IsAny <GetProfileResponse>())). Callback((CustomerIds i, string u, GetProfileResponse r) => { r.ErrorList.Add(Faults.HPIDInvalidToken); }).Returns(false); GetProfileResponse response = custUtils.GetCustomerProfileforHPID(null, sessionToken, It.IsAny <bool>(), It.IsAny <APIMethods>()); Assert.IsTrue(response.ErrorList.Count == 1); Assert.IsTrue(response.ErrorList.Contains(Faults.InvalidCredentials)); }