Exemplo n.º 1
0
        private static string CompareReports(string sFile, string dFile, CompareReport reports)
        {
            DateTime dt = DateTime.Now;

            StringBuilder finalReport = new System.Text.StringBuilder();

            finalReport.Append(titleString);
            finalReport.Append(reportSignals);
            foreach (object o in reports.AddDestinationStrings)
            {
                finalReport.Append(o.ToString());
            }

            foreach (object o in reports.DeleteSourceStrings)
            {
                finalReport.Append(o.ToString());
            }

            foreach (object o in reports.ReplaceStrings)
            {
                finalReport.Append(o.ToString());
            }

            return(finalReport.ToString());
        }
Exemplo n.º 2
0
        private static CompareReport CompareMatchedResponseBody(EnergyViewDataBody[] expectedData, EnergyViewDataBody[] actualData)
        {
            CompareReport report = new CompareReport();
            StringBuilder st     = new StringBuilder();

            for (int i = 0; i < expectedData.Length; i++)
            {
                string headerInfo = "Header" + i.ToString() + "\n";

                if (!String.Equals(expectedData[i].EnergyViewDatas, actualData[i].EnergyViewDatas))
                {
                    st.Append(headerInfo + "期望值:" + expectedData[i].EnergyViewDatas + "\n");
                    st.Append("实际值:" + actualData[i].EnergyViewDatas + "\n");
                }
            }

            report.errorMessage = "The actual response body not euqal to expected response body, and both the body have the same blocks";
            report.detailedInfo = st.ToString();

            return(report);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public static string CompareTextFiles(string sFile, string dFile)
        {
            DiffList_TextFile sLF = null;
            DiffList_TextFile dLF = null;
            bool   IsEqual        = true;
            string reportStr      = null;

            try
            {
                sLF = new DiffList_TextFile(sFile);
                dLF = new DiffList_TextFile(dFile);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            try
            {
                double     time = 0;
                DiffEngine de   = new DiffEngine();
                time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.FastImperfect);

                ArrayList     rep        = de.DiffReport();
                CompareReport theReports = Results(sLF, dLF, rep, time, out IsEqual);

                if (!IsEqual)
                {
                    reportStr = CompareReports(sFile, dFile, theReports);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(reportStr);
        }
Exemplo n.º 5
0
        public static CompareReport CompareEnergyUseResponseBody(string expectedResponseBodyStr, string actualResponseBodyStr, out bool outResult)
        {
            string expectedResponseBody;
            string actualResponseBody;

            expectedResponseBody = expectedResponseBodyStr;
            actualResponseBody   = actualResponseBodyStr;

            CompareReport report = new CompareReport();

            #region Confirm that if respons body is empty

            CompareStringResult resultEmpty = IsResponseBodyEqual(expectedResponseBodyStr, actualResponseBodyStr);

            switch (resultEmpty)
            {
            case CompareStringResult.acEmpty:
                outResult           = false;
                report.errorMessage = "Actual Response body is empty, but expected not\n";
                return(report);

            case CompareStringResult.exEmpty:
                outResult           = false;
                report.errorMessage = "Expected Response body is empty, but actual not\n";
                return(report);

            case CompareStringResult.equal:
                outResult           = true;
                report.errorMessage = "Expected Response body is equal to actual response body.\n";
                return(report);

            case CompareStringResult.bothEmpty:
                outResult           = true;
                report.errorMessage = "Expected Response body and actual response bady are both empty.\n";
                return(report);

            default:
                break;
            }

            #endregion

            #region confirm that if response body return error code message

            //format6--当期望值或实际值是errorcode
            CompareStringErrorResult resultError = IsResponseBodyErrorMsgEqual(expectedResponseBodyStr, actualResponseBodyStr);

            switch (resultError)
            {
            case CompareStringErrorResult.acError:
                outResult           = false;
                report.errorMessage = "Actual Response body return error message, but expected not\n";
                return(report);

            case CompareStringErrorResult.exError:
                outResult           = false;
                report.errorMessage = "Expected Response body return error message, but actual not\n";
                return(report);

            case CompareStringErrorResult.notEqual:
                outResult           = false;
                report.errorMessage = "Expected and actual Response body return error message, but not equal\n";
                return(report);

            case CompareStringErrorResult.equal:
                outResult = true;
                return(report);

            default:
                break;
            }

            #endregion

            EnergyViewDataBody[] expectedData = EnergyViewDataDtoConvertor.GetEnergyViewDataDtoGroups(expectedResponseBody);
            EnergyViewDataBody[] actualData   = EnergyViewDataDtoConvertor.GetEnergyViewDataDtoGroups(actualResponseBody);

            #region confirm if there is no data but structure only
            //format5-完全没有TargetEnergyData内容的情况,即response只是:TargetEnergyData[]
            if (expectedData == null && actualData == null)
            {
                outResult = String.Equals(expectedData, actualData);

                if (!outResult)
                {
                    report.errorMessage = "Expected and actual have no data, but the structure are different as [] and TargetEnergyData[]";
                }

                return(report);
            }
            else if (!(expectedData == null) && actualData == null)
            {
                outResult           = false;
                report.errorMessage = "Expected response body have return value, but actual not, only have TargetEnergyData[] or []";
                return(report);
            }
            else if (expectedData == null && !(actualData == null))
            {
                outResult           = false;
                report.errorMessage = "Actual response body have return value, but expected not, only have TargetEnergyData[] or []";
                return(report);
            }

            #endregion

            #region confirm if the body response target number not equal
            //format2--当helader即target信息在实际结果存在,但期望不存在,即多返回了block,此时不需要比较里面的energydata
            //format3--当helader即target信息在实际结果中没有时,即少返回了block,此时不需要进一步比较里面的energydata
            if (expectedData.Length < actualData.Length)
            {
                outResult           = false;
                report.errorMessage = "actual response body block is more than Expected response body";
                report.detailedInfo = CompareBodyHelper.CompareResponseBodyByFiles(expectedResponseBody, actualResponseBody);
                return(report);
            }
            else if (expectedData.Length > actualData.Length)
            {
                outResult           = false;
                report.errorMessage = "actual response body block is less than Expected response body";
                report.detailedInfo = CompareBodyHelper.CompareResponseBodyByFiles(expectedResponseBody, actualResponseBody);
                return(report);
            }

            #endregion

            #region confirm if the body num is same but not equal
            //format1--当helader即target信息和期望的target一致时,此时要去验证内部energydata数据
            //format7:pie chart
            if (string.Equals(expectedResponseBody, actualResponseBody))
            {
                outResult = true;
                return(report);
            }
            else
            {
                outResult = false;
                report    = CompareMatchedResponseBody(expectedData, actualData);
                return(report);
            }
            #endregion
        }
Exemplo n.º 6
0
        private static CompareReport Results(DiffList_TextFile source, DiffList_TextFile destination, ArrayList DiffLines, double time, string failedFileName, out bool result)
        {
            int           cnt = 1;
            int           i;
            bool          tmpResult  = true;
            string        addStr     = "+                ";
            string        deleteStr  = "-                ";
            CompareReport tmpReports = new CompareReport();

            tmpReports.AddDestinationStrings = new ArrayList();
            tmpReports.DeleteSourceStrings   = new ArrayList();
            tmpReports.ReplaceStrings        = new ArrayList();

            StreamWriter sw = new StreamWriter(failedFileName);

            sw.WriteLine(titleString);
            sw.WriteLine(reportSignals);

            foreach (DiffResultSpan drs in DiffLines)
            {
                switch (drs.Status)
                {
                case DiffResultSpanStatus.DeleteSource:
                    tmpResult = false;
                    tmpReports.DeleteSourceStrings.Add(deleteString + cnt.ToString() + reportSignals);
                    for (i = 0; i < drs.Length; i++)
                    {
                        tmpReports.DeleteSourceStrings.Add(deleteStr + ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n");
                        cnt++;
                    }
                    foreach (object o in tmpReports.DeleteSourceStrings)
                    {
                        sw.WriteLine(o.ToString());
                    }
                    break;

                case DiffResultSpanStatus.NoChange:
                    for (i = 0; i < drs.Length; i++)
                    {
                        cnt++;
                    }
                    break;

                case DiffResultSpanStatus.AddDestination:
                    tmpResult = false;
                    tmpReports.AddDestinationStrings.Add(addString + cnt.ToString() + reportSignals);
                    for (i = 0; i < drs.Length; i++)
                    {
                        tmpReports.AddDestinationStrings.Add(addStr + ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n");
                        cnt++;
                    }
                    foreach (object o in tmpReports.AddDestinationStrings)
                    {
                        sw.WriteLine(o.ToString());
                    }
                    break;

                case DiffResultSpanStatus.Replace:
                    tmpResult = false;
                    tmpReports.ReplaceStrings.Add(replaceString + cnt.ToString() + reportSignals);
                    for (i = 0; i < drs.Length; i++)
                    {
                        tmpReports.ReplaceStrings.Add(deleteStr + ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line + "\n");
                        tmpReports.ReplaceStrings.Add(addStr + ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line + "\n");
                        cnt++;
                    }
                    foreach (object o in tmpReports.ReplaceStrings)
                    {
                        sw.WriteLine(o.ToString());
                    }
                    break;
                }
            }

            sw.Close();
            sw.Dispose();

            result = tmpResult;

            return(tmpReports);
        }
Exemplo n.º 7
0
        private static void CompareReports(string sFile, string dFile, string failedFileName, CompareReport reports, string path)
        {
            DateTime dt = DateTime.Now;

            string actualFileName = Path.Combine(path, failedFileName);

            StreamWriter sw = new StreamWriter(actualFileName);

            sw.WriteLine(titleString);
            foreach (object o in reports.AddDestinationStrings)
            {
                sw.WriteLine(o.ToString());
            }

            foreach (object o in reports.DeleteSourceStrings)
            {
                sw.WriteLine(o.ToString());
            }

            foreach (object o in reports.ReplaceStrings)
            {
                sw.WriteLine(o.ToString());
            }

            sw.Close();
            sw.Dispose();
        }