Exemple #1
0
        public void Test_Post_CreateAddress_ByPL_Success()
        {
            string strPLorSLNumber = "PL0000799911";

            RAL.SAPCallManager objSAPCallManager = new RAL.SAPCallManager(_strBaseUrl);
            Model.SAP.Responses.CreateAddressResponse objCreateAddressResponse = objSAPCallManager.PostCreateAddressQueueItem(strPLorSLNumber);
            Assert.IsTrue(objCreateAddressResponse != null);
            Assert.IsTrue(objSAPCallManager.ErrorMessages.Count == 0);
            Assert.IsTrue(objSAPCallManager.HttpStatusCodeResult == System.Net.HttpStatusCode.OK);

            Assert.IsTrue(objCreateAddressResponse.ET_RETURN.Count() > 0);
            Assert.IsTrue(objCreateAddressResponse.PL_SL_CODE.Count() > 0);
            Assert.IsTrue(objCreateAddressResponse.PL_SL_CODE.Where(p => p.PL_SL_ID.Trim().ToUpper() == strPLorSLNumber.Trim().ToUpper()).Count() > 0);
        }
Exemple #2
0
        public void Test_Post_CreateAddress_ByPL_Success_NoSiteCodeInGLM_Test2()
        {
            //http://glmenv1.level3.com/GLMSWeb/Location/Details/PL0000713667

            string strPLorSLNumber = "PL0000713667";

            RAL.SAPCallManager objSAPCallManager = new RAL.SAPCallManager(_strBaseUrl);
            Model.SAP.Responses.CreateAddressResponse objCreateAddressResponse = objSAPCallManager.PostCreateAddressQueueItem(strPLorSLNumber);
            Assert.IsTrue(objCreateAddressResponse != null);
            Assert.IsTrue(objSAPCallManager.ErrorMessages.Count == 0);
            Assert.IsTrue(objSAPCallManager.HttpStatusCodeResult == System.Net.HttpStatusCode.OK);

            Assert.IsTrue(objCreateAddressResponse.ET_RETURN.Count() > 0);
            Assert.IsTrue(objCreateAddressResponse.PL_SL_CODE.Count() > 0);
            Assert.IsTrue(objCreateAddressResponse.PL_SL_CODE.Where(p => p.PL_SL_ID.Trim().ToUpper() == strPLorSLNumber.Trim().ToUpper()).Count() > 0);
        }
Exemple #3
0
        public Model.SAP.Responses.CreateAddressResponse PostCreateAddressQueueItem(string strPLNumber)
        {
            // Instantiate a stopwatch to write runtimes to a log file
            Stopwatch objStopWatch = new Stopwatch();

            objStopWatch.Start();

            Model.SAP.Responses.CreateAddressResponse objCreateAddressResponse = null;

            try
            {
                // Although this is a POST, it has no Content Body

                string strFinalRouteAndQueryString = String.Format("saml2={0}", "disabled");
                _strFinalRouteAndQueryString = String.Concat(_strRoute_CreateAddress, "?", strFinalRouteAndQueryString);

                Model.SAP.Requests.CreateAddressRequest objCreateAddressRequest = new Model.SAP.Requests.CreateAddressRequest();
                objCreateAddressRequest.PL_SL_CODE             = new Model.SAP.Requests.PL_SL_CODE[1];
                objCreateAddressRequest.PL_SL_CODE[0]          = new Model.SAP.Requests.PL_SL_CODE();
                objCreateAddressRequest.PL_SL_CODE[0].PL_SL_ID = strPLNumber;

                string strJsonContentString = Model.SerializationUtil.SerializeToJsonString(objCreateAddressRequest);

                // Initialize the objects used to POST the message to SAP
                HttpResponseMessage objHttpResponseMessage = null;
                using (_objHttpClient = new HttpClient())
                {
                    // Prep the http client object with the required http header info and endpoint
                    PrepHttpClient();

                    // Since this is a POST, which has a content body... create the http content body, and set the corresponding content-type header value
                    HttpContent objHttpContentBody = new StringContent(strJsonContentString);
                    objHttpContentBody.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    _objLogger.Debug(String.Concat("About to execute the post to SAP via REST.  Post Url = [", _strBaseUrl, "]"));



                    // Invoke the RESTful POST method
                    objHttpResponseMessage = _objHttpClient.PostAsync(_strFinalRouteAndQueryString, objHttpContentBody).Result;

                    _objLogger.Debug(String.Concat("Post Complete. Resulting Http Status Code = [", objHttpResponseMessage.StatusCode, "]"));

                    _httpStatusCodeResult = objHttpResponseMessage.StatusCode;

                    if (objHttpResponseMessage.IsSuccessStatusCode)
                    {
                        string strResult = objHttpResponseMessage.Content.ReadAsStringAsync().Result;
                        objCreateAddressResponse = Model.SerializationUtil.DeserializeFromJson <Model.SAP.Responses.CreateAddressResponse>(strResult);
                    }
                    else
                    {
                        string strErrorResult  = objHttpResponseMessage.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                        string strErrorMessage = String.Format("The HTTP response code received from SAP indicated failure.  The object returned to the caller will be null.  Http Response Code = [{0}], Http Content Body Received from SAP = [{1}]", objHttpResponseMessage.StatusCode, strErrorResult);

                        _objLogger.Warn(String.Format("The call to SAP failed.  An error message has been added to the list on this object. Error Message Added = [{0}]", strErrorMessage));

                        throw new Exception(strErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                _objLogger.Warn(String.Concat("There was an issue while trying to POST the CREATE ADDRESS request to SAP.  Error Message = [", ex.Message, "]"));
                _lstErrorMessages.Add(String.Format("Exception Message = [{0}].  INNER Exception Message = [{1}]", ex.Message, ex.InnerException.Message));
                objCreateAddressResponse = null;
            }


            // Stop the watch and log the call to the DB
            objStopWatch.Stop();
            TimeSpan objTimeSpan = objStopWatch.Elapsed;

            LogAPICallToDB(objTimeSpan);


            // Return the result
            return(objCreateAddressResponse);
        }