Example #1
0
        private void GetResponseStreamHelper(AsyncRestHandler handler, HttpWebRequest request, bool generatesException = false)
        {
            IdsException exception = null;

            byte[] response = new byte[0];
            handler.OnCallCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    response = e.ByteResult;
                }
                else
                {
                    exception = e.Error;
                }
            };

            handler.GetResponseStream(request);
            System.Threading.Thread.Sleep(10000);
            if (exception != null)
            {
                if (!generatesException)
                {
                    //Assert.Fail(exception.ToString());
                    throw exception;
                }
            }
            else
            {
                Assert.IsTrue(response.Length > 0);
            }
        }
Example #2
0
        private void GetResponseHelper(AsyncRestHandler handler, HttpWebRequest request, bool generatesException = false)
        {
            IdsException exception = null;
            string       response  = null;

            handler.OnCallCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    response = e.Result;
                }
                else
                {
                    exception = e.Error;
                }
            };

            handler.GetResponse(request);
            System.Threading.Thread.Sleep(10000);
            if (exception != null)
            {
                if (!generatesException)
                {
                    Assert.Fail(exception.ToString());
                }
            }
            else
            {
                Assert.IsTrue(!string.IsNullOrWhiteSpace(response));
            }
        }
Example #3
0
        /// <summary>
        /// Gets entitlements against a specified realm. The realm must be set in the context.
        /// </summary>
        /// <param name="entitlementBaseUrl">Base Url of the Entitlements API for OAuth1 vs OAuth2. Default is set to OAuth2 prod environment</param>
        /// <returns>Returns EntitlementsResponse</returns>
        public void GetEntitlementsAsync(string entitlementBaseUrl = Utility.CoreConstants.ENTITLEMENT_BASEURL)
        {
            Console.Write("GetEntitlementsAsync started \n");
            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Called Method GetEntitlements Asynchronously.");
            AsyncRestHandler asyncRestHandler = new AsyncRestHandler(this.serviceContext);

            asyncRestHandler.OnCallCompleted += new EventHandler <AsyncCallCompletedEventArgs>(this.GetEntitlementsAsyncCompleted);

            EntitlementCallCompletedEventArgs <Intuit.Ipp.Data.EntitlementsResponse> entitlementCallCompletedEventArgs = new EntitlementCallCompletedEventArgs <Intuit.Ipp.Data.EntitlementsResponse>();

            try
            {
                string uri = string.Format(CultureInfo.InvariantCulture, "{0}/entitlements/{1}/{2}", entitlementBaseUrl, Utility.CoreConstants.VERSION, serviceContext.RealmId);

                orginialSerializationFormat = this.serviceContext.IppConfiguration.Message.Response.SerializationFormat;
                // Only XML format is supported by Entitlements API
                serviceContext.IppConfiguration.Message.Response.SerializationFormat = Core.Configuration.SerializationFormat.Xml;
                // Creates request parameters
                RequestParameters parameters = new RequestParameters(uri, HttpVerbType.GET, Utility.CoreConstants.CONTENTTYPE_APPLICATIONXML);

                HttpWebRequest request = asyncRestHandler.PrepareRequest(parameters, null, uri);
                asyncRestHandler.GetResponse(request);
            }
            catch (SystemException systemException)
            {
                this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, systemException.Message);
                IdsException idsException = new IdsException(systemException.Message);
                entitlementCallCompletedEventArgs.Error = idsException;
                this.OnGetEntilementAsyncCompleted(this, entitlementCallCompletedEventArgs);
            }
        }
Example #4
0
        public void GetResponseSuccessTest()
        {
            ServiceContext   serviceContext = Initializer.InitializeServiceContextQbo();
            AsyncRestHandler handler        = new AsyncRestHandler(serviceContext);
            string           query          = "select * from Account startPosition 1 maxResults 10";
            string           resourceUri    = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/query", CoreConstants.VERSION, serviceContext.RealmId);

            RequestParameters parameters = new RequestParameters(resourceUri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONTEXT);
            HttpWebRequest    request    = handler.PrepareRequest(parameters, query);

            this.GetResponseHelper(handler, request);
        }
Example #5
0
        public void GetResponseWithRetryPolicySuccessTest()
        {
            ServiceContext serviceContext = Initializer.InitializeServiceContextQbo();

            serviceContext.IppConfiguration.RetryPolicy = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(2));
            AsyncRestHandler  handler     = new AsyncRestHandler(serviceContext);
            string            AccountId   = "1";
            string            resourceUri = string.Format("v3/company/{0}/account/{1}", serviceContext.RealmId, AccountId);
            RequestParameters parameters  = new RequestParameters(resourceUri, HttpVerbType.GET, CoreConstants.CONTENTTYPE_TEXTXML);
            HttpWebRequest    request     = handler.PrepareRequest(parameters, null);

            this.GetResponseHelper(handler, request);
        }
Example #6
0
        public void GetResponseStreamSuccessTest()
        {
            ServiceContext      serviceContext = Initializer.InitializeServiceContextQbo();
            AsyncRestHandler    handler        = new AsyncRestHandler(serviceContext);
            List <SalesReceipt> salesReceipts  = Helper.FindAll <SalesReceipt>(serviceContext, new SalesReceipt());

            Assert.IsTrue(salesReceipts.Count > 0);
            string            resourceUri = string.Format("v3/company/{0}/salesreceipt/{1}/pdf", serviceContext.RealmId, salesReceipts[0].Id);
            RequestParameters parameters  = new RequestParameters(resourceUri, HttpVerbType.GET, CoreConstants.CONTENTTYPE_APPLICATIONXML);
            HttpWebRequest    request     = handler.PrepareRequest(parameters, null, includeRequestId: false);

            request.Accept = CoreConstants.CONTENTTYPE_APPLICATIONPDF;
            this.GetResponseStreamHelper(handler, request);
        }
        public void GetResponseInvalidTokenExceptionTest()
        {
            OAuthRequestValidator validator  = new OAuthRequestValidator("adfas", "afd", "adfas", "asdfa");
            string            realmId        = ConfigurationManager.AppSettings["RealmIAQBO"];
            ServiceContext    serviceContext = new ServiceContext(realmId, IntuitServicesType.QBO, validator);
            AsyncRestHandler  handler        = new AsyncRestHandler(serviceContext);
            string            resourceUri    = string.Format("v3/company/{0}/customer", serviceContext.RealmId);
            RequestParameters parameters     = new RequestParameters(resourceUri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONXML);

            Intuit.Ipp.Data.Customer customer = new Data.Customer();
            HttpWebRequest           request  = handler.PrepareRequest(parameters, customer);

            this.GetResponseHelper(handler, request, true);
        }
Example #8
0
        /// <summary>
        /// Executes a Report (asynchronously) under the specified realm in an asynchronous manner. The realm must be set in the context.
        /// </summary>
        /// <param name="reportName">Name of the Report to Run</param>
        /// <param name="reportsQueryParameters">Report Parameters for query string</param>
        public void ExecuteReportAsync(string reportName, string reportsQueryParameters)
        {
            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Called Method ExecuteReport Asynchronously.");
            AsyncRestHandler asyncRestHandler = new AsyncRestHandler(this.serviceContext);

            asyncRestHandler.OnCallCompleted += new EventHandler <AsyncCallCompletedEventArgs>(this.ExecuteReportAsynCompleted);
            ReportCallCompletedEventArgs <Report> reportCallCompletedEventArgs = new ReportCallCompletedEventArgs <Report>();
            string resourceString = reportName;

            try
            {
                // Builds resource Uri
                string uri = "";
                if (!string.IsNullOrEmpty(reportsQueryParameters))
                {
                    uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/reports/{2}?{3}", Utility.CoreConstants.VERSION, this.serviceContext.RealmId, resourceString, reportsQueryParameters);
                }
                else
                {
                    uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/reports/{2}", Utility.CoreConstants.VERSION, this.serviceContext.RealmId, resourceString);
                }

                // Create request parameters
                RequestParameters parameters;
                if (this.serviceContext.IppConfiguration.Message.Request.SerializationFormat == Intuit.Ipp.Core.Configuration.SerializationFormat.Json)
                {
                    parameters = new RequestParameters(uri, HttpVerbType.GET, Utility.CoreConstants.CONTENTTYPE_APPLICATIONJSON);
                }
                else
                {
                    parameters = new RequestParameters(uri, HttpVerbType.GET, Utility.CoreConstants.CONTENTTYPE_APPLICATIONXML);
                }

                // Prepare request
                HttpWebRequest request = asyncRestHandler.PrepareRequest(parameters, new Report());

                //// get response
                asyncRestHandler.GetResponse(request);
            }
            catch (SystemException systemException)
            {
                this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, systemException.Message);
                IdsException idsException = new IdsException(systemException.Message);
                reportCallCompletedEventArgs.Error = idsException;
                this.OnExecuteReportAsyncCompleted(this, reportCallCompletedEventArgs);
            }
        }
Example #9
0
        /// <summary>
        /// This method executes the batch request Asynchronously.
        /// </summary>
        public void ExecuteAsync()
        {
            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Started Executing Method ExecuteAsync for Batch");
            AsyncRestHandler asyncRestHandler = new AsyncRestHandler(this.serviceContext);

            asyncRestHandler.OnCallCompleted += new EventHandler <AsyncCallCompletedEventArgs>(this.BatchAsyncompleted);
            BatchExecutionCompletedEventArgs batchCompletedEventArgs = new BatchExecutionCompletedEventArgs();

            // Create Intuit Batch Request
            IntuitBatchRequest intuitBatchRequest = new IntuitBatchRequest();

            intuitBatchRequest.BatchItemRequest = this.batchRequests.ToArray <BatchItemRequest>();
            string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/batch", Utility.CoreConstants.VERSION, this.serviceContext.RealmId);

            // Creates request parameters
            RequestParameters parameters;

            if (this.serviceContext.IppConfiguration.Message.Request.SerializationFormat == Intuit.Ipp.Core.Configuration.SerializationFormat.Json)
            {
                parameters = new RequestParameters(uri, HttpVerbType.POST, Utility.CoreConstants.CONTENTTYPE_APPLICATIONJSON);
            }
            else
            {
                parameters = new RequestParameters(uri, HttpVerbType.POST, Utility.CoreConstants.CONTENTTYPE_APPLICATIONXML);
            }

            // Prepares request
            HttpWebRequest request = asyncRestHandler.PrepareRequest(parameters, intuitBatchRequest);

            try
            {
                // gets response
                asyncRestHandler.GetResponse(request);
            }
            catch (SystemException systemException)
            {
                IdsException idsException = new IdsException(systemException.Message);
                this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString());
                batchCompletedEventArgs.Error = idsException;
                this.OnBatchExecuteAsyncCompleted(this, batchCompletedEventArgs);
            }
        }
Example #10
0
        /// <summary>
        /// Adds an entity (asynchronously) under the specified realm in an asynchronous manner. The realm must be set in the context.
        /// </summary>
        /// <param name="entity">Entity to Add</param>
        public void AddTaxCodeAsync(Intuit.Ipp.Data.TaxService taxCode)
        {
            this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(Diagnostics.TraceLevel.Info, "Called Method Add Asynchronously.");
            AsyncRestHandler asyncRestHandler = new AsyncRestHandler(this.serviceContext);

            asyncRestHandler.OnCallCompleted += new EventHandler <AsyncCallCompletedEventArgs>(this.AddTaxCodeAsyncCompleted);
            GlobalTaxServiceCallCompletedEventArgs <Intuit.Ipp.Data.TaxService> taxServiceCallCompletedEventArgs = new GlobalTaxServiceCallCompletedEventArgs <Intuit.Ipp.Data.TaxService>();
            string resourceString = taxCode.GetType().Name.ToLower(CultureInfo.InvariantCulture);



            try
            {
                // Builds resource Uri
                string uri = string.Format(CultureInfo.InvariantCulture, "{0}/company/{1}/{2}/taxcode", CoreConstants.VERSION, this.serviceContext.RealmId, resourceString);

                // Create request parameters
                RequestParameters parameters;
                if (this.serviceContext.IppConfiguration.Message.Request.SerializationFormat == Intuit.Ipp.Core.Configuration.SerializationFormat.Json)
                {
                    parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONJSON);
                }
                else
                {
                    parameters = new RequestParameters(uri, HttpVerbType.POST, CoreConstants.CONTENTTYPE_APPLICATIONXML);
                }

                // Prepare request
                HttpWebRequest request = asyncRestHandler.PrepareRequest(parameters, taxCode);

                //// get response
                asyncRestHandler.GetResponse(request);
            }
            catch (SystemException systemException)
            {
                this.serviceContext.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, systemException.Message);
                IdsException idsException = new IdsException(systemException.Message);
                taxServiceCallCompletedEventArgs.Error = idsException;
                this.OnAddTaxCodeAsyncCompleted(this, taxServiceCallCompletedEventArgs);
            }
        }