internal static TestCaseResult GenerateTestCase602Result(TestCase602 testCase602)
        {
            List <IMetric> metrics = new List <IMetric>();

            if (testCase602.Results.Count() == 0)
            {
                DoubleMetric _errorRate2 = new DoubleMetric(MetricName.errorRate,
                                                            100,
                                                            "%");
                log.DebugFormat("Error Rate : {0}{1}", _errorRate2.Value, _errorRate2.Uom);
                metrics.Add(_errorRate2);
                var _tcr2 = new TestCaseResult(testCase602.Id, metrics, testCase602.StartTime, testCase602.EndTime);
                _tcr2.ClassName = testCase602.GetType().ToString();
                return(_tcr2);
            }

            Dictionary <string, double>          totalResults           = new Dictionary <string, double>();
            Dictionary <string, double>          wrongResultsCounts     = new Dictionary <string, double>();
            Dictionary <string, double>          validatedResultsCounts = new Dictionary <string, double>();
            Dictionary <string, double>          readResultsCounts      = new Dictionary <string, double>();
            Dictionary <string, long>            avaAvgLatencies        = new Dictionary <string, long>();
            Dictionary <string, long>            avaMaxLatencies        = new Dictionary <string, long>();
            Dictionary <string, ExceptionMetric> exceptions             = new Dictionary <string, ExceptionMetric>();

            long errors = 0;

            foreach (var testUnit in testCase602.Results)
            {
                string          dataCollectionDivision = testUnit.Metrics.Where(m => m.Name == MetricName.dataCollectionDivision).Cast <StringMetric>().Select(m => m.Value).FirstOrDefault();
                long            totalResult            = testUnit.Metrics.Where(m => m.Name == MetricName.maxTotalResults).Cast <LongMetric>().Select(m => m.Value).FirstOrDefault();
                long            readResultsCount       = testUnit.Metrics.Where(m => m.Name == MetricName.totalReadResults).Cast <LongMetric>().Select(m => m.Value).FirstOrDefault();
                long            validatedResultsCount  = testUnit.Metrics.Where(m => m.Name == MetricName.totalValidatedResults).Cast <LongMetric>().Select(m => m.Value).FirstOrDefault();
                long            wrongResultsCount      = testUnit.Metrics.Where(m => m.Name == MetricName.wrongResultsCount).Cast <LongMetric>().Select(m => m.Value).FirstOrDefault();
                ExceptionMetric exception = (ExceptionMetric)testUnit.Metrics.Where(m => m.Name == MetricName.exception).FirstOrDefault();

                if (exception != null)
                {
                    errors++;
                }

                if (totalResults.ContainsKey(dataCollectionDivision))
                {
                    log.WarnFormat("Data collection with key '{0} is duplicated, please check the config");
                    continue;
                }
                totalResults.Add(dataCollectionDivision, totalResult);
                validatedResultsCounts.Add(dataCollectionDivision, validatedResultsCount);
                readResultsCounts.Add(dataCollectionDivision, readResultsCount);
                wrongResultsCounts.Add(dataCollectionDivision, wrongResultsCount);
                exceptions.Add(dataCollectionDivision, exception);

                var avaAvgLatency = testUnit.Metrics.FirstOrDefault(m => m.Name == MetricName.avgDataAvailabilityLatency);
                var avaMaxLatency = testUnit.Metrics.FirstOrDefault(m => m.Name == MetricName.maxDataAvailabilityLatency);

                if (avaAvgLatency != null)
                {
                    avaAvgLatencies.Add(dataCollectionDivision, ((LongMetric)avaAvgLatency).Value);
                }
                else
                {
                    avaAvgLatencies.Add(dataCollectionDivision, -1);
                }
                if (avaMaxLatency != null)
                {
                    avaMaxLatencies.Add(dataCollectionDivision, ((LongMetric)avaMaxLatency).Value);
                }
                else
                {
                    avaMaxLatencies.Add(dataCollectionDivision, -1);
                }
            }

            DoubleMetric _errorRate = new DoubleMetric(MetricName.errorRate,
                                                       (errors / testCase602.Results.Count()) * 100,
                                                       "%");

            log.DebugFormat("Error Rate : {0}{1}", _errorRate.Value, _errorRate.Uom);
            metrics.Add(_errorRate);

            StringArrayMetric _dataCollectionDivisions = new StringArrayMetric(MetricName.dataCollectionDivision,
                                                                               totalResults.Keys.ToArray(),
                                                                               "string");

            log.DebugFormat("Data Collection Division : {0}", string.Join(",", _dataCollectionDivisions.Value));
            metrics.Add(_dataCollectionDivisions);

            StringArrayMetric _exceptions = new StringArrayMetric(MetricName.exception,
                                                                  exceptions.Values.Select(e => e == null ? null : e.Exception.Message).ToArray(),
                                                                  "string");

            log.DebugFormat("Exceptions : {0}", string.Join(",", _exceptions.Value));
            metrics.Add(_exceptions);

            DoubleArrayMetric _coverages = new DoubleArrayMetric(MetricName.maxTotalResults,
                                                                 totalResults.Values.ToArray(),
                                                                 "#");

            log.DebugFormat("Total Results : {0}", string.Join(",", _coverages.Value));
            metrics.Add(_coverages);

            DoubleArrayMetric _totalRead = new DoubleArrayMetric(MetricName.totalReadResults,
                                                                 readResultsCounts.Values.ToArray(),
                                                                 "#");

            log.DebugFormat("Read : {0}", string.Join(",", _totalRead.Value));
            metrics.Add(_totalRead);

            DoubleArrayMetric _wrong = new DoubleArrayMetric(MetricName.totalWrongResults,
                                                             wrongResultsCounts.Values.ToArray(),
                                                             "#");

            log.DebugFormat("Wrong : {0}", string.Join(",", _wrong.Value));
            metrics.Add(_wrong);

            DoubleArrayMetric _validated = new DoubleArrayMetric(MetricName.totalValidatedResults,
                                                                 validatedResultsCounts.Values.ToArray(),
                                                                 "#");

            log.DebugFormat("Validated : {0}", string.Join(",", _validated.Value));
            metrics.Add(_validated);

            LongArrayMetric _avaAvgLatencies = new LongArrayMetric(MetricName.avgDataAvailabilityLatency,
                                                                   avaAvgLatencies.Values.ToArray(),
                                                                   "sec");

            log.DebugFormat("Availability Average Latencies : {0}", string.Join(",", Array.ConvertAll(_avaAvgLatencies.Value, t => TimeSpan.FromSeconds(t).ToString())));
            metrics.Add(_avaAvgLatencies);

            LongArrayMetric _avaMaxLatencies = new LongArrayMetric(MetricName.maxDataAvailabilityLatency,
                                                                   avaMaxLatencies.Values.ToArray(),
                                                                   "sec");

            log.DebugFormat("Availability Max Latencies : {0}", string.Join(",", Array.ConvertAll(_avaMaxLatencies.Value, t => TimeSpan.FromSeconds(t).ToString())));
            metrics.Add(_avaMaxLatencies);



            var _tcr = new TestCaseResult(testCase602.Id, metrics, testCase602.StartTime, testCase602.EndTime);

            _tcr.ClassName = testCase602.GetType().ToString();
            return(_tcr);
        }
        internal static TestCaseResult GenerateTestCase601Result(TestCase601 testCase601)
        {
            List <IMetric> metrics = new List <IMetric>();

            if (testCase601.Results.Count() == 0)
            {
                DoubleMetric _errorRate2 = new DoubleMetric(MetricName.errorRate,
                                                            100,
                                                            "%");
                log.DebugFormat("Error Rate : {0}{1}", _errorRate2.Value, _errorRate2.Uom);
                metrics.Add(_errorRate2);
                var _tcr2 = new TestCaseResult(testCase601.Id, metrics, testCase601.StartTime, testCase601.EndTime);
                _tcr2.ClassName = testCase601.GetType().ToString();
                return(_tcr2);
            }

            Dictionary <string, double> totalResults           = new Dictionary <string, double>();
            Dictionary <string, double> wrongResultsCounts     = new Dictionary <string, double>();
            Dictionary <string, double> validatedResultsCounts = new Dictionary <string, double>();
            Dictionary <string, double> readResultsCounts      = new Dictionary <string, double>();
            Dictionary <string, long>   opsAvgLatencies        = new Dictionary <string, long>();
            Dictionary <string, long>   opsMaxLatencies        = new Dictionary <string, long>();
            // Dictionary<string, ExceptionMetric> exceptions = new Dictionary<string, ExceptionMetric>();

            double errors = 0;

            foreach (var testUnit in testCase601.Results)
            {
                string dataCollectionDivision = testUnit.Metrics.Where(m => m.Name == MetricName.dataCollectionDivision).Cast <StringMetric>().Select(m => m.Value).FirstOrDefault();

                long            totalResult           = testUnit.Metrics.Where(m => m.Name == MetricName.maxTotalResults).Cast <LongMetric>().Select(m => m.Value).FirstOrDefault();
                long            readResultsCount      = testUnit.Metrics.Where(m => m.Name == MetricName.totalReadResults).Cast <LongMetric>().Select(m => m.Value).FirstOrDefault();
                long            validatedResultsCount = testUnit.Metrics.Where(m => m.Name == MetricName.totalValidatedResults).Cast <LongMetric>().Select(m => m.Value).FirstOrDefault();
                long            wrongResultsCount     = testUnit.Metrics.Where(m => m.Name == MetricName.wrongResultsCount).Cast <LongMetric>().Select(m => m.Value).FirstOrDefault();
                ExceptionMetric exception             = (ExceptionMetric)testUnit.Metrics.Where(m => m.Name == MetricName.exception).FirstOrDefault();

                if (exception != null)
                {
                    errors++;
                }

                totalResults.Add(dataCollectionDivision, totalResult);
                validatedResultsCounts.Add(dataCollectionDivision, validatedResultsCount);
                readResultsCounts.Add(dataCollectionDivision, readResultsCount);
                wrongResultsCounts.Add(dataCollectionDivision, wrongResultsCount);
                // exceptions.Add(dataCollectionDivision, exception);

                try
                {
                    opsAvgLatencies.Add(dataCollectionDivision, ((LongMetric)testUnit.Metrics.FirstOrDefault(m => m.Name == MetricName.avgDataOperationalLatency)).Value);
                    opsMaxLatencies.Add(dataCollectionDivision, ((LongMetric)testUnit.Metrics.FirstOrDefault(m => m.Name == MetricName.maxDataOperationalLatency)).Value);
                }
                catch
                {
                    opsAvgLatencies.Add(dataCollectionDivision, -1);
                    opsMaxLatencies.Add(dataCollectionDivision, -1);
                }
            }

            DoubleMetric _errorRate = new DoubleMetric(MetricName.errorRate,
                                                       (errors / testCase601.Results.Count()) * 100,
                                                       "%");

            log.DebugFormat("Error Rate : {0}{1}", _errorRate.Value, _errorRate.Uom);
            metrics.Add(_errorRate);

            StringArrayMetric _dataCollectionDivisions = new StringArrayMetric(MetricName.dataCollectionDivision,
                                                                               totalResults.Keys.ToArray(),
                                                                               "string");

            log.DebugFormat("Data Collection Division : {0}", string.Join(",", _dataCollectionDivisions.Value));
            metrics.Add(_dataCollectionDivisions);

            // StringArrayMetric _exceptions = new StringArrayMetric(MetricName.exception,
            //         exceptions.Values.Select(e => e == null ? null : e.Exception.Message).ToArray(),
            //          "string");
            // log.DebugFormat("Exceptions : {0}", string.Join(",", _exceptions.Value));
            // metrics.Add(_exceptions);

            DoubleArrayMetric _coverages = new DoubleArrayMetric(MetricName.maxTotalResults,
                                                                 totalResults.Values.ToArray(),
                                                                 "#");

            log.DebugFormat("Total Results : {0}", string.Join(",", _coverages.Value));
            metrics.Add(_coverages);

            DoubleArrayMetric _totalRead = new DoubleArrayMetric(MetricName.totalReadResults,
                                                                 readResultsCounts.Values.ToArray(),
                                                                 "#");

            log.DebugFormat("Read : {0}", string.Join(",", _totalRead.Value));
            metrics.Add(_totalRead);

            DoubleArrayMetric _wrong = new DoubleArrayMetric(MetricName.totalWrongResults,
                                                             wrongResultsCounts.Values.ToArray(),
                                                             "#");

            log.DebugFormat("Wrong : {0}", string.Join(",", _wrong.Value));
            metrics.Add(_wrong);

            DoubleArrayMetric _validated = new DoubleArrayMetric(MetricName.totalValidatedResults,
                                                                 validatedResultsCounts.Values.ToArray(),
                                                                 "#");

            log.DebugFormat("Validated : {0}", string.Join(",", _validated.Value));
            metrics.Add(_validated);

            LongArrayMetric _opsAvgLatencies = new LongArrayMetric(MetricName.avgDataOperationalLatency,
                                                                   opsAvgLatencies.Values.ToArray(),
                                                                   "sec");

            log.DebugFormat("Operational Average Latencies : {0}", string.Join(",", Array.ConvertAll(_opsAvgLatencies.Value, t => TimeSpan.FromSeconds(t).ToString())));
            metrics.Add(_opsAvgLatencies);

            LongArrayMetric _opsMaxLatencies = new LongArrayMetric(MetricName.maxDataOperationalLatency,
                                                                   opsMaxLatencies.Values.ToArray(),
                                                                   "sec");

            log.DebugFormat("Operational Max Latencies : {0}", string.Join(",", Array.ConvertAll(_opsMaxLatencies.Value, t => TimeSpan.FromSeconds(t).ToString())));
            metrics.Add(_opsMaxLatencies);

            var _tcr = new TestCaseResult(testCase601.Id, metrics, testCase601.StartTime, testCase601.EndTime);

            _tcr.ClassName = testCase601.GetType().ToString();
            return(_tcr);
        }