Beispiel #1
0
        private SolutionResult GenerateAnalysisResult()
        {
            _portSolutionResult.AddSolutionResult(_solutionAnalysisResult);
            if (!string.IsNullOrEmpty(_solutionPath))
            {
                PortSolutionResultReportGenerator reportGenerator = new PortSolutionResultReportGenerator(_context, _portSolutionResult, _projectTypeFeatureResults);
                reportGenerator.GenerateAnalysisReport();

                LogHelper.LogInformation("Generating Post-Analysis Report");
                LogHelper.LogError($"{Constants.MetricsTag}: {reportGenerator.AnalyzeSolutionResultJsonReport}");
            }
            return(_solutionAnalysisResult);
        }
        public void Setup()
        {
            Directory.CreateDirectory(_tempDir);
            var solutionPath   = $"{_tempDir}/solution.sln";
            var projectPath1   = $"{_tempDir}/project1.csproj";
            var projectPath2   = $"{_tempDir}/project2.csproj";
            var projectResult1 = new ProjectWorkspace(projectPath1)
            {
                ProjectGuid = "1234-5678"
            };
            var projectResult2 = new ProjectWorkspace(projectPath2)
            {
                ProjectGuid = "ABCD-EFGH"
            };
            var analyzerResult1 = new AnalyzerResult
            {
                ProjectResult = projectResult1
            };
            var analyzerResult2 = new AnalyzerResult
            {
                ProjectResult = projectResult2
            };
            var analyzerResults = new List <AnalyzerResult>
            {
                analyzerResult1,
                analyzerResult2
            };
            var context = new MetricsContext(solutionPath, analyzerResults);

            var buildErrors = new Dictionary <string, Dictionary <string, int> >
            {
                { projectPath1, new Dictionary <string, int>
                  {
                      { "CS0000: BuildError1", 100 },
                      { "BuildError2", 200 }
                  } },
                { "ProjectFilePath2", new Dictionary <string, int>
                  {
                      { "BuildError3", 300 },
                      { "BuildError4", 400 }
                  } }
            };
            var references = new HashSet <string>
            {
                "System.Web",
                "System.Web.Mvc"
            };
            var downloadedFiles = new HashSet <string>
            {
                "project.all.json"
            };
            var projectResults = new BlockingCollection <CTA.Rules.Models.ProjectResult>
            {
                new CTA.Rules.Models.ProjectResult
                {
                    ProjectFile    = projectPath1,
                    TargetVersions = new List <string>()
                    {
                        Constants.DefaultCoreVersion
                    },
                    UpgradePackages = new List <PackageAction>()
                    {
                        new PackageAction()
                        {
                            Name = "Newtonsoft.Json", OriginalVersion = "9.0.0", Version = "12.0.0"
                        }
                    },
                    MissingMetaReferences = new List <string> {
                        @"C://reference1.dll", @"C://reference2.dll"
                    },
                    ProjectActions = new ProjectActions()
                    {
                        FileActions = new BlockingCollection <FileActions>()
                        {
                            new FileActions()
                            {
                                FilePath         = "FilePath1",
                                AttributeActions = new HashSet <AttributeAction>()
                                {
                                    new AttributeAction()
                                    {
                                        Key   = "SampleKey1",
                                        Type  = "GA1 Type",
                                        Name  = "GA1 Name",
                                        Value = "GA1 Value",
                                    },
                                    new AttributeAction()
                                    {
                                        Key   = "SampleKey2",
                                        Type  = "GA2 Type",
                                        Name  = "GA2 Name",
                                        Value = "GA2 Value",
                                    }
                                }
                            }
                        }
                    },
                    ExecutedActions = new Dictionary <string, List <GenericActionExecution> >
                    {
                        { "FilePath1", new List <GenericActionExecution>
                          {
                              new GenericActionExecution
                              {
                                  Type              = "GA1 Type",
                                  Name              = "GA1 Name",
                                  Value             = "GA1 Value",
                                  TimesRun          = 2,
                                  InvalidExecutions = 1
                              },
                              new GenericActionExecution
                              {
                                  Type              = "GA2 Type",
                                  Name              = "GA2 Name",
                                  Value             = "GA2 Value",
                                  TimesRun          = 3,
                                  InvalidExecutions = 0
                              }
                          } }
                    }
                }
            };
            var portSolutionResult = new PortSolutionResult(solutionPath)
            {
                BuildErrors     = buildErrors,
                References      = references,
                DownloadedFiles = downloadedFiles,
                ProjectResults  = projectResults
            };

            var featureDetectionResults = new Dictionary <string, FeatureDetectionResult>
            {
                { projectPath1, new FeatureDetectionResult
                  {
                      FeatureStatus =
                      {
                          { "Feature 1",  true  },
                          { "Feature 1a", true  },
                          { "Feature 1b", false },
                      },
                      ProjectPath = projectPath1
                  } },
                { projectPath2, new FeatureDetectionResult
                  {
                      FeatureStatus =
                      {
                          { "Feature 2",  false },
                          { "Feature 2a", false },
                          { "Feature 2b", false },
                      },
                      ProjectPath = projectPath2
                  } },
            };

            ReportGenerator = new PortSolutionResultReportGenerator(context, portSolutionResult);
            ReportGenerator.GenerateAnalysisReport();
            ReportGenerator.GenerateAndExportReports();

            ReportGeneratorWithFeatureDetection = new PortSolutionResultReportGenerator(context, portSolutionResult, featureDetectionResults);
            ReportGeneratorWithFeatureDetection.GenerateAnalysisReport();
        }