コード例 #1
0
        public static OpenAPICases[] RequestToResponse(OpenAPICases[] Cases, string appKey, string secret, bool flagUpdate = false)
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            byte[] ciphertext;

            string requestBody = "";

            for (int i = 0; i < Cases.Length; i++)
            {
                requestBody = Cases[i].requestBody;

                string jsonFormatRequestBody             = ConvertJson.String2Json(requestBody);
                string jsonAndLocalTimeFormatRequestBody = EnergyViewDataDtoConvertor.GetEnergyViewDataWithLocalTime(jsonFormatRequestBody);
                Cases[i].formatRequestBody = jsonAndLocalTimeFormatRequestBody;

                WebRequest request = HttpWebRequest.Create(Cases[i].url);
                request.ContentType = "application/json";
                request.Headers.Add("X-Auth-AppKey", appKey);
                request.Method = "POST";
                ciphertext     = md5.ComputeHash(UnicodeEncoding.UTF8.GetBytes(appKey + requestBody + secret));
                string s = BitConverter.ToString(ciphertext).Replace("-", string.Empty);
                request.Headers.Add("X-Auth-Fig", s);

                var requestBodyBytes = Encoding.UTF8.GetBytes(requestBody);
                using (var requestBodyStream = request.GetRequestStream())
                {
                    requestBodyStream.Write(requestBodyBytes, 0, requestBodyBytes.Length);
                }
                using (var response = request.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        using (var sr = new StreamReader(responseStream, Encoding.UTF8))
                        {
                            string originalResponseBody               = sr.ReadToEnd().ToString();
                            string jsonFormatResponseBody             = ConvertJson.String2Json(originalResponseBody);
                            string jsonAndLocalTimeFormatResponseBody = EnergyViewDataDtoConvertor.GetEnergyViewDataWithLocalTime(jsonFormatResponseBody);

                            //response body save to expectedResponseBody when update cases
                            if (true == flagUpdate)
                            {
                                Cases[i].expectedResponseBody       = originalResponseBody;
                                Cases[i].formatExpectedResponseBody = jsonAndLocalTimeFormatResponseBody;
                                Cases[i].result = "NA";
                            }
                            else
                            {
                                Cases[i].actualResponseBody       = originalResponseBody;
                                Cases[i].formatActualResponseBody = jsonAndLocalTimeFormatResponseBody;
                                Cases[i].result = "NA";
                            }
                        }
                    }
                }
            }
            return(Cases);
        }
コード例 #2
0
        public static OpenAPICases[] CompareCases(OpenAPICases[] Cases)
        {
            string expectedStr;
            string actualStr;

            string tmpExpectedStr;
            string tmpActualStr;

            CompareReport report = new CompareReport();
            bool          isOutResult;

            for (int i = 0; i < Cases.Length; i++)
            {
                expectedStr = Cases[i].expectedResponseBody;
                actualStr   = Cases[i].actualResponseBody;

                if (Cases[i].url.Contains("Aggregate") || Cases[i].url.Contains("Ranking") || Cases[i].requestBody.Contains("RankingType"))
                {
                    tmpExpectedStr = ConvertJson.String2Json(expectedStr);
                    tmpActualStr   = ConvertJson.String2Json(actualStr);

                    expectedStr = FilterStrings(tmpExpectedStr);
                    actualStr   = FilterStrings(tmpActualStr);
                }

                report = CompareEnergyUseResponseBody(expectedStr, actualStr, out isOutResult);

                if (true == isOutResult)
                {
                    Cases[i].result = "Pass:"******"Fail:" + report.errorMessage;
                }
                Cases[i].resultReport = report.detailedInfo;
            }
            return(Cases);
        }