Exemple #1
0
        public void GetFeed_WhereServiceIsAvailable_ReturnsValues()
        {
            var url  = ConfigurationManager.AppSettings["currenciesGatewayUrl"];
            var feed = APIUtilities.Get(url);

            Assert.IsTrue(feed.Length > 0);
        }
Exemple #2
0
        public void GetAll_WhereQuoationsExists_ReturnsMoreThanZero()
        {
            var url    = ConfigurationManager.AppSettings["quotesGatewayUrl"];
            var quotes = APIUtilities.Get(url);

            Assert.IsTrue(quotes.Length > 0);
        }
Exemple #3
0
        public void PostGenerate_WhereServiceIsAvailable_ReturnsValues()
        {
            var request = new QuoteRequest
            {
                Name = "MONO"
            };

            var url  = ConfigurationManager.AppSettings["quotesGatewayUrl"];
            var feed = APIUtilities.Post(request, url);

            Assert.IsTrue(feed.Length > 0);
        }
Exemple #4
0
 internal static void sendRequest(string request)
 {
     if (request.Equals("Post"))
     {
         APIUtilities.sendPostRequest();
     }
     else if (request.Equals("UnauthorizedPost"))
     {
         //send Postman Request with wrong Password
         APIUtilities.sendUnauthorizedPostReq();
     }
 }
Exemple #5
0
        public CurrencyFeed GetFeed()
        {
            var feedString = APIUtilities.Get("http://www.apilayer.net/api/live?access_key=4633a6c0baf8136ca5b9d56a09cce755");

            return(JsonConvert.DeserializeObject <CurrencyFeed>(feedString));
        }
Exemple #6
0
 internal static void fetchValFromResp(string jsonKey, string keyVal)
 {
     APIUtilities.fetchValFromJsonResp(jsonKey, keyVal);
 }
Exemple #7
0
 internal static void createRequest(string paymentNo, string amount)
 {
     APIUtilities.createJsonRequest(paymentNo, amount);
 }
Exemple #8
0
 internal static void fetchCustPayDt()
 {
     APIUtilities.fetchsetCustPayDt();
 }
Exemple #9
0
 internal static void setUrl(string apiName)
 {
     APIUtilities.setApiUrl(apiName);
 }
        /// <summary>
        /// Parses and runs ApiTest XElement
        /// </summary>
        /// <param name="suite"></param>
        /// <param name="apiTestElement"></param>
        /// <param name="XmlNamespace"></param>
        /// <param name="resultsListBox"></param>
        /// <returns></returns>
        public async Task RunApiTest(String suite, XElement apiTestElement, XNamespace XmlNamespace, System.Windows.Forms.ListBox resultsListBox)
        {
            // Increment counter for Total number of tests (this will be shown when batch is complete)
            TotalRunTests += 1;

            // Retrieve XML Attributes for ApiTest XElement
            string     apiTestId  = apiTestElement.Attributes("id").FirstOrDefault().Value;
            string     uri        = apiTestElement.Attributes("Uri").FirstOrDefault().Value;
            HttpMethod httpMethod = APIUtilities.GetHttpMethodFromText(apiTestElement.Attributes("HttpMethod").FirstOrDefault().Value);

            bool       includeDateInHttpHeader = true;
            XAttribute includeDateInHeader     = apiTestElement.Attributes("IncludeDateInHeader").FirstOrDefault();

            if (includeDateInHeader != null)
            {
                includeDateInHttpHeader = bool.Parse(includeDateInHeader.Value);
            }


            // Set Base URI in ClinetState object from querying XElement
            ClientState.BaseURI = RetrieveBaseURI(XmlNamespace, this.xmlConfig, apiTestElement.Attributes("BaseUriId").FirstOrDefault().Value);

            // Retrieve Request Content before request is submitted to API
            XElement requestContent = apiTestElement.Elements(XmlNamespace + "RequestContent").FirstOrDefault();

            string request          = string.Empty;
            string requestFormatted = string.Empty;

            if (requestContent != null)
            {
                request          = requestContent.Value;
                requestFormatted = new Regex(ClientState.RemoveNewLineRegEx).Replace(request, ""); // Removing New Lines before sent to API
            }

            // Create API Test Case Object
            APIEndpointExecuter apiTestRun = new APIEndpointExecuter(string.Format("{0}{1}", ClientState.BaseURI, uri), httpMethod);

            // Retrieve Expected Response
            string expectedResponse          = apiTestElement.Elements(XmlNamespace + "ExpectedResponse").FirstOrDefault().Value;
            string expectedResponseFormatted = new Regex(ClientState.RemoveNewLineAndWhiteSpaceRegEx).Replace(expectedResponse, ""); // remove new lines and whitespace before comparing with actual response

            HttpStatusCode expectedStatusCode = ((HttpStatusCode)(Convert.ToInt32(apiTestElement.Elements(XmlNamespace + "ExpectedStatusCode").FirstOrDefault().Value)));

            DateTime requestTime = DateTime.Now;

            APIEndpointExecuterResult apiTestRunResult = await apiTestRun.Run(new Regex(ClientState.RemoveNewLineRegEx).Replace(request, ""), includeDateInHttpHeader);

            string actualResponseFormatted = new Regex(ClientState.RemoveNewLineAndWhiteSpaceRegEx).Replace(apiTestRunResult.ResponseContent, "");             // remove new lines and whitespace before comparing with expected response

            DateTime responseTime = DateTime.Now;

            HttpStatusCode actualStatusCode = apiTestRunResult.Response.StatusCode;

            bool testPassed = (actualStatusCode.Equals(expectedStatusCode) && actualResponseFormatted.Equals(expectedResponseFormatted));

            if (testPassed)
            {
                TotalPassed += 1;
            }
            else
            {
                TotalFailed += 1;
                this.FailedTestLists.Add(string.Format("Test: {0} (Suite: {1})", apiTestId, suite));
            }

            resultsListBox.Items.Add(new ListBoxItem(testPassed ? Color.Green : Color.Red, String.Format("   ApiTest: {0} {1}", apiTestId, testPassed ? "PASSED" : "FAILED")));
            resultsListBox.SelectedIndex = resultsListBox.Items.Count - 1;

            // format request and expected response for log
            string requestFormattedWithNewLines          = new Regex(ClientState.RemoveNewLineRegEx).Replace(request, Environment.NewLine);          // add new lines for readability purposes for log
            string expectedResponseFormattedWithNewLines = new Regex(ClientState.RemoveNewLineRegEx).Replace(expectedResponse, Environment.NewLine); // add new lines for readability purposes for log

            // Update Log
            UpdateLog(suite, apiTestId, testPassed, apiTestRun, apiTestRunResult, requestFormattedWithNewLines, expectedStatusCode, expectedResponseFormattedWithNewLines, apiTestRunResult.ResponseContent, requestTime, responseTime);
        }