public void CanCreate_Using_ApiHelper_BadCredential_ThrowsWebServiceException() { var badCredential = new RqlCredential { Site = Credential.Site, UserName = "******", Password = "******" }; Assert.Throws <WebServiceException>(() => ApiHelper.CreateAuthenticatedBusinessApiClient(badCredential)); }
public void CanCreate_Using_AuthenticatedApiClientFactory_BadCredential_ReturnsNull() { var badCredential = new RqlCredential(Credential) { UserName = "******", Password = "******" }; var api = new AuthenticatedApiClientFactory() .CreateBusinessApiClient(badCredential); Assert.That(api, Is.Null); }
public void BaseFixtureSetup() { Credential = new RqlCredential { Site = ConfigurationManager.AppSettings["Site"], UserName = ConfigurationManager.AppSettings["UserName"], Password = ConfigurationManager.AppSettings["Password"] }; Assert.That(Credential.Site, Is.Not.Null.And.Not.Empty, "The app.config doesn't have a value for key=Site"); Assert.That(Credential.UserName, Is.Not.Null.And.Not.Empty, "The app.config doesn't have a value for key=UserName"); Assert.That(Credential.Password, Is.Not.Null.And.Not.Empty, "The app.config doesn't have a value for key=Password"); //will throw an exception if can't authenticate. ApiClient = ApiHelper.CreateAuthenticatedBusinessApiClient(Credential); }
/// <summary> /// This method will page through objects, providing a callback that receives the internal storeId. This storeId may /// be used to lookup an object, and updates performed on it. /// </summary> /// <param name="api">the API client instance</param> /// <param name="credential">the credential to use in case the API needs to be reauthenticated</param> /// <param name="appName">the name of the app objects are queried from</param> /// <param name="filter">a sql filter to limit the rows being processed</param> /// <param name="processObjectByStoreIdCallback"> /// a lamda that receives a storeId of the found Object. Use the storeId to /// get the object detail record via the API. /// </param> /// <returns>returns the # of objects iterated.</returns> protected static int IterateObjectsBasedOnFilter(IRqlBusinessApiClient api, RqlCredential credential, string appName, string filter, Action <string> processObjectByStoreIdCallback) { //Count the # of objects that match the filter //so we can page through the results. var numberOfObjects = api.CountObjects(new CountObjects { AppName = appName, Filter = filter }).Count; if (numberOfObjects == 0) { return(0); } //paging control variables: const int maxPageSize = 100; //could be bigger. var totalUpdated = 0; var pageIndex = 0; var pageSize = Math.Min(maxPageSize, numberOfObjects); bool moreToProcess; do { //reauthenticate periodically on long tasks ApiHelper.ReauthenticateIfNearingExpiration(api, credential); //get the current page full of users to update based on the filter var storeIds = api.ListObjects(new ListObjects { AppName = appName, Filter = filter, PageIndex = pageIndex, PageSize = pageSize }) .Items .Select(item => item.StoreId) .ToList(); var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Debugger.IsAttached ? 1 : Math.Min(Environment.ProcessorCount, 2) }; Parallel.ForEach(storeIds, parallelOptions, (storeId, loopState) => { //if (loopState.ShouldExitCurrentIteration) return; processObjectByStoreIdCallback(storeId); }); totalUpdated += storeIds.Count; moreToProcess = storeIds.Count == pageSize && totalUpdated < numberOfObjects; pageIndex++; } while (moreToProcess); return(numberOfObjects); }