Esempio n. 1
0
        private static AssemblyModel GetAssemblyModel(
            string assemblyFileName,
            string etlFileName,
            string sessionName,
            IEnumerable <PerformanceTestMessage> performanceTestMessages)
        {
            using (var reader = GetEtwReader(etlFileName, sessionName, performanceTestMessages))
            {
                var assemblyModel = new AssemblyModel
                {
                    Name       = Path.GetFileName(assemblyFileName),
                    Collection = new List <TestModel>()
                };

                foreach (var test in performanceTestMessages)
                {
                    var metrics = new List <MetricModel>();
                    foreach (var metric in test.Metrics)
                    {
                        metrics.Add(new MetricModel
                        {
                            DisplayName = metric.DisplayName,
                            Name        = metric.Id,
                            Unit        = metric.Unit,
                        });
                    }

                    var testModel = new TestModel
                    {
                        Name        = test.TestCase.DisplayName,
                        Method      = test.TestCase.TestMethod.Method.Name,
                        ClassName   = test.TestCase.TestMethod.TestClass.Class.Name,
                        Performance = new PerformanceModel {
                            Metrics = metrics, IterationModels = new List <IterationModel>()
                        },
                    };

                    var values = reader.GetValues(testModel.Name);
                    if (values == null)
                    {
                        continue; // If the test was not run, then it will not be found on the trace (e.g. user only ran a subset of all tests).
                    }
                    foreach (var dict in values)
                    {
                        var iterationModel = new IterationModel {
                            Iteration = new Dictionary <string, double>()
                        };
                        foreach (var kvp in dict)
                        {
                            iterationModel.Iteration.Add(kvp.Key, kvp.Value);
                        }
                        if (iterationModel.Iteration.Count > 0)
                        {
                            testModel.Performance.IterationModels.Add(iterationModel);
                        }
                    }

                    assemblyModel.Collection.Add(testModel);
                }

                return(assemblyModel);
            }
        }